Determine WebDynpro Server Host and Port

To determine the host and port a web dynpro app is running on. This does not take into account multi node environment.
getAbsoluteWebResourceURL() method is deprecated, however there is no other method at the moment that returns an
absolute Url.

private String getWDBaseURL() {
    String result = null;
        String str = WDURLGenerator.getAbsoluteWebResourceURL("/");
        if (str != null)
            URL url = new URL(str);            
         result = 
         + "://"
         + url.getHost()
         + ":"
         + url.getPort();
    catch (Exception e)
        // TODO Auto-generated catch block
    // will return just http://host:port
    return result;

To generate a full path to an image, just tack the image url to the end of the string that the method generates.

String imgPath = getWDBaseURL() + "/imagepath/image.jpg";
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License