Search code examples
javaapachehttphttpentity

How do I modify the content of an HttpEntity


I've got an HttpResponse with an HttpEntity (all from org.apache.http).

My HttpEntity has some application/json content that I want to modify before sending it forward.

I can read the content as a string with

EntityUtils.toString(response.getEntity());

But how do I store the modified content of my entity back into my response?


Solution

  • Solved using EntityBuilder.

    response.setEntity(EntityBuilder.create().setText(newText).setContentType(ContentType.APPLICATION_JSON).build());