Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to get the assets like images on the server behind the firewall?

DZone's Guide to

How to get the assets like images on the server behind the firewall?

Free Resource
To retrieve the asset in the web server behind the firewall, the getLocalName() and getLocalPort() methods must be used to reconstruct the URL.

The request.getServerName() method returns the name of the server that the HTTP request was sent to.  If this method is used, it would return the name of the public server name configured in the firewall.

The request.getLocalName() method returns the name of the server that actually received the request. So this must be used to reconstruct the URL and get the desired asset in the web server.

Note: Asset could be a template (XSLT), image etc.

public static String getAssetUrl(HttpServletRequest request, String fileName) {
    String scheme = request.getScheme();               
    String localServerName= request.getLocalName();
    int localServerPort = request.getLocalPort();
    String contextPath = request.getContextPath();
    String pathInfo = request.getPathInfo();      

    // Reconstruct original request URL
    String url = scheme + "://" + localServerName+":" + localServerPort + contextPath + "/asset?fileImage=/" + fileName;

    if (pathInfo != null) {
        url += pathInfo;
    }

    return url;
}    
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}