0

I am working on RESTFul (JAX-RS) application and will be having a java class file in a jar file separated from war file which needs to access Headers from HttpServletRequest.

If the java class is in war file, i know i can access HttpHeaders using @Context in the resource method or on the resource class as @Context private HttpServletRequest httpRequest OR i can listen to events from ServletListener and get the HttpHeaders as well.

Since the jar file SHOULD NOT depend on war file, i am not sure how to get headers from HTTPServletRequest.

Is there a possible way we can get HTTPheaders by annotations or CDI?

EDIT: Actually, 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.

user923499
  • 305
  • 1
  • 6
  • 18

1 Answers1

0

Your jar file needs to depend on the javaee-api-x.0.jar and you need to have an empty beans.xml file in it. If you do that, you should be able to inject HttpServletRequest without any problems.

The version of the javaee api you use is dependent on the server you're using.

Baldy
  • 2,002
  • 14
  • 14