Olá,
Não estou conseguindo fazer um post de um serviço de portal de pagamento. O estranho é que utilizando o Poster no firefox eu consigo tranquilamente apenas enviando o Json e a URL obtenho sucesso, porém no Java tenho o SocketException toda vez. Lembrando que é https. Alguém já passou por isso ? Consegue dar uma luz ?
Método post no client:
public static HttpResponse sendPost(String json, String contentType) {
URIBuilder builder = new URIBuilder();
builder.setScheme("https").setHost("api.mundipagg.com").setPath("/checkout/v1/tokens");
post.setEntity(new ByteArrayEntity(json.toString().getBytes("UTF8")));
if (contentType != null) {
post.setHeader("Content-type", contentType);
} else {
post.setHeader("Content-type", "application/json");
}
if (FacesContext.getCurrentInstance() != null) {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
Object token = session.getAttribute("TOKEN");
if (token != null) {
post.setHeader("Authorization", (String) token);
}
}
return httpclient.execute(post);
}
Segue stacktrace:
09:07:10,440 ERROR [stderr] (default task-39) java.net.SocketException: Connection reset
09:07:10,441 ERROR [stderr] (default task-39) at java.net.SocketInputStream.read(SocketInputStream.java:196)
09:07:10,442 ERROR [stderr] (default task-39) at java.net.SocketInputStream.read(SocketInputStream.java:122)
09:07:10,443 ERROR [stderr] (default task-39) at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
09:07:10,444 ERROR [stderr] (default task-39) at sun.security.ssl.InputRecord.read(InputRecord.java:480)
09:07:10,446 ERROR [stderr] (default task-39) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
09:07:10,447 ERROR [stderr] (default task-39) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
09:07:10,448 ERROR [stderr] (default task-39) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
09:07:10,449 ERROR [stderr] (default task-39) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
09:07:10,450 ERROR [stderr] (default task-39) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394)
09:07:10,451 ERROR [stderr] (default task-39) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)
09:07:10,452 ERROR [stderr] (default task-39) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141)
09:07:10,453 ERROR [stderr] (default task-39) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
09:07:10,454 ERROR [stderr] (default task-39) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
09:07:10,455 ERROR [stderr] (default task-39) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
09:07:10,456 ERROR [stderr] (default task-39) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
09:07:10,457 ERROR [stderr] (default task-39) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
09:07:10,458 ERROR [stderr] (default task-39) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
09:07:10,459 ERROR [stderr] (default task-39) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
09:07:10,460 ERROR [stderr] (default task-39) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
09:07:10,461 ERROR [stderr] (default task-39) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
09:07:10,462 ERROR [stderr] (default task-39) at br.com.pagamentoonline.utils.WebServiceUtils.sendPostMundipagg(WebServiceUtils.java:108)
09:07:10,463 ERROR [stderr] (default task-39) at br.com.pagamentoonline.utils.WebServiceUtils.sendPostMundi(WebServiceUtils.java:58)
09:07:10,464 ERROR [stderr] (default task-39) at br.com.caspagamentoonline.mb.CasInfoPedidoMB.realizarPagamento(CasInfoPedidoMB.java:94)
09:07:10,466 ERROR [stderr] (default task-39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
09:07:10,467 ERROR [stderr] (default task-39) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
09:07:10,468 ERROR [stderr] (default task-39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
09:07:10,468 ERROR [stderr] (default task-39) at java.lang.reflect.Method.invoke(Method.java:606)
09:07:10,469 ERROR [stderr] (default task-39) at com.sun.el.parser.AstValue.invoke(AstValue.java:292)
09:07:10,470 ERROR [stderr] (default task-39) at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
09:07:10,471 ERROR [stderr] (default task-39) at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
09:07:10,472 ERROR [stderr] (default task-39) at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
09:07:10,473 ERROR [stderr] (default task-39) at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
09:07:10,474 ERROR [stderr] (default task-39) at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
09:07:10,475 ERROR [stderr] (default task-39) at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
09:07:10,476 ERROR [stderr] (default task-39) at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
09:07:10,477 ERROR [stderr] (default task-39) at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
09:07:10,478 ERROR [stderr] (default task-39) at javax.faces.component.UICommand.broadcast(UICommand.java:300)
09:07:10,479 ERROR [stderr] (default task-39) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
09:07:10,480 ERROR [stderr] (default task-39) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
09:07:10,481 ERROR [stderr] (default task-39) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
09:07:10,482 ERROR [stderr] (default task-39) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
09:07:10,482 ERROR [stderr] (default task-39) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
09:07:10,483 ERROR [stderr] (default task-39) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
09:07:10,484 ERROR [stderr] (default task-39) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
09:07:10,485 ERROR [stderr] (default task-39) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
09:07:10,486 ERROR [stderr] (default task-39) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
09:07:10,487 ERROR [stderr] (default task-39) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
09:07:10,488 ERROR [stderr] (default task-39) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:07:10,489 ERROR [stderr] (default task-39) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
09:07:10,490 ERROR [stderr] (default task-39) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
09:07:10,491 ERROR [stderr] (default task-39) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:07:10,492 ERROR [stderr] (default task-39) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
09:07:10,493 ERROR [stderr] (default task-39) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63)
09:07:10,494 ERROR [stderr] (default task-39) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
09:07:10,495 ERROR [stderr] (default task-39) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
09:07:10,496 ERROR [stderr] (default task-39) at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
09:07:10,497 ERROR [stderr] (default task-39) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:07:10,498 ERROR [stderr] (default task-39) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
09:07:10,500 ERROR [stderr] (default task-39) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:07:10,501 ERROR [stderr] (default task-39) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:07:10,502 ERROR [stderr] (default task-39) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261)
09:07:10,503 ERROR [stderr] (default task-39) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247)
09:07:10,503 ERROR [stderr] (default task-39) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76)
09:07:10,504 ERROR [stderr] (default task-39) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166)
09:07:10,505 ERROR [stderr] (default task-39) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197)
09:07:10,506 ERROR [stderr] (default task-39) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759)
09:07:10,507 ERROR [stderr] (default task-39) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
09:07:10,508 ERROR [stderr] (default task-39) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
09:07:10,509 ERROR [stderr] (default task-39) at java.lang.Thread.run(Thread.java:745)