2016-06-07 343 views
1

我已經配置了。我曾嘗試使用WebService的模板通過HTTPS這裏是我的配置如何配置WebServiceTemplate以在HTTPS下向服務器發送soap請求?

public GetCountryResponse find() throws MalformedURLException, GeneralSecurityException, IOException { 
    GetCountryRequest request = new GetCountryRequest(); 
    request.setName("Spain"); 
    SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault(); 

    LayeredConnectionSocketFactory sslSocketFactory = null; 
    try { 
     sslSocketFactory = new SSLConnectionSocketFactory(SSLContext.getDefault(), 
       SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); 
    } catch (NoSuchAlgorithmException e) { 
    } 

    KeyStore keyStore = KeyStore.getInstance("PKCS12"); 
    FileInputStream instream = new FileInputStream(new File("C:\\client.p12")); 
    try { 
     keyStore.load(instream, "password".toCharArray()); 
    } finally { 
     instream.close(); 
    } 

    // Trust own CA and all self-signed certs 
    SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, "password".toCharArray()) 
      // .loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()) 
      .build(); 
    // Allow TLSv1 protocol only 
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, 
      SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); // TODO 
    HttpClient httpclient = HttpClients.custom() 
      .setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) // TODO 
      .setSSLSocketFactory(sslsf).addInterceptorFirst(new ContentRemover()).build(); 

    HttpComponentsMessageSender messageSender = new HttpComponentsMessageSender(httpclient); 

    WebServiceMessageSender sender = messageSender; 

    WebServiceTemplate webServiceTemplate = getWebServiceTemplate(); 
    webServiceTemplate.setMessageSender(sender); 

    GetCountryResponse response = (GetCountryResponse) webServiceTemplate.marshalSendAndReceive(
      "https://localhost:8443/ws/countries.wsdl", request, 
      new SoapActionCallback("https://localhost:8443/ws/")); 

    return response; 
} 

我收到以下錯誤

%% Invalidated: [Session-4, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384] 
    http-nio-8444-exec-2, SEND TLSv1.2 ALERT: fatal, description = certificate_unknown 
    http-nio-8444-exec-2, WRITE: TLSv1.2 Alert, length = 2 
    http-nio-8444-exec-2, called closeSocket() 
    http-nio-8444-exec-2, handling exception: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
    14:38:01.080 [http-nio-8444-exec-2] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-1: Shutdown connection 
    http-nio-8444-exec-2, called close() 
    http-nio-8444-exec-2, called closeInternal(true) 
    14:38:01.080 [http-nio-8444-exec-2] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection discarded 
    14:38:01.080 [http-nio-8444-exec-2] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-1: Close connection 
    14:38:01.080 [http-nio-8444-exec-2] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 1][route: {s}->https://localhost:8443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20] 
    14:38:01.080 [http-nio-8444-exec-2] DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Resolving exception from handler [public com.covenant.app.wsdl.GetCountryResponse com.covenant.app.controllers.DealController.findAllDeals()]: org.springframework.ws.client.WebServiceIOException: I/O error: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
    14:38:01.080 [http-nio-8444-exec-2] DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Invoking @ExceptionHandler method: public org.springframework.http.ResponseEntity<java.lang.String> com.covenant.app.controllers.DealController.errorHandler(java.lang.Exception) 
    14:38:01 [http-nio-8444-exec-2] DealController - I/O error: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
    org.springframework.ws.client.WebServiceIOException: I/O error: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
     at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:561) 
     at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390) 
     at com.covenant.app.services.WeatherClient.find(WeatherClient.java:90) 
     at com.covenant.app.controllers.DealController.findAllDeals(DealController.java:34) 
     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:136) 
     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:777) 
     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706) 
     at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) 
     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) 
     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) 
     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) 
     at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) 
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) 
     at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) 
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 
     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.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:614) 
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) 
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 
     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) 
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) 
     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) 
     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) 
     at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1757) 
     at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1716) 
     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: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
     at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) 
     at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949) 
     at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) 
     at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) 
     at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509) 
     at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216) 
     at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979) 
     at sun.security.ssl.Handshaker.process_record(Handshaker.java:914) 
     at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062) 
     at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) 
     at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) 
     at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) 
     at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:262) 
     at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:118) 
     at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) 
     at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) 
     at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) 
     at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) 
     at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) 
     at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) 
     at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) 
     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 org.springframework.ws.transport.http.HttpComponentsConnection.onSendAfterWrite(HttpComponentsConnection.java:121) 
     at org.springframework.ws.transport.AbstractWebServiceConnection.send(AbstractWebServiceConnection.java:48) 
     at org.springframework.ws.client.core.WebServiceTemplate.sendRequest(WebServiceTemplate.java:658) 
     at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:606) 
     at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555) 
     ... 41 more 
    Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
     at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387) 
     at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292) 
     at sun.security.validator.Validator.validate(Validator.java:260) 
     at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324) 
     at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229) 
     at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124) 
     at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491) 
     ... 65 more 
    Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
     at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:146) 
     at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:131) 
     at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280) 
     at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382) 
     ... 71 more 
    14:38:01.094 [http-nio-8444-exec-2] DEBUG org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdviceChain - Invoking ResponseBodyAdvice chain for body=I/O error: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
    14:38:01.094 [http-nio-8444-exec-2] DEBUG org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdviceChain - After ResponseBodyAdvice chain body=I/O error: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
    http-nio-8444-exec-2, WRITE: TLSv1.2 Application Data, length = 669 
    14:38:01.096 [http-nio-8444-exec-2] DEBUG org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor - Written [I/O error: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target] as "text/html" using [[email protected]423e86] 
    14:38:01.096 [http-nio-8444-exec-2] DEBUG org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling 
    14:38:01.096 [http-nio-8444-exec-2] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request 
    http-nio-8444-exec-2, called closeOutbound() 
    http-nio-8444-exec-2, closeOutboundInternal() 
    http-nio-8444-exec-2, SEND TLSv1.2 ALERT: warning, description = close_notify 
    http-nio-8444-exec-2, WRITE: TLSv1.2 Alert, length = 26 
    http-nio-8444-exec-4, called closeOutbound() 
    http-nio-8444-exec-4, closeOutboundInternal() 

在瀏覽器中使用Web服務的應用程序密鑰存儲和trustore我收到以下錯誤

I/O error: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 

我在互聯網上搜索解決方案,所以我嘗試使用

SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, 
      SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); // TODO 
    HttpClient httpclient = HttpClients.custom() 
      .setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) // TODO 
      .setSSLSocketFactory(sslsf).build(); 

    HttpComponentsMessageSender messageSender = new HttpComponentsMessageSender(httpclient); 

    WebServiceMessageSender sender = messageSender; 

    WebServiceTemplate webServiceTemplate = getWebServiceTemplate(); 
    webServiceTemplate.setMessageSender(sender); 

但後來我得到下面的異常

trustStore is: C:\trustore.jks 
    trustStore type is : jks 
    trustStore provider is : 
    init truststore 
    adding as trusted cert: 
     Subject: [email protected], CN=localhost, OU=localhost, O=ITCOVENANT, L=Coimbatore, ST=Tamil Badu, C=IN 
     Issuer: [email protected], CN=localhost, OU=localhost, O=ITCOVENANT, L=Coimbatore, ST=Tamil Badu, C=IN 
     Algorithm: RSA; Serial number: 0x9f141ecadb1b5892 
     Valid from Mon Jun 06 22:09:30 IST 2016 until Tue Jun 06 22:09:30 IST 2017 

    trigger seeding of SecureRandom 
    done seeding SecureRandom 
    00:00:38.964 [http-nio-8444-exec-2] DEBUG org.springframework.ws.client.core.WebServiceTemplate - Opening [[email protected]7cea62b] to [https://localhost:8443/ws/countries.wsdl] 
    00:00:39.032 [http-nio-8444-exec-2] DEBUG org.springframework.ws.client.MessageTracing.sent - Sent request [SaajSoapMessage {http://spring.io/guides/gs-producing-web-service}getCountryRequest] 
    00:00:39.085 [http-nio-8444-exec-2] DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Resolving exception from handler [public com.covenant.app.wsdl.GetCountryResponse com.covenant.app.controllers.DealController.findAllDeals() throws java.net.MalformedURLException,java.security.GeneralSecurityException,java.io.IOException]: org.springframework.ws.client.WebServiceIOException: I/O error: null; nested exception is org.apache.http.client.ClientProtocolException 
    00:00:39.089 [http-nio-8444-exec-2] DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Invoking @ExceptionHandler method: public org.springframework.http.ResponseEntity<java.lang.String> com.covenant.app.controllers.DealController.errorHandler(java.lang.Exception) 
    00:00:39 [http-nio-8444-exec-2] DealController - I/O error: null; nested exception is org.apache.http.client.ClientProtocolException 
    org.springframework.ws.client.WebServiceIOException: I/O error: null; nested exception is org.apache.http.client.ClientProtocolException 
     at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:561) 
     at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390) 
     at com.covenant.app.services.WeatherClient.find(WeatherClient.java:98) 
     at com.covenant.app.controllers.DealController.findAllDeals(DealController.java:37) 
     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:136) 
     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:777) 
     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706) 
     at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) 
     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) 
     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) 
     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) 
     at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) 
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) 
     at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) 
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 
     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.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:614) 
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) 
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 
     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) 
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) 
     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) 
     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) 
     at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1757) 
     at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1716) 
     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: org.apache.http.client.ClientProtocolException 
     at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:188) 
     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 org.springframework.ws.transport.http.HttpComponentsConnection.onSendAfterWrite(HttpComponentsConnection.java:121) 
     at org.springframework.ws.transport.AbstractWebServiceConnection.send(AbstractWebServiceConnection.java:48) 
     at org.springframework.ws.client.core.WebServiceTemplate.sendRequest(WebServiceTemplate.java:658) 
     at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:606) 
     at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555) 
     ... 41 more 
    Caused by: org.apache.http.ProtocolException: Content-Length header already present 
     at org.apache.http.protocol.RequestContent.process(RequestContent.java:96) 
     at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:132) 
     at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:192) 
     at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) 
     at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) 
     at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) 
     ... 49 more 
    00:00:39.111 [http-nio-8444-exec-2] DEBUG org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdviceChain - Invoking ResponseBodyAdvice chain for body=I/O error: null; nested exception is org.apache.http.client.ClientProtocolException 
    00:00:39.111 [http-nio-8444-exec-2] DEBUG org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdviceChain - After ResponseBodyAdvice chain body=I/O error: null; nested exception is org.apache.http.client.ClientProtocolException 
    http-nio-8444-exec-2, WRITE: TLSv1.2 Application Data, length = 303 
    00:00:39.115 [http-nio-8444-exec-2] DEBUG org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor - Written [I/O error: null; nested exception is org.apache.http.client.ClientProtocolException] as "text/html" using [[email protected]c86e91] 
    00:00:39.115 [http-nio-8444-exec-2] DEBUG org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling 
    00:00:39.115 [http-nio-8444-exec-2] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request 
    http-nio-8444-exec-2, called closeOutbound() 
    http-nio-8444-exec-2, closeOutboundInternal() 
    http-nio-8444-exec-2, SEND TLSv1.2 ALERT: warning, description = close_notify 
    http-nio-8444-exec-2, WRITE: TLSv1.2 Alert, length = 26 
    http-nio-8444-exec-5, called closeOutbound() 
    http-nio-8444-exec-5, closeOutboundInternal() 
    http-nio-8444-exec-5, SEND TLSv1.2 ALERT: warning, description = close_notify 
    http-nio-8444-exec-5, WRITE: TLSv1.2 Alert, length = 26 
    http-nio-8444-exec-4, called closeOutbound() 
    http-nio-8444-exec-4, closeOutboundInternal() 
    http-nio-8444-exec-4, SEND TLSv1.2 ALERT: warning, description = close_notify 
    http-nio-8444-exec-4, WRITE: TLSv1.2 Alert, length = 26 
    http-nio-8444-exec-9, called closeOutbound() 
    http-nio-8444-exec-9, closeOutboundInternal() 
    http-nio-8444-exec-9, SEND TLSv1.2 ALERT: warning, description = close_notify 
    http-nio-8444-exec-9, WRITE: TLSv1.2 Alert, length = 26 

如果我

HttpClient httpclient = HttpClients.custom() 
       .setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) // TODO 
      .setSSLSocketFactory(sslsf).addInterceptorFirst(new ContentRemover()).build(); 

內容卸妝類一起添加以下代碼:

public class ContentRemover implements HttpRequestInterceptor{ 

@Override 
public void process(HttpRequest request, HttpContext context) 
     throws HttpException, IOException { 

    if (request instanceof HttpEntityEnclosingRequest) { 
     System.out.println("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"); 
     if (request.containsHeader(HTTP.TRANSFER_ENCODING)) { 
      request.removeHeaders(HTTP.TRANSFER_ENCODING); 
     } 
     if (request.containsHeader(HTTP.CONTENT_LEN)) { 
      request.removeHeaders(HTTP.CONTENT_LEN); 
     } 
    } 
} 

}

再說我得到的是

I/O error: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 

敬請幫助。如果任何鏈接或代碼示例相同的錯誤好心更新

回答

1

我終於找到了解決方案,我剛同時運行Tomcat 7指定密鑰存儲和trustore作爲VM參數工作

-Djavax.net.ssl.keyStoreType=jks 
-Djavax.net.ssl.keyStore="C:\keystore.jks" 
-Djavax.net.ssl.keyStorePassword=password 
-Djavax.net.ssl.trustStore="C:\trustore.jks" 
-Djavax.net.ssl.trustStorePassword=password 
-Djavax.net.debug=SSL 
1

按照以下步驟永久性的解決方案

步驟1

  1. 在Chrome瀏覽器中打開您的https鏈接。
  2. 在地址欄中點擊您網址左側的鎖定符號。
  3. 點擊查看詳情>>查看證書
  4. 點擊層級中最頂層的證書。
  5. 將該矩形證書圖像拖放到桌面上。

步驟2 請參考this鏈接,以節省您的證書是在桌面上,現在到CACERT文件。

步驟3 重新啓動您的IDE

你的問題現在已經解決了!

+1

它開始我已經添加了證書CACERT文件,但我仍然得到同樣的錯誤 – briantaurostack7

+0

確保它是這個應用程序使用的同一個jre cacerts文件!很多時候可能存在多個jre!把證書放在每一個cacerts文件中。如果你的問題沒有解決,請把所有的細節都放在這裏,這樣我就可以找出可能的解決方案。 – positivecrux

+0

我已經將證書添加到jdk和jre,但它仍然給我提供了同樣的錯誤 – briantaurostack7

相關問題