SSLHandshakeException使用Spring WebServiceTemplate与https Web服务进行通信 [英] SSLHandshakeException talking to a https Web service using Spring WebServiceTemplate

查看:279
本文介绍了SSLHandshakeException使用Spring WebServiceTemplate与https Web服务进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误与https网络服务交谈。

I am getting the below error talking to a https webservice.

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

我使用的是Spring的WebServiceTemplate,而下面是我的xml配置

I am using spring's WebServiceTemplate and below's my xml configuration for it

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     
xmlns:p="http://www.springframework.org/schema/p"
xmlns:sws="http://www.springframework.org/schema/web-services"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/web-services
       http://www.springframework.org/schema/web-services/web-services-2.0.xsd
       http://www.springframework.org/schema/oxm 
       http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd">

<bean id="webServiceTemplate"
class="org.springframework.ws.client.core.WebServiceTemplate"
p:marshaller-ref="jaxbMarshaller" 
p:unmarshaller-ref="jaxbMarshaller"
p:defaultUri="https://XXXXXXXXXXXXXXXX"
p:messageSender-ref="messageSender">
<constructor-arg ref="messageFactory" />
</bean>

<bean id="messageSender"
class="org.springframework.ws.transport.http.CommonsHttpMessageSender" />

 <!-- <bean id="messageSender"
class="org.springframework.ws.transport.http.HttpsUrlConnectionMessageSender" /> -->

<bean id="messageFactory"
class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />

<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"
p:contextPath="com.test.schemas" />

</beans>

我可以从soapui获取服务,但不能从我编写的示例java代码中获取。有人可以指出为什么会发生这种情况以及如何解决这个问题?我们是否应该从第三方wsdl人那里收到一些安全证书?

I am able to hit the service from soapui but not from the sample java code I wrote. Could some one please point me to why this is happening and how I can resolve this? Should we have received some security certificates from the 3'rd party wsdl folks?

推荐答案

检查是否有效:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     
xmlns:p="http://www.springframework.org/schema/p"
xmlns:sws="http://www.springframework.org/schema/web-services"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/web-services
       http://www.springframework.org/schema/web-services/web-services-2.0.xsd
       http://www.springframework.org/schema/oxm 
       http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd">


<!-- HTTPS connection to trust self signed certificates -->
<bean id="sslSocketFactory" class="org.apache.http.conn.ssl.SSLSocketFactory">
    <constructor-arg name="trustStrategy">
        <bean class="org.apache.http.conn.ssl.TrustSelfSignedStrategy" />
    </constructor-arg>
    <constructor-arg name="hostnameVerifier">
        <bean class="org.apache.http.conn.ssl.AllowAllHostnameVerifier" />
    </constructor-arg>
</bean>

<bean id="httpsSchemaRegistry" class="org.apache.http.conn.scheme.SchemeRegistry">
    <property name="items">
        <map>
            <entry key="https">
                <bean class="org.apache.http.conn.scheme.Scheme">

                    <constructor-arg value="https" />
                    <constructor-arg value="443" />
                    <constructor-arg ref="sslSocketFactory" />
                </bean>
            </entry>
        </map>
    </property>
</bean>
<bean id="httpClient" class="org.apache.http.impl.client.DefaultHttpClient">
    <constructor-arg>
        <bean class="org.apache.http.impl.conn.PoolingClientConnectionManager">
            <constructor-arg ref="httpsSchemaRegistry" />
        </bean>
    </constructor-arg>
</bean>

<!-- <bean id="apacheHttpsRequestFactory"
    class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
    <constructor-arg ref="httpClient" />
-->
<bean id="webServiceTemplate"
class="org.springframework.ws.client.core.WebServiceTemplate"
p:marshaller-ref="jaxbMarshaller" 
p:unmarshaller-ref="jaxbMarshaller"
p:defaultUri="https://XXXXXXXXXXXXXXXX"
p:messageSender-ref="messageSender">
<constructor-arg ref="messageFactory" />
</bean>

<bean id="messageSender"
class="org.springframework.ws.transport.http.HttpComponentsMessageSender"
p:httpClient="httpClient" />


<bean id="messageFactory"
class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />

<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"
p:contextPath="com.test.schemas" />


</beans>

这篇关于SSLHandshakeException使用Spring WebServiceTemplate与https Web服务进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆