@@ -389,88 +389,88 @@ private <Result, Body, DeserializeType> Result processResponse(final Response re
389389 final Class <Result > resultClass ,
390390 final Body serializable ,
391391 final IStatefulResponseHandler <Result , DeserializeType > handler ) {
392- try (final ResponseBody body = response .body ()) {
392+ final ResponseBody body = response .body ();
393+ try {
394+ InputStream in = null ;
395+ boolean isBinaryStreamInput = false ;
393396 try {
394- InputStream in = null ;
395- boolean isBinaryStreamInput = false ;
396- try {
397397
398- // Call being executed
398+ // Call being executed
399399
400400
401- if (handler != null ) {
402- handler .configConnection (response );
403- }
401+ if (handler != null ) {
402+ handler .configConnection (response );
403+ }
404404
405- logger .logDebug (String .format (Locale .ROOT , "Response code %d, %s" ,
406- response .code (),
407- response .message ()));
405+ logger .logDebug (String .format (Locale .ROOT , "Response code %d, %s" ,
406+ response .code (),
407+ response .message ()));
408408
409- if (handler != null ) {
410- logger .logDebug ("StatefulResponse is handling the HTTP response." );
411- return handler .generateResult (
412- request , response , this .serializer , this .logger );
413- }
409+ if (handler != null ) {
410+ logger .logDebug ("StatefulResponse is handling the HTTP response." );
411+ return handler .generateResult (
412+ request , response , this .serializer , this .logger );
413+ }
414414
415- if (response .code () >= HttpResponseCode .HTTP_CLIENT_ERROR ) {
416- logger .logDebug ("Handling error response" );
417- in = body .byteStream ();
418- handleErrorResponse (request , serializable , response );
419- }
415+ if (response .code () >= HttpResponseCode .HTTP_CLIENT_ERROR ) {
416+ logger .logDebug ("Handling error response" );
417+ in = body .byteStream ();
418+ handleErrorResponse (request , serializable , response );
419+ }
420420
421- final Map <String , List <String >> responseHeaders = response .headers ().toMultimap ();
421+ final Map <String , List <String >> responseHeaders = response .headers ().toMultimap ();
422422
423- if (response .code () == HttpResponseCode .HTTP_NOBODY
424- || response .code () == HttpResponseCode .HTTP_NOT_MODIFIED ) {
425- logger .logDebug ("Handling response with no body" );
426- return handleEmptyResponse (responseHeaders , resultClass );
427- }
423+ if (response .code () == HttpResponseCode .HTTP_NOBODY
424+ || response .code () == HttpResponseCode .HTTP_NOT_MODIFIED ) {
425+ logger .logDebug ("Handling response with no body" );
426+ return handleEmptyResponse (responseHeaders , resultClass );
427+ }
428428
429- if (response .code () == HttpResponseCode .HTTP_ACCEPTED ) {
430- logger .logDebug ("Handling accepted response" );
431- return handleEmptyResponse (responseHeaders , resultClass );
432- }
429+ if (response .code () == HttpResponseCode .HTTP_ACCEPTED ) {
430+ logger .logDebug ("Handling accepted response" );
431+ return handleEmptyResponse (responseHeaders , resultClass );
432+ }
433433
434- in = new BufferedInputStream (body .byteStream ());
435-
436- if (body == null || body .contentLength () == 0 )
437- return null ;
438-
439- if (body .contentType () != null && body .contentType ().subtype ().contains ("json" )
440- && resultClass != InputStream .class ) {
441- logger .logDebug ("Response json" );
442- return handleJsonResponse (in , responseHeaders , resultClass );
443- } else if (resultClass == InputStream .class ) {
444- logger .logDebug ("Response binary" );
445- isBinaryStreamInput = true ;
446- return (Result ) handleBinaryStream (in );
447- } else if (body .contentType () != null && resultClass != InputStream .class &&
448- body .contentType ().type ().contains ("text" ) &&
449- body .contentType ().subtype ().contains ("plain" )) {
450- return handleRawResponse (in , resultClass );
451- } else {
452- return null ;
453- }
454- } finally {
455- if (!isBinaryStreamInput ) {
456- try {
457- if (in != null ) in .close ();
458- }catch (IOException e ) {
459- logger .logError (e .getMessage (), e );
460- }
461- if (response != null ) response .close ();
434+ in = new BufferedInputStream (body .byteStream ());
435+
436+ if (body == null || body .contentLength () == 0 )
437+ return null ;
438+
439+ if (body .contentType () != null && body .contentType ().subtype ().contains ("json" )
440+ && resultClass != InputStream .class ) {
441+ logger .logDebug ("Response json" );
442+ return handleJsonResponse (in , responseHeaders , resultClass );
443+ } else if (resultClass == InputStream .class ) {
444+ logger .logDebug ("Response binary" );
445+ isBinaryStreamInput = true ;
446+ return (Result ) handleBinaryStream (in );
447+ } else if (body .contentType () != null && resultClass != InputStream .class &&
448+ body .contentType ().type ().contains ("text" ) &&
449+ body .contentType ().subtype ().contains ("plain" )) {
450+ return handleRawResponse (in , resultClass );
451+ } else {
452+ return null ;
453+ }
454+ } finally {
455+ if (!isBinaryStreamInput ) {
456+ try {
457+ if (in != null ) in .close ();
458+ if (body != null ) body .close ();
459+ }catch (IOException e ) {
460+ logger .logError (e .getMessage (), e );
462461 }
462+ if (response != null ) response .close ();
463463 }
464- } catch (final GraphServiceException ex ) {
465- final boolean shouldLogVerbosely = logger .getLoggingLevel () == LoggerLevel .DEBUG ;
466- logger .logError ("Graph service exception " + ex .getMessage (shouldLogVerbosely ), ex );
467- throw ex ;
468- } catch (final Exception ex ) {
469- final ClientException clientException = new ClientException ("Error during http request" ,
470- ex );
471- logger .logError ("Error during http request" , clientException );
472- throw clientException ;
473464 }
465+ } catch (final GraphServiceException ex ) {
466+ final boolean shouldLogVerbosely = logger .getLoggingLevel () == LoggerLevel .DEBUG ;
467+ logger .logError ("Graph service exception " + ex .getMessage (shouldLogVerbosely ), ex );
468+ throw ex ;
469+ } catch (final Exception ex ) {
470+ final ClientException clientException = new ClientException ("Error during http request" ,
471+ ex );
472+ logger .logError ("Error during http request" , clientException );
473+ throw clientException ;
474474 }
475475 }
476476 /**
0 commit comments