eclipse-ee4j / eclipse-ee4j/jersey
Injecting HttpServletRequest into ContainerRequestFilter causes exception
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
I have the following JAX-RS Filter which implements the `ContainerRequestFilter`:
```
@Provider
@Priority(Priorities.AUTHENTICATION)
public class AuthenticationFilter implements ContainerRequestFilter {
@Context
HttpServletRequest request;
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
// ...
}
}
```
Upon trying to run the Jetty server where the Servlet is deployed, I receive the following MultiException:
...
Caused by: A MultiException has 4 exceptions. They are:
1\. java.lang.IllegalArgumentException: interface org.glassfish.hk2.api.ProxyCtl is not visible from class loader
2\. java.lang.IllegalArgumentException: While attempting to create a Proxy for javax.servlet.http.HttpServletRequest in scope org.glassfish.jersey.process.internal.RequestScoped an error occured while creating the proxy
3\. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of resteasy.AuthenticationFilter errors were found
4\. java.lang.IllegalStateException: Unable to perform operation: resolve on resteasy.AuthenticationFilter
As far as I have been able to tell, this used to be a bug in Jersey <2.4, which should have been fixed. However, every newer Jersey version I have tried has yielded the same result, and I cannot implement a token-based authentication method as a result (i.e. no request.login() ).
Additional details:
pom.xml entry:
```
org.glassfish.jersey.containers
jersey-container-servlet
2.23.1
```
Server start up and deployment:
```
public class JettyServer {
public static void main(String[] args) throws Exception {
WebAppContext webapp = new WebAppContext();
webapp.setDescriptor("./src/webapp/WEB-INF/web.xml");
webapp.setWar("/tmp/resteasy.war");
webapp.setSessionHandler(new SessionHandler());
Server server = new Server(20080);
HashLoginService loginService = new HashLoginService("DefaultRealm");
loginService.setConfig("./src/webapp/default-realm.txt");
server.addBean(loginService);
server.setHandler(webapp);
ServletHolder jerseyServlet = webapp.addServlet(ServletContainer.class, "/v1/*");
jerseyServlet.setInitOrder(0);
Map params = new HashMap();
params.put("jersey.config.server.provider.packages", "resteasy");
jerseyServlet.setInitParameters(params);
try {
server.start();
server.join();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
server.destroy();
}
}
}
```
#### Environment
JAX-RS 3.0.18.Final
Jersey Servlet Container 2.23.1
Jetty 9.3.11.v20160721
JDK 8
Debian 8.5 Jessie
#### Affected Versions
[2.23.1]
Contributor guide
Assessment
This issue has not been assessed yet.