Skip to content

Commit

Permalink
#1
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Popov committed Dec 25, 2019
1 parent 893b498 commit 2ee89ba
Show file tree
Hide file tree
Showing 156 changed files with 3,289 additions and 3,355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public final class AlternateMailboxCollection {
* Initializes a new instance of the class
*/
public AlternateMailboxCollection() {
this.setEntries(new ArrayList<AlternateMailbox>());
this.setEntries(new ArrayList<>());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private DnsSrvRecord findBestMatchingSrvRecord(String domain)
return null;
}

List<DnsSrvRecord> bestDnsSrvRecordList = new ArrayList<DnsSrvRecord>();
List<DnsSrvRecord> bestDnsSrvRecordList = new ArrayList<>();
for (DnsSrvRecord dnsSrvRecord : dnsSrvRecordList) {
if (dnsSrvRecord.getPort() == SslPort &&
dnsSrvRecord.getPriority() == priority &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public abstract class AutodiscoverResponseCollection
*/
public AutodiscoverResponseCollection() {
super();
this.responses = new ArrayList<TResponse>();
this.responses = new ArrayList<>();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,11 @@ TSettings getLegacyUserSettingsAtUrl(

TSettings settings = cls.newInstance();

HttpWebRequest request = null;
try {
request = this.prepareHttpWebRequestForUrl(url);
try (HttpWebRequest request = this.prepareHttpWebRequestForUrl(url)) {

this.traceHttpRequestHeaders(
TraceFlags.AutodiscoverRequestHttpHeaders,
request);
TraceFlags.AutodiscoverRequestHttpHeaders,
request);
// OutputStreamWriter out = new
// OutputStreamWriter(request.getOutputStream());
OutputStream urlOutStream = request.getOutputStream();
Expand All @@ -285,16 +283,16 @@ TSettings getLegacyUserSettingsAtUrl(
PrintWriter writer = new PrintWriter(urlOutStream);
this.writeLegacyAutodiscoverRequest(emailAddress, settings, writer);

/* Flush Start */
/* Flush Start */
writer.flush();
urlOutStream.flush();
urlOutStream.close();
/* Flush End */
/* Flush End */
}
request.executeRequest();
request.getResponseCode();
URI redirectUrl;
OutParam<URI> outParam = new OutParam<URI>();
OutParam<URI> outParam = new OutParam<>();
if (this.tryGetRedirectionResponse(request, outParam)) {
redirectUrl = outParam.getParam();
settings.makeRedirectionResponse(redirectUrl);
Expand All @@ -321,7 +319,7 @@ TSettings getLegacyUserSettingsAtUrl(

this.traceResponse(request, memoryStream);
ByteArrayInputStream memoryStreamIn = new ByteArrayInputStream(
memoryStream.toByteArray());
memoryStream.toByteArray());
EwsXmlReader reader = new EwsXmlReader(memoryStreamIn);
reader.read(new XmlNodeType(XmlNodeType.START_DOCUMENT));
settings.loadFromXml(reader);
Expand All @@ -333,15 +331,8 @@ TSettings getLegacyUserSettingsAtUrl(
}

serviceResponseStream.close();
} finally {
if (request != null) {
try {
request.close();
} catch (Exception e2) {
// Ignore exception while closing the request.
}
}
}
// Ignore exception while closing the request.

return settings;
}
Expand Down Expand Up @@ -386,10 +377,7 @@ private URI getRedirectUrl(String domainName)
traceMessage(TraceFlags.AutodiscoverConfiguration,
String.format("Trying to get Autodiscover redirection URL from %s.", url));

HttpWebRequest request = null;

try {
request = new HttpClientWebRequest(httpClient, httpContext);
try (HttpWebRequest request = new HttpClientWebRequest(httpClient, httpContext)) {
request.setProxy(getWebProxy());

try {
Expand All @@ -416,19 +404,12 @@ private URI getRedirectUrl(String domainName)
return null;
}

OutParam<URI> outParam = new OutParam<URI>();
OutParam<URI> outParam = new OutParam<>();
if (tryGetRedirectionResponse(request, outParam)) {
return outParam.getParam();
}
} finally {
if (request != null) {
try {
request.close();
} catch (Exception e) {
// Ignore exception when closing the request
}
}
}
// Ignore exception when closing the request

traceMessage(TraceFlags.AutodiscoverConfiguration, "No Autodiscover redirection URL was returned.");
return null;
Expand Down Expand Up @@ -516,9 +497,9 @@ else if (!(this.domain == null || this.domain.isEmpty())) {
// No Url or Domain specified, need to
//figure out which endpoint to use.
int currentHop = 1;
OutParam<Integer> outParam = new OutParam<Integer>();
OutParam<Integer> outParam = new OutParam<>();
outParam.setParam(currentHop);
List<String> redirectionEmailAddresses = new ArrayList<String>();
List<String> redirectionEmailAddresses = new ArrayList<>();
return this.internalGetLegacyUserSettings(
cls,
emailAddress,
Expand Down Expand Up @@ -547,7 +528,7 @@ TSettings internalGetLegacyUserSettings(
String domainName = EwsUtilities.domainFromEmailAddress(emailAddress);

int scpUrlCount;
OutParam<Integer> outParamInt = new OutParam<Integer>();
OutParam<Integer> outParamInt = new OutParam<>();
List<URI> urls = this.getAutodiscoverServiceUrls(domainName, outParamInt);
scpUrlCount = outParamInt.getParam();
if (urls.size() == 0) {
Expand Down Expand Up @@ -682,7 +663,7 @@ TSettings internalGetLegacyUserSettings(
} catch (Exception ex) {
HttpWebRequest response = null;
URI redirectUrl;
OutParam<URI> outParam1 = new OutParam<URI>();
OutParam<URI> outParam1 = new OutParam<>();
if ((response != null) &&
this.tryGetRedirectionResponse(response, outParam1)) {
redirectUrl = outParam1.getParam();
Expand Down Expand Up @@ -717,7 +698,7 @@ TSettings internalGetLegacyUserSettings(
// address. (This will be a common scenario for
// DataCenter deployments).
URI redirectionUrl = this.getRedirectUrl(domainName);
OutParam<TSettings> outParam = new OutParam<TSettings>();
OutParam<TSettings> outParam = new OutParam<>();
if ((redirectionUrl != null)
&& this.tryLastChanceHostRedirection(cls, emailAddress,
redirectionUrl, outParam)) {
Expand Down Expand Up @@ -800,7 +781,7 @@ protected URI getRedirectionUrlFromDnsSrvRecord(String domainName)
Class<TSettings> cls, String emailAddress, URI redirectionUrl,
OutParam<TSettings> settings) throws AutodiscoverLocalException,
AutodiscoverRemoteException, Exception {
List<String> redirectionEmailAddresses = new ArrayList<String>();
List<String> redirectionEmailAddresses = new ArrayList<>();

// Bug 60274: Performing a non-SSL HTTP GET to retrieve a redirection
// URL is potentially unsafe. We allow the caller
Expand All @@ -825,7 +806,7 @@ protected URI getRedirectionUrlFromDnsSrvRecord(String domainName)
// in SCP lookups. Disable consideration of SCP records.
this.disableScpLookupIfDuplicateRedirection(settings.getParam().getRedirectTarget(),
redirectionEmailAddresses);
OutParam<Integer> outParam = new OutParam<Integer>();
OutParam<Integer> outParam = new OutParam<>();
outParam.setParam(currentHop);
settings.setParam(
this.internalGetLegacyUserSettings(cls,
Expand Down Expand Up @@ -886,7 +867,7 @@ protected URI getRedirectionUrlFromDnsSrvRecord(String domainName)
} catch (Exception ex) {
// TODO: BUG response is always null
HttpWebRequest response = null;
OutParam<URI> outParam = new OutParam<URI>();
OutParam<URI> outParam = new OutParam<>();
if ((response != null)
&& this.tryGetRedirectionResponse(response,
outParam)) {
Expand Down Expand Up @@ -978,10 +959,10 @@ protected GetUserSettingsResponse internalGetLegacyUserSettings(
protected GetUserSettingsResponse internalGetSoapUserSettings(
String smtpAddress,
List<UserSettingName> requestedSettings) throws Exception {
List<String> smtpAddresses = new ArrayList<String>();
List<String> smtpAddresses = new ArrayList<>();
smtpAddresses.add(smtpAddress);

List<String> redirectionEmailAddresses = new ArrayList<String>();
List<String> redirectionEmailAddresses = new ArrayList<>();
redirectionEmailAddresses.add(smtpAddress.toLowerCase());

for (int currentHop = 0; currentHop < AutodiscoverService.AutodiscoverMaxRedirections; currentHop++) {
Expand Down Expand Up @@ -1120,7 +1101,7 @@ else if (!(this.domain == null || this.domain.isEmpty())) {

String domainName = getDomainMethod.func();
int scpHostCount;
OutParam<Integer> outParam = new OutParam<Integer>();
OutParam<Integer> outParam = new OutParam<>();
List<String> hosts = this.getAutodiscoverServiceHosts(domainName,
outParam);
scpHostCount = outParam.getParam();
Expand All @@ -1132,7 +1113,7 @@ else if (!(this.domain == null || this.domain.isEmpty())) {
for (int currentHostIndex = 0; currentHostIndex < hosts.size(); currentHostIndex++) {
String host = hosts.get(currentHostIndex);
boolean isScpHost = currentHostIndex < scpHostCount;
OutParam<URI> outParams = new OutParam<URI>();
OutParam<URI> outParams = new OutParam<>();
if (this.tryGetAutodiscoverEndpointUrl(host, outParams)) {
autodiscoverUrl = outParams.getParam();
response = getSettingsMethod.func(identities, settings,
Expand All @@ -1155,7 +1136,7 @@ else if (!(this.domain == null || this.domain.isEmpty())) {
// Next-to-last chance: try unauthenticated GET over HTTP to be
// redirected to appropriate service endpoint.
autodiscoverUrl = this.getRedirectUrl(domainName);
OutParam<URI> outParamUrl = new OutParam<URI>();
OutParam<URI> outParamUrl = new OutParam<>();
if ((autodiscoverUrl != null) &&
this
.callRedirectionUrlValidationCallback(
Expand Down Expand Up @@ -1323,7 +1304,7 @@ private GetDomainSettingsResponseCollection internalGetDomainSettings(
*/
private URI getAutodiscoverEndpointUrl(String host) throws Exception {
URI autodiscoverUrl = null;
OutParam<URI> outParam = new OutParam<URI>();
OutParam<URI> outParam = new OutParam<>();
if (this.tryGetAutodiscoverEndpointUrl(host, outParam)) {
return autodiscoverUrl;
} else {
Expand All @@ -1345,7 +1326,7 @@ private boolean tryGetAutodiscoverEndpointUrl(String host,
throws Exception {
EnumSet<AutodiscoverEndpoints> endpoints;
OutParam<EnumSet<AutodiscoverEndpoints>> outParam =
new OutParam<EnumSet<AutodiscoverEndpoints>>();
new OutParam<>();
if (this.tryGetEnabledEndpointsForHost(host, outParam)) {
endpoints = outParam.getParam();
url
Expand Down Expand Up @@ -1454,7 +1435,7 @@ protected List<URI> getAutodiscoverServiceUrls(String domainName,
OutParam<Integer> scpHostCount) throws URISyntaxException {
List<URI> urls;

urls = new ArrayList<URI>();
urls = new ArrayList<>();

scpHostCount.setParam(urls.size());

Expand All @@ -1481,7 +1462,7 @@ protected List<String> getAutodiscoverServiceHosts(String domainName,
ClassNotFoundException {

List<URI> urls = this.getAutodiscoverServiceUrls(domainName, outParam);
List<String> lst = new ArrayList<String>();
List<String> lst = new ArrayList<>();
for (URI url : urls) {
lst.add(url.getHost());
}
Expand All @@ -1508,9 +1489,7 @@ private boolean tryGetEnabledEndpointsForHost(String host,

endpoints.setParam(EnumSet.of(AutodiscoverEndpoints.None));

HttpWebRequest request = null;
try {
request = new HttpClientWebRequest(httpClient, httpContext);
try (HttpWebRequest request = new HttpClientWebRequest(httpClient, httpContext)) {
request.setProxy(getWebProxy());

try {
Expand All @@ -1535,30 +1514,23 @@ private boolean tryGetEnabledEndpointsForHost(String host,
return false;
}

OutParam<URI> outParam = new OutParam<URI>();
OutParam<URI> outParam = new OutParam<>();
if (this.tryGetRedirectionResponse(request, outParam)) {
URI redirectUrl = outParam.getParam();
this.traceMessage(TraceFlags.AutodiscoverConfiguration,
String.format("Host returned redirection to host '%s'", redirectUrl.getHost()));
String.format("Host returned redirection to host '%s'", redirectUrl.getHost()));

host = redirectUrl.getHost();
} else {
endpoints.setParam(this.getEndpointsFromHttpWebResponse(request));

this.traceMessage(TraceFlags.AutodiscoverConfiguration,
String.format("Host returned enabled endpoint flags: %s", endpoints.getParam().toString()));
String.format("Host returned enabled endpoint flags: %s", endpoints.getParam().toString()));

return true;
}
} finally {
if (request != null) {
try {
request.close();
} catch (Exception e) {
// Connection can't be closed. We'll ignore this...
}
}
}
// Connection can't be closed. We'll ignore this...
}

this.traceMessage(TraceFlags.AutodiscoverConfiguration,
Expand Down Expand Up @@ -1833,7 +1805,7 @@ public AutodiscoverService(ExchangeServiceBase service) {
*/
public GetUserSettingsResponse getUserSettings(String userSmtpAddress,
UserSettingName... userSettingNames) throws Exception {
List<UserSettingName> requestedSettings = new ArrayList<UserSettingName>();
List<UserSettingName> requestedSettings = new ArrayList<>();
requestedSettings.addAll(Arrays.asList(userSettingNames));

if (userSmtpAddress == null || userSmtpAddress.isEmpty()) {
Expand Down Expand Up @@ -1871,9 +1843,9 @@ public GetUserSettingsResponseCollection getUsersSettings(
String.format("The Autodiscover service only supports %s or a later version.",
MinimumRequestVersionForAutoDiscoverSoapService));
}
List<String> smtpAddresses = new ArrayList<String>();
List<String> smtpAddresses = new ArrayList<>();
smtpAddresses.addAll((Collection<? extends String>) userSmtpAddresses);
List<UserSettingName> settings = new ArrayList<UserSettingName>();
List<UserSettingName> settings = new ArrayList<>();
settings.addAll(Arrays.asList(userSettingNames));
return this.getUserSettings(smtpAddresses, settings);
}
Expand All @@ -1891,10 +1863,10 @@ public GetUserSettingsResponseCollection getUsersSettings(
public GetDomainSettingsResponse getDomainSettings(String domain,
ExchangeVersion requestedVersion,
DomainSettingName... domainSettingNames) throws Exception {
List<String> domains = new ArrayList<String>(1);
List<String> domains = new ArrayList<>(1);
domains.add(domain);

List<DomainSettingName> settings = new ArrayList<DomainSettingName>();
List<DomainSettingName> settings = new ArrayList<>();
settings.addAll(Arrays.asList(domainSettingNames));

return this.getDomainSettings(domains, settings, requestedVersion).
Expand All @@ -1915,10 +1887,10 @@ public GetDomainSettingsResponseCollection getDomainSettings(
Iterable<String> domains, ExchangeVersion requestedVersion,
DomainSettingName... domainSettingNames)
throws Exception {
List<DomainSettingName> settings = new ArrayList<DomainSettingName>();
List<DomainSettingName> settings = new ArrayList<>();
settings.addAll(Arrays.asList(domainSettingNames));

List<String> domainslst = new ArrayList<String>();
List<String> domainslst = new ArrayList<>();
domainslst.addAll((Collection<? extends String>) domains);

return this.getDomainSettings(domainslst, settings, requestedVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ protected static ProtocolConnection loadFromXml(EwsXmlReader reader)
reader.read();

if (reader.getNodeType().getNodeType() == XmlNodeType.START_ELEMENT) {
if (reader.getLocalName().equals(
XmlElementNames.EncryptionMethod)) {
connection.setEncryptionMethod(reader
.readElementValue(String.class));
} else if (reader.getLocalName().equals(
XmlElementNames.Hostname)) {
connection.setHostname(reader
.readElementValue(String.class));
} else if (reader.getLocalName().equals(XmlElementNames.Port)) {
connection.setPort(reader.readElementValue(int.class));
}
switch (reader.getLocalName()) {
case XmlElementNames.EncryptionMethod:
connection.setEncryptionMethod(reader
.readElementValue(String.class));
break;
case XmlElementNames.Hostname:
connection.setHostname(reader
.readElementValue(String.class));
break;
case XmlElementNames.Port:
connection.setPort(reader.readElementValue(int.class));
break;
}
}
} while (!reader.isEndElement(XmlNamespace.Autodiscover,
XmlElementNames.ProtocolConnection));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class ProtocolConnectionCollection {
* cref="ProtocolConnectionCollection"/> class.
*/
ProtocolConnectionCollection() {
this.connections = new ArrayList<ProtocolConnection>();
this.connections = new ArrayList<>();
}

/**
Expand Down
Loading

0 comments on commit 2ee89ba

Please sign in to comment.