开发者社区> 问答> 正文

ews-java-api-2.0 访问SSL异常?报错

测试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)

展开
收起
爱吃鱼的程序员 2020-06-14 15:25:10 1240 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    服务器证书和证书上的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);

     

     

    2020-06-14 15:25:27
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Boot2.0实战Redis分布式缓存 立即下载
CUDA MATH API 立即下载
API PLAYBOOK 立即下载