We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could you place put an example how to manipulate the content with the HttpResponseInterceptor?
It's not clear how to replace the HttpEntity.
In this Example I like to convert all Text to uppercase:
@Test public void shoudConvertEverythingToUpperCase() throws ClientProtocolException, IOException { final DefaultHttpClient defaultHttpClient = new DefaultHttpClient(); defaultHttpClient.addResponseInterceptor(new HttpResponseInterceptor() { @Override public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { final HttpEntity entity = response.getEntity(); final HttpEntity upperCaseEntity = makeAllUppercase(entity); response.setEntity(upperCaseEntity); } private HttpEntity makeAllUppercase(final HttpEntity entity) { // how to uppercase everything and return the cloned HttpEntity return null; } }); final HttpResponse httpResponse = defaultHttpClient.execute(new HttpGet("http://opensource.webmetrics.com/browsermob-proxy/")); assertTrue(StringUtils.isAllUpperCase(EntityUtils.toString(httpResponse.getEntity()))); }
The text was updated successfully, but these errors were encountered:
Here is how you can get access to content:
server.addRequestInterceptor(new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { EntityEnclosingRequestWrapper wrapper = (EntityEnclosingRequestWrapper) request; requests.add((ClonedInputStream) wrapper.getEntity().getContent()); try { Field consumed = EntityEnclosingRequestWrapper.class.getDeclaredField("consumed"); consumed.setAccessible(true); consumed.set(wrapper, Boolean.FALSE); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } }); server.addResponseInterceptor(new HttpResponseInterceptor() { @Override public void process(HttpResponse httpResponse, HttpContext httpContext) throws HttpException, IOException { ClonedInputStream cloned = new ClonedInputStream(httpResponse.getEntity().getContent()); try { Field content = BasicHttpEntity.class.getDeclaredField("content"); content.setAccessible(true); content.set(httpResponse.getEntity(), cloned); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } responses.add(cloned); } });
Sorry, something went wrong.
No branches or pull requests
Could you place put an example how to manipulate the content with the HttpResponseInterceptor?
It's not clear how to replace the HttpEntity.
In this Example I like to convert all Text to uppercase:
The text was updated successfully, but these errors were encountered: