1
java -cp catalina.jar org.apache.catalina.util.ServerInfo
Server version: Apache Tomcat/6.0.53
Server built:   Apr 19 2017 22:34:06 UTC
Server number:  6.0.53.0
OS Name:        Linux
OS Version:     4.1.7-15.23.amzn1.x86_64
Architecture:   amd64
JVM Version:    1.8.0_171-b10
JVM Vendor:     Oracle Corporation

当我在独立的 java 代码中运行相同的代码时,我得到响应,而当我在 web 应用程序中运行时,我得到了这个错误

Java 1.8 和 tomcat 6.0.53 原因:java.io.EOFException:SSL 对等体错误关闭

代码:

HttpClient httpclient = HttpClientBuilder.create().build();
//        HttpClient httpclient = buildInfoPayHttpClient();
//        if (httpclient == null) {
//            return null;
//        }
        try {
            StringBuilder sb = new StringBuilder();
            sb.append(FlintoUtils.getPayUFetchUrl());

            List<NameValuePair> postParameters =  new ArrayList<NameValuePair>();
            postParameters.add(new BasicNameValuePair("key", FlintoUtils.getPayuMerchantKey()));
            postParameters.add(new BasicNameValuePair("command", "verify_payment"));
            postParameters.add(new BasicNameValuePair("hash", hash));
            postParameters.add(new BasicNameValuePair("var1", orderId.toString()));

            HttpPost httppost = new HttpPost(sb.toString());
            httppost.setEntity(new UrlEncodedFormEntity(postParameters));

            HttpResponse response = httpclient.execute(httppost);

            _log.warn(orderId.toString() + " Url:"+FlintoUtils.getPayUFetchUrl() + " Response: " + response.toString());

            // Get hold of the response entity
            HttpEntity outputEntity = response.getEntity();

            // If the response does not enclose an entity, there is no need
            // to worry about connection release
            if (outputEntity != null) {
                try {
                    String output = EntityUtils.toString(outputEntity);
                    _log.warn("output for order:" +orderId + "  is:" +output);
                    JSONObject jsonObject = new JSONObject(output);
                    return jsonObject;

                } catch (Exception ex) {
                    _log.error("Exception in fetchPayuStatus: " , ex);
                    throw ex;

                } 
            }
        } catch (Exception e) {
           _log.error("Exception in fetchPayuStatus: " , e);
        } 
        return null;


javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
            at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:963)
            at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1342)
            at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1369)
            at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1353)
            at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:275)
            at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:254)
            at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
            at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
            at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
            at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
            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 org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
            at com.flinto.core.admin.WebClientUtility.fetchPayuStatus(WebClientUtility.java:377)
            at com.flinto.web.controller.CreateOrderAdminController.updateOrderPaymentStatus(CreateOrderAdminController.java:849)
            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:219)
            at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
            at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100)
            at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604)
            at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565)
            at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
            at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
            at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
            at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
            at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at com.flinto.web.utils.WebCommon.urlRedirectByAccessRole(WebCommon.java:402)
            at com.flinto.web.filter.UrlRedirectionFilter.doFilter(UrlRedirectionFilter.java:37)
            at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
            at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:322)
            at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
            at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
            at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
            at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
            at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
            at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
            at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
            at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
            at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
            at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
            at org.springframework.security.web.access.channel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:144)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
            at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:184)
            at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:155)
            at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
            at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
            at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at com.flinto.web.filter.ApexDomainRedirectFilter.doFilter(ApexDomainRedirectFilter.java:37)
            at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
            at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
            at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:652)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
            at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:883)
            at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:756)
            at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:2391)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:622)
            at java.lang.Thread.run(Thread.java:748)
    Caused by: java.io.EOFException: SSL peer shut down incorrectly
            at sun.security.ssl.InputRecord.read(InputRecord.java:482)
            at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:944)
            ... 92 more
4

2 回答 2

1

最后我在朋友的帮助下解决了。我们能够调试并指出启用 SSL 调试的问题-Djavax.net.debug=ssl这将提供与 SSL 相关的所有调试日志。

问题是tomcat指的是java 1.8的旧版本。与旧版本的密码套件相比,新版本的 Java 1.8 具有更多可支持的密码套件。

服务器期待更强大的密码套件(从 TLS1.0 到 TLS1.2 的 PCI 标准更新)我很幸运地了解了底层过程

  1. 当我们调用 API 时,客户端通过提供安全协议和密码套件向服务器打招呼。 *** ClientHello, TLSv1.2

  2. 客户端 - 服务器握手发生

  3. 服务器向客户端发送 Hello

    Extension extended_master_secret Extension server_name, server_name: [type=host_name (0), value=*****] http-443-exec-5, WRITE: TLSv1.2 Handshake, length = 206 http-443-exec-5, READ :TLSv1.2 握手,长度 = 93 *** ServerHello,TLSv1.2

  4. 使用密码套件验证证书

  5. 允许对服务器的 api 调用
  6. 写回复给客户

SSL - 对我来说仍然是一个未解之谜,也是一个永远工作的可爱话题。SSL 将双手伸入大脑 :-)

于 2018-05-14T14:05:32.003 回答
1

你必须添加下面的行来解决握手错误

System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");

您可以在此处此处找到相关文章

于 2018-05-08T12:47:19.003 回答