Skip to content

Commit 18fc27b

Browse files
committed
Merge branch 'dev' into beta/pipelinebuild/3629075
2 parents 1744c45 + 08b8cd2 commit 18fc27b

26 files changed

+581
-124
lines changed

README.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,8 @@ For known issues, see [issues](https://github.com/MicrosoftGraph/msgraph-beta-sd
112112

113113
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).
114114

115-
Thanks to everyone who has already devoted time to improving the library:
116-
117-
<!-- ALL-CONTRIBUTORS-LIST:START -->
118-
<!-- prettier-ignore -->
119-
| [<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") |
120-
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
121-
| [<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")
122-
<!-- ALL-CONTRIBUTORS-LIST:END -->
123-
124-
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind are welcome!
125-
126115
## 7. Supported Java versions
116+
127117
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).
128118

129119
## 8. License

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies {
3333

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

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

3838
// Core Http library
3939
implementation 'com.microsoft.graph:microsoft-graph-core:1.0.2'

src/main/java/com/microsoft/graph/core/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ private Constants() {
2828
public static final String APPID = "app-id";
2929
public static final String USERNAME = "user@email.com";
3030
public static final String PASSWORD = "password";
31+
public static final String TENANTID = "tenantid";
32+
public static final String CLIENTSECRET = "clientsecret";
3133
public static final String VERSION_NAME = "0.1.0";
3234
}

src/main/java/com/microsoft/graph/core/DefaultConnectionConfig.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void setReadTimeout(int readTimeoutValue) {
110110
* @param maxRedirects Max redirects that a request can take
111111
*/
112112
public void setMaxRedirects(int maxRedirects) {
113-
this.maxRedirects = maxRedirects;
113+
DefaultConnectionConfig.maxRedirects = maxRedirects;
114114
}
115115

116116
/**
@@ -128,7 +128,7 @@ public int getMaxRedirects() {
128128
* @param shouldRedirect Callback called before doing a redirect
129129
*/
130130
public void setShouldRedirect(IShouldRedirect shouldRedirect) {
131-
this.shouldRedirect = shouldRedirect;
131+
DefaultConnectionConfig.shouldRedirect = shouldRedirect;
132132
}
133133

134134
/**
@@ -146,7 +146,7 @@ public IShouldRedirect getShouldRedirect() {
146146
* @param shouldretry The callback called before retry
147147
*/
148148
public void setShouldRetry(IShouldRetry shouldretry) {
149-
this.shouldRetry = shouldretry;
149+
DefaultConnectionConfig.shouldRetry = shouldretry;
150150
}
151151

152152
/**
@@ -164,7 +164,7 @@ public IShouldRetry getShouldRetry() {
164164
* @param maxRetries Max retries for a request
165165
*/
166166
public void setMaxRetries(int maxRetries) {
167-
this.maxRetries = maxRetries;
167+
DefaultConnectionConfig.maxRetries = maxRetries;
168168
}
169169

170170
/**
@@ -182,7 +182,7 @@ public int getMaxRetries() {
182182
* @param delay Delay in seconds between retries
183183
*/
184184
public void setDelay(long delay) {
185-
this.delay = delay;
185+
DefaultConnectionConfig.delay = delay;
186186
}
187187

188188
/**

src/main/java/com/microsoft/graph/http/BaseRequest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
package com.microsoft.graph.http;
2424

25-
import java.net.URI;
26-
import javax.ws.rs.core.UriBuilder;
25+
import okhttp3.HttpUrl;
26+
import okhttp3.HttpUrl.Builder;
2727

2828
import com.microsoft.graph.concurrency.ICallback;
2929
import com.microsoft.graph.core.IBaseClient;
@@ -172,11 +172,10 @@ public BaseRequest(final String requestUrl,
172172
@Override
173173
public URL getRequestUrl() {
174174
String requestUrl = addFunctionParameters();
175-
URI baseUrl = URI.create(requestUrl);
176-
final UriBuilder uriBuilder = UriBuilder.fromUri(baseUrl);
175+
final Builder uriBuilder = HttpUrl.parse(requestUrl).newBuilder();
177176

178177
for (final QueryOption option : queryOptions) {
179-
uriBuilder.queryParam(option.getName(), option.getValue().toString());
178+
uriBuilder.addQueryParameter(option.getName(), option.getValue().toString());
180179
}
181180

182181
try {

src/main/java/com/microsoft/graph/http/CoreHttpProvider.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,13 @@ public MediaType contentType() {
398398
} else {
399399
logger.logDebug("Response binary");
400400
isBinaryStreamInput = true;
401-
//no inspection unchecked
402-
return (Result) handleBinaryStream(in);
401+
if (resultClass == InputStream.class) {
402+
return (Result) handleBinaryStream(in);
403+
} else if(response.body() != null && response.body().contentLength() > 0) { // some services reply in text/plain with a JSON representation...
404+
return handleJsonResponse(in, CoreHttpProvider.getResponseHeadersAsMapOfStringList(response), resultClass);
405+
} else {
406+
return (Result) null;
407+
}
403408
}
404409
} finally {
405410
if (!isBinaryStreamInput) {

src/main/java/com/microsoft/graph/http/GraphServiceException.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
import java.util.List;
2929
import java.util.Locale;
3030
import java.util.Map;
31+
import java.util.Collections;
3132

3233
import com.google.gson.Gson;
3334
import com.google.gson.GsonBuilder;
3435
import com.microsoft.graph.core.ClientException;
35-
import com.microsoft.graph.core.GraphErrorCodes;
3636
import com.microsoft.graph.logger.ILogger;
3737
import com.microsoft.graph.logger.LoggerLevel;
3838
import com.microsoft.graph.options.HeaderOption;
@@ -150,8 +150,16 @@ protected GraphServiceException(final String method,
150150
this.responseHeaders = responseHeaders;
151151
this.error = error;
152152
this.verbose = verbose;
153+
for(String requestHeader : requestHeaders) {
154+
for(String headerKeyToRedact : requestHeadersToRedact) {
155+
if(requestHeader.startsWith(headerKeyToRedact)) {
156+
Collections.replaceAll(requestHeaders, requestHeader, headerKeyToRedact + " : [PII_REDACTED]");
157+
break;
158+
}
159+
}
160+
}
153161
}
154-
162+
private static String[] requestHeadersToRedact = {"Authorization"};
155163
/**
156164
* Gets the The HTTP response message
157165
*
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) 2017 Microsoft Corporation
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
// ------------------------------------------------------------------------------
22+
23+
package com.microsoft.graph.serializer;
24+
import java.util.Arrays;
25+
import java.util.List;
26+
27+
import com.google.gson.JsonArray;
28+
import com.google.gson.JsonElement;
29+
import com.google.gson.JsonObject;
30+
import com.google.gson.JsonParseException;
31+
import com.google.gson.JsonParser;
32+
import com.microsoft.graph.logger.ILogger;
33+
import com.microsoft.graph.models.extensions.Attachment;
34+
import com.microsoft.graph.requests.extensions.AttachmentCollectionPage;
35+
import com.microsoft.graph.requests.extensions.AttachmentCollectionResponse;
36+
37+
public class AttachmentCollectionPageSerializer {
38+
39+
private static DefaultSerializer serializer;
40+
41+
/**
42+
* Not available for instantiation
43+
*/
44+
private AttachmentCollectionPageSerializer() {
45+
}
46+
47+
/**
48+
* Serializes an AttachmentCollectionPage
49+
*
50+
* @param src the AttachmentCollectionPage variable for serialization
51+
* @param logger the logger
52+
* @return JsonElement of AttachmentCollectionPage
53+
*/
54+
public static JsonElement serialize(final AttachmentCollectionPage src, final ILogger logger) {
55+
if(src == null) {
56+
return null;
57+
}
58+
JsonArray jsonArray = new JsonArray();
59+
List<Attachment> attachments = src.getCurrentPage();
60+
serializer = new DefaultSerializer(logger);
61+
String json;
62+
JsonObject jsonObject;
63+
for(Attachment attachment : attachments) {
64+
jsonObject = new JsonObject();
65+
json = serializer.serializeObject(attachment);
66+
jsonObject = (JsonObject)JsonParser.parseString(json);
67+
jsonArray.add(jsonObject);
68+
}
69+
return jsonArray;
70+
}
71+
72+
/**
73+
* Deserializes the JsonElement
74+
*
75+
* @param json the source AttachmentCollectionPage's Json
76+
* @param logger the logger
77+
* @throws JsonParseException the parse exception
78+
* @return the deserialized AttachmentCollectionPage
79+
*/
80+
public static AttachmentCollectionPage deserialize(final JsonElement json, final ILogger logger) throws JsonParseException {
81+
if (json == null) {
82+
return null;
83+
}
84+
final AttachmentCollectionResponse response = new AttachmentCollectionResponse();
85+
serializer = new DefaultSerializer(logger);
86+
final JsonObject[] sourceArray = serializer.deserializeObject(json.toString(), JsonObject[].class);
87+
final Attachment[] array = new Attachment[sourceArray.length];
88+
for (int i = 0; i < sourceArray.length; i++) {
89+
array[i] = serializer.deserializeObject(sourceArray[i].toString(), Attachment.class);
90+
array[i].setRawObject(serializer, sourceArray[i]);
91+
}
92+
response.value = Arrays.asList(array);
93+
return new AttachmentCollectionPage(response, null);
94+
}
95+
}

0 commit comments

Comments
 (0)