protected void prepareRequest ( List < BoxAPIRequest > requests ) { JsonObject body = new JsonObject ( ) ; JsonArray requestsJSONArray = new JsonArray ( ) ; for ( BoxAPIRequest request : requests ) { JsonObject batchRequest = new JsonObject ( ) ; batchRequest . add ( "method" , request . getMethod ( ) ) ; batchRequest . add ( "relative_url" , request . getUrl ( ) . toString ( ) . substring ( this . api . getBaseURL ( ) . length ( ) - 1 ) ) ; //If the actual request has a JSON body then add it to vatch request if ( request instanceof BoxJSONRequest ) { BoxJSONRequest jsonRequest = ( BoxJSONRequest ) request ; batchRequest . add ( "body" , jsonRequest . getBodyAsJsonValue ( ) ) ; } //Add any headers that are in the request, except Authorization if ( request . getHeaders ( ) != null ) { JsonObject batchRequestHeaders = new JsonObject ( ) ; for ( RequestHeader header : request . getHeaders ( ) ) { if ( header . getKey ( ) != null && ! header . getKey ( ) . isEmpty ( ) && ! HttpHeaders . AUTHORIZATION . equals ( header . getKey ( ) ) ) { batchRequestHeaders . add ( header . getKey ( ) , header . getValue ( ) ) ; } } batchRequest . add ( "headers" , batchRequestHeaders ) ; } //Add the request to array requestsJSONArray . add ( batchRequest ) ; } //Add the requests array to body body . add ( "requests" , requestsJSONArray ) ; super . setBody ( body ) ; }
Prepare a batch api request using list of individual reuests .