Java笔记-解决WebServiceTemplate中No subject alternative names matching IP address xxx
Posted IT1995
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java笔记-解决WebServiceTemplate中No subject alternative names matching IP address xxx相关的知识,希望对你有一定的参考价值。
主要的原因是证书有问题,就是程序的IP地址和证书的IP地址不匹配。
这里是客户端报错,使用的是spring-ws
对应的Maven如下;
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-security</artifactId>
<version>3.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>3.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-support</artifactId>
<version>3.0.8.RELEASE</version>
</dependency>
生成的bean
@Bean
HttpsUrlConnectionMessageSender messageSender(
KeyStoreFactoryBean keyStore,
TrustManagersFactoryBean trustManagers
) throws Exception {
HttpsUrlConnectionMessageSender sender = new HttpsUrlConnectionMessageSender();
KeyManagersFactoryBean keyManagersFactoryBean = new KeyManagersFactoryBean();
keyManagersFactoryBean.setKeyStore(keyStore.getObject());
keyManagersFactoryBean.setPassword(KEYSTORE_PASSWORD);
keyManagersFactoryBean.afterPropertiesSet();
sender.setKeyManagers(keyManagersFactoryBean.getObject());
sender.setTrustManagers(trustManagers.getObject());
sender.setHostnameVerifier(new TrustAnyHostnameVerifier());
return sender;
}
public class TrustAnyHostnameVerifier implements HostnameVerifier {
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
这里调用代码:
@Autowired
HttpsUrlConnectionMessageSender sender;
public XXXResponse clear(String para){
XXXRequest request = new XXXRequest();
request.setValue(para);
getWebServiceTemplate().setMessageSender(sender);
JAXBElement<XXXtResponse> o = (JAXBElement<XXXtResponse>)
getWebServiceTemplate().marshalSendAndReceive("https://xxx.xxx.xxx.xxx:xxx/ws/xxxx", request);
return o.getValue();
}
这里要注意,要将生成的bean放到getWebserviceTemplate()的Sender中才能,不然不会生效的。
以上是关于Java笔记-解决WebServiceTemplate中No subject alternative names matching IP address xxx的主要内容,如果未能解决你的问题,请参考以下文章