protected List < BoxAPIResponse > parseResponse ( BoxJSONResponse batchResponse ) { JsonObject responseJSON = JsonObject . readFrom ( batchResponse . getJSON ( ) ) ; List < BoxAPIResponse > responses = new ArrayList < BoxAPIResponse > ( ) ; Iterator < JsonValue > responseIterator = responseJSON . get ( "responses" ) . asArray ( ) . iterator ( ) ; while ( responseIterator . hasNext ( ) ) { JsonObject jsonResponse = responseIterator . next ( ) . asObject ( ) ; BoxAPIResponse response = null ; //Gather headers Map < String , String > responseHeaders = new HashMap < String , String > ( ) ; if ( jsonResponse . get ( "headers" ) != null ) { JsonObject batchResponseHeadersObject = jsonResponse . get ( "headers" ) . asObject ( ) ; for ( JsonObject . Member member : batchResponseHeadersObject ) { String headerName = member . getName ( ) ; String headerValue = member . getValue ( ) . asString ( ) ; responseHeaders . put ( headerName , headerValue ) ; } } // Construct a BoxAPIResponse when response is null, or a BoxJSONResponse when there's a response // (not anticipating any other response as per current APIs. // Ideally we should do it based on response header) if ( jsonResponse . get ( "response" ) == null || jsonResponse . get ( "response" ) . isNull ( ) ) { response = new BoxAPIResponse ( jsonResponse . get ( "status" ) . asInt ( ) , responseHeaders ) ; } else { response = new BoxJSONResponse ( jsonResponse . get ( "status" ) . asInt ( ) , responseHeaders , jsonResponse . get ( "response" ) . asObject ( ) ) ; } responses . add ( response ) ; } return responses ; }
Parses btch api response to create a list of BoxAPIResponse objects .