Modifying the Request Body
To modify the request body in the preprocessing stage, employ the content source and content producer to read from and write to the HTTP request.
Procedure
-
Get content source from the request.
-
Get input stream from the content source.
-
Read content from the input stream.
-
Modify the content.
-
Create a content producer.
-
Set the request body to the created content producer.
ContentSource body = event.getCallContext().getRequest().getBody();
final InputStream inputStream = body.getInputStream() ;
//use input stream to read content
//modify content
httpReq.setBody(new ContentProducer() { //set new content body
.........
public void writeTo(OutputStream out) throws IOException {
out.write("modified content")
out.flush();
out.close();
}
});
note
Refer to the working code in examples/ModifyRequestBody.java.