Java URL Resolve resolveURL(String urlValue)

Here you can find the source of resolveURL(String urlValue)

Description

First try to use the externalURLValue as a URL string and if this fails to produce a valid URL treat the externalURLValue as a system property name from which to obtain the URL string.

License

LGPL

Declaration

public static URL resolveURL(String urlValue) throws MalformedURLException 

Method Source Code

//package com.java2s;
/*/*  w w w .  j a va  2 s.  c  o  m*/
 * JBoss, the OpenSource J2EE WebOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    /** First try to use the externalURLValue as a URL string and if this
    fails to produce a valid URL treat the externalURLValue as a system
    property name from which to obtain the URL string. This allows the
    proxy url to not be set until the proxy is unmarshalled in the client
    vm, and is necessary when the server is sitting behind a firewall or
    proxy and does not know what its public http interface is named.
    */
    public static URL resolveURL(String urlValue) throws MalformedURLException {
        if (urlValue == null)
            return null;

        URL externalURL = null;
        try {
            externalURL = new URL(urlValue);
        } catch (MalformedURLException e) {
            // See if externalURL refers to a property
            String urlProperty = System.getProperty(urlValue);
            if (urlProperty == null)
                throw e;
            externalURL = new URL(urlProperty);
        }
        return externalURL;
    }
}

Related

  1. resolveRelativeURL(String contextUri, String relativeUri)
  2. resolveResourceAsURL(Class clazz, String name)
  3. resolveResourceURL(Class base, String resource)
  4. resolveRootUrl(Class knownClass)
  5. resolveUrl(String url, Properties properties)
  6. resolveURL(URL base, String target)
  7. resolveURL(URL contextURL, String url)
  8. resolveURL(URL url)
  9. resolveWsURI(String url)