0

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?

fdr
  • 119
  • 6

2 Answers2

1

Solved using EntityBuilder.

response.setEntity(EntityBuilder.create().setText(newText).setContentType(ContentType.APPLICATION_JSON).build());
fdr
  • 119
  • 6
0

using the toString method is used to 'print' an object. Most of the time, you'll use the toStringmethod for logging. You should rather access the variables you want to read or modify via the getters. For example:

reponse.getEntity().getContentEncoding().getName();
reponse.getEntity().getContentEncoding().getValue()
Loic Mouchard
  • 1,121
  • 7
  • 22