Olá. Na URL funciona (http://localhost:8080/casadocodigo/service/pagamento?uuid=9c5e2ed8-f490-427d-987b-73814f086ce2) Porém da HTTP ERROR 500 Segue Exception:
16:08:29,158 ERROR [org.jboss.resteasy.resteasy_jaxrs.i18n] (pool-13-thread-3) RESTEASY002010: Failed to execute: javax.ws.rs.WebApplicationException: HTTP 500 Internal Server Error
at br.com.casadocodigo.service.PagamentoService.lambda$0(PagamentoService.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.jboss.resteasy.spi.LoggableFailure: RESTEASY003880: Unable to find contextual data of type: javax.servlet.ServletContext
at org.jboss.resteasy.core.ContextParameterInjector$GenericDelegatingProxy.invoke(ContextParameterInjector.java:75)
at com.sun.proxy.$Proxy113.getContextPath(Unknown Source)
at br.com.casadocodigo.service.PagamentoService.lambda$0(PagamentoService.java:46)
Segue código: @Inject private PagamentoGateWay pagamentoGateway;
@Context
private ServletContext context;
private static ExecutorService executor = Executors.newFixedThreadPool(50);
@POST public void pagar(@Suspended final AsyncResponse ar, @QueryParam("uuid") String uuid) {
Compra compra = compraDao.buscaPorUuid(uuid);
executor.submit(() -> {
try {
pagamentoGateway.pagar(compra.getTotal());
System.out.println("http://localhost:8080" + context.getContextPath() + "/index.xhtml");
URI responseURI = UriBuilder
.fromPath("http://localhost:8080" + context.getContextPath() + "/index.xhtml")
.queryParam("msg", "Compra realizada com sucesso!!!").build();
Response response = Response.seeOther(responseURI).build();
ar.resume(response);
} catch (Exception e) {
ar.resume(new WebApplicationException(e));
}
});
}
código finalizar do CheckoutBean: @Transactional public void finalizar() { Compra compra = new Compra(); compra.setUsuario(usuario); carrinho.finalizar(compra);
String contextName = facesContext.getExternalContext().getRequestContextPath();
HttpServletResponse response = (HttpServletResponse) facesContext
.getExternalContext()
.getResponse();
response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT); //=307
response.setHeader("Location", contextName + "/service/pagamento?uuid="+compra.getUuid());
}