Hello!
I've started to run some tests with Jersey on top of several simple web
containers. In particular, I'm about to use Jersey in conjunction with
Grizzly2 (2.2.1).
And I've got the problem that I cannot successfully inject
ServletContext / HttpServletRequest / HttpServletResponse by the help
of @Context.
My code is like:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{userId: [0-9]+}")
public Response getUser( @PathParam("userId") long userId, @Context
HttpServletRequest req ) {
...
}
Without the @Context parameter everything works like a charm. But as
soon as I add the @Context parameter I encounter the following error:
SCHWERWIEGEND: The following errors and warnings have been detected
with resource and/or provider classes:
SEVERE: Missing dependency for method public
javax.ws.rs.core.Response
de.justphil.tcg.tcgserver.rest.resources.UserResource.getUser(long,java
x.servlet.http.HttpServletRequest) at parameter at index 1
SEVERE: Method, public javax.ws.rs.core.Response
de.justphil.tcg.tcgserver.rest.resources.UserResource.getUser(long,java
x.servlet.http.HttpServletRequest), annotated with GET of resource,
class de.justphil.tcg.tcgserver.rest.resources.UserResource, is not
recognized as valid resource method.
Exception in thread "main"
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
at
com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
at
com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
at
com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
at
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebA
pplicationImpl.java:773)
at
com.sun.jersey.api.container.ContainerFactory.createContainer(Container
Factory.java:172)
at
com.sun.jersey.api.container.ContainerFactory.createContainer(Container
Factory.java:134)
at
com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory.createHttpSe
rver(GrizzlyServerFactory.java:242)
at
de.justphil.tcg.tcgserver.rest.TCGRestServer.startServer(TCGRestServer.
java:47)
at
de.justphil.tcg.tcgserver.rest.TCGRestServer.main(TCGRestServer.java:56
)
The same resource works great in the older Grizzly 1.9 (using
GrizzlyWebContainerFactory).
Any hints on how I can resolve this problem?
Thanks in advance!
Philipp