Hallo,

I can find the servername by this:

        String servername;
        try
        {
            servername = InetAddress.getLocalHost().getHostName(); //
mymachine

        }
        catch (UnknownHostException e)
        {
            servername = System.getenv("COMPUTERNAME");    // MYMACHINE on
Windows
            if servername == null || servername.length() == 0)
            {
                servername = System.getenv("HOSTNAME"); // mymachine on Unix
            }
        }


But I still have to find out the port and the protocol of my app. I would
prefer to read it from the machine than to configure it in the web.xml
manually. Any proposals?

Thanks!



2014-06-05 14:59 GMT+02:00 Georg Füchsle <[email protected]>:

> 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?
>
>
> Thanks,
>
> Gio
>
>

Reply via email to