0
自動検出URLを使用してExchangeサーバーに接続しようとしています。 RESTクライアントを使用して実行している場合、URLは、WSDLファイルを返して:Javaで自動検出を使用してExchange Serverに接続する
System.setProperty("javax.net.ssl.trustStore", "truststore.jks");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(new FileInputStream("truststore.jks"), null);
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
SSLContext ctx = SSLContext.getInstance("SSL");
ctx.init(null, trustManagerFactory.getTrustManagers(), null);
HostnameVerifier hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
ClientConfig config = new com.sun.jersey.api.client.config.DefaultClientConfig();
client = Client.create(config);
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hostnameVerifier, ctx));
webResource = client.resource("https://autodiscover.company.com/xxxx/autodiscover.svc");
client.addFilter(new HTTPBasicAuthFilter(username, password));
しかし、交換サービスを使用して実行しているとき、それは401不正エラーを返して:
System.setProperty("javax.net.ssl.trustStore", "truststore.jks");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(new FileInputStream("truststore.jks"),null);
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
SSLContext ctx = SSLContext.getInstance("SSL");
ctx.init(null, trustManagerFactory.getTrustManagers(), null);
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.setTraceEnabled(true);
service.setPreAuthenticate(true);
ExchangeCredentials credentials = new WebCredentials(username,password,domain);
service.setCredentials(credentials);
service.setUserAgent(user);
service.setUrl(new java.net.URI("https://autodiscover.company.com/xxxx/autodiscover.svc"));
には、以下のスタックトレースです:
microsoft.exchange.webservices.data.HttpErrorException: The remote server returned an error: (401)Unauthorize
at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:729)
at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:36)
at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:140)
at microsoft.exchange.webservices.data.ExchangeService.findItems(ExchangeService.java:945)
at microsoft.exchange.webservices.data.ExchangeService.findItems(ExchangeService.java:998)
at microsoft.exchange.webservices.data.ExchangeService.findItems(ExchangeService.java:1070)
をお勧めします。