javax.net.ssl.SSLException: Received fatal alert: handshake_failure - java

I have been trying to connect to a service endpoint which is https. I am using Spring resttemplate, I have added the certificate in keystore of weblogic and java cacerts. I am able to connect to other https Endpoints. but I am getting the HandShake fatal error.
I am getting the following error
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "path":Received fatal alert: handshake_failure; nested exception is javax.net.ssl.SSLException: Received fatal alert: handshake_failure
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:558)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:503)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:445)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:751)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:341)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:238)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3363)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3333)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2220)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2146)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2124)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1564)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)
Caused by: javax.net.ssl.SSLException: Received fatal alert: handshake_failure
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1619)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1587)
at sun.security.ssl.SSLEngineImpl.recvAlert(SSLEngineImpl.java:1756)
at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:1060)
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:884)
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:758)
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:664)
at weblogic.security.SSL.jsseadapter.JaSSLEngine$5.run(JaSSLEngine.java:134)
at weblogic.security.SSL.jsseadapter.JaSSLEngine.doAction(JaSSLEngine.java:732)
at weblogic.security.SSL.jsseadapter.JaSSLEngine.unwrap(JaSSLEngine.java:132)
at weblogic.socket.JSSEFilterImpl.unwrap(JSSEFilterImpl.java:603)
at weblogic.socket.JSSEFilterImpl.unwrapAndHandleResults(JSSEFilterImpl.java:507)
at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:96)
at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:75)
at weblogic.socket.JSSEFilterImpl.write(JSSEFilterImpl.java:448)
at weblogic.socket.JSSESocket$JSSEOutputStream.write(JSSESocket.java:93)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
at java.io.FilterOutputStream.flush(FilterOutputStream.java:140)
at weblogic.net.http.HttpURLConnection.writeRequests(HttpURLConnection.java:192)
at weblogic.net.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:304)
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:80)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:52)at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:542)
... 39 more
private String getAuthenticationToken() {
LOGGER.info("Autehenitcation Initiated");
System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
ObjectMapper objectMapper = new ObjectMapper();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
String JsonRequest= String.format("{\"userName\":\"%s\",\"password\":\"%s\",\"companyName\":\"%s\"}",user, passwrd, Cname);
HttpEntity<String> request = new HttpEntity<String>(JsonRequest, httpHeaders);
LOGGER.info("Calling Authenticate Service");
RestTemplate restTemplate = new RestTemplate();
try {
ResponseEntity<String> response = restTemplate.exchange("https://url", HttpMethod.POST, request, String.class);
if(response.getStatusCode() != HttpStatus.OK) {
LOGGER.warn(" Authenticate Service Error");
return null;
}
else {
Modelclass model = objectMapper.readValue(response.getBody(), Modelclass.class);
LOGGER.info("Returning Authentication token");
return model.AuthenticateResult;
}
}
catch (Exception ex) {
ex.printStackTrace();
LOGGER.warn("Error in Processing Request");
return null;
}
can anyone help me with this please.

Related

com.google.firebase.messaging.FirebaseMessagingException: Error while calling FCM backend service

I am trying to send the fcm notification :
MulticastMessage message = MulticastMessage.builder()
.addAllTokens(registrationTokens)
.putAllData(body)
.build();
System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
BatchResponse response = FirebaseMessaging.getInstance().sendMulticast(message);
Sometimes the code on the server encounters this problem
com.google.firebase.messaging.FirebaseMessagingException: Error while calling FCM backend service
at com.google.firebase.messaging.FirebaseMessagingClientImpl.sendAll(FirebaseMessagingClientImpl.java:142)
at com.google.firebase.messaging.FirebaseMessaging$2.execute(FirebaseMessaging.java:293)
at com.google.firebase.messaging.FirebaseMessaging$2.execute(FirebaseMessaging.java:290)
at com.google.firebase.internal.CallableOperation.call(CallableOperation.java:36)
at com.google.firebase.messaging.FirebaseMessaging.sendAll(FirebaseMessaging.java:183)
at com.google.firebase.messaging.FirebaseMessaging.sendMulticast(FirebaseMessaging.java:252)
at com.google.firebase.messaging.FirebaseMessaging.sendMulticast(FirebaseMessaging.java:227)
at ir.mirorim.vn.serviceImp.userService.NotificationServiceImp.sendMultipleMessage(NotificationServiceImp.java:351)
at ir.mirorim.vn.serviceImp.userService.NotificationServiceImp.testNotification(NotificationServiceImp.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1623)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
What i am doing wrong. All the config are with the code while compilation.
The part where I load the Firebase configuration file
#PostConstruct
public void init() {
try {
String configPath = servletContext.getRealPath("/WEB-INF/mm-firebase-adminsdk-oqtey-c111bb111c.json");
FileInputStream serviceAccount =
new FileInputStream(configPath);
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://****-****.firebaseio.com")
.build();
FirebaseApp.initializeApp(options);
}
catch (Exception e){
e.printStackTrace();
}
}
my json config:
{
"type": "service_account",
"project_id": "mm-1111",
"private_key_id": "**************************",
"private_key": "-----BEGIN PRIVATE KEY-----
xxx
---END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk-kvj7w#mm-1111.iam.gserviceaccount.com",
"client_id": "1000559483501236*****",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-kvj7w%mm-1111.iam.gserviceaccount.com"
}
Are these server blocked or what? How should I debug those?
Can anyone help me?

417 Expectation Failed when doing POST request using RestTemplate

I need to create a POST request using RestTemplate to an authentication endpoint to get a token. The endpoint requires a raw JSON that looks something like this:
{
"client_id" : "12345"
"client_secret" : "12345"
}
I am tried adding the json as a map into the HttpEntity along with the Application/Json content type in the hedaer. the raw JSON is the only thing that i needs
String url = "https://oauth/token";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
MultiValueMap<String,String> map = new LinkedMultiValueMap<>();
map.add("client_id", "b890" );
map.add("client_secret", "576a0");
HttpEntity<MultiValueMap<String,String>> request = new HttpEntity<>(map, headers);
ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
assert(response.hasBody());
ObjectMapper mapper = new ObjectMapper();
System.out.println(response.getBody());
JsonNode jsonNode;
try
{
jsonNode = mapper.readTree(response.getBody());
token = jsonNode.get("access_token").asText();
}
catch (Exception e)
{
System.out.println(e.toString());
}
System.out.println(token);
I get the following stacktrace:
org.springframework.web.client.HttpClientErrorException: 417 Expectation Failed
at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:101) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:122) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:102) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:778) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:736) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:670) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:445) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at monitor.ScheduledTasks.getToken(ScheduledTasks.java:86) ~[classes!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_211]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_211]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_211]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_211]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_211]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_211]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_211]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_211]

ERROR java.net.SocketException: Connection reset

What's the problem?
I do not know the cause.
I want to get a solution.
The same error occurs when increasing the timeout.
Should I also consider proxy issues?
⇒ java: 1.8
⇒ ssl/tls: 1.2
Source
RequestConfig.Builder requestBuilder = RequestConfig.custom().setConnectTimeout(60*1000)
.setConnectionRequestTimeout(60*1000).setSocketTimeout(60*1000);
HttpClientBuilder builder = HttpClientBuilder.create().setDefaultRequestConfig(requestBuilder.build());
CloseableHttpClient httpClient = builder.build();
logger.info("sendXml START : "+ uri.toString() +", TIME : "+ System.currentTimeMillis());
try {
HttpPost httpPost = new HttpPost();
httpPost.setURI(uri);
httpPost.setHeader("Content-Type", "application/xml");
HttpEntity entity = new ByteArrayEntity(xml.getBytes("UTF-8"));
httpPost.setEntity(entity);
CloseableHttpResponse response = httpClient.execute(httpPost);
try {
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
logger.error("Response Status is not OK : " + response.getStatusLine().getStatusCode());
throw new SwabException("$systxt.errSystem");
}
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
parser.parse(response.getEntity().getContent(), handler);
} catch (Exception e) {
throw e;
} finally {
response.close();
}
logger.info("Send Xml End");
} catch (Exception e2) {
throw e2;
} finally {
httpClient.close();
}
ERROR
ERROR 2019-01-28 13:10:20 j.c.u.clienteling.server.XmlUtil - HttpClient:java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:930)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:136)
at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:152)
at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:270)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:161)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:153)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
at jp.co.ui2.clienteling.server.XmlUtil.sendXml(XmlUtil.java:278)
at jp.co.ui2.clienteling.server.clients.ClientsServiceImpl.getClientInfoDetail(ClientsServiceImpl.java:110)
at sun.reflect.GeneratedMethodAccessor267.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy80.getClientInfoDetail(Unknown Source)
at sun.reflect.GeneratedMethodAccessor266.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.traceok.swab.server.HibernateRPCServiceExporter.invokeMethodOnService(HibernateRPCServiceExporter.java:60)
at org.gwtwidgets.server.spring.GWTRPCServiceExporter.processCall(GWTRPCServiceExporter.java:410)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:305)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at org.gwtwidgets.server.spring.GWTRPCServiceExporter.handleRequest(GWTRPCServiceExporter.java:478)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:855)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.filters.ExpiresFilter.doFilter(ExpiresFilter.java:1179)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:190)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
If the connection is "https" and you can reach the server with the navigator (Chrome, Firefox, etc.) could be a SSL problem. Take care of put your certificate in cacerts of the JVM that runs your code.

Paypal Java-SDK Payment Execute issue

I am trying to integrate Papal with my Spring Web Service. I am refering Advanced Server Integration and using this SDK Create Payment Sample.
Here is my Client Side Code
<script src="https://www.paypalobjects.com/api/checkout.js">
</script>
<h1>Paypal Integration - Advanced Server Side Integration</h1>
<div id="paypal-button-container"></div>
<script>
// Render the PayPal button
paypal.Button.render({
// Set your environment
env: 'sandbox', // sandbox | production
// Wait for the PayPal button to be clicked
payment: function() {
// Make a call to the merchant server to set up the payment
return paypal.request.post('http://localhost:8080/api/createpayment').then(function(res) {
console.log(res);
return res.payToken;
});
},
// Wait for the payment to be authorized by the customer
onAuthorize: function(data, actions) {
// Make a call to the merchant server to execute the payment
return paypal.request.post('http://localhost:8080/api/executepayment', {
payToken: data.paymentID,
payerId: data.payerID
}).then(function(res) {
console.log(res);
document.querySelector('#paypal-button-container').innerText = 'Payment Complete!';
});
}
}, '#paypal-button-container');
</script>
Here is my Web Service
#RequestMapping(value = "/executepayment", method = RequestMethod.POST)
public #ResponseBody
Payment executePayment(HttpServletRequest request, HttpServletResponse response) {
Map<String, String> map = new HashMap<String, String>();
Payment createdPayment = null;
try {
final String clientID = "<clientId>";
final String clientSecret = "<clientSecret>";
// ### Api Context
// Pass in a `ApiContext` object to authenticate
// the call and to send a unique request id
// (that ensures idempotency). The SDK generates
// a request id if you do not pass one explicitly.
APIContext apiContext = new APIContext(clientID, clientSecret, "sandbox");
if (request.getParameter("payerId") != null) {
logger.info("Payment Execution");
Payment payment = new Payment();
if (request.getParameter("guid") != null) {
payment.setId(map.get(request.getParameter("guid")));
}
PaymentExecution paymentExecution = new PaymentExecution();
paymentExecution.setPayerId(request.getParameter("payerId"));
createdPayment = payment.execute(apiContext, paymentExecution);
logger.info("Executed Payment - Request :: \n " + Payment.getLastRequest());
logger.info("Exceuted Payment - Response :; \n " + Payment.getLastResponse());
//ResultPrinter.addResult(req, resp, "Executed The Payment", Payment.getLastRequest(), Payment.getLastResponse(), null);
//ResultPrinter.addResult(req, resp, "Executed The Payment", Payment.getLastRequest(), null, e.getMessage());
}
} catch (Exception e) {
logger.error("Execute Payment Exception ");
e.printStackTrace();
}
return createdPayment;
}
When I click on Paypal Checkout button. It popups the Paypal Login Screen and authorization is working fine. After that I am trying to execute payment using my API. But I am getting 500 Internal Server Error when I call payment.execute(apiContext, paymentExecution) method. Here is the complete Stacktrace
[http-nio-8080-exec-42] ERROR com.paypal.base.HttpConnection - Response code: 500 Error response: <html><head><title>JBoss Web/7.0.17.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: com.paypal.foundation.security.ObjectEncryptionException.<init>(Lcom/paypal/platform/ec/InternalError;Ljava/lang/Throwable;[Ljava/lang/String;)V org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116) org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:336) org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:249) org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:181) org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:289) org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209) javax.servlet.http.HttpServlet.service(HttpServlet.java:754) org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265) org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) com.paypal.api.utils.MultiReadServletFilter.doFilter(MultiReadServletFilter.java:23) com.paypal.foundation.service.rest.logging.StandardOuterTransactionCALFilter.doFilter(StandardOuterTransactionCALFilter.java:95) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) com.paypal.common.resource.filter.SecurityContextFilter.doFilter(SecurityContextFilter.java:75)</pre></p><p><b>root cause</b> <pre>org.apache.cxf.interceptor.Fault: com.paypal.foundation.security.ObjectEncryptionException.<init>(Lcom/paypal/platform/ec/InternalError;Ljava/lang/Throwable;[Ljava/lang/String;)V org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:170) org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:136) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:204) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:101) org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94) org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:249) org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:181) org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:289) org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209) javax.servlet.http.HttpServlet.service(HttpServlet.java:754) org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265) org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) com.paypal.api.utils.MultiReadServletFilter.doFilter(MultiReadServletFilter.java:23) com.paypal.foundation.service.rest.logging.StandardOuterTransactionCALFilter.doFilter(StandardOuterTransactionCALFilter.java:95) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) com.paypal.common.resource.filter.SecurityContextFilter.doFilter(SecurityContextFilter.java:75)</pre></p><p><b>root cause</b> <pre>java.lang.NoSuchMethodError: com.paypal.foundation.security.ObjectEncryptionException.<init>(Lcom/paypal/platform/ec/InternalError;Ljava/lang/Throwable;[Ljava/lang/String;)V com.paypal.foundation.security.InvalidInputDataException.<init>(InvalidInputDataException.java:11) com.paypal.foundation.security.crypto.AbstractIdEncryptor.decrypt(AbstractIdEncryptor.java:81) com.paypal.domains.common.utils.crypto.impl.IdCryptUtilImpl.decryptId(IdCryptUtilImpl.java:103) com.paypal.domains.payment.dal.dao.impl.PaymentsFacadeDAOImpl.findPaymentByEncryptedId(PaymentsFacadeDAOImpl.java:301) com.paypal.domains.payment.bo.impl.PaymentBOFactory.getPaymentForRoutingCheck(PaymentBOFactory.java:340) com.paypal.api.service.impl.PaymentServiceImpl.checkRoutingToSymphony(PaymentServiceImpl.java:2167) com.paypal.api.service.impl.PaymentServiceImpl.executePayment(PaymentServiceImpl.java:811) sun.reflect.GeneratedMethodAccessor168.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:188) org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:104) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:204) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:101) org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94) org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:249) org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:181) org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:289) org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209) javax.servlet.http.HttpServlet.service(HttpServlet.java:754) org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265) org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerReque2017-05-03 17:48:33 ERROR UserController:740 - Create Payment Exception
stFilter.java:76) com.paypal.api.utils.MultiReadServletFilter.doFilter(MultiReadServletFilter.java:23) com.paypal.foundation.service.rest.logging.StandardOuterTransactionCALFilter.doFilter(StandardOuterTransactionCALFilter.java:95) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) com.paypal.common.resource.filter.SecurityContextFilter.doFilter(SecurityContextFilter.java:75)</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the JBoss Web/7.0.17.Final logs.</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.0.17.Final</h3></body></html>
response-code: 500 details: null
at com.paypal.base.rest.PayPalRESTException.createFromHttpErrorException(PayPalRESTException.java:72)
at com.paypal.base.rest.PayPalResource.execute(PayPalResource.java:431)
at com.paypal.base.rest.PayPalResource.configureAndExecute(PayPalResource.java:295)
at com.paypal.base.rest.PayPalResource.configureAndExecute(PayPalResource.java:228)
at com.paypal.api.payments.Payment.execute(Payment.java:226)
at com.statementgames.controllers.UserController.createPayment(UserController.java:640)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at com.statementgames.filters.CORSFilter.doFilter(CORSFilter.java:54)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:509)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.paypal.base.exception.HttpErrorException: Response code: 500 Error response: <html><head><title>JBoss Web/7.0.17.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: com.paypal.foundation.security.ObjectEncryptionException.<init>(Lcom/paypal/platform/ec/InternalError;Ljava/lang/Throwable;[Ljava/lang/String;)V org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116) org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:336) org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:249) org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:181) org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:289) org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209) javax.servlet.http.HttpServlet.service(HttpServlet.java:754) org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265) org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) com.paypal.api.utils.MultiReadServletFilter.doFilter(MultiReadServletFilter.java:23) com.paypal.foundation.service.rest.logging.StandardOuterTransactionCALFilter.doFilter(StandardOuterTransactionCALFilter.java:95) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) com.paypal.common.resource.filter.SecurityContextFilter.doFilter(SecurityContextFilter.java:75)</pre></p><p><b>root cause</b> <pre>org.apache.cxf.interceptor.Fault: com.paypal.foundation.security.ObjectEncryptionException.<init>(Lcom/paypal/platform/ec/InternalError;Ljava/lang/Throwable;[Ljava/lang/String;)V org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:170) org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:136) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:204) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:101) org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94) org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:249) org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:181) org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:289) org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209) javax.servlet.http.HttpServlet.service(HttpServlet.java:754) org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265) org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) com.paypal.api.utils.MultiReadServletFilter.doFilter(MultiReadServletFilter.java:23) com.paypal.foundation.service.rest.logging.StandardOuterTransactionCALFilter.doFilter(StandardOuterTransactionCALFilter.java:95) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) com.paypal.common.resource.filter.SecurityContextFilter.doFilter(SecurityContextFilter.java:75)</pre></p><p><b>root cause</b> <pre>java.lang.NoSuchMethodError: com.paypal.foundation.security.ObjectEncryptionException.<init>(Lcom/paypal/platform/ec/InternalError;Ljava/lang/Throwable;[Ljava/lang/String;)V com.paypal.foundation.security.InvalidInputDataException.<init>(InvalidInputDataException.java:11) com.paypal.foundation.security.crypto.AbstractIdEncryptor.decrypt(AbstractIdEncryptor.java:81) com.paypal.domains.common.utils.crypto.impl.IdCryptUtilImpl.decryptId(IdCryptUtilImpl.java:103) com.paypal.domains.payment.dal.dao.impl.PaymentsFacadeDAOImpl.findPaymentByEncryptedId(PaymentsFacadeDAOImpl.java:301) com.paypal.domains.payment.bo.impl.PaymentBOFactory.getPaymentForRoutingCheck(PaymentBOFactory.java:340) com.paypal.api.service.impl.PaymentServiceImpl.checkRoutingToSymphony(PaymentServiceImpl.java:2167) com.paypal.api.service.impl.PaymentServiceImpl.executePayment(PaymentServiceImpl.java:811) sun.reflect.GeneratedMethodAccessor168.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:188) org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:104) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:204) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:101) org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94) org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:249) org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:181) org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:289) org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209) javax.servlet.http.HttpServlet.service(HttpServlet.java:754) org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265) org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) com.paypal.api.utils.MultiReadServletFilter.doFilter(MultiReadServletFilter.java:23) com.paypal.foundation.service.rest.logging.StandardOuterTransactionCALFilter.doFilter(StandardOuterTransactionCALFilter.java:95) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) com.paypal.common.resource.filter.SecurityContextFilter.doFilter(SecurityContextFilter.java:75)</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the JBoss Web/7.0.17.Final logs.</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.0.17.Final</h3></body></html>
at com.paypal.base.HttpConnection.executeWithStream(HttpConnection.java:162)
at com.paypal.base.HttpConnection.execute(HttpConnection.java:65)
at com.paypal.base.rest.PayPalResource.execute(PayPalResource.java:417)
... 45 more
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: https://api.sandbox.paypal.com/v1/payments/payment/706473799bd24b5792e463df41140a61/execute
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1890)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1885)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1884)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1457)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at com.paypal.base.HttpConnection.executeWithStream(HttpConnection.java:132)
... 47 more
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: https://api.sandbox.paypal.com/v1/payments/payment/706473799bd24b5792e463df41140a61/execute
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
at com.paypal.base.HttpConnection.executeWithStream(HttpConnection.java:117)
... 47 more
I can't figure out whats going wrong. Is there any issue in Paypal-Java-SDK or in my Server side code. Am I doing anything Wrong?
This error is because of wrong Payment Id. I just changed the code as
if (request.getParameter("paymentId") != null) {
payment.setId(request.getParameter("paymentId"));
}
I think Paypal should handle this kind of errors and show some proper error message in Response JSON like Payment ID missing, Invalid Payment ID or something. It's weird to get 500 Internal Server Error and It's very hard to debug.

Exception sending file (greater than small size) with Spring security and Rest web services

I added basic authentication to my Rest web service (created through Spring) but for RestTemplate I use with success this class:
public class RestClient extends RestTemplate {
public RestClient(String username, String password) {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(null, -1),
new UsernamePasswordCredentials(username, password));
HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
}
}
but for my HttpPost I'm using this:
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(null,-1),
new UsernamePasswordCredentials(username, password));
try(CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build()){
HttpPost httppost = new HttpPost(serverIp + "ATS/client/file");
File file = new File(filePath);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
ContentBody cbFile = new FileBody(file);
ContentBody cbPath= new StringBody(toStorePath,ContentType.TEXT_PLAIN);
builder.addPart("file", cbFile);
builder.addPart("toStorePath",cbPath);
httppost.setEntity(builder.build());
CloseableHttpResponse httpResponse = httpClient.execute(httppost);
HttpEntity resEntity = httpResponse.getEntity();
if (resEntity != null) {
ObjectMapper mapper = new ObjectMapper();
Response response = mapper.readValue(resEntity.getContent(), Response.class);
EntityUtils.consume(resEntity) ;
return response;
}
//It should never be thrown
else return new Response(false, false, "Error with server response" , null);
}catch(Exception e){
ErrorResponse errorResponse= ErrorResponseBuilder.buildErrorResponse(e);
return new Response(false, false,"Error sending the file!" , errorResponse);
}
but the request doesn't arrive to server because client throws this exception:
INFO 11284 --- [nio-8080-exec-7] o.apache.http.impl.execchain.RetryExec : I/O exception (java.net.SocketException) caught when processing request to {}->http://localhost:8086: Connection reset by peer: socket write error
2015-12-23 12:49:45.815 INFO 11284 --- [nio-8080-exec-7] o.apache.http.impl.execchain.RetryExec : Retrying request to {}->http://localhost:8086
2015-12-23 12:49:46.818 INFO 11284 --- [nio-8080-exec-7] o.apache.http.impl.execchain.RetryExec : I/O exception (java.net.SocketException) caught when processing request to {}->http://localhost:8086: Connection reset by peer: socket write error
2015-12-23 12:49:46.818 INFO 11284 --- [nio-8080-exec-7] o.apache.http.impl.execchain.RetryExec : Retrying request to {}->http://localhost:8086
2015-12-23 12:49:47.821 INFO 11284 --- [nio-8080-exec-7] o.apache.http.impl.execchain.RetryExec : I/O exception (java.net.SocketException) caught when processing request to {}->http://localhost:8086: Connection reset by peer: socket write error
2015-12-23 12:49:47.821 INFO 11284 --- [nio-8080-exec-7] o.apache.http.impl.execchain.RetryExec : Retrying request to {}->http://localhost:8086
2015-12-23 12:49:48.825 ERROR 11284 --- [nio-8080-exec-7] client.controller.ErrorController : org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:8086/ATS/client/file":Connection reset by peer: socket write error; nested exception is java.net.SocketException: Connection reset by peer: socket write error
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:580)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:530)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:330)
at client.services.FileServicesImpl.sendFile(FileServicesImpl.java:116)
at client.wbcontroller.ControllerMatlab.Write(ControllerMatlab.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at org.apache.http.impl.io.SessionOutputBufferImpl.streamWrite(SessionOutputBufferImpl.java:123)
at org.apache.http.impl.io.SessionOutputBufferImpl.write(SessionOutputBufferImpl.java:157)
at org.apache.http.impl.io.ContentLengthOutputStream.write(ContentLengthOutputStream.java:115)
at org.apache.http.entity.ByteArrayEntity.writeTo(ByteArrayEntity.java:112)
at org.apache.http.impl.DefaultBHttpClientConnection.sendRequestEntity(DefaultBHttpClientConnection.java:155)
at org.apache.http.impl.conn.CPoolProxy.sendRequestEntity(CPoolProxy.java:149)
at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:236)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:91)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:569)
... 45 more
If I use a very small file, like 10Kb, all works ine, if I tray with 10MB file receive exception.
The same problem there is with the below code:
#Override
public Response sendFile(String username, String password, String serverIp, String toStorePath, String filePath) {
MultiValueMap<String, Object> mvm = new LinkedMultiValueMap<String, Object>();
mvm.add("file", new FileSystemResource(filePath));
mvm.add("toStorePath",toStorePath);
RestClient restClient = new RestClient(username, password);
return restClient.postForObject(serverIp + "ATS/client/file", mvm, Response.class);
On the server I have this spring security configuration:
#Configuration
#Order(1)
public static class ApiWebSecurityConfig extends WebSecurityConfigurerAdapter{
#Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.antMatcher("/client/**")
.authorizeRequests().antMatchers("/client/file/**").permitAll()
//
.anyRequest().authenticated()
.and()
.httpBasic();
}
}
If I add .antMatchers("/client/file/**").permitAll() (or rather I dasable authentication) it works.
The odd thing is that without authentication I can send file over 300MB (I use the method with HTTP post to use streaming file).
How can I fix it? And with this method, user and password are hidden with https? I spend already 2 days. Thanks

Categories