There is something I am not sure I understand correctlty, therefore, I need help:)
I have seen this: example,
@Path("/resource")
public class Resource {
@Context
private HttpHeaders headers;
@GET
public void get(@Context UriInfo uriInfo) {
/* use headers or uriInfo variable here */
}
}
Does this mean that for each request the class that is transformed to 'endpoint' creates a separate thread? Because, otherwise, the headers information would not be accurate...
Can you please indicate a (short:) ) resource, not JAX-WS specifications, where I can find info about this?
I can't think of a shorter and more direct resource than the JAX-RS 1.1 spec itself. It is clear about what you are asking:
May I add for completeness: that context information is obtained through the
@Context
annotation. As of resources, the context information is only available to the ones annotated with@Path
(also called root resources). Also,@Context
can inject the following context types:Application
,UriInfo
,HttpHeaders
,Request
,SecurityContext
andProviders
.And about the lifecycle (request/thread management):
The conclusion is:
Each specific implementation may change this lifecycle a bit, but the principles should be maintained (a context specific to each request).
As you can see, also, the spec says nothing about thread management. Since most JAX-RS implementations are Servlet-based, we can assume with certain safety that the each request instance goes to a different thread - as servlet containers are thread per request.