Hi all,
I am using HttpClient to do some reverse-proxy inside java web
applications. Maybe it could be useful to other people. What about adding a
reverse-proxy as a subproject to HttpClient project ?
I was thinking of 2 classes :
- ProxyHttpRequest
- ProxyHttpResponse
A basic use inside an HttpServlet would look like this :
protected void doPost(HttpServletRequest httpServletRequest,
HttpServletResponse httpResponse)
throws ServletException, IOException {
HttpRequest httpRequest = new ProxyRequest(httpServletRequest);
HttpResponse httpResponse = httpClient.execute(target, httpRequest);
ProxyHttpResponse proxyHttpResponse = new
ProxyHttpResponse(httpResponse);
proxyHttpResponse.forward(httpServletResponse);
}
So these classes would take care of all the problems of copying the right
Http headers and entity of the request or response. They will make the
translation between Servlet API and HttpClient API.
In addition it would be possible to modify the request or the response
before forwarding them depending on your needs.
--
Regards,
Francois-Xavier Bonnet