I am trying to migrate a long running REST API server from JBoss 7.1.1 to Wildfly. The application is deploying fine and works for the most part. However my security interceptor loads the servlet request and response using @Context. It works fine under 7.1.1 but is always null under Wildfly.
I read through the migration guide at:
and didn't see anything that referenced this.
Under 7.1.1, this is the security interceptor with the details in the middle removed:
@Provider
@ServerInterceptor
@SecurityPrecedence
public class SecurityInterceptor implements PreProcessInterceptor {
@Context
private HttpServletRequest _servletRequest;
@Context
private HttpServletResponse _servletResponse;
@Override
public ServerResponse preProcess(HttpRequest request, ResourceMethod method) throws Failure {
// _servletRequest and _servletResponse are set correctly and are non-null
}
}
I changed the security interceptor to comply with Resteasy 3.x (some classes were deprecated) and it now looks like this:
@Provider
public class SecurityInterceptor implements ContainerRequestFilter {
@Context
private HttpServletRequest _servletRequest;
@Context
private HttpServletResponse _servletResponse;
@Override
public void filter(ContainerRequestContext requestContext) throws Failure {
// _servletRequest and _servletResponse are always NULL
}
}
I tried loading the request and response from the RestEasyProviderFactory like this
@Provider
public class SecurityInterceptor implements ContainerRequestFilter {
private HttpServletRequest _servletRequest;
private HttpServletResponse _servletResponse;
@Override
public void filter(ContainerRequestContext requestContext) throws Failure {
_servletRequest = ResteasyProviderFactory.getContextData(HttpServletRequest.class);
_servletResponse = ResteasyProviderFactory.getContextData(HttpServletResponse.class);
// _servletRequest and _servletResponse are now correct
}
}
and that works. So just the @Context injection is not working.
Is there something that needs to be set up differently in Wildfly for this to work?
UPDATE:
I've looked at context injection in a resource class. I'm starting to think that class-level injection the problem. Method level injection seems to work fine. Here is a resource example that shows the problem:
@Path("/mypath")
@Produces({MediaType.APPLICATION_JSON})
public class MyResource {
@Context
private HttpServletRequest _httpServletRequest;
@GET
@Path("/path1")
public String test1() {
// _httpServletRequest is null here
}
@GET
@Path("/path2")
public String test2(@Context HttpServletRequest request) {
// request is correct
}
}
Was class-level injection removed in Wildfly or does it have to be enabled in some way?