hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Warren Bell <warrenbe...@gmail.com>
Subject Proxy org.apache.http.HttpResponse into javax.servlet.http.HttpServletResponse
Date Thu, 09 Feb 2012 03:10:15 GMT
I am writing a small proxy servlet and want to know what is the best way
to convert the entity from an org.apache.http.HttpResponse, I am getting
from a destination server through HttpClient, into the
javax.servlet.http.HttpServletResponse outputStream I need in my servlet
to send back to the client's browser. I am currently doing something
like this below, but I am running into issues with chunked data.

I have already transferred all response headers from
orgApacheHttpHttpResponse to javaxServletHttpHttpServletResponse before
the code below.


HttpEntity entity = orgApacheHttpHttpResponse.getEntity();

InputStream inputStream = null;
  inputStream = entity.getContent();
  BufferedInputStream bufferedInputStream = new
  OutputStream outputStream =
  int intNextByte;
  while((intNextByte = bufferedInputStream.read()) != -1)
catch(IOException ioex)
catch(RuntimeException rex)
  Close all streams

The code above does work when I manually exclude the "Transfer-Encoding:
chunked" header from the javax.servlet.http.HttpServletResponse, but am
I suppose to do that ? Basically the response that comes back to the
client's browser should be the same as the response that comes back to
HTTPClient in my servlet.

Also, are there any response headers that I should not transfer over to
javax.servlet.http.HttpServletResponse like maybe Transfer-Encoding ?
Are there headers that get added by the web server after my response has
left the servlet ?


Warren Bell

To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org

View raw message