• Post Reply Bookmark Topic Watch Topic
  • New Topic

Http header in java project  RSS feed

 
Vani Kumar
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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
  • 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: 42972
73
  • Mark post as helpful
  • send pies
  • 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
  • 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: 42972
73
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!