• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Http header in java project

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to get the header value (e.g., id) from the http request in WAR project (JAX-RS project, lets call it as WAR1) and then refer or use it in another java project(so that i can use it for processing some business logic or querying database) that can be copied or deployed as jar file to the WAR1 project.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JAX-RS can inject an javax.ws.rs.core.HttpHeaders object via the @Context annotation; that provides access to the HTTP headers.

I don't understand the 2nd part of the question, but once you have the value you can use it any way you see fit.
 
Vani Kumar
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, with JAX-RS i can inject an javax.ws.rs.core.HttpHeaders object via the @Context annotation in Web application. Once i get it, I need to use the same value in different Java project (again the same java project will be deployed as JAR back to the web application).
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's the part I don't understand. On a server there are no "projects", only web apps. If the code is running as part of the same web app, then I don't see any issue - please elaborate if you do.

If the value is needed in some other web app then there are myriad ways of getting it there - search these forums for something like "communication between web apps" to find the many previous discussions on this topic.
 
Vani Kumar
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My Java project (JAR) shouldn't have any dependency on J2EE api (like servlet, JAX-RS). The JAR project is independent of web project (WAR) but needs to be able to get http headers from web project.

I just tried to add JAX-RS library to my JAR project and checked if i can access to http header but didn't work.

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, we don't know what you tried (I'm afraid your description is rather vague and unclear), but as long as you talk about "projects" we won't get anywhere. "Projects" are a development concept that does not exist at runtime. If the "project" results in a jar file that is then part of the same web app as the JAX-RS services, I don't see any problems for it to use whatever data the REST WS creates. Store it in a context attribute, maybe. In any case, tell us specifically what prevents you from using whatever data the WS creates in the jar file.
 
Vani Kumar
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I resolved this having access the header value in the filter and save it to utility class. The value can be accessed in any project refering the utility class. I was thinking too much on this
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic