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:com.cloud.bridge.io.S3CAStorBucketAdapter.java

@Override
public DataHandler loadObject(String mountedRoot, String bucket, String fileName) {
    try {//from  ww w  . ja  v a 2s .c om
        return new DataHandler(new URL(castorURL(mountedRoot, bucket, fileName)));
    } catch (MalformedURLException e) {
        s_logger.error("Failed to loadObject from CAStor", e);
        throw new FileNotExistException("Unable to load object from CAStor: " + e.getMessage());
    }
}

From source file:au.com.onegeek.lambda.core.Lambda.java

/**
 * Set's the Test Website hostname (including protocol) for this test suite.
 * //from  ww  w. j a v a  2 s.com
 * @param hostname
 *            The name of the host to connect to i.e. http://www.google.com
 * @throws IOException
 *             If the hostname is malformed or host doesn't exist, an
 *             IOException is thrown.
 */
public void setHostname(String hostname) throws IOException {
    try {
        URL url = new URL(hostname);
        URLConnection conn = url.openConnection();
        //         conn.connect();
        //conn.getInputStream();
    } catch (MalformedURLException e) {
        throw new MalformedURLException("Test URL Provided is invalid: " + e.getMessage());
    } catch (IOException e) {
        throw new IOException("Test URL Provided does not exist: " + e.getMessage());
    }

    this.hostname = hostname;
}

From source file:de.bayern.gdi.services.Atom.java

/**
 * Constuctor./*from  w  ww  . j a  v  a  2s .  c  o  m*/
 * @param serviceURL the URL to the service
 * @param userName username
 * @param password password
 * @throws URISyntaxException if the url is wrong
 * @throws SAXException if the xml is wrong
 * @throws ParserConfigurationException if the config is wrong
 * @throws IOException if something in io is wrong
 */
public Atom(String serviceURL, String userName, String password) throws URISyntaxException,
        ParserConfigurationException, IOException, IllegalArgumentException, SAXException {
    this.serviceURL = serviceURL;
    this.username = userName;
    this.password = password;
    URL url = null;
    try {
        url = new URL(this.serviceURL);
    } catch (MalformedURLException e) {
        log.log(Level.SEVERE, e.getMessage(), e);
    }
    //System.out.println(this.serviceURL);
    this.nscontext = new NamespaceContextMap(null, "http://www.w3.org/2005/Atom", "georss",
            "http://www.georss.org/georss", "inspire_dls",
            "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0");
    this.mainDoc = getDocument(url, this.username, this.password);
    preLoad();
}

From source file:JavaFiles.NCBIBlastClient.java

/**
 * Ensure that a service proxy is available to call the web service.
 * //from  w w  w .  j a v  a 2 s. co m
 * @throws ServiceException
 */
protected void srvProxyConnect() throws ServiceException {
    printDebugMessage("srvProxyConnect", "Begin", 11);
    if (this.srvProxy == null) {
        JDispatcherService_Service service = new JDispatcherService_ServiceLocatorExtended();
        if (this.getServiceEndPoint() != null) {
            try {
                this.srvProxy = service
                        .getJDispatcherServiceHttpPort(new java.net.URL(this.getServiceEndPoint()));
            } catch (java.net.MalformedURLException ex) {
                System.err.println(ex.getMessage());
                System.err.println("Warning: problem with specified endpoint URL. Default endpoint used.");
                this.srvProxy = service.getJDispatcherServiceHttpPort();
            }
        } else {
            this.srvProxy = service.getJDispatcherServiceHttpPort();
        }
    }
    printDebugMessage("srvProxyConnect", "End", 11);
}

From source file:com.dtolabs.client.utils.BaseFormAuthenticator.java

/**
 * Authenticate the client http state so that the colony requests can be made.
 *
 * @param baseURL URL requested for colony
 * @param client  HttpClient instance// w  ww  . j a  va2 s .  c  o  m
 *
 * @return true if authentication succeeded.
 *
 * @throws com.dtolabs.client.utils.HttpClientException
 *
 */
public boolean authenticate(final URL baseURL, final HttpClient client) throws HttpClientException {
    final HttpState state = client.getState();
    if (hasSessionCookie(baseURL, state, basePath)) {
        return true;
    }
    final byte[] buffer = new byte[1024];

    boolean doPostLogin = false;
    boolean isLoginFormContent = false;
    logger.debug("No session found, must login...");
    try {
        final URL newUrl = new URL(baseURL.getProtocol(), baseURL.getHost(), baseURL.getPort(),
                basePath + getInitialPath());

        //load welcome page, which should forward to form based logon page.
        final GetMethod get = new GetMethod(newUrl.toExternalForm());
        get.setDoAuthentication(false);
        get.setFollowRedirects(false);
        logger.debug("Requesting: " + newUrl);
        int res = client.executeMethod(get);
        logger.debug("Result is: " + res);

        /*
          Tomcat container auth behaves differently than Jetty.  Tomcat will respond 200 OK and include the login form
          when auth is required, as well as on auth failure, it will also require complete GET of original URL after
          successful auth.
          Jetty will redirect to login page when auth is required, and will redirect to error page on failure.
         */

        String body = get.getResponseBodyAsString();
        if (null != body && body.contains(J_SECURITY_CHECK) && body.contains(JAVA_USER_PARAM)
                && body.contains(JAVA_PASS_PARAM)) {
            isLoginFormContent = true;
        }
        get.releaseConnection();

        if ((res == HttpStatus.SC_UNAUTHORIZED)) {
            if (get.getResponseHeader("WWW-Authenticate") != null
                    && get.getResponseHeader("WWW-Authenticate").getValue().matches("^Basic.*")) {
                logger.warn("Form-based login received UNAUTHORIZED, trying to use Basic authentication");
                final BasicAuthenticator auth = new BasicAuthenticator(username, password);
                return auth.authenticate(baseURL, client);
            } else {
                throw new HttpClientException(
                        "Form-based login received UNAUTHORIZED, but didn't recognize it as Basic authentication: unable to get a session");
            }

        }
        //should now have the proper session cookie
        if (!hasSessionCookie(baseURL, state, basePath)) {
            throw new HttpClientException("Unable to get a session from URL : " + newUrl);
        }
        if (res == HttpStatus.SC_OK && isLoginFormContent) {
            doPostLogin = true;
        } else if ((res == HttpStatus.SC_MOVED_TEMPORARILY) || (res == HttpStatus.SC_MOVED_PERMANENTLY)
                || (res == HttpStatus.SC_SEE_OTHER) || (res == HttpStatus.SC_TEMPORARY_REDIRECT)) {
            Header locHeader = get.getResponseHeader("Location");
            if (locHeader == null) {
                throw new HttpClientException("Redirect with no Location header, request URL: " + newUrl);
            }
            String location = locHeader.getValue();
            if (!isValidLoginRedirect(get)) {
                //unexpected response
                throw new HttpClientException("Unexpected redirection when getting session: " + location);
            }
            logger.debug("Follow redirect: " + res + ": " + location);

            final GetMethod redir = new GetMethod(location);
            redir.setFollowRedirects(true);
            res = client.executeMethod(redir);
            InputStream ins = redir.getResponseBodyAsStream();
            while (ins.available() > 0) {
                //read and discard response body
                ins.read(buffer);
            }
            redir.releaseConnection();

            if (res != HttpStatus.SC_OK) {
                throw new HttpClientException("Login page status was not OK: " + res);
            }
            logger.debug("Result: " + res);

            doPostLogin = true;
        } else if (res != HttpStatus.SC_OK) {
            //if request to welcome page was OK, we figure that the session is already set
            throw new HttpClientException("Request to welcome page returned error: " + res + ": " + get);
        }
        if (doPostLogin) {
            //now post login
            final URL loginUrl = new URL(baseURL.getProtocol(), baseURL.getHost(), baseURL.getPort(),
                    basePath + JAVA_AUTH_PATH);

            final PostMethod login = new PostMethod(loginUrl.toExternalForm());
            login.setRequestBody(new NameValuePair[] { new NameValuePair(JAVA_USER_PARAM, getUsername()),
                    new NameValuePair(JAVA_PASS_PARAM, getPassword()) });

            login.setFollowRedirects(false);
            logger.debug("Post login info to URL: " + loginUrl);

            res = client.executeMethod(login);

            final InputStream ins = login.getResponseBodyAsStream();
            while (ins.available() > 0) {
                //read and discard response body
                ins.read(buffer);
            }
            login.releaseConnection();

            Header locHeader = login.getResponseHeader("Location");
            String location = null != locHeader ? locHeader.getValue() : null;
            if (isLoginError(login)) {
                logger.error("Form-based auth failed");
                return false;
            } else if (null != location && !location.equals(newUrl.toExternalForm())) {

                logger.warn("Form-based auth succeeded, but last URL was unexpected");
            }
            if (isFollowLoginRedirect()
                    && ((res == HttpStatus.SC_MOVED_TEMPORARILY) || (res == HttpStatus.SC_MOVED_PERMANENTLY)
                            || (res == HttpStatus.SC_SEE_OTHER) || (res == HttpStatus.SC_TEMPORARY_REDIRECT))) {

                if (location == null) {
                    throw new HttpClientException("Redirect with no Location header, request URL: " + newUrl);
                }
                final GetMethod get2 = new GetMethod(location);
                //                    logger.debug("Result: " + res + ": " + location + ", following redirect");
                res = client.executeMethod(get2);
            } else if (res != HttpStatus.SC_OK) {
                throw new HttpClientException(
                        "Login didn't seem to work: " + res + ": " + login.getResponseBodyAsString());
            }
            logger.debug("Result: " + res);
        }
    } catch (MalformedURLException e) {
        throw new HttpClientException("Bad URL", e);
    } catch (HttpException e) {
        throw new HttpClientException("HTTP Error: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new HttpClientException(
                "Error occurred while trying to authenticate to server: " + e.getMessage(), e);
    }

    return true;
}

From source file:com.vmware.bdd.manager.SoftwareManagerCollector.java

/**
*
* @param appMgrName/*from  w  ww  . java2s  .  c  o  m*/
* @param urlStr
*/
private void checkServerConnection(String appMgrName, String urlStr) {
    URL url = null;
    try {
        url = new URL(urlStr);
    } catch (MalformedURLException e) {
        logger.error("Url parse error: " + e.getMessage());
        throw SoftwareManagerCollectorException.CONNECT_FAILURE(appMgrName, e.getMessage());
    }

    final String host = url.getHost();
    final int port = url.getPort();

    logger.debug("Check the connection to the application manager.");
    boolean connectOK = CommonUtil.checkServerConnection(host, port, waitTimeForAppMgrConn);
    if (!connectOK) {
        logger.error(
                "Cannot connect to application manager " + appMgrName + ", check the connection information.");
        throw SoftwareManagerCollectorException.CONNECT_FAILURE(appMgrName, "Failed to connect to the server.");
    }
}

From source file:fullThreadDump.java

private void connect(boolean jbossRemotingJMX, String hostname, String user, String passwd) {
    String urlString;/*from   w  ww.  j a v a  2s. c o m*/
    try {
        HashMap<String, String[]> env = new HashMap<String, String[]>();
        String[] creds = new String[2];
        creds[0] = user;
        creds[1] = passwd;
        env.put(JMXConnector.CREDENTIALS, creds);
        if (jbossRemotingJMX) {
            urlString = "service:jmx:remoting-jmx://" + hostname;
            this.serviceURL = new JMXServiceURL(urlString);
            System.out.println("\n\nConnecting to " + urlString);
        } else {
            urlString = "/jndi/rmi://" + hostname + "/jmxrmi";
            this.serviceURL = new JMXServiceURL("rmi", "", 0, urlString);
            System.out.println("\n\nConnecting to " + urlString);
        }

        //this.jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
        this.jmxConnector = JMXConnectorFactory.connect(serviceURL, env);
        this.server = jmxConnector.getMBeanServerConnection();
    } catch (MalformedURLException e) {
        // should not reach here
    } catch (IOException e) {
        System.err.println("\nCommunication error: " + e.getMessage());
        System.exit(1);
    }
}

From source file:edu.mayo.informatics.lexgrid.convert.directConversions.UMLSHistoryFileToSQL.java

/**
 * Private method, reads MRCONSO.RRF file and loads the concept descriptions
 * in a Map./* w ww.  jav  a2 s.co m*/
 * 
 * @param metaFolderPath
 * @throws Exception
 */
private void readMrConso(URI metaFolderPath) throws Exception {

    if (metaFolderPath == null) {
        if (failOnAllErrors_) {
            message_.fatalAndThrowException("URI unspecified for 'MRCONSO.RRF' file.");
        }
    }

    Snapshot snap1 = SimpleMemUsageReporter.snapshot();
    message_.info("Reading 'MRCONSO.RRF'...");

    BufferedReader mrconsoFile = null;

    try {
        mrconsoFile = getReader(metaFolderPath.resolve("MRCONSO.RRF"));

        String line = mrconsoFile.readLine();

        int lineNo = 0;
        while (line != null) {

            ++lineNo;

            if (line.startsWith("#") || line.length() == 0) {
                line = mrconsoFile.readLine();
                continue;
            }

            List<String> elements = deTokenizeString(line, token_);
            if (elements.size() > 14 && "y".equalsIgnoreCase(elements.get(6))) {

                if (!mrconsoConceptName_.keySet().contains(elements.get(0))) {
                    mrconsoConceptName_.put(elements.get(0), elements.get(14));
                }
            }
            line = mrconsoFile.readLine();
        }

    } catch (MalformedURLException e) {
        message_.error("Exceptions while reading MRCONSO.RRF: " + e.getMessage());
    } catch (IOException e) {
        message_.error("Exceptions while reading MRCONSO.RRF: " + e.getMessage());
    } finally {
        mrconsoFile.close();
    }

    Snapshot snap2 = SimpleMemUsageReporter.snapshot();
    message_.info("Done reading 'MRCONSO.RRF': Time taken: "
            + SimpleMemUsageReporter.formatTimeDiff(snap2.getTimeDelta(snap1)));

}