Skip to content

Commit effe6ef

Browse files
authored
Merge pull request #165 from microsoftgraph/dev
1.0.9 release
2 parents 5e23205 + 81079a5 commit effe6ef

File tree

6 files changed

+65
-100
lines changed

6 files changed

+65
-100
lines changed

build.gradle

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ plugins {
1313
id 'eclipse'
1414
id 'maven-publish'
1515
id 'signing'
16-
id 'com.jfrog.bintray' version '1.8.5'
1716
}
1817

1918
java {
@@ -30,15 +29,13 @@ sourceSets {
3029

3130
// In this section you declare where to find the dependencies of your project
3231
repositories {
33-
// Use jcenter for resolving your dependencies.
3432
// You can declare any Maven/Ivy/file repository here.
35-
jcenter()
3633
mavenCentral()
3734
}
3835

3936
dependencies {
4037
// Use JUnit test framework
41-
testImplementation 'junit:junit:4.13.1'
38+
testImplementation 'junit:junit:4.13.2'
4239

4340
api 'com.squareup.okhttp3:okhttp:3.12.1'
4441

@@ -153,34 +150,6 @@ publishing {
153150
}
154151
}
155152
}
156-
157-
maven {
158-
url = 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
159-
name = 'jfrogSnapshot'
160-
161-
credentials {
162-
if (project.rootProject.file('local.properties').exists()) {
163-
Properties properties = new Properties()
164-
properties.load(project.rootProject.file('local.properties').newDataInputStream())
165-
username = (properties.containsKey('bintray.user')) ? properties.getProperty('bintray.user').toLowerCase() : "BINTRAY_USERNAME"
166-
password = properties.getProperty('bintray.apikey')
167-
}
168-
}
169-
}
170-
171-
maven {
172-
url = 'https://oss.jfrog.org/artifactory/libs-release'
173-
name = 'jfrog'
174-
175-
credentials {
176-
if (project.rootProject.file('local.properties').exists()) {
177-
Properties properties = new Properties()
178-
properties.load(project.rootProject.file('local.properties').newDataInputStream())
179-
username = (properties.containsKey('bintray.user')) ? properties.getProperty('bintray.user').toLowerCase() : "BINTRAY_USERNAME"
180-
password = properties.getProperty('bintray.apikey')
181-
}
182-
}
183-
}
184153
}
185154
}
186155

@@ -196,38 +165,6 @@ def fixAscNames = { name ->
196165
name.replace('msgraph-sdk-java-core', "${project.property('mavenArtifactId')}-${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}")
197166
}
198167
}
199-
bintray {
200-
if (project.rootProject.file('local.properties').exists()) {
201-
Properties properties = new Properties()
202-
properties.load(project.rootProject.file('local.properties').newDataInputStream())
203-
user = (properties.containsKey('bintray.user')) ? properties.getProperty('bintray.user').toLowerCase() : "BINTRAY_USERNAME"
204-
key = properties.getProperty('bintray.apikey')
205-
}
206-
publications = ['mavenCentralRelease']
207-
filesSpec {
208-
from ('build/libs') {
209-
include 'msgraph-sdk-java-core*.jar.asc'
210-
rename fixAscNames
211-
}
212-
from ('build') {
213-
include 'generated-pom.xml.asc'
214-
rename fixAscNames
215-
}
216-
into "com/microsoft/graph/${project.property('mavenArtifactId')}/${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}/"
217-
}
218-
pkg {
219-
repo = 'Maven'
220-
name = project.property('mavenArtifactId')
221-
userOrg = 'microsoftgraph'
222-
licenses = ['MIT']
223-
vcsUrl = 'https://github.com/microsoftgraph/msgraph-sdk-java-core.git'
224-
publicDownloadNumbers = true
225-
version {
226-
name = "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}"
227-
vcsTag = "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}"
228-
}
229-
}
230-
}
231168

232169
compileJava {
233170
sourceCompatibility = 1.7

gradle.properties

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

3231
#These values are used to run functional tests
3332
#If you wish to run the functional tests, edit the gradle.properties

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ Add the repository and a compile dependency for `microsoft-graph-core` to your p
1515

1616
```gradle
1717
repositories {
18-
jcenter()
18+
mavenCentral()
1919
}
2020
2121
dependencies {
2222
// Include the sdk as a dependency
23-
implementation 'com.microsoft.graph:microsoft-graph-core:1.0.8'
23+
implementation 'com.microsoft.graph:microsoft-graph-core:1.0.9'
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.8</version>
35+
<version>1.0.9</version>
3636
</dependency>
3737
```
3838

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

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ public class RetryHandler implements Interceptor{
2222
*/
2323
private final String RETRY_ATTEMPT_HEADER = "Retry-Attempt";
2424
private final String RETRY_AFTER = "Retry-After";
25-
private final String TRANSFER_ENCODING = "Transfer-Encoding";
26-
private final String TRANSFER_ENCODING_CHUNKED = "chunked";
27-
private final String APPLICATION_OCTET_STREAM = "application/octet-stream";
28-
private final String CONTENT_TYPE = "Content-Type";
25+
/** Content length request header value */
26+
private final String CONTENT_LENGTH = "Content-Length";
2927

3028
public static final int MSClientErrorCodeTooManyRequests = 429;
3129
public static final int MSClientErrorCodeServiceUnavailable = 503;
@@ -66,7 +64,7 @@ boolean retryRequest(Response response, int executionCount, Request request, Ret
6664
// without any retry attempt.
6765
shouldRetry =
6866
(executionCount <= retryOptions.maxRetries())
69-
&& checkStatus(statusCode) && isBuffered(response, request)
67+
&& checkStatus(statusCode) && isBuffered(request)
7068
&& shouldRetryCallback != null
7169
&& shouldRetryCallback.shouldRetry(retryOptions.delay(), executionCount, request, response);
7270

@@ -106,27 +104,22 @@ boolean checkStatus(int statusCode) {
106104
|| statusCode == MSClientErrorCodeGatewayTimeout);
107105
}
108106

109-
boolean isBuffered(Response response, Request request) {
110-
String methodName = request.method();
111-
if(methodName.equalsIgnoreCase("GET") || methodName.equalsIgnoreCase("DELETE") || methodName.equalsIgnoreCase("HEAD") || methodName.equalsIgnoreCase("OPTIONS"))
112-
return true;
107+
boolean isBuffered(Request request) {
108+
final String methodName = request.method();
113109

114-
boolean isHTTPMethodPutPatchOrPost = methodName.equalsIgnoreCase("POST") ||
110+
final boolean isHTTPMethodPutPatchOrPost = methodName.equalsIgnoreCase("POST") ||
115111
methodName.equalsIgnoreCase("PUT") ||
116112
methodName.equalsIgnoreCase("PATCH");
117113

118-
if(isHTTPMethodPutPatchOrPost) {
119-
boolean isStream = response.header(CONTENT_TYPE)!=null && response.header(CONTENT_TYPE).equalsIgnoreCase(APPLICATION_OCTET_STREAM);
120-
if(!isStream) {
121-
String transferEncoding = response.header(TRANSFER_ENCODING);
122-
boolean isTransferEncodingChunked = (transferEncoding != null) &&
123-
transferEncoding.equalsIgnoreCase(TRANSFER_ENCODING_CHUNKED);
124-
125-
if(request.body() != null && isTransferEncodingChunked)
126-
return true;
127-
}
114+
if(isHTTPMethodPutPatchOrPost && request.body() != null) {
115+
try {
116+
return request.body().contentLength() != -1L;
117+
} catch (IOException ex) {
118+
// expected
119+
return false;
120+
}
128121
}
129-
return false;
122+
return true;
130123
}
131124

132125
@Override

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.8";
15+
public static final String VERSION = "v1.0.9";
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";

src/test/java/com/microsoft/graph/httpcore/RetryHandlerTest.java

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.junit.Assert.assertNotNull;
55
import static org.junit.Assert.assertTrue;
66

7+
import java.io.IOException;
78
import java.net.HttpURLConnection;
89

910
import org.junit.Test;
@@ -16,6 +17,7 @@
1617
import okhttp3.Request;
1718
import okhttp3.RequestBody;
1819
import okhttp3.Response;
20+
import okio.BufferedSink;
1921

2022
public class RetryHandlerTest {
2123

@@ -76,7 +78,7 @@ public void testRetryRequestWithMaxRetryAttempts() {
7678
// Default retry options with Number of maxretries default to 3
7779
RetryOptions retryOptions = new RetryOptions();
7880
// Try to execute one more than allowed default max retries
79-
int executionCount = RetryOptions.DEFAULT_MAX_RETRIES + 1;
81+
int executionCount = RetryOptions.DEFAULT_MAX_RETRIES + 1;
8082
assertFalse(retryhandler.retryRequest(response, executionCount, httpget, retryOptions));
8183
}
8284

@@ -87,7 +89,7 @@ public void testRetryRequestForStatusCode() {
8789
Response response = new Response.Builder()
8890
.protocol(Protocol.HTTP_1_1)
8991
// For status code 500 which is not in (429 503 504), So NO retry
90-
.code(HTTP_SERVER_ERROR)
92+
.code(HTTP_SERVER_ERROR)
9193
.message( "Internal Server Error")
9294
.request(httpget)
9395
.build();
@@ -100,7 +102,7 @@ public void testRetryRequestWithTransferEncoding() {
100102
Request httppost = new Request.Builder().url(testmeurl).post(RequestBody.create(MediaType.parse("application/json"), "TEST")).build();
101103
Response response = new Response.Builder()
102104
.protocol(Protocol.HTTP_1_1)
103-
.code(HttpURLConnection.HTTP_GATEWAY_TIMEOUT)
105+
.code(HttpURLConnection.HTTP_GATEWAY_TIMEOUT)
104106
.message( "gateway timeout")
105107
.request(httppost)
106108
.addHeader("Transfer-Encoding", "chunked")
@@ -114,15 +116,15 @@ public void testRetryRequestWithExponentialBackOff() {
114116
Request httppost = new Request.Builder().url(testmeurl).post(RequestBody.create(MediaType.parse("application/json"), "TEST")).build();
115117
Response response = new Response.Builder()
116118
.protocol(Protocol.HTTP_1_1)
117-
.code(HttpURLConnection.HTTP_GATEWAY_TIMEOUT)
119+
.code(HttpURLConnection.HTTP_GATEWAY_TIMEOUT)
118120
.message( "gateway timeout")
119121
.request(httppost)
120122
.addHeader("Transfer-Encoding", "chunked")
121123
.build();
122-
124+
123125
assertTrue(retryhandler.retryRequest(response, 1, httppost, new RetryOptions()));
124126
}
125-
127+
126128
@Test
127129
public void testGetRetryAfterWithHeader() {
128130
RetryHandler retryHandler = new RetryHandler();
@@ -131,7 +133,7 @@ public void testGetRetryAfterWithHeader() {
131133
delay = retryHandler.getRetryAfter(TestResponse().newBuilder().addHeader("Retry-After", "1").build(), 2, 3);
132134
assertTrue(delay == 1000);
133135
}
134-
136+
135137
@Test
136138
public void testGetRetryAfterOnFirstExecution() {
137139
RetryHandler retryHandler = new RetryHandler();
@@ -140,14 +142,48 @@ public void testGetRetryAfterOnFirstExecution() {
140142
delay = retryHandler.getRetryAfter(TestResponse(), 3, 2);
141143
assertTrue(delay > 3100);
142144
}
143-
145+
144146
@Test
145147
public void testGetRetryAfterMaxExceed() {
146148
RetryHandler retryHandler = new RetryHandler();
147149
long delay = retryHandler.getRetryAfter(TestResponse(), 190, 1);
148150
assertTrue(delay == 180000);
149151
}
150-
152+
@Test
153+
public void testIsBuffered() {
154+
final RetryHandler retryHandler = new RetryHandler();
155+
Request request = new Request.Builder().url("https://localhost").method("GET", null).build();
156+
assertTrue("Get Request is buffered", retryHandler.isBuffered(request));
157+
158+
request = new Request.Builder().url("https://localhost").method("DELETE", null).build();
159+
assertTrue("Delete Request is buffered", retryHandler.isBuffered(request));
160+
161+
request = new Request.Builder().url("https://localhost")
162+
.method("POST",
163+
RequestBody.create(MediaType.parse("application/json"),
164+
"{\"key\": 42 }"))
165+
.build();
166+
assertTrue("Post Request is buffered", retryHandler.isBuffered(request));
167+
168+
request = new Request.Builder().url("https://localhost")
169+
.method("POST",
170+
new RequestBody() {
171+
172+
@Override
173+
public MediaType contentType() {
174+
return MediaType.parse("application/octet-stream");
175+
}
176+
177+
@Override
178+
public void writeTo(BufferedSink sink) throws IOException {
179+
// TODO Auto-generated method stub
180+
181+
}
182+
})
183+
.build();
184+
assertFalse("Post Stream Request is not buffered", retryHandler.isBuffered(request));
185+
}
186+
151187
Response TestResponse() {
152188
return new Response.Builder()
153189
.code(429)

0 commit comments

Comments
 (0)