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.denimgroup.threadfix.service.defects.utils.RestUtilsImpl.java

/**
 *
 * @param urlString JIRA URL to connect to
 * @return VALID if we get a HTTP 200,//  w ww  .  j a v  a  2  s  . com
 *      UNAUTHORIZED if we get an HTTP 401,
 *      OTHER if we get another HTTP response code,
 *      INVALID if a MalformedURLException or IOException is thrown,
 *      INVALID_CERTIFICATE if a SSLHandshakeException is thrown.
 */
public ConnectionStatus checkConnectionStatus(String urlString) {
    LOG.info("Checking to see if we get an HTTP 401 error for the URL '" + urlString + "'");

    ConnectionStatus retVal;

    HttpClient httpClient;
    try {
        if (proxyService == null) {
            httpClient = new HttpClient();
        } else {
            httpClient = proxyService.getClientWithProxyConfig(classToProxy);
        }

        GetMethod get = new GetMethod(urlString);

        int responseCode = httpClient.executeMethod(get);
        LOG.info("Got HTTP response code of: " + responseCode);

        if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
            retVal = ConnectionStatus.UNAUTHORIZED;
        } else if (responseCode == HttpURLConnection.HTTP_OK) {
            retVal = ConnectionStatus.VALID;
        } else {
            retVal = ConnectionStatus.OTHER;
        }

    } catch (MalformedURLException e) {
        LOG.warn("URL string of '" + urlString + "' is not a valid URL.", e);
        retVal = ConnectionStatus.INVALID;
    } catch (SSLHandshakeException e) {
        LOG.warn("Certificate Error encountered while trying to find the response code.", e);
        retVal = ConnectionStatus.INVALID_CERTIFICATE;
    } catch (IOException e) {
        LOG.warn("IOException encountered while trying to find the response code: " + e.getMessage(), e);
        retVal = ConnectionStatus.INVALID;
    } catch (IllegalArgumentException e) {
        LOG.warn("IllegalArgumentException encountered while trying to find the response code: "
                + e.getMessage(), e);
        retVal = ConnectionStatus.INVALID;
    }

    LOG.info("Return value will be " + retVal);

    return retVal;
}

From source file:com.googlecode.fightinglayoutbugs.DetectInvalidImageUrls.java

private void checkStyleElements() {
    for (WebElement styleElement : _webPage.findElements(By.tagName("style"))) {
        final String css = (String) _webPage.executeJavaScript("return arguments[0].innerHTML", styleElement);
        for (String importUrl : getImportUrlsFrom(css)) {
            checkCssResourceAsync(importUrl + " (imported in <style> element)", importUrl, _baseUrl,
                    _documentCharset);/* ww w.j av a 2s. c  o  m*/
        }
        for (String url : extractUrlsFrom(css)) {
            try {
                checkImageUrl(url, "Detected <style> element with invalid image URL \"" + url + "\"");
            } catch (MalformedURLException e) {
                addLayoutBugIfNotPresent(
                        "Detected <style> element with invalid image URL \"" + url + "\" -- " + e.getMessage());
            }
        }
    }
}

From source file:edu.harvard.i2b2.eclipse.LoginView.java

private void getCellStatus(StatusLabelPaintListener statusLabelPaintListener2, Label statusLabel) {
    StringBuffer result = new StringBuffer();
    boolean coreDown = false;
    if (userInfoBean.getCellList() == null) {
        statusLabelPaintListener.setOvalColor(badColor);
        return;//w ww  . j  a v  a 2s.  co  m
    }
    for (String cellID : userInfoBean.getCellList()) {
        try {
            URL url = new URL(userInfoBean.getCellDataUrl(cellID));
            URLConnection connection = url.openConnection();
            connection.connect();
        } catch (MalformedURLException e) { // new URL() failed
            log.debug(e.getMessage());
            if (userInfoBean.isCoreCell(cellID))
                coreDown = true;
            result.append(userInfoBean.getCellName(cellID));
            result.append("\n"); //$NON-NLS-1$
        } catch (IOException e) { // openConnection() failed
            log.debug(e.getMessage());
            if (userInfoBean.isCoreCell(cellID))
                coreDown = true;
            result.append(userInfoBean.getCellName(cellID));
            result.append("\n"); //$NON-NLS-1$
        }
    }

    if (result.length() > 0) {
        statusOvalLabel
                .setToolTipText(Messages.getString("LoginView.TooltipCellUnavailable") + result.toString()); //$NON-NLS-1$

        if (coreDown)
            statusLabelPaintListener.setOvalColor(badColor);
        else
            statusLabelPaintListener.setOvalColor(warningColor);
    }
}

From source file:org.commonjava.couch.db.CouchManager.java

protected String buildViewUrl(final ViewRequest req) throws CouchDBException {
    try {//w  w  w. ja va 2s  . c  o m
        return buildUrl(config.getDatabaseUrl(), req.getRequestParameters(), APP_BASE, req.getApplication(),
                VIEW_BASE, req.getView());
    } catch (final MalformedURLException e) {
        throw new CouchDBException("Failed to format view URL for: %s.\nReason: %s", e, req, e.getMessage());
    }
}

From source file:org.commonjava.couch.db.CouchManager.java

public boolean appExists(final String appName) throws CouchDBException {
    try {/*from  w  ww .j  a  v a 2s. co  m*/
        return exists(buildUrl(config.getDatabaseUrl(), (Map<String, String>) null, APP_BASE, appName));
    } catch (final MalformedURLException e) {
        throw new CouchDBException("Cannot format application URL: %s. Reason: %s", e, appName, e.getMessage());
    } catch (final CouchDBException e) {
        throw new CouchDBException("Cannot verify existence of application: %s. Reason: %s", e, appName,
                e.getMessage());
    }
}

From source file:org.opendap.d1.DAPMNodeService.java

/** 
 * Handle the ping() call of the MNCore API.
 * //w  w  w . j  a  va2 s . c  o  m
 * To test if the server is working, dereference the base URL as set
 * in the opendap.properties file and see if that returns a HTTP status
 * code of 200. No redirects allowed.
 * 
 * @return Today's date/time if the underlying DAP server associated with
 * this D1 Member Node is working, null otherwise.
 * 
 * @see org.dataone.service.mn.tier1.v1.MNCore#ping()
 */
// @Override
public Date ping() throws NotImplemented, ServiceFailure, InsufficientResources {
    log.trace("In ping(); DAPServerBaseURL: "
            + Settings.getConfiguration().getString("org.opendap.d1.DAPServerBaseURL"));

    try {
        URL baseURL = new URL(Settings.getConfiguration().getString("org.opendap.d1.DAPServerBaseURL"));
        HttpURLConnection URLConnection = (HttpURLConnection) baseURL.openConnection();
        if (URLConnection.getResponseCode() != HttpURLConnection.HTTP_OK) {
            return null;
        }
    } catch (MalformedURLException e) {
        ServiceFailure sf = new ServiceFailure("2042", e.getMessage());
        sf.initCause(e);
        throw sf;
    } catch (IOException e) {
        ServiceFailure sf = new ServiceFailure("2042", e.getMessage());
        sf.initCause(e);
        throw sf;
    }

    return Calendar.getInstance().getTime();
}

From source file:org.commonjava.couch.db.CouchManager.java

public boolean exists(final String path) throws CouchDBException {
    boolean exists = false;

    String url;/*from w ww  .  j  a v a2 s  .  co  m*/
    try {
        url = buildUrl(config.getDatabaseUrl(), path);
    } catch (final MalformedURLException e) {
        throw new CouchDBException("Invalid path: %s. Reason: %s", e, path, e.getMessage());
    }

    final HttpHead request = new HttpHead(url);
    try {
        final HttpResponse response = client.executeHttpWithResponse(request, "Failed to ping database URL");

        final StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() == SC_OK) {
            exists = true;
        } else if (statusLine.getStatusCode() != SC_NOT_FOUND) {
            final HttpEntity entity = response.getEntity();
            CouchError error;

            try {
                error = serializer.toError(entity);
            } catch (final IOException e) {
                throw new CouchDBException(
                        "Failed to ping database URL: %s.\nReason: %s\nError: Cannot read error status: %s", e,
                        url, statusLine, e.getMessage());
            }

            throw new CouchDBException("Failed to ping database URL: %s.\nReason: %s\nError: %s", url,
                    statusLine, error);
        }
    } finally {
        client.cleanup(request);
    }

    return exists;
}

From source file:org.commonjava.couch.db.CouchManager.java

public <T extends CouchDocument> List<T> getDocuments(final Class<T> docType, final CouchDocRefSet refSet,
        final boolean allowMissing) throws CouchDBException {
    String url;/*from  w  ww .j a va 2  s. c o m*/
    try {
        url = buildUrl(config.getDatabaseUrl(), Collections.singletonMap(ViewRequest.INCLUDE_DOCS, "true"),
                ALL_DOCS);
    } catch (final MalformedURLException e) {
        throw new CouchDBException("Failed to format multi-doc URL: %s", e, e.getMessage());
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Selecting multiple documents from: " + url);
    }

    final HttpPost request = new HttpPost(url);
    try {
        final String body = serializer.toString(refSet);
        request.setEntity(new StringEntity(body, "application/json", "UTF-8"));
    } catch (final UnsupportedEncodingException e) {
        throw new CouchDBException("Failed to encode POST entity for multi-document selection: %s", e,
                e.getMessage());
    }

    final TypeToken<CouchObjectList<T>> tt = new TypeToken<CouchObjectList<T>>() {
    };

    final CouchObjectListDeserializer<T> deser = new CouchObjectListDeserializer<T>(tt, docType, allowMissing);

    final CouchObjectList<T> listing = client.executeHttpAndReturn(request,
            new TypeToken<CouchObjectList<T>>() {
            }.getType(), new ToString("Failed to retrieve documents for: %s", refSet), deser);

    for (final T t : listing) {
        if (t instanceof DenormalizedCouchDoc) {
            ((DenormalizedCouchDoc) t).calculateDenormalizedFields();
        }

    }

    return listing.getItems();
}

From source file:org.apache.manifoldcf.authorities.authorities.generic.GenericAuthority.java

protected DefaultHttpClient getClient() throws ManifoldCFException {
    synchronized (this) {
        if (client != null) {
            return client;
        }/*from  ww w  .j a  v  a  2  s. c om*/
        DefaultHttpClient cl = new DefaultHttpClient();
        if (genericLogin != null && !genericLogin.isEmpty()) {
            try {
                URL url = new URL(genericEntryPoint);
                Credentials credentials = new UsernamePasswordCredentials(genericLogin, genericPassword);
                cl.getCredentialsProvider().setCredentials(new AuthScope(url.getHost(),
                        url.getPort() > 0 ? url.getPort() : 80, AuthScope.ANY_REALM), credentials);
                cl.addRequestInterceptor(new PreemptiveAuth(credentials), 0);
            } catch (MalformedURLException ex) {
                client = null;
                sessionExpirationTime = -1L;
                throw new ManifoldCFException("getClient exception: " + ex.getMessage(), ex);
            }
        }
        HttpConnectionParams.setConnectionTimeout(cl.getParams(), connectionTimeoutMillis);
        HttpConnectionParams.setSoTimeout(cl.getParams(), socketTimeoutMillis);
        sessionExpirationTime = System.currentTimeMillis() + 300000L;
        client = cl;
        return cl;
    }
}