I created a Controller to processs all requests to /tunnel
.
This is my controller:
@Controller
@RequestMapping("/tunnel/**")
public class TunnelController {
@RequestMapping
public void process(HttpServletRequest request, HttpServletResponse response) throws IOException {
String url = request.getRequestURI().substring(request.getContextPath().length() + "/tunnel".length());
System.out.println(url);
CloseableHttpClient client = HttpClientBuilder.create().build();
try {
// inject custom HEADERS
// tunnel the request and the response to other server
} finally {
client.close();
}
}
}
Then, when I request to http://myserver/my-tunneler/tunnel/resrouce/image.jpg this controller must tunnel internally to http://myotherserver/resource/image.jpg.
How can I tunnel this requests, cloning the request (headers, attributes, parameters, etc), and tunnel to other server using the HttpClient?