myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "l.penet@senat.fr" <l.pe...@senat.fr>
Subject Re: Read Server Ip and Port inside JSF
Date Thu, 05 Jun 2014 15:01:47 GMT
On 05/06/2014 14:59, Georg F├╝chsle wrote:
> Hallo,
>
> my Application is deployed inside a Firewall and/or behind a Load-Balancer.
>
> My application provies a web-app and an web-service. At some time i have to
> call my own web-service from the web-app. In this case I have to use the
> internal URL of my server.
>
> At another time I have to give the public URL of my web-app to an interface
> to other apps or services. In that caes i have to use the external URL of
> my web-app. ( That is the URL of the firewall
> or the load balancer)
>
> For example:
>
> The App is deployed internal on the Server with the name webserver1. So the
> internal URL would be:
>
> http://webserver1:8080/myapp/
>
> But from outside the office I have to call the Url of the Firewall/Load
> balancer:
>
> http::// www.mycompany.com/myapp/
>
>
>
> I found a way to read the current URL from the request:
>
> HttpServletRequest request = (HttpServletRequest)
> FacesContext.getCurrentInstance().getExternalContext().getRequest();
> URL reconstructedURL;
> reconstructedURL = new URL(request.getScheme(), request.getServerName(),
> request.getServerPort(), "");
>
> But the result is the internal URL, when the User is using the internal URL
> and the external URL, when the user is using the external URL.
>
>
> Is there a possibility to read  the internal server-name and port in any
> case?
This is not exactly your question, but I have a similar problem when I 
have to get the real source address of a forwarded request.

I use this function in this case :

     public static String getRemoteAddr(HttpServletRequest req) {
         String forwardedFor = req.getHeader("X-Forwarded-For");
         if(StringUtils.isNotBlank(forwardedFor)) {
             return forwardedFor.split("\\s*,\\s*", 2)[0]; // liste 
d'adresses de la forme : client, proxy1, proxy2, etc.
         }
         return req.getRemoteAddr();
     }

I guess, but do not have a requyest to your server at hand to check it, 
that there must be a header in your request that you can analyse in a 
similar way to get what you are looking for.
With forwardedFor.split("\\s*,\\s*", 2)[1] , I guess that you would have 
your public address.

Hope this helps.

Ludovic
|
| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
|


Mime
View raw message