Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ae90c4c
Updated wiki links
NakulSabharwal Mar 13, 2019
9176405
Merge pull request #16 from microsoftgraph/wiki-links
NakulSabharwal Mar 13, 2019
22085cf
Added CONTRIBUTING.md
Mar 13, 2019
eb2abcd
Added THIRD PARTY NOTICES
Mar 13, 2019
17181e9
Merge pull request #17 from microsoftgraph/contributing
NakulSabharwal Mar 15, 2019
06721c1
Added gradle-wrapper.jar
Apr 3, 2019
2a9dc73
Telemetry handler and its tests
NakulSabharwal Apr 15, 2019
c42ccb9
Changed flags from String to int
NakulSabharwal Apr 17, 2019
34534e5
Merge pull request #22 from microsoftgraph/telemetryhandler
NakulSabharwal Apr 17, 2019
71c1083
Merge pull request #20 from microsoftgraph/gradlejar
NakulSabharwal Apr 17, 2019
0fdaef2
Added null check for telemetry options
Apr 22, 2019
d93a7f0
Added telemetry handler in custom builder
Apr 23, 2019
9b5ea78
Added Iterator and map response over BatchResponse and update with Ba…
NakulSabharwal Apr 23, 2019
71c1f93
edited nextLink updation
NakulSabharwal Apr 23, 2019
b3e88f1
Merge pull request #23 from microsoftgraph/telemetry-fix
NakulSabharwal Apr 23, 2019
78d94c9
Edited responses iterator
Apr 24, 2019
51fa9b7
Merge pull request #24 from microsoftgraph/batch-fix
NakulSabharwal Apr 24, 2019
de336ea
edited retry after calculation, check for requestid is not empty
Apr 25, 2019
1d53c73
added Relative reference in location url
Apr 25, 2019
4db7fce
Merge pull request #25 from microsoftgraph/getRetryDelay-fix
NakulSabharwal Apr 25, 2019
b6d28e1
version update to 1.0.0 and bintray url update
Apr 25, 2019
e1dcf19
Merge pull request #26 from microsoftgraph/version-update
NakulSabharwal Apr 25, 2019
ef82d2e
Updated readme with GA
NakulSabharwal Apr 26, 2019
02f463a
Updated title in readme
NakulSabharwal Apr 26, 2019
2a30957
Merge pull request #27 from microsoftgraph/readme
NakulSabharwal Apr 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Contributing to the Microsoft Graph Core SDK for Java

The Microsoft Graph Core SDK for Java is available for all manner of contribution. There are a couple of different recommended paths to get contributions into the released version of this SDK.

__NOTE__ A signed a contribution license agreement is required for all contributions, and is checked automatically on new pull requests. Please read and sign the agreement https://cla.microsoft.com/ before starting any work for this repository.

## File issues

The best way to get started with a contribution is to start a dialog with the owners of this repository. Sometimes features will be under development or out of scope for this SDK and it's best to check before starting work on contribution.

## Submit pull requests for trivial changes

If you are making a change that does not affect the interface components and does not affect other downstream callers, feel free to make a pull request against the __dev__ branch. The dev branch will be updated frequently.

Revisions of this nature will result in a 0.0.X change of the version number.

## Submit pull requests for features

If major functionality is being added, or there will need to be gestation time for a change, it should be submitted against the __feature__ branch.

Revisions of this nature will result in a 0.X.X change of the version number.

## Add yourself as a contributor

This project follows the [all contributors](https://github.com/kentcdodds/all-contributors) specification. When making a contribution, please add yourself to the table of contributors:

1. In section 5. of the [README.md](https://github.com/microsoftgraph/msgraph-sdk-java-core/blob/dev/readme.md), after the last "|", copy and paste a new blank contributor element
```html
[<img src="https://avatars.githubusercontent.com/u/<your-uid>?v=4" width="100px;"/><br />
<sub><b>Your Name</b></sub>](your website or github page)<br />
[emoji](link "alt-text") |
```

You can get your GitHub UID by inspecting your GitHub avatar image.

2. For each contribution type (see [emoji key](https://github.com/kentcdodds/all-contributors#emoji-key) for a list of contribution types), add an emoji and a relevant link and alt-text.

For example, if you write a blogpost on how to use the SDK, you would include:

```html
[??]("https://myblog.com/using-the-java-sdk" "Blog Post")
26 changes: 26 additions & 0 deletions THIRD PARTY NOTICES
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
This file is based on or incorporates material from the projects listed below
(Third Party IP). The original copyright notice and the license under which
Microsoft received such Third Party IP, are set forth below. Such licenses and
notices are provided for informational purposes only. Microsoft licenses the
Third Party IP to you under the licensing terms for the Microsoft product.
Microsoft reserves all other rights not expressly granted under this agreement,
whether by implication, estoppel or otherwise.

Gson
Copyright 2008-2011 Google Inc.

Provided for Informational Purposes Only

Apache 2.0 License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0

THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.

See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
## linux requires 10G, OSX requires 11G
org.gradle.jvmargs=-XX:MaxPermSize=512m -Xmx2g

mavenRepoUrl = https://api.bintray.com/content/microsoftgraph/Maven/microsoft-graph
mavenRepoUrl = https://api.bintray.com/content/microsoftgraph/Maven/microsoft-graph-core
mavenBintraySnapshotUrl = http://oss.jfrog.org/artifactory/oss-snapshot-local
mavenGroupId = com.microsoft.graph
mavenArtifactId = microsoft-graph-core
mavenMajorVersion = 0
mavenMinorVersion = 1
mavenMajorVersion = 1
mavenMinorVersion = 0
mavenPatchVersion = 0
mavenArtifactSuffix =
nightliesUrl = http://dl.bintray.com/MicrosoftGraph/Maven
Expand Down
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
46 changes: 12 additions & 34 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Microsoft Graph Core Preview SDK for Java
# Microsoft Graph Core SDK for Java

Get started with the Microsoft Graph Core SDK for Java by integrating the [Microsoft Graph API](https://graph.microsoft.io/en-us/getting-started) into your Java application!
Get started with the Microsoft Graph Core SDK for Java by integrating the [Microsoft Graph API](https://graph.microsoft.io/en-us/getting-started) into your Java and Android application!

## Important Note about the Microsoft Graph Core Java Preview
During the preview we may make changes to the API, and other mechanisms of this library, which you will be required to take along with bug fixes or feature improvements. This may impact your application. An API change may require you to update your code. When we provide the General Availability release we will require you to update to the General Availability version within six months, as applications written using a preview version of library may no longer work.
## Samples and usage guide
[Middleware usage](https://github.com/microsoftgraph/msgraph-sdk-java-core/wiki)</br>
[Batching](https://github.com/microsoftgraph/msgraph-sdk-java-core/wiki/Batching)

## 1. Installation

Expand All @@ -14,14 +15,11 @@ Add the repository and a compile dependency for `microsoft-graph-core` to your p
```gradle
repository {
jcenter()
jcenter{
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
}
}

dependency {
// Include the sdk as a dependency
compile('com.microsoft.graph:microsoft-graph-core:0.1.0-SNAPSHOT')
compile('com.microsoft.graph:microsoft-graph-core:1.0.0')
}
```

Expand All @@ -31,34 +29,10 @@ Add the dependency in `dependencies` in pom.xml
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph-core</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>1.0.0</version>
</dependency>
```

Add `profiles` in `project` to download Snapshot release binary:
```
<profiles>
<profile>
<id>allow-snapshots</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
```

### 1.3 Enable ProGuard (Android)
The nature of the Graph API is such that the SDK needs quite a large set of classes to describe its functionality. You need to ensure that [ProGuard](https://developer.android.com/studio/build/shrink-code.html) is enabled on your project. Otherwise, you will incur long build times for functionality that is not necessarily relevant to your particular application. If you are still hitting the 64K method limit, you can also enable [multidexing](https://developer.android.com/studio/build/multidex.html).

Expand All @@ -70,7 +44,11 @@ Register your application by following the steps at [Register your app with the

### 2.2 Create an IAuthenticationProvider object

An instance of the **HttpClients** class handles building client. To create a new instance of this class, you need to provide an instance of `ICoreAuthenticationProvider`, which can authenticate requests to Microsoft Graph.
An instance of the **HttpClients** class handles building client. To create a new instance of this class, you need to provide an instance of `ICoreAuthenticationProvider`, which can authenticate requests to Microsoft Graph.
### To get instance of HttpClients
Auth in Java app [here](https://github.com/microsoftgraph/msgraph-sdk-java-auth)

Auth in Android app [here](https://github.com/microsoftgraph/msgraph-sdk-android-auth)

### 2.3 Get a HttpClients object
You must get a **HttpClients** object to make requests against the service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class MSBatchRequestStep {
public MSBatchRequestStep(String requestId, Request request, List<String> arrayOfDependsOnIds) {
if(requestId == null)
throw new IllegalArgumentException("Request Id cannot be null.");
if(requestId.length() == 0)
throw new IllegalArgumentException("Request Id cannot be empty.");
if(request == null)
new IllegalArgumentException("Request cannot be null.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.json.simple.JSONArray;
Expand All @@ -18,33 +19,17 @@

public class MSBatchResponseContent {

private JSONObject batchResponseObj;
private Response batchResponse;
private Map<String, Request> batchRequestsHashMap;
private JSONArray batchResponseArray;
private String nextLink;

/*
* @param batchResponse OkHttp batch response on execution of batch requests
*/
public MSBatchResponseContent(Response batchResponse) {
if(batchResponse == null)
throw new IllegalArgumentException("Batch Response cannot be null");

this.batchRequestsHashMap = createBatchRequestsHashMap(batchResponse);
this.batchResponse = batchResponse;
if(batchResponse.body() != null) {
try {
String batchResponseData = batchResponse.body().string();
if(batchResponseData != null) {
batchResponseObj = stringToJSONObject(batchResponseData);
if(batchResponseObj != null) {
batchResponseArray = (JSONArray)batchResponseObj.get("responses");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
update(batchResponse);
}

/*
Expand All @@ -54,12 +39,9 @@ public MSBatchResponseContent(Response batchResponse) {
* @return OkHttp Response corresponding to requestId
*/
public Response getResponseById(String requestId) {
if(batchResponseObj == null)
return null;
if(batchResponseArray == null) return null;

JSONArray responses = (JSONArray)batchResponseObj.get("responses");
if(responses == null)
return null;
JSONArray responses = batchResponseArray;

for(Object response : responses) {
JSONObject jsonresponse = (JSONObject)response;
Expand Down Expand Up @@ -104,20 +86,71 @@ public Response getResponseById(String requestId) {
return null;
}

/*
* @return responses as a string
/**
* Get map of id and responses
*
* @return responses in Map of id and response
*/
public String getResponses() {
return batchResponseArray != null ? batchResponseArray.toJSONString() : null;
public Map<String, Response> getResponses() {
if(batchResponseArray == null)
return null;
Map<String, Response> responsesMap = new HashMap<>();
for(String id : batchRequestsHashMap.keySet()) {
responsesMap.put(id, getResponseById(id));
}
return responsesMap;
}

/**
* Get iterator over the responses
*
* @return iterator for responses
*/
public Iterator<Map.Entry<String, Response>> getResponsesIterator() {
Map<String, Response> responsesMap = getResponses();
return responsesMap != null ? responsesMap.entrySet().iterator() : null;
}

public void update(Response batchResponse) {
if(batchResponse == null)
throw new IllegalArgumentException("Batch Response cannot be null");

Map<String, Request> requestMap = createBatchRequestsHashMap(batchResponse);
if(batchRequestsHashMap == null)
batchRequestsHashMap = new HashMap<>();
if(requestMap != null)
batchRequestsHashMap.putAll(requestMap);

if(batchResponse.body() != null) {
try {
String batchResponseData = batchResponse.body().string();
if(batchResponseData != null) {
JSONObject batchResponseObj = stringToJSONObject(batchResponseData);
if(batchResponseObj != null) {

JSONObject nextLinkObject = (JSONObject) batchResponseObj.get("@odata.nextLink");
if(nextLinkObject!=null)
nextLink = nextLinkObject.toString();

if(batchResponseArray == null)
batchResponseArray = new JSONArray();

JSONArray responseArray = (JSONArray)batchResponseObj.get("responses");
if(responseArray!=null)
batchResponseArray.addAll(responseArray);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

/*
* @return nextLink of batch response
*/
public String nextLink() {
if(batchResponseObj == null) return null;
Object nextLinkObject = batchResponseObj.get("nextLink");
return nextLinkObject != null ? ((JSONObject)nextLinkObject).toString() : null;
return nextLink;
}

private Map<String, Request> createBatchRequestsHashMap(Response batchResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;

import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType;
import com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions;

import okhttp3.Interceptor;
import okhttp3.Request;
Expand All @@ -21,6 +22,11 @@ public AuthenticationHandler(ICoreAuthenticationProvider authProvider) {
@Override
public Response intercept(Chain chain) throws IOException {
Request originalRequest = chain.request();

if(originalRequest.tag(TelemetryOptions.class) == null)
originalRequest = originalRequest.newBuilder().tag(TelemetryOptions.class, new TelemetryOptions()).build();
originalRequest.tag(TelemetryOptions.class).setFeatureUsage(TelemetryOptions.AUTH_HANDLER_ENABLED_FLAG);

Request authenticatedRequest = authProvider.authenticateRequest(originalRequest);
return chain.proceed(authenticatedRequest);
}
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/com/microsoft/graph/httpcore/HttpClients.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.microsoft.graph.httpcore;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.OkHttpClient.Builder;

Expand All @@ -15,7 +16,7 @@ private HttpClients() {
* @return OkHttpClient.Builder() custom builder for developer to add its own interceptors to it
*/
public static Builder custom() {
return new OkHttpClient.Builder();
return new OkHttpClient.Builder().addInterceptor(new TelemetryHandler());
}

/**
Expand All @@ -30,6 +31,24 @@ public static OkHttpClient createDefault(ICoreAuthenticationProvider auth) {
.followRedirects(false)
.addInterceptor(new RetryHandler())
.addInterceptor(new RedirectHandler())
.addInterceptor(new TelemetryHandler())
.build();
}

/**
* Creates {@link OkHttpClient} instance with interceptors
*
* @param interceptors Use interceptors provided while constructing http client
* @return OkHttpClient build with interceptors provided
*/
public static OkHttpClient createFromInterceptors(Interceptor[] interceptors) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
if(interceptors != null)
for(Interceptor interceptor : interceptors) {
if(interceptor != null)
builder.addInterceptor(interceptor);
}
builder.addInterceptor(new TelemetryHandler());
return builder.build();
}
}
Loading