Skip to content

Commit 5e23205

Browse files
authored
Merge pull request #141 from microsoftgraph/dev
1.0.8 release
2 parents 22036b0 + 973bc01 commit 5e23205

File tree

6 files changed

+65
-61
lines changed

6 files changed

+65
-61
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mavenGroupId = com.microsoft.graph
2525
mavenArtifactId = microsoft-graph-core
2626
mavenMajorVersion = 1
2727
mavenMinorVersion = 0
28-
mavenPatchVersion = 7
28+
mavenPatchVersion = 8
2929
mavenArtifactSuffix =
3030
nightliesUrl = http://dl.bintray.com/MicrosoftGraph/Maven
3131

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repositories {
2020
2121
dependencies {
2222
// Include the sdk as a dependency
23-
implementation 'com.microsoft.graph:microsoft-graph-core:1.0.7'
23+
implementation 'com.microsoft.graph:microsoft-graph-core:1.0.8'
2424
}
2525
```
2626

@@ -32,7 +32,7 @@ Add the dependency in `dependencies` in pom.xml
3232
<dependency>
3333
<groupId>com.microsoft.graph</groupId>
3434
<artifactId>microsoft-graph-core</artifactId>
35-
<version>1.0.7</version>
35+
<version>1.0.8</version>
3636
</dependency>
3737
```
3838

src/main/java/com/microsoft/graph/httpcore/HttpClients.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static Builder custom() {
2222
return new OkHttpClient.Builder()
2323
.addInterceptor(new TelemetryHandler())
2424
.followRedirects(false)
25+
.followSslRedirects(false)
2526
.protocols(Arrays.asList(Protocol.HTTP_1_1)); //https://stackoverflow.com/questions/62031298/sockettimeout-on-java-11-but-not-on-java-8
2627
}
2728

src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
import okhttp3.Response;
2020

2121
public class RedirectHandler implements Interceptor{
22-
22+
2323
public final MiddlewareType MIDDLEWARE_TYPE = MiddlewareType.REDIRECT;
24-
24+
2525
private RedirectOptions mRedirectOptions;
26-
26+
2727
/*
2828
* Initialize using default redirect options, default IShouldRedirect and max redirect value
2929
*/
3030
public RedirectHandler() {
3131
this(null);
3232
}
33-
33+
3434
/*
3535
* @param redirectOptions pass instance of redirect options to be used
3636
*/
@@ -40,16 +40,16 @@ public RedirectHandler(RedirectOptions redirectOptions) {
4040
this.mRedirectOptions = new RedirectOptions();
4141
}
4242
}
43-
43+
4444
boolean isRedirected(Request request, Response response, int redirectCount, RedirectOptions redirectOptions) throws IOException {
4545
// Check max count of redirects reached
4646
if(redirectCount > redirectOptions.maxRedirects()) return false;
47-
47+
4848
// Location header empty then don't redirect
4949
final String locationHeader = response.header("location");
5050
if(locationHeader == null)
5151
return false;
52-
52+
5353
// If any of 301,302,303,307,308 then redirect
5454
final int statusCode = response.code();
5555
if(statusCode == HTTP_PERM_REDIRECT || //308
@@ -58,31 +58,31 @@ boolean isRedirected(Request request, Response response, int redirectCount, Redi
5858
statusCode == HTTP_SEE_OTHER || //303
5959
statusCode == HTTP_MOVED_TEMP) //302
6060
return true;
61-
61+
6262
return false;
6363
}
64-
64+
6565
Request getRedirect(
6666
final Request request,
67-
final Response userResponse) throws ProtocolException {
67+
final Response userResponse) throws ProtocolException {
6868
String location = userResponse.header("Location");
6969
if (location == null || location.length() == 0) return null;
70-
70+
7171
// For relative URL in location header, the new url to redirect is relative to original request
7272
if(location.startsWith("/")) {
7373
if(request.url().toString().endsWith("/")) {
7474
location = location.substring(1);
7575
}
7676
location = request.url() + location;
7777
}
78-
78+
7979
HttpUrl requestUrl = userResponse.request().url();
80-
80+
8181
HttpUrl locationUrl = userResponse.request().url().resolve(location);
82-
82+
8383
// Don't follow redirects to unsupported protocols.
8484
if (locationUrl == null) return null;
85-
85+
8686
// Most redirects don't include a request body.
8787
Request.Builder requestBuilder = userResponse.request().newBuilder();
8888

@@ -94,7 +94,7 @@ Request getRedirect(
9494
if (!sameScheme || !sameHost) {
9595
requestBuilder.removeHeader("Authorization");
9696
}
97-
97+
9898
// Response status code 303 See Other then POST changes to GET
9999
if(userResponse.code() == HTTP_SEE_OTHER) {
100100
requestBuilder.method("GET", null);
@@ -107,29 +107,30 @@ Request getRedirect(
107107
@Override
108108
public Response intercept(Chain chain) throws IOException {
109109
Request request = chain.request();
110-
110+
111111
if(request.tag(TelemetryOptions.class) == null)
112112
request = request.newBuilder().tag(TelemetryOptions.class, new TelemetryOptions()).build();
113113
request.tag(TelemetryOptions.class).setFeatureUsage(TelemetryOptions.REDIRECT_HANDLER_ENABLED_FLAG);
114-
114+
115115
Response response = null;
116116
int requestsCount = 1;
117-
117+
118118
// Use should retry pass along with this request
119119
RedirectOptions redirectOptions = request.tag(RedirectOptions.class);
120120
redirectOptions = redirectOptions != null ? redirectOptions : this.mRedirectOptions;
121-
121+
122122
while(true) {
123123
response = chain.proceed(request);
124-
boolean shouldRedirect = isRedirected(request, response, requestsCount, redirectOptions)
124+
final boolean shouldRedirect = isRedirected(request, response, requestsCount, redirectOptions)
125125
&& redirectOptions.shouldRedirect().shouldRedirect(response);
126126
if(!shouldRedirect) break;
127-
128-
Request followup = getRedirect(request, response);
129-
if(followup == null) break;
130-
request = followup;
131-
132-
requestsCount++;
127+
128+
final Request followup = getRedirect(request, response);
129+
if(followup != null) {
130+
response.close();
131+
request = followup;
132+
requestsCount++;
133+
}
133134
}
134135
return response;
135136
}

src/main/java/com/microsoft/graph/httpcore/RetryHandler.java

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
import okhttp3.Response;
1313

1414
public class RetryHandler implements Interceptor{
15-
15+
1616
public final MiddlewareType MIDDLEWARE_TYPE = MiddlewareType.RETRY;
1717

1818
private RetryOptions mRetryOption;
19-
19+
2020
/*
2121
* constant string being used
2222
*/
@@ -26,13 +26,13 @@ public class RetryHandler implements Interceptor{
2626
private final String TRANSFER_ENCODING_CHUNKED = "chunked";
2727
private final String APPLICATION_OCTET_STREAM = "application/octet-stream";
2828
private final String CONTENT_TYPE = "Content-Type";
29-
29+
3030
public static final int MSClientErrorCodeTooManyRequests = 429;
3131
public static final int MSClientErrorCodeServiceUnavailable = 503;
3232
public static final int MSClientErrorCodeGatewayTimeout = 504;
33-
33+
3434
private final long DELAY_MILLISECONDS = 1000;
35-
35+
3636
/*
3737
* @retryOption Create Retry handler using retry option
3838
*/
@@ -48,28 +48,28 @@ public RetryHandler(RetryOptions retryOption) {
4848
public RetryHandler() {
4949
this(null);
5050
}
51-
51+
5252
boolean retryRequest(Response response, int executionCount, Request request, RetryOptions retryOptions) {
53-
53+
5454
// Should retry option
5555
// Use should retry common for all requests
5656
IShouldRetry shouldRetryCallback = null;
5757
if(retryOptions != null) {
5858
shouldRetryCallback = retryOptions.shouldRetry();
5959
}
60-
60+
6161
boolean shouldRetry = false;
6262
// Status codes 429 503 504
6363
int statusCode = response.code();
64-
// Only requests with payloads that are buffered/rewindable are supported.
65-
// Payloads with forward only streams will be have the responses returned
64+
// Only requests with payloads that are buffered/rewindable are supported.
65+
// Payloads with forward only streams will be have the responses returned
6666
// without any retry attempt.
67-
shouldRetry =
68-
(executionCount <= retryOptions.maxRetries())
67+
shouldRetry =
68+
(executionCount <= retryOptions.maxRetries())
6969
&& checkStatus(statusCode) && isBuffered(response, request)
70-
&& shouldRetryCallback != null
70+
&& shouldRetryCallback != null
7171
&& shouldRetryCallback.shouldRetry(retryOptions.delay(), executionCount, request, response);
72-
72+
7373
if(shouldRetry) {
7474
long retryInterval = getRetryAfter(response, retryOptions.delay(), executionCount);
7575
try {
@@ -80,7 +80,7 @@ && checkStatus(statusCode) && isBuffered(response, request)
8080
}
8181
return shouldRetry;
8282
}
83-
83+
8484
/**
8585
* Get retry after in milliseconds
8686
* @param response Response
@@ -100,28 +100,28 @@ long getRetryAfter(Response response, long delay, int executionCount) {
100100
}
101101
return (long)Math.min(retryDelay, RetryOptions.MAX_DELAY * DELAY_MILLISECONDS);
102102
}
103-
103+
104104
boolean checkStatus(int statusCode) {
105-
return (statusCode == MSClientErrorCodeTooManyRequests || statusCode == MSClientErrorCodeServiceUnavailable
105+
return (statusCode == MSClientErrorCodeTooManyRequests || statusCode == MSClientErrorCodeServiceUnavailable
106106
|| statusCode == MSClientErrorCodeGatewayTimeout);
107107
}
108-
108+
109109
boolean isBuffered(Response response, Request request) {
110110
String methodName = request.method();
111-
if(methodName.equalsIgnoreCase("GET") || methodName.equalsIgnoreCase("DELETE") || methodName.equalsIgnoreCase("HEAD") || methodName.equalsIgnoreCase("OPTIONS"))
111+
if(methodName.equalsIgnoreCase("GET") || methodName.equalsIgnoreCase("DELETE") || methodName.equalsIgnoreCase("HEAD") || methodName.equalsIgnoreCase("OPTIONS"))
112112
return true;
113-
113+
114114
boolean isHTTPMethodPutPatchOrPost = methodName.equalsIgnoreCase("POST") ||
115115
methodName.equalsIgnoreCase("PUT") ||
116116
methodName.equalsIgnoreCase("PATCH");
117-
117+
118118
if(isHTTPMethodPutPatchOrPost) {
119119
boolean isStream = response.header(CONTENT_TYPE)!=null && response.header(CONTENT_TYPE).equalsIgnoreCase(APPLICATION_OCTET_STREAM);
120120
if(!isStream) {
121121
String transferEncoding = response.header(TRANSFER_ENCODING);
122-
boolean isTransferEncodingChunked = (transferEncoding != null) &&
122+
boolean isTransferEncodingChunked = (transferEncoding != null) &&
123123
transferEncoding.equalsIgnoreCase(TRANSFER_ENCODING_CHUNKED);
124-
124+
125125
if(request.body() != null && isTransferEncodingChunked)
126126
return true;
127127
}
@@ -132,24 +132,26 @@ boolean isBuffered(Response response, Request request) {
132132
@Override
133133
public Response intercept(Chain chain) throws IOException {
134134
Request request = chain.request();
135-
135+
136136
if(request.tag(TelemetryOptions.class) == null)
137137
request = request.newBuilder().tag(TelemetryOptions.class, new TelemetryOptions()).build();
138138
request.tag(TelemetryOptions.class).setFeatureUsage(TelemetryOptions.RETRY_HANDLER_ENABLED_FLAG);
139-
139+
140140
Response response = chain.proceed(request);
141-
141+
142142
// Use should retry pass along with this request
143143
RetryOptions retryOption = request.tag(RetryOptions.class);
144144
retryOption = retryOption != null ? retryOption : mRetryOption;
145-
145+
146146
int executionCount = 1;
147147
while(retryRequest(response, executionCount, request, retryOption)) {
148148
request = request.newBuilder().addHeader(RETRY_ATTEMPT_HEADER, String.valueOf(executionCount)).build();
149149
executionCount++;
150-
if(response != null && response.body() != null) {
151-
response.body().close();
152-
}
150+
if(response != null) {
151+
if(response.body() != null)
152+
response.body().close();
153+
response.close();
154+
}
153155
response = chain.proceed(request);
154156
}
155157
return response;

src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public class TelemetryHandler implements Interceptor{
1313

1414
public static final String SDK_VERSION = "SdkVersion";
15-
public static final String VERSION = "v1.0.7";
15+
public static final String VERSION = "v1.0.8";
1616
public static final String GRAPH_VERSION_PREFIX = "graph-java-core";
1717
public static final String JAVA_VERSION_PREFIX = "java";
1818
public static final String ANDROID_VERSION_PREFIX = "android";

0 commit comments

Comments
 (0)