Example usage for java.net MalformedURLException getMessage

List of usage examples for java.net MalformedURLException getMessage

Introduction

In this page you can find the example usage for java.net MalformedURLException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:JTop.java

private static MBeanServerConnection connect(String hostname, int port) {
    // Create an RMI connector client and connect it to
    // the RMI connector server
    String urlPath = "/jndi/rmi://" + hostname + ":" + port + "/jmxrmi";
    MBeanServerConnection server = null;
    try {// ww  w .j a va2  s.c  o m
        JMXServiceURL url = new JMXServiceURL("rmi", "", 0, urlPath);
        JMXConnector jmxc = JMXConnectorFactory.connect(url);
        server = jmxc.getMBeanServerConnection();
    } catch (MalformedURLException e) {
        // should not reach here
    } catch (IOException e) {
        System.err.println("\nCommunication error: " + e.getMessage());
        System.exit(1);
    }
    return server;
}

From source file:cn.ctyun.amazonaws.services.s3.internal.ServiceUtils.java

/**
 * Converts the specified request object into a URL, containing all the
 * specified parameters, the specified request endpoint, etc.
 *
 * @param request//w ww .  jav  a 2  s .  c  om
 *            The request to convert into a URL.
 * @return A new URL representing the specified request.
 *
 * @throws AmazonClientException
 *             If the request cannot be converted to a well formed URL.
 */
public static URL convertRequestToUrl(Request<?> request) {
    String urlString = request.getEndpoint() + "/" + ServiceUtils.urlEncode(request.getResourcePath());

    boolean firstParam = true;
    for (String param : request.getParameters().keySet()) {
        if (firstParam) {
            urlString += "?";
            firstParam = false;
        } else {
            urlString += "&";
        }

        String value = request.getParameters().get(param);
        urlString += param + "=" + ServiceUtils.urlEncode(value);
    }

    try {
        return new URL(urlString);
    } catch (MalformedURLException e) {
        throw new AmazonClientException("Unable to convert request to well formed URL: " + e.getMessage(), e);
    }
}

From source file:com.sina.scs.ServiceUtils.java

/**
 * Converts the specified request object into a URL, containing all the
 * specified parameters, the specified request endpoint, etc.
 *
 * @param request//from   ww w  .jav a 2s.  c o m
 *            The request to convert into a URL.
 * @param removeLeadingSlashInResourcePath
 *            Whether the leading slash in resource-path should be removed
 *            before appending to the endpoint.
 * @return A new URL representing the specified request.
 *
 * @throws AmazonClientException
 *             If the request cannot be converted to a well formed URL.
 */
public static URL convertRequestToUrl(Request<?> request, boolean removeLeadingSlashInResourcePath) {
    String resourcePath = HttpUtils.urlEncode(request.getResourcePath(), true);

    // Removed the padding "/" that was already added into the request's resource path.
    if (removeLeadingSlashInResourcePath && resourcePath.startsWith("/")) {
        resourcePath = resourcePath.substring(1);
    }

    // Some http client libraries (e.g. Apache HttpClient) cannot handle
    // consecutive "/"s between URL authority and path components.
    // So we escape "////..." into "/%2F%2F%2F...", in the same way as how
    // we treat consecutive "/"s in AmazonS3Client#presignRequest(...)
    String urlPath = "/" + resourcePath;
    urlPath = urlPath.replaceAll("(?<=/)/", "%2F");
    String urlString = request.getEndpoint() + urlPath;

    boolean firstParam = true;
    for (String param : request.getParameters().keySet()) {
        if (firstParam) {
            urlString += "?";
            firstParam = false;
        } else {
            urlString += "&";
        }

        String value = request.getParameters().get(param);
        urlString += param + "=" + HttpUtils.urlEncode(value, false);
    }

    try {
        return new URL(urlString);
    } catch (MalformedURLException e) {
        throw new SCSClientException("Unable to convert request to well formed URL: " + e.getMessage(), e);
    }
}

From source file:org.apache.solr.util.SSLTestConfig.java

/**
 * Helper utility for building resources from arbitrary user input paths/urls
 * if input is null, returns null; otherwise attempts to build Resource and verifies that Resource exists.
 *///from  ww  w.j  a  v a 2  s.  co  m
private static final Resource tryNewResource(String userInput, String type) {
    if (null == userInput) {
        return null;
    }
    Resource result;
    try {
        result = Resource.newResource(userInput);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Can't build " + type + " Resource: " + e.getMessage(), e);
    }
    if (!result.exists()) {
        throw new IllegalArgumentException(type + " Resource does not exist " + result.getName());
    }
    return result;
}

From source file:com.sinacloud.scs.services.scs.internal.ServiceUtils.java

/**
 * Converts the specified request object into a URL, containing all the
 * specified parameters, the specified request endpoint, etc.
 *
 * @param request//from w  w w  .  j  a  v  a2s .  co m
 *            The request to convert into a URL.
 * @param removeLeadingSlashInResourcePath
 *            Whether the leading slash in resource-path should be removed
 *            before appending to the endpoint.
 * @return A new URL representing the specified request.
 *
 * @throws AmazonClientException
 *             If the request cannot be converted to a well formed URL.
 */
public static URL convertRequestToUrl(Request<?> request, boolean removeLeadingSlashInResourcePath) {
    String resourcePath = HttpUtils.urlEncode(request.getResourcePath(), true);
    // Removed the padding "/" that was already added into the request's resource path.
    if (removeLeadingSlashInResourcePath && resourcePath.startsWith("/")) {
        resourcePath = resourcePath.substring(1);
    }

    // Some http client libraries (e.g. Apache HttpClient) cannot handle
    // consecutive "/"s between URL authority and path components.
    // So we escape "////..." into "/%2F%2F%2F...", in the same way as how
    // we treat consecutive "/"s in AmazonS3Client#presignRequest(...)
    String urlPath = "/" + resourcePath;
    urlPath = urlPath.replaceAll("(?<=/)/", "%2F");
    String urlString = request.getEndpoint() + urlPath;

    boolean firstParam = true;
    for (String param : request.getParameters().keySet()) {
        if (firstParam) {
            urlString += "?";
            firstParam = false;
        } else {
            urlString += "&";
        }

        String value = request.getParameters().get(param);
        if (value != null)
            if (!"ssig".equalsIgnoreCase(param))
                urlString += param + "=" + HttpUtils.urlEncode(value, false);
            else
                urlString += param + "=" + value;
        else
            urlString += param;
    }

    try {
        return new URL(urlString);
    } catch (MalformedURLException e) {
        throw new SCSClientException("Unable to convert request to well formed URL: " + e.getMessage(), e);
    }
}

From source file:com.amazonaws.services.s3.internal.ServiceUtils.java

/**
 * Converts the specified request object into a URL, containing all the
 * specified parameters, the specified request endpoint, etc.
 *
 * @param request// w  w w .ja  v a 2  s.  c om
 *            The request to convert into a URL.
 * @param removeLeadingSlashInResourcePath
 *            Whether the leading slash in resource-path should be removed
 *            before appending to the endpoint.
 * @return A new URL representing the specified request.
 *
 * @throws AmazonClientException
 *             If the request cannot be converted to a well formed URL.
 */
public static URL convertRequestToUrl(Request<?> request, boolean removeLeadingSlashInResourcePath) {
    String resourcePath = HttpUtils.urlEncode(request.getResourcePath(), true);

    // Removed the padding "/" that was already added into the request's resource path.
    if (removeLeadingSlashInResourcePath && resourcePath.startsWith("/")) {
        resourcePath = resourcePath.substring(1);
    }

    // Some http client libraries (e.g. Apache HttpClient) cannot handle
    // consecutive "/"s between URL authority and path components.
    // So we escape "////..." into "/%2F%2F%2F...", in the same way as how
    // we treat consecutive "/"s in AmazonS3Client#presignRequest(...)

    String urlPath = "/" + resourcePath;
    urlPath = urlPath.replaceAll("(?<=/)/", "%2F");
    StringBuilder url = new StringBuilder(request.getEndpoint().toString());
    url.append(urlPath);

    boolean firstParam = true;
    Map<String, String> requestParams = request.getParameters();
    for (Map.Entry<String, String> entry : requestParams.entrySet()) {
        String param = entry.getKey();
        String value = entry.getValue();

        if (firstParam) {
            url.append("?");
            firstParam = false;
        } else {
            url.append("&");
        }

        url.append(param).append("=").append(HttpUtils.urlEncode(value, false));
    }

    try {
        return new URL(url.toString());
    } catch (MalformedURLException e) {
        throw new AmazonClientException("Unable to convert request to well formed URL: " + e.getMessage(), e);
    }
}

From source file:com.sina.cloudstorage.services.scs.internal.ServiceUtils.java

/**
 * Converts the specified request object into a URL, containing all the
 * specified parameters, the specified request endpoint, etc.
 *
 * @param request/*from  w w w .  ja v  a2 s  .  c  o  m*/
 *            The request to convert into a URL.
 * @param removeLeadingSlashInResourcePath
 *            Whether the leading slash in resource-path should be removed
 *            before appending to the endpoint.
 * @return A new URL representing the specified request.
 *
 * @throws AmazonClientException
 *             If the request cannot be converted to a well formed URL.
 */
public static URL convertRequestToUrl(Request<?> request, boolean removeLeadingSlashInResourcePath) {
    String resourcePath = HttpUtils.urlEncode(request.getResourcePath(), true);
    // Removed the padding "/" that was already added into the request's resource path.
    if (removeLeadingSlashInResourcePath && resourcePath.startsWith("/")) {
        resourcePath = resourcePath.substring(1);
    }

    // Some http client libraries (e.g. Apache HttpClient) cannot handle
    // consecutive "/"s between URL authority and path components.
    // So we escape "////..." into "/%2F%2F%2F...", in the same way as how
    // we treat consecutive "/"s in AmazonS3Client#presignRequest(...)
    String urlPath = "/" + resourcePath;
    urlPath = urlPath.replaceAll("(?<=/)/", "%2F");
    String urlString = request.getEndpoint() + urlPath;

    boolean firstParam = true;
    for (String param : request.getParameters().keySet()) {
        if (firstParam) {
            urlString += "?";
            firstParam = false;
        } else {
            urlString += "&";
        }

        String value = request.getParameters().get(param);
        System.out.println("param:" + param + "   value:" + value);
        if (value != null) {
            if (!"ssig".equalsIgnoreCase(param))
                urlString += param + "=" + HttpUtils.urlEncode(value, false);
            else
                urlString += param + "=" + value;
        } else
            urlString += param;
    }

    try {
        return new URL(urlString);
    } catch (MalformedURLException e) {
        throw new SCSClientException("Unable to convert request to well formed URL: " + e.getMessage(), e);
    }
}

From source file:edu.ucsb.eucalyptus.admin.server.EucalyptusManagement.java

private static String getExternalIpAddress() {
    String ipAddr = null;// w  w  w .j av  a 2  s.com
    HttpClient httpClient = new HttpClient();
    //support for http proxy
    if (HttpServerBootstrapper.httpProxyHost != null && (HttpServerBootstrapper.httpProxyHost.length() > 0)) {
        String proxyHost = HttpServerBootstrapper.httpProxyHost;
        if (HttpServerBootstrapper.httpProxyPort != null
                && (HttpServerBootstrapper.httpProxyPort.length() > 0)) {
            int proxyPort = Integer.parseInt(HttpServerBootstrapper.httpProxyPort);
            httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
        } else {
            httpClient.getHostConfiguration().setProxyHost(new ProxyHost(proxyHost));
        }
    }
    // Use Rightscale's "whoami" service
    GetMethod method = new GetMethod("https://my.rightscale.com/whoami?api_version=1.0&cloud=0");
    Integer timeoutMs = new Integer(3 * 1000); // TODO: is this working?
    method.getParams().setSoTimeout(timeoutMs);

    try {
        httpClient.executeMethod(method);
        String str = "";
        InputStream in = method.getResponseBodyAsStream();
        byte[] readBytes = new byte[1024];
        int bytesRead = -1;
        while ((bytesRead = in.read(readBytes)) > 0) {
            str += new String(readBytes, 0, bytesRead);
        }
        Matcher matcher = Pattern.compile(".*your ip is (.*)").matcher(str);
        if (matcher.find()) {
            ipAddr = matcher.group(1);
        }

    } catch (MalformedURLException e) {
        LOG.warn("Malformed URL exception: " + e.getMessage());
        e.printStackTrace();

    } catch (IOException e) {
        LOG.warn("I/O exception: " + e.getMessage());
        e.printStackTrace();

    } finally {
        method.releaseConnection();
    }

    return ipAddr;
}

From source file:com.amazonaws.eclipse.core.regions.RegionUtils.java

/**
 * Searches through all known regions to find one with any service at the
 * specified endpoint. If no region is found with a service at that
 * endpoint, an exception is thrown.// ww w . j  a  v  a2  s . c  o  m
 *
 * @param endpoint
 *            The endpoint for any service residing in the desired region.
 * @return The region containing any service running at the specified
 *         endpoint, otherwise an exception is thrown if no region is found
 *         with a service at the specified endpoint.
 */
public static Region getRegionByEndpoint(String endpoint) {
    URL targetEndpointUrl = null;
    try {
        targetEndpointUrl = new URL(endpoint);
    } catch (MalformedURLException e) {
        throw new RuntimeException("Unable to parse service endpoint: " + e.getMessage());
    }

    String targetHost = targetEndpointUrl.getHost();
    for (Region region : getRegions()) {
        for (String serviceEndpoint : region.getServiceEndpoints().values()) {
            try {
                URL serviceEndpointUrl = new URL(serviceEndpoint);
                if (serviceEndpointUrl.getHost().equals(targetHost)) {
                    return region;
                }
            } catch (MalformedURLException e) {
                Status status = new Status(Status.ERROR, AwsToolkitCore.PLUGIN_ID,
                        "Unable to parse service endpoint: " + serviceEndpoint, e);
                StatusManager.getManager().handle(status, StatusManager.LOG);
            }
        }
    }

    throw new RuntimeException("No region found with any service for endpoint " + endpoint);
}

From source file:eu.fthevenet.binjr.sources.jrds.adapters.JrdsDataAdapter.java

/**
 * Builds a new instance of the {@link JrdsDataAdapter} class from the provided parameters.
 *
 * @param address the URL to the JRDS webapp.
 * @param zoneId  the id of the time zone used to record dates.
 * @return a new instance of the {@link JrdsDataAdapter} class.
 */// w  ww  . j av a  2 s. c om
public static JrdsDataAdapter fromUrl(String address, ZoneId zoneId, JrdsTreeViewTab treeViewTab, String filter)
        throws DataAdapterException {
    try {
        // Detect if URL protocol is present. If not, assume http.
        if (!uriSchemePattern.matcher(address).find()) {
            address = "http://" + address;
        }
        URL url = new URL(address.replaceAll("/$", ""));
        if (url.getHost().trim().isEmpty()) {
            throw new CannotInitializeDataAdapterException("Malformed URL: no host");
        }
        return new JrdsDataAdapter(url, zoneId, "utf-8", treeViewTab, filter);
    } catch (MalformedURLException e) {
        throw new CannotInitializeDataAdapterException("Malformed URL: " + e.getMessage(), e);
    }
}