Java Servlet API can forward requests to another path within the same server (identical host:port). But, forwarding to a different host:port — like proxy do — is another story.
I've tried to do that with Jersey Client, adapting the ServletRequest — method, headers, mediatype and body — to a Jersey ClientRequest (with a different base uri), making the call, and adapting back the Jersey ClientResponse — method, headers, mediatype and body — to the ServletResponse.
Adapting those manually seems wrong to me.
Isn't there a pure Servlet API solution? Or an HTTP client capable of adapting requests back and forth when changing the host:port?
You should use javax.net.HttpURLConnection
Here is the psuedo code for that:
As far as I understand You need to send
request
s from Servlet and getresponse
from other server into yours, may be you need a HTTP Client (Overview) for that.This question might also help you.
HTTP-Proxy-Servlet does exactly what you need.
Quick configuration
pom.xml
web.xml
Spring Integration
see also: HTTP-Proxy-Servlet Issue #15
pom.xml
ServletWrappingControllerExt.java
Beans configuration