How can I reliably access HttpServletRequest in jspx when it is behind a proxy?

I have jspx that the current HttpServletRequest getServerName() should know. Jspx can get this using #{mybean.serverName} from its bean, for example:

 public String getServerName() { HttpServletRequest request = (HttpServletRequest) FacesInstance.getCurrentInstance().getExternalContent().getRequest(); return request.getServerName(); } 

However, when this is serviced by a proxy (Apache with mod_proxy), getServerName() will return the hostname node several times instead of the hostname of the interface. In other cases, it works correctly.

Simple jsp with <% request.getServerName(); %> <% request.getServerName(); %> will, however, always return the hostname of the interface.

What is the problem with FacesInstance HttpServletRequest ? Is there a way to get the "real" request object?

+4
source share
1 answer

What is the problem with FacesContext HttpServletRequest?

You get a basic implementation request (which turns out to be a servlet API). This has little to do with JSF since you leave the API to invoke the object provided by the container into the JSF servlet.

The JSP request object is also javax.servlet.ServletRequest ; they are likely to be the same object.

There is a possibility that the request is wrapped (for example, HttpServletRequestWrapper ), but it is difficult to understand what to get by changing the return value from getServerName() .

I suspect there is some kind of side effect to how the hostname is resolved. I would see how the implementation of getServerName() on your server works.

FYI: you should be able to reference a value without a managed bean. The expression EL ${pageContext.request.serverName} (untested) should return a value ( pageContext is an implicit variable in JSP).

+4
source

All Articles