eclipse-ee4j / eclipse-ee4j/jersey

Injection of @Context dependencies fails in JerseyTest with JettyTestContainerFactory

Open
#4,625 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

In a JerseyTest of an application with a resource that requires injection of a `@Context`-annotated dependency, e.g. `HttpServletRequest`, HK2 fails to inject the dependency. I would expect the container to be able to supply the current `org.eclipse.jetty.server.Request` object to satisfy the dependency.

I have confirmed this behavior in version 2.32.

To reproduce the failure, in [JettyContainerTest.java](https://github.com/eclipse-ee4j/jersey/blob/2.32/test-framework/providers/jetty/src/test/java/org/glassfish/jersey/test/jetty/JettyContainerTest.java), modify the resource by changing

@Path("one")
public static class Resource {
@GET
public String getSomething() {
return "get";
}
}

to

@Path("one")
public static class Resource {
public String getSomething(@Context HttpServletRequest request) {
return request.getMethod().toLowerCase();
}
}

and the `testJettyContainerTarget()` test will fail because null is passed as the value of the `request` parameter.

Is there a way to wire up the JettyTestContainer so that `@Context` dependencies are resolved correctly?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.