private R2Request < GenericRecord > buildWriteRequest ( BufferedRecord < GenericRecord > record ) { if ( record == null ) { return null ; } R2Request < GenericRecord > request = new R2Request <> ( ) ; HttpOperation httpOperation = HttpUtils . toHttpOperation ( record . getRecord ( ) ) ; // Set uri URI uri = HttpUtils . buildURI ( urlTemplate , httpOperation . getKeys ( ) , httpOperation . getQueryParams ( ) ) ; if ( uri == null ) { return null ; } RestRequestBuilder builder = new RestRequestBuilder ( uri ) . setMethod ( method . getHttpMethod ( ) . toString ( ) ) ; // Set headers Map < String , String > headers = httpOperation . getHeaders ( ) ; if ( headers != null && headers . size ( ) != 0 ) { builder . setHeaders ( headers ) ; } builder . setHeader ( RestConstants . HEADER_RESTLI_PROTOCOL_VERSION , protocolVersion ) ; builder . setHeader ( RestConstants . HEADER_RESTLI_REQUEST_METHOD , method . toString ( ) ) ; // Add payload int bytesWritten = addPayload ( builder , httpOperation . getBody ( ) ) ; if ( bytesWritten == - 1 ) { throw new RuntimeException ( "Fail to write payload into request" ) ; } request . markRecord ( record , bytesWritten ) ; request . setRawRequest ( build ( builder ) ) ; return request ; }
Build a request from a single record