File tree Expand file tree Collapse file tree 3 files changed +29
-9
lines changed
main/java/com/microsoft/graph
test/java/com/microsoft/graph/functional Expand file tree Collapse file tree 3 files changed +29
-9
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,10 @@ private Constants() {
1717 * The content type for JSON responses
1818 */
1919 public static final String JSON_CONTENT_TYPE = "application/json" ;
20+ /**
21+ * The content type for text responses
22+ */
23+ public static final String TEXT_CONTENT_TYPE = "text/plain" ;
2024 /**
2125 * The binary content type header's value
2226 */
Original file line number Diff line number Diff line change @@ -417,20 +417,20 @@ public Request authenticateRequest(Request request) {
417417
418418 final Map <String , String > headers = CoreHttpProvider .getResponseHeadersAsMapStringString (response );
419419
420+ if (response .body () == null || response .body ().contentLength () == 0 )
421+ return (Result ) null ;
422+
420423 final String contentType = headers .get (Constants .CONTENT_TYPE_HEADER_NAME );
421- if (contentType != null && contentType .contains (Constants .JSON_CONTENT_TYPE )) {
424+ if (contentType != null && resultClass != InputStream .class &&
425+ (contentType .contains (Constants .JSON_CONTENT_TYPE ) || contentType .contains (Constants .TEXT_CONTENT_TYPE ))) { // some services reply in text/plain with a JSON representation...
422426 logger .logDebug ("Response json" );
423427 return handleJsonResponse (in , CoreHttpProvider .getResponseHeadersAsMapOfStringList (response ), resultClass );
424- } else {
428+ } else if ( resultClass == InputStream . class ) {
425429 logger .logDebug ("Response binary" );
426430 isBinaryStreamInput = true ;
427- if (resultClass == InputStream .class ) {
428- return (Result ) handleBinaryStream (in );
429- } else if (response .body () != null && response .body ().contentLength () > 0 ) { // some services reply in text/plain with a JSON representation...
430- return handleJsonResponse (in , CoreHttpProvider .getResponseHeadersAsMapOfStringList (response ), resultClass );
431- } else {
432- return (Result ) null ;
433- }
431+ return (Result ) handleBinaryStream (in );
432+ } else {
433+ return (Result ) null ;
434434 }
435435 } finally {
436436 if (!isBinaryStreamInput ) {
Original file line number Diff line number Diff line change 11package com .microsoft .graph .functional ;
22
33import static org .junit .Assert .assertFalse ;
4+ import static org .junit .Assert .assertTrue ;
45
56import java .io .IOException ;
67import java .io .InputStream ;
1314import com .microsoft .graph .concurrency .ChunkedUploadProvider ;
1415import com .microsoft .graph .concurrency .IProgressCallback ;
1516import com .microsoft .graph .core .ClientException ;
17+ import com .microsoft .graph .http .CoreHttpProvider ;
1618import com .microsoft .graph .models .extensions .DriveItem ;
1719import com .microsoft .graph .models .extensions .DriveItemUploadableProperties ;
1820import com .microsoft .graph .models .extensions .UploadSession ;
@@ -85,4 +87,18 @@ public void testDownloadWithCustomRequest() throws IOException {
8587 assertFalse ("stream should not be empty" , stream .read () == -1 );
8688 }
8789 }
90+ @ Test
91+ public void downloadJsonFileFromOneDrive () throws Exception {
92+ final InputStream stream = testBase .graphClient .me ()
93+ .drive ()
94+ .root ()
95+ .itemWithPath ("test.json" )
96+ .content ()
97+ .buildRequest ()
98+ .get ();
99+
100+ final String fileContent = CoreHttpProvider .streamToString (stream );
101+
102+ assertTrue (fileContent .length () > 0 );
103+ }
88104}
You can’t perform that action at this time.
0 commit comments