Manjusha Nair
Manjusha Nair

Reputation: 21

Unable to inject HttpServletRequest inside thread in Wildfly 12.0

In my Java Web Application with RESTful WebService, I was using Wildfly 8.2 which had weld 2.2.6. I am injecting HttpServletRequest object in thread and reading parameters from it. After upgrading to Wildfly 12.0 with weld 3.0.3, using instance of HttpServletRequest in thread gives the following error :

org.jboss.weld.contexts.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped

Is there any way to fix this issue?

I tried a patch update of weld 3.0.4 for Wildfly 12, tried using AsyncContext. tried injecting as @context. This code works fine in Wildfly 12, it does not even work in Wildfly 16.

@Path("test")
public class TestWildfly12 {

    @Inject
    private HttpServletRequest request1;

    @GET
    public Response testRequest() {

        request1.setAttribute("test", "test");
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        executorService.execute(() -> {

            Object value = request1.getAttribute("test");
            System.out.println(value);
        });

        final Response response = Response.build().entity(true);
        response.setStatus(Status.OK.getStatusCode());

        return response;
    }
}

I want the code to get data from the request parameter in the thread.

Upvotes: 1

Views: 408

Answers (0)

Related Questions