Skip to content

Commit

Permalink
Merge pull request #165 from microsoftgraph/dev
Browse files Browse the repository at this point in the history
1.0.9 release
  • Loading branch information
baywet authored Mar 2, 2021
2 parents 5e23205 + 81079a5 commit effe6ef
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 100 deletions.
65 changes: 1 addition & 64 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ plugins {
id 'eclipse'
id 'maven-publish'
id 'signing'
id 'com.jfrog.bintray' version '1.8.5'
}

java {
Expand All @@ -30,15 +29,13 @@ sourceSets {

// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
mavenCentral()
}

dependencies {
// Use JUnit test framework
testImplementation 'junit:junit:4.13.1'
testImplementation 'junit:junit:4.13.2'

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

Expand Down Expand Up @@ -153,34 +150,6 @@ publishing {
}
}
}

maven {
url = 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
name = 'jfrogSnapshot'

credentials {
if (project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
username = (properties.containsKey('bintray.user')) ? properties.getProperty('bintray.user').toLowerCase() : "BINTRAY_USERNAME"
password = properties.getProperty('bintray.apikey')
}
}
}

maven {
url = 'https://oss.jfrog.org/artifactory/libs-release'
name = 'jfrog'

credentials {
if (project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
username = (properties.containsKey('bintray.user')) ? properties.getProperty('bintray.user').toLowerCase() : "BINTRAY_USERNAME"
password = properties.getProperty('bintray.apikey')
}
}
}
}
}

Expand All @@ -196,38 +165,6 @@ def fixAscNames = { name ->
name.replace('msgraph-sdk-java-core', "${project.property('mavenArtifactId')}-${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}")
}
}
bintray {
if (project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
user = (properties.containsKey('bintray.user')) ? properties.getProperty('bintray.user').toLowerCase() : "BINTRAY_USERNAME"
key = properties.getProperty('bintray.apikey')
}
publications = ['mavenCentralRelease']
filesSpec {
from ('build/libs') {
include 'msgraph-sdk-java-core*.jar.asc'
rename fixAscNames
}
from ('build') {
include 'generated-pom.xml.asc'
rename fixAscNames
}
into "com/microsoft/graph/${project.property('mavenArtifactId')}/${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}/"
}
pkg {
repo = 'Maven'
name = project.property('mavenArtifactId')
userOrg = 'microsoftgraph'
licenses = ['MIT']
vcsUrl = 'https://github.com/microsoftgraph/msgraph-sdk-java-core.git'
publicDownloadNumbers = true
version {
name = "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}"
vcsTag = "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}"
}
}
}

compileJava {
sourceCompatibility = 1.7
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ mavenGroupId = com.microsoft.graph
mavenArtifactId = microsoft-graph-core
mavenMajorVersion = 1
mavenMinorVersion = 0
mavenPatchVersion = 8
mavenPatchVersion = 9
mavenArtifactSuffix =
nightliesUrl = http://dl.bintray.com/MicrosoftGraph/Maven

#These values are used to run functional tests
#If you wish to run the functional tests, edit the gradle.properties
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ Add the repository and a compile dependency for `microsoft-graph-core` to your p

```gradle
repositories {
jcenter()
mavenCentral()
}
dependencies {
// Include the sdk as a dependency
implementation 'com.microsoft.graph:microsoft-graph-core:1.0.8'
implementation 'com.microsoft.graph:microsoft-graph-core:1.0.9'
}
```

Expand All @@ -32,7 +32,7 @@ Add the dependency in `dependencies` in pom.xml
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph-core</artifactId>
<version>1.0.8</version>
<version>1.0.9</version>
</dependency>
```

Expand Down
35 changes: 14 additions & 21 deletions src/main/java/com/microsoft/graph/httpcore/RetryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ public class RetryHandler implements Interceptor{
*/
private final String RETRY_ATTEMPT_HEADER = "Retry-Attempt";
private final String RETRY_AFTER = "Retry-After";
private final String TRANSFER_ENCODING = "Transfer-Encoding";
private final String TRANSFER_ENCODING_CHUNKED = "chunked";
private final String APPLICATION_OCTET_STREAM = "application/octet-stream";
private final String CONTENT_TYPE = "Content-Type";
/** Content length request header value */
private final String CONTENT_LENGTH = "Content-Length";

public static final int MSClientErrorCodeTooManyRequests = 429;
public static final int MSClientErrorCodeServiceUnavailable = 503;
Expand Down Expand Up @@ -66,7 +64,7 @@ boolean retryRequest(Response response, int executionCount, Request request, Ret
// without any retry attempt.
shouldRetry =
(executionCount <= retryOptions.maxRetries())
&& checkStatus(statusCode) && isBuffered(response, request)
&& checkStatus(statusCode) && isBuffered(request)
&& shouldRetryCallback != null
&& shouldRetryCallback.shouldRetry(retryOptions.delay(), executionCount, request, response);

Expand Down Expand Up @@ -106,27 +104,22 @@ boolean checkStatus(int statusCode) {
|| statusCode == MSClientErrorCodeGatewayTimeout);
}

boolean isBuffered(Response response, Request request) {
String methodName = request.method();
if(methodName.equalsIgnoreCase("GET") || methodName.equalsIgnoreCase("DELETE") || methodName.equalsIgnoreCase("HEAD") || methodName.equalsIgnoreCase("OPTIONS"))
return true;
boolean isBuffered(Request request) {
final String methodName = request.method();

boolean isHTTPMethodPutPatchOrPost = methodName.equalsIgnoreCase("POST") ||
final boolean isHTTPMethodPutPatchOrPost = methodName.equalsIgnoreCase("POST") ||
methodName.equalsIgnoreCase("PUT") ||
methodName.equalsIgnoreCase("PATCH");

if(isHTTPMethodPutPatchOrPost) {
boolean isStream = response.header(CONTENT_TYPE)!=null && response.header(CONTENT_TYPE).equalsIgnoreCase(APPLICATION_OCTET_STREAM);
if(!isStream) {
String transferEncoding = response.header(TRANSFER_ENCODING);
boolean isTransferEncodingChunked = (transferEncoding != null) &&
transferEncoding.equalsIgnoreCase(TRANSFER_ENCODING_CHUNKED);

if(request.body() != null && isTransferEncodingChunked)
return true;
}
if(isHTTPMethodPutPatchOrPost && request.body() != null) {
try {
return request.body().contentLength() != -1L;
} catch (IOException ex) {
// expected
return false;
}
}
return false;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class TelemetryHandler implements Interceptor{

public static final String SDK_VERSION = "SdkVersion";
public static final String VERSION = "v1.0.8";
public static final String VERSION = "v1.0.9";
public static final String GRAPH_VERSION_PREFIX = "graph-java-core";
public static final String JAVA_VERSION_PREFIX = "java";
public static final String ANDROID_VERSION_PREFIX = "android";
Expand Down
54 changes: 45 additions & 9 deletions src/test/java/com/microsoft/graph/httpcore/RetryHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.net.HttpURLConnection;

import org.junit.Test;
Expand All @@ -16,6 +17,7 @@
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okio.BufferedSink;

public class RetryHandlerTest {

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

Expand All @@ -87,7 +89,7 @@ public void testRetryRequestForStatusCode() {
Response response = new Response.Builder()
.protocol(Protocol.HTTP_1_1)
// For status code 500 which is not in (429 503 504), So NO retry
.code(HTTP_SERVER_ERROR)
.code(HTTP_SERVER_ERROR)
.message( "Internal Server Error")
.request(httpget)
.build();
Expand All @@ -100,7 +102,7 @@ public void testRetryRequestWithTransferEncoding() {
Request httppost = new Request.Builder().url(testmeurl).post(RequestBody.create(MediaType.parse("application/json"), "TEST")).build();
Response response = new Response.Builder()
.protocol(Protocol.HTTP_1_1)
.code(HttpURLConnection.HTTP_GATEWAY_TIMEOUT)
.code(HttpURLConnection.HTTP_GATEWAY_TIMEOUT)
.message( "gateway timeout")
.request(httppost)
.addHeader("Transfer-Encoding", "chunked")
Expand All @@ -114,15 +116,15 @@ public void testRetryRequestWithExponentialBackOff() {
Request httppost = new Request.Builder().url(testmeurl).post(RequestBody.create(MediaType.parse("application/json"), "TEST")).build();
Response response = new Response.Builder()
.protocol(Protocol.HTTP_1_1)
.code(HttpURLConnection.HTTP_GATEWAY_TIMEOUT)
.code(HttpURLConnection.HTTP_GATEWAY_TIMEOUT)
.message( "gateway timeout")
.request(httppost)
.addHeader("Transfer-Encoding", "chunked")
.build();

assertTrue(retryhandler.retryRequest(response, 1, httppost, new RetryOptions()));
}

@Test
public void testGetRetryAfterWithHeader() {
RetryHandler retryHandler = new RetryHandler();
Expand All @@ -131,7 +133,7 @@ public void testGetRetryAfterWithHeader() {
delay = retryHandler.getRetryAfter(TestResponse().newBuilder().addHeader("Retry-After", "1").build(), 2, 3);
assertTrue(delay == 1000);
}

@Test
public void testGetRetryAfterOnFirstExecution() {
RetryHandler retryHandler = new RetryHandler();
Expand All @@ -140,14 +142,48 @@ public void testGetRetryAfterOnFirstExecution() {
delay = retryHandler.getRetryAfter(TestResponse(), 3, 2);
assertTrue(delay > 3100);
}

@Test
public void testGetRetryAfterMaxExceed() {
RetryHandler retryHandler = new RetryHandler();
long delay = retryHandler.getRetryAfter(TestResponse(), 190, 1);
assertTrue(delay == 180000);
}

@Test
public void testIsBuffered() {
final RetryHandler retryHandler = new RetryHandler();
Request request = new Request.Builder().url("https://localhost").method("GET", null).build();
assertTrue("Get Request is buffered", retryHandler.isBuffered(request));

request = new Request.Builder().url("https://localhost").method("DELETE", null).build();
assertTrue("Delete Request is buffered", retryHandler.isBuffered(request));

request = new Request.Builder().url("https://localhost")
.method("POST",
RequestBody.create(MediaType.parse("application/json"),
"{\"key\": 42 }"))
.build();
assertTrue("Post Request is buffered", retryHandler.isBuffered(request));

request = new Request.Builder().url("https://localhost")
.method("POST",
new RequestBody() {

@Override
public MediaType contentType() {
return MediaType.parse("application/octet-stream");
}

@Override
public void writeTo(BufferedSink sink) throws IOException {
// TODO Auto-generated method stub

}
})
.build();
assertFalse("Post Stream Request is not buffered", retryHandler.isBuffered(request));
}

Response TestResponse() {
return new Response.Builder()
.code(429)
Expand Down

0 comments on commit effe6ef

Please sign in to comment.