Issue
I have a tomcat application server and I need the origin url, the client called in order to send back a link for another resource. However the URL is remapped by the api-gateway as well as the load balancer after the api-gateway.
When calling requestContext.getUriInfo().getRequestUri()
I get the internal uri of the application server which is not accessible from outside.
Is there a way to get the original called url?
Solution
A decent gateway or loadbalancer which rewrites the URL normally puts (parts of) the original URL in the request headers. Which request header name exactly that is depends on the exact gateway and/or loadbalancer being used as there is no definitive standard for it (yet?). Usually consulting its documentation should give clues, or at least manually inspecting the headers of a sample request as below:
List<String> headerNames = Collections.list(request.getHeaderNames());
for (String headerName : headerNames) {
List<String> headerValues = Collections.list(request.getHeaders(headerName));
System.out.println(headerName + " = " + headerValues);
}
As per the comments, you already discovered it to be X-Replaced-Path
and X-Forwarded-Host
.
Answered By - BalusC