Skip to content

Commit

Permalink
Merge branch 'dev' into beta/pipelinebuild/3629075
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet committed Sep 9, 2020
2 parents 1744c45 + 08b8cd2 commit 18fc27b
Show file tree
Hide file tree
Showing 26 changed files with 581 additions and 124 deletions.
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,8 @@ For known issues, see [issues](https://github.com/MicrosoftGraph/msgraph-beta-sd

The Microsoft Graph SDK is open for contribution. To contribute to this project, see [Contributing](https://github.com/microsoftgraph/msgraph-beta-sdk-java/blob/master/CONTRIBUTING.md).

Thanks to everyone who has already devoted time to improving the library:

<!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore -->
| [<img src="https://avatars.githubusercontent.com/u/2273297?v=4" width="100px;"/><br /><sub><b>Caitlin Bales</b></sub>](https://developer.microsoft.com/graph)<br />[💬](#question-cbales "Answering Questions") [💻](https://github.com/microsoftgraph/msgraph-sdk-java/commits?author=cbales "Code") [📖](https://github.com/microsoftgraph/msgraph-sdk-java/wiki "Documentation") [👀](#review-cbales "Reviewed Pull Requests") [⚠️](https://github.com/microsoftgraph/msgraph-sdk-java/commits?author=cbales "Tests")| [<img src="https://avatars.githubusercontent.com/u/318187?v=4" width="100px;"/><br /><sub><b>David Moten</b></sub>](https://github.com/davidmoten)<br /> [🐛](https://github.com/microsoftgraph/msgraph-sdk-java/issues?q=is%3Aissue+author%3Adavidmoten "Bug reports") [💻](https://github.com/microsoftgraph/msgraph-sdk-java/commits?author=davidmoten "Code") [📖](https://github.com/microsoftgraph/msgraph-sdk-java/commit/87389b5a4240072e3f2226a2f04f089916ffed0b#diff-04c6e90faac2675aa89e2176d2eec7d8 "Documentation") [🤔](#ideas-davidmoten "Ideas & Planning") [👀](#review-davidmoten "Reviewed Pull Requests") [⚠️](https://github.com/microsoftgraph/msgraph-sdk-java/commits?author=davidmoten "Tests") | [<img src="https://avatars.githubusercontent.com/u/8527305?v=4" width="100px;"/><br /><sub><b>Michael Mainer</b></sub>](https://developer.microsoft.com/graph)<br /> [💬](#question-cbales "Answering Questions") [🤔](#ideas-MIchaelMainer "Ideas & Planning") [👀](#review-MIchaelMainer "Reviewed Pull Requests") | [<img src="https://avatars.githubusercontent.com/u/27295799?v=4" width="100px;"/><br /><sub><b>Linda Caputo</b></sub>](https://developer.microsoft.com/graph)<br />[📖](https://github.com/microsoftgraph/msgraph-sdk-java/wiki "Documentation") | [<img src="https://avatars.githubusercontent.com/u/8884923?v=4" width="100px;"/><br /><sub><b>John Austin</b></sub>](https://developer.microsoft.com/graph)<br />[🐛](https://github.com/microsoftgraph/msgraph-sdk-java/issues "Bug reports") | [<img src="https://avatars.githubusercontent.com/u/3460953?v=4" width="100px;"/><br /><sub><b>Dmitry Pimenov</b></sub>](https://developer.microsoft.com/graph)<br />[🤔](#ideas-dpim "Ideas & Planning") | [<img src="https://avatars.githubusercontent.com/u/1427840?v=4" width="100px;"/><br /><sub><b>Jonathan Giles</b></sub>](https://github.com/JonathanGiles)<br />[🤔](#ideas-JonathanGiles "Ideas & Planning") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars.githubusercontent.com/u/881767?v=4" width="100px;"/><br /><sub><b>Martin Sawicki</b></sub>](https://github.com/martinsawicki)<br />[🤔](#ideas-martinsawicki "Ideas & Planning") | [<img src="https://avatars.githubusercontent.com/u/29152134?v=4" width="100px;"/><br /><sub><b>Louis Maresca</b></sub>](https://github.com/LouMM)<br />[🤔](#ideas-LouMM "Ideas & Planning") [👀](#review-LouMM "Reviewed Pull Requests") | [<img src="https://avatars.githubusercontent.com/u/604089?v=4" width="100px;"/><br /><sub><b>Josef H.B. Schneider</b></sub>](https://j0s.at/)<br />[🐛](https://github.com/microsoftgraph/msgraph-sdk-java/issues?q=is%3Aissue+author%3AJ0s3f "Bug reports") [💻](https://github.com/microsoftgraph/msgraph-sdk-java/commits?author=J0s3f "Code") | [<img src="https://avatars2.githubusercontent.com/u/3197588?v=4" width="100px;"/><br /><sub><b>Deepak Agrawal</b></sub>](https://github.com/deepak2016)<br />[💻](https://github.com/microsoftgraph/msgraph-sdk-java/commits?author=deepak2016 "Code") | <img src="https://avatars.githubusercontent.com/u/22523479?v=4" width="100px;"/><br /><sub><b>Ben Tipper</b></sub><br /> | [<img src="https://avatars3.githubusercontent.com/u/16473684?v=4" width="100px;"/><br /><sub><b>Nakul Sabharwal</b></sub>](https://github.com/NakulSabharwal)<br />[💻](https://github.com/microsoftgraph/msgraph-sdk-java/commits?author=NakulSabharwal "Code") [👀](#review-NakulSabharwal "Reviewed Pull Requests") | [<img src="https://avatars.githubusercontent.com/u/1620069?v=4" width="100px;"/><br /><sub><b>Dave Spurling</b></sub>](https://github.com/dspurling)<br />[🐛](https://github.com/microsoftgraph/msgraph-sdk-java/issues "Bug reports")
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind are welcome!

## 7. Supported Java versions

The Microsoft Graph beta SDK for Java library is supported at runtime for Java 8+ and [Android API revision 15](http://source.android.com/source/build-numbers.html) and greater through [desugaring](https://developer.android.com/studio/write/java8-support.html#library-desugaring).

## 8. License
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {

implementation 'com.google.code.gson:gson:2.8.6'

implementation 'com.sun.jersey:jersey-server:1.19.4'
implementation 'com.squareup.okhttp3:okhttp:3.12.1'

// Core Http library
implementation 'com.microsoft.graph:microsoft-graph-core:1.0.2'
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/microsoft/graph/core/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ private Constants() {
public static final String APPID = "app-id";
public static final String USERNAME = "[email protected]";
public static final String PASSWORD = "password";
public static final String TENANTID = "tenantid";
public static final String CLIENTSECRET = "clientsecret";
public static final String VERSION_NAME = "0.1.0";
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void setReadTimeout(int readTimeoutValue) {
* @param maxRedirects Max redirects that a request can take
*/
public void setMaxRedirects(int maxRedirects) {
this.maxRedirects = maxRedirects;
DefaultConnectionConfig.maxRedirects = maxRedirects;
}

/**
Expand All @@ -128,7 +128,7 @@ public int getMaxRedirects() {
* @param shouldRedirect Callback called before doing a redirect
*/
public void setShouldRedirect(IShouldRedirect shouldRedirect) {
this.shouldRedirect = shouldRedirect;
DefaultConnectionConfig.shouldRedirect = shouldRedirect;
}

/**
Expand All @@ -146,7 +146,7 @@ public IShouldRedirect getShouldRedirect() {
* @param shouldretry The callback called before retry
*/
public void setShouldRetry(IShouldRetry shouldretry) {
this.shouldRetry = shouldretry;
DefaultConnectionConfig.shouldRetry = shouldretry;
}

/**
Expand All @@ -164,7 +164,7 @@ public IShouldRetry getShouldRetry() {
* @param maxRetries Max retries for a request
*/
public void setMaxRetries(int maxRetries) {
this.maxRetries = maxRetries;
DefaultConnectionConfig.maxRetries = maxRetries;
}

/**
Expand All @@ -182,7 +182,7 @@ public int getMaxRetries() {
* @param delay Delay in seconds between retries
*/
public void setDelay(long delay) {
this.delay = delay;
DefaultConnectionConfig.delay = delay;
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/microsoft/graph/http/BaseRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

package com.microsoft.graph.http;

import java.net.URI;
import javax.ws.rs.core.UriBuilder;
import okhttp3.HttpUrl;
import okhttp3.HttpUrl.Builder;

import com.microsoft.graph.concurrency.ICallback;
import com.microsoft.graph.core.IBaseClient;
Expand Down Expand Up @@ -172,11 +172,10 @@ public BaseRequest(final String requestUrl,
@Override
public URL getRequestUrl() {
String requestUrl = addFunctionParameters();
URI baseUrl = URI.create(requestUrl);
final UriBuilder uriBuilder = UriBuilder.fromUri(baseUrl);
final Builder uriBuilder = HttpUrl.parse(requestUrl).newBuilder();

for (final QueryOption option : queryOptions) {
uriBuilder.queryParam(option.getName(), option.getValue().toString());
uriBuilder.addQueryParameter(option.getName(), option.getValue().toString());
}

try {
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/microsoft/graph/http/CoreHttpProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,13 @@ public MediaType contentType() {
} else {
logger.logDebug("Response binary");
isBinaryStreamInput = true;
//no inspection unchecked
return (Result) handleBinaryStream(in);
if (resultClass == InputStream.class) {
return (Result) handleBinaryStream(in);
} else if(response.body() != null && response.body().contentLength() > 0) { // some services reply in text/plain with a JSON representation...
return handleJsonResponse(in, CoreHttpProvider.getResponseHeadersAsMapOfStringList(response), resultClass);
} else {
return (Result) null;
}
}
} finally {
if (!isBinaryStreamInput) {
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/microsoft/graph/http/GraphServiceException.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Collections;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.microsoft.graph.core.ClientException;
import com.microsoft.graph.core.GraphErrorCodes;
import com.microsoft.graph.logger.ILogger;
import com.microsoft.graph.logger.LoggerLevel;
import com.microsoft.graph.options.HeaderOption;
Expand Down Expand Up @@ -150,8 +150,16 @@ protected GraphServiceException(final String method,
this.responseHeaders = responseHeaders;
this.error = error;
this.verbose = verbose;
for(String requestHeader : requestHeaders) {
for(String headerKeyToRedact : requestHeadersToRedact) {
if(requestHeader.startsWith(headerKeyToRedact)) {
Collections.replaceAll(requestHeaders, requestHeader, headerKeyToRedact + " : [PII_REDACTED]");
break;
}
}
}
}

private static String[] requestHeadersToRedact = {"Authorization"};
/**
* Gets the The HTTP response message
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// ------------------------------------------------------------------------------
// Copyright (c) 2017 Microsoft Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ------------------------------------------------------------------------------

package com.microsoft.graph.serializer;
import java.util.Arrays;
import java.util.List;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.microsoft.graph.logger.ILogger;
import com.microsoft.graph.models.extensions.Attachment;
import com.microsoft.graph.requests.extensions.AttachmentCollectionPage;
import com.microsoft.graph.requests.extensions.AttachmentCollectionResponse;

public class AttachmentCollectionPageSerializer {

private static DefaultSerializer serializer;

/**
* Not available for instantiation
*/
private AttachmentCollectionPageSerializer() {
}

/**
* Serializes an AttachmentCollectionPage
*
* @param src the AttachmentCollectionPage variable for serialization
* @param logger the logger
* @return JsonElement of AttachmentCollectionPage
*/
public static JsonElement serialize(final AttachmentCollectionPage src, final ILogger logger) {
if(src == null) {
return null;
}
JsonArray jsonArray = new JsonArray();
List<Attachment> attachments = src.getCurrentPage();
serializer = new DefaultSerializer(logger);
String json;
JsonObject jsonObject;
for(Attachment attachment : attachments) {
jsonObject = new JsonObject();
json = serializer.serializeObject(attachment);
jsonObject = (JsonObject)JsonParser.parseString(json);
jsonArray.add(jsonObject);
}
return jsonArray;
}

/**
* Deserializes the JsonElement
*
* @param json the source AttachmentCollectionPage's Json
* @param logger the logger
* @throws JsonParseException the parse exception
* @return the deserialized AttachmentCollectionPage
*/
public static AttachmentCollectionPage deserialize(final JsonElement json, final ILogger logger) throws JsonParseException {
if (json == null) {
return null;
}
final AttachmentCollectionResponse response = new AttachmentCollectionResponse();
serializer = new DefaultSerializer(logger);
final JsonObject[] sourceArray = serializer.deserializeObject(json.toString(), JsonObject[].class);
final Attachment[] array = new Attachment[sourceArray.length];
for (int i = 0; i < sourceArray.length; i++) {
array[i] = serializer.deserializeObject(sourceArray[i].toString(), Attachment.class);
array[i].setRawObject(serializer, sourceArray[i]);
}
response.value = Arrays.asList(array);
return new AttachmentCollectionPage(response, null);
}
}
Loading

0 comments on commit 18fc27b

Please sign in to comment.