Source:
private URI getRedirectUrl(String domainName) throws EWSHttpException, XMLStreamException, IOException, ServiceLocalException, URISyntaxException { String url = String.format(AutodiscoverLegacyHttpUrl, "autodiscover." + domainName); this.traceMessage(TraceFlags.AutodiscoverConfiguration, String.format( "Trying to get Autodiscover redirection URL from %s.", url)); HttpWebRequest request = null; try { request = new HttpClientWebRequest(this.getSimpleHttpConnectionManager()); try { request.setUrl(URI.create(url).toURL()); } catch (MalformedURLException e) { String strErr = String.format("Incorrect format : %s", url); throw new ServiceLocalException(strErr); } request.setAllowAutoRedirect(false); request.setPreAuthenticate(false); request.setRequestMethod("GET"); request.setUseDefaultCredentials(this.getUseDefaultCredentials()); if (!this.getUseDefaultCredentials()) { ExchangeCredentials serviceCredentials = this.getCredentials(); if (null == serviceCredentials) { throw new ServiceLocalException(Strings.CredentialsRequired); } serviceCredentials.preAuthenticate(); serviceCredentials.prepareWebRequest(request); } try { request.prepareAsyncConnection(); } catch (Exception ex) { ex.getMessage(); request = null; } if (request != null) { URI redirectUrl; OutParam<URI> outParam = new OutParam<URI>(); if (this.tryGetRedirectionResponse(request, outParam)) { redirectUrl = outParam.getParam(); return redirectUrl; } } } finally { if (request != null) { try { request.close(); } catch (Exception e2) { } } } this.traceMessage(TraceFlags.AutodiscoverConfiguration, "No Autodiscover redirection URL was returned."); return null; }

Target:
private URI getRedirectUrl(String domainName) throws EWSHttpException, XMLStreamException, IOException, ServiceLocalException, URISyntaxException { String url = String.format(AutodiscoverLegacyHttpUrl, "autodiscover." + domainName); traceMessage(TraceFlags.AutodiscoverConfiguration, String.format("Trying to get Autodiscover redirection URL from %s.", url)); HttpWebRequest request = null; try { request = new HttpClientWebRequest(this.getSimpleHttpConnectionManager()); try { request.setUrl(URI.create(url).toURL()); } catch (MalformedURLException e) { String strErr = String.format("Incorrect format : %s", url); throw new ServiceLocalException(strErr); } request.setAllowAutoRedirect(false); request.setPreAuthenticate(false); request.setRequestMethod("GET"); request.setUseDefaultCredentials(this.getUseDefaultCredentials()); if (!this.getUseDefaultCredentials()) { ExchangeCredentials serviceCredentials = this.getCredentials(); if (null == serviceCredentials) { throw new ServiceLocalException(Strings.CredentialsRequired); } serviceCredentials.preAuthenticate(); serviceCredentials.prepareWebRequest(request); } try { request.prepareAsyncConnection(); } catch (Exception e) { log.warn("Error while preparing asynchronous connection.", e); traceMessage(TraceFlags.AutodiscoverConfiguration, "No Autodiscover redirection URL was returned."); return null; } OutParam<URI> outParam = new OutParam<URI>(); if (tryGetRedirectionResponse(request, outParam)) { return outParam.getParam(); } } finally { if (request != null) { try { request.close(); } catch (Exception e) { } } } traceMessage(TraceFlags.AutodiscoverConfiguration, "No Autodiscover redirection URL was returned."); return null; }