测试ews-java-api是否能和exchange服务通信,代码如下:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
ExchangeCredentials credentials = new WebCredentials(username,}
jar包:
运行后 报错:
microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. The request failed. Host name '192.xxx.xxx.xxx' does not match the certificate subject provided by the peer (CN=exchange)
服务器证书和证书上的CN字段不匹配楼主怎么解决的?
大神,这个问题解决了吗?
我是通过修改域名验证器来解决,先新写一个类:
publicclassExchangeServiceWithHostVerifyextendsExchangeService{ //不对任何域名做验证 privatefinalstaticHostnameVerifierhostnameVerifierWithOutVerfy=newHostnameVerifier(){ <aclass="referer"target="_blank">@Override publicbooleanverify(Strings,SSLSessionsslSession){ returntrue; } }; publicExchangeServiceWithHostVerify(){ super(); } publicExchangeServiceWithHostVerify(ExchangeVersionrequestedServerVersion){ super(requestedServerVersion); } protectedRegistry<ConnectionSocketFactory>createConnectionSocketFactoryRegistry(){ try{ returnRegistryBuilder.<ConnectionSocketFactory>create() .register(EWSConstants.HTTP_SCHEME,newPlainConnectionSocketFactory()) .register(EWSConstants.HTTPS_SCHEME,EwsSSLProtocolSocketFactory.build(null,hostnameVerifierWithOutVerfy)) .build(); }catch(GeneralSecurityExceptione){ thrownewRuntimeException( "CouldnotinitializeConnectionSocketFactoryinstancesforHttpClientConnectionManager",e ); } }}
建立客户端的时候:
ExchangeServiceservice=newExchangeServiceWithHostVerify(ExchangeVersion.Exchange2007_SP1);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。