ews-java-api-2.0 访问SSL异常

elewyeen 发布于 2015/06/16 17:11
阅读 2K+
收藏 0

测试ews-java-api是否能和exchange服务通信,代码如下:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);

ExchangeCredentials credentials = new WebCredentials(username,
password);
 service.setCredentials(credentials);
service.setTraceEnabled(true);
        try {
service.setUrl(new URI("https://192.xxx.xxx.xxx/EWS/Exchange.asmx"));

 Folder inbox = Folder.bind(service, WellKnownFolderName.Inbox);//该行抛出异常
       System.out.println(inbox.getDisplayName());

} catch ( Exception e) {
e.printStackTrace();

}

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)

加载中
0
揽胜极光
揽胜极光
服务器证书和证书上的CN字段不匹配
0
ooooooooosc
ooooooooosc
楼主怎么解决的?
0
漫步1223
漫步1223

大神,这个问题解决了吗?


0
_鱼_
_鱼_

我是通过修改域名验证器来解决,先新写一个类:

public class ExchangeServiceWithHostVerify extends ExchangeService {     //不对任何域名做验证     private final static HostnameVerifier hostnameVerifierWithOutVerfy = new HostnameVerifier(){         @Override         public boolean verify(String s, SSLSession sslSession) {             return true;         }     };     public ExchangeServiceWithHostVerify() {         super();     }     public ExchangeServiceWithHostVerify(ExchangeVersion requestedServerVersion) {         super(requestedServerVersion);     }     protected Registry<ConnectionSocketFactory> createConnectionSocketFactoryRegistry() {         try {             return RegistryBuilder.<ConnectionSocketFactory>create()                     .register(EWSConstants.HTTP_SCHEME, new PlainConnectionSocketFactory())                     .register(EWSConstants.HTTPS_SCHEME, EwsSSLProtocolSocketFactory.build(null,hostnameVerifierWithOutVerfy))                     .build();         } catch (GeneralSecurityException e) {             throw new RuntimeException(                     "Could not initialize ConnectionSocketFactory instances for HttpClientConnectionManager", e             );         }     } }

建立客户端的时候:

ExchangeService service = new ExchangeServiceWithHostVerify(ExchangeVersion.Exchange2007_SP1);

 

 

返回顶部
顶部