Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
7.0.2, 7.0.3
-
None
Description
Using the following code works fine with Tomee (mvn tomee:run) and return a 201 OK response along with the location.
@POST public void post(@Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse, @NotNull @Valid MyDTO myDTO) throws ParseException { CompletableFuture<MyBean> cf = supplyAsync(() -> doSomething(myDTO), executorService); cf .thenAccept(myBean -> { URI location = uriInfo.getRequestUri().resolve(uriInfo.getPath() + "/" + myBean.getId()); Response response = Response.created(location).build(); asyncResponse.resume(response); }).exceptionally(e -> { logger.error("An Error occurred.", e); asyncResponse.resume(Response.serverError().build()); return null; }); }
But when called in tests with OPENEJB EMBEDDED like this :
Properties p = new Properties(); p.setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true"); p.setProperty(EJBContainer.APP_NAME, "/app"); EJBContainer ejbContainer = EJBContainer.createEJBContainer(p);
It fails with this.context being null at (with exceptionnaly not bein called in my method) :
java.lang.NullPointerException
at org.apache.openejb.server.httpd.OpenEJBAsyncContext.dispatch(OpenEJBAsyncContext.java:230)
at org.apache.openejb.server.httpd.OpenEJBAsyncContext.dispatch(OpenEJBAsyncContext.java:223)
at org.apache.openejb.server.httpd.OpenEJBAsyncContext.dispatch(OpenEJBAsyncContext.java:218)
at org.apache.openejb.server.httpd.EEFilter$AsynContextWrapper.dispatch(EEFilter.java:171)
at org.apache.cxf.transport.http.Servlet3ContinuationProvider$Servlet3Continuation.redispatch(Servlet3ContinuationProvider.java:125)
at org.apache.cxf.transport.http.Servlet3ContinuationProvider$Servlet3Continuation.resume(Servlet3ContinuationProvider.java:131)
at org.apache.cxf.jaxrs.impl.AsyncResponseImpl.doResumeFinal(AsyncResponseImpl.java:96)
at org.apache.cxf.jaxrs.impl.AsyncResponseImpl.doResume(AsyncResponseImpl.java:89)
at org.apache.cxf.jaxrs.impl.AsyncResponseImpl.resume(AsyncResponseImpl.java:73)
at com.engagetech.challenge.service.ExpenseService.lambda$post$1(MyService.java:80)
at java.util.concurrent.CompletableFuture.uniAccept(CompletableFuture.java:656)
at java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:632)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1595)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)