Example usage for org.apache.commons.httpclient URIException getMessage

List of usage examples for org.apache.commons.httpclient URIException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.httpclient URIException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:no.trank.openpipe.wikipedia.download.HttpDownloader.java

public void init() {
    if (targetFile == null || !targetFile.getParentFile().isDirectory()) {
        throw new IllegalArgumentException("Invalid targetFile '" + targetFile + '\'');
    }/*w ww .ja v a 2  s  . c  o  m*/
    if (rssUrl == null) {
        throw new NullPointerException("sourceUrl cannot be null");
    }
    try {
        new URI(rssUrl, true);
    } catch (URIException e) {
        throw new IllegalArgumentException("rssUrl '" + rssUrl + "' must be a valid URL: " + e.getMessage());
    }
    if (httpClient == null) {
        httpClient = new HttpClient();
    }
}

From source file:no.trank.openpipe.wikipedia.producer.HttpDownloader.java

public void init() {
    if (targetFile == null || !targetFile.getParentFile().isDirectory()) {
        throw new IllegalArgumentException("Invalid targetFile '" + targetFile + '\'');
    }/*  ww  w. j  a v  a2 s. com*/
    if (sourceUrl == null) {
        throw new NullPointerException("sourceUrl cannot be null");
    }
    try {
        new URI(sourceUrl, true);
    } catch (URIException e) {
        throw new IllegalArgumentException(
                "sourceUrl '" + sourceUrl + "' must be a valid URL: " + e.getMessage());
    }
}

From source file:org.alfresco.jive.impl.JiveOpenClientImpl.java

/**
 * Debugging method for obtaining the state of a request as a String.
 * /*  www  .  j  a  v a  2 s  .c o m*/
 * @param method The method to retrieve the request state from <i>(may be null)</i>.
 * @return The request state as a human-readable string value <i>(will not be null)</i>.
 */
private String requestToString(final HttpMethod method, final String body) {
    StringBuffer result = new StringBuffer(128);

    if (method != null) {
        result.append("\n\tMethod: ");
        result.append(method.getName());
        result.append("\n\tURL: ");

        try {
            result.append(String.valueOf(method.getURI()));
        } catch (final URIException ue) {
            result.append("unknown, due to: " + ue.getMessage());
        }

        result.append("\n\tHeaders: ");

        for (final Header header : method.getRequestHeaders()) {
            result.append("\n\t\t");
            result.append(header.getName());
            result.append(" : ");
            result.append(header.getValue());
        }

        result.append("\n\tAuthenticating? " + method.getDoAuthentication());

        if (body != null) {
            result.append("\n\tBody: ");
            result.append(body);
        }
    } else {
        result.append("(null)");
    }

    return (result.toString());
}

From source file:org.apache.abdera.ext.oauth.OAuthScheme.java

private String generateSignature(OAuthCredentials credentials, HttpMethod method, String nonce, long timestamp)
        throws AuthenticationException {
    try {//from  w  w  w  .  j av a 2s .  c om
        String baseString = method.getName().toUpperCase() + method.getURI().toString()
                + OAUTH_KEYS.OAUTH_CONSUMER_KEY.toLowerCase() + "=" + credentials.getConsumerKey()
                + OAUTH_KEYS.OAUTH_TOKEN.toLowerCase() + "=" + credentials.getToken()
                + OAUTH_KEYS.OAUTH_SIGNATURE_METHOD.toLowerCase() + "=" + credentials.getSignatureMethod()
                + OAUTH_KEYS.OAUTH_TIMESTAMP.toLowerCase() + "=" + timestamp
                + OAUTH_KEYS.OAUTH_NONCE.toLowerCase() + "=" + nonce + OAUTH_KEYS.OAUTH_VERSION.toLowerCase()
                + "=" + credentials.getVersion();
        return sign(credentials.getSignatureMethod(), URLEncoder.encode(baseString, "UTF-8"),
                credentials.getCert());
    } catch (URIException e) {
        throw new AuthenticationException(e.getMessage(), e);
    } catch (UnsupportedEncodingException e) {
        throw new AuthenticationException(e.getMessage(), e);
    }
}

From source file:org.apache.any23.source.HTTPDocumentSource.java

private String normalize(String uri) throws URISyntaxException {
    try {/*from w  ww .j  ava  2 s .  c  o m*/
        URI normalized = new URI(uri, DefaultHTTPClient.isUrlEncoded(uri));
        normalized.normalize();
        return normalized.toString();
    } catch (URIException e) {
        LOG.warn("Invalid uri: {}", uri);
        LOG.error("Can not convert URL", e);
        throw new URISyntaxException(uri, e.getMessage());
    }
}

From source file:org.apache.eagle.alert.engine.publisher.email.AlertEmailGenerator.java

private Map<String, String> buildAlertContext(AlertStreamEvent event) {
    Map<String, String> alertContext = new HashMap<>();

    if (event.getContext() != null) {
        for (Map.Entry<String, Object> entry : event.getContext().entrySet()) {
            if (entry.getValue() == null) {
                alertContext.put(entry.getKey(), "N/A");
            } else {
                alertContext.put(entry.getKey(), entry.getValue().toString());
            }/* w  w  w . j  a v a2  s .c o  m*/
        }
    }

    alertContext.put(PublishConstants.ALERT_EMAIL_SUBJECT, event.getSubject());
    alertContext.put(PublishConstants.ALERT_EMAIL_BODY, getAlertBody(event));
    alertContext.put(PublishConstants.ALERT_EMAIL_POLICY_ID, event.getPolicyId());
    alertContext.put(PublishConstants.ALERT_EMAIL_ALERT_ID, event.getAlertId());
    alertContext.put(PublishConstants.ALERT_EMAIL_ALERT_DATA, event.getDataMap().toString());
    alertContext.put(PublishConstants.ALERT_EMAIL_ALERT_DATA_DESC, generateAlertDataDesc(event));
    alertContext.put(PublishConstants.ALERT_EMAIL_ALERT_CATEGORY, event.getCategory());
    alertContext.put(PublishConstants.ALERT_EMAIL_ALERT_SEVERITY, event.getSeverity().toString());
    alertContext.put(PublishConstants.ALERT_EMAIL_TIME,
            DateTimeUtil.millisecondsToHumanDateWithSeconds(event.getCreatedTime()));
    alertContext.put(PublishConstants.ALERT_EMAIL_STREAM_ID, event.getStreamId());
    alertContext.put(PublishConstants.ALERT_EMAIL_CREATOR, event.getCreatedBy());
    alertContext.put(PublishConstants.ALERT_EMAIL_VERSION, Version.version);

    String rootUrl = this.getServerPort() == 80 ? String.format("http://%s", this.getServerHost())
            : String.format("http://%s:%s", this.getServerHost(), this.getServerPort());
    try {
        alertContext.put(PublishConstants.ALERT_EMAIL_ALERT_DETAIL_URL, String.format("%s/#/alert/detail/%s",
                rootUrl, URIUtil.encodeQuery(event.getAlertId(), "UTF-8")));
        alertContext.put(PublishConstants.ALERT_EMAIL_POLICY_DETAIL_URL, String.format("%s/#/policy/detail/%s",
                rootUrl, URIUtil.encodeQuery(event.getPolicyId(), "UTF-8")));
    } catch (URIException e) {
        LOG.warn(e.getMessage(), e);
        alertContext.put(PublishConstants.ALERT_EMAIL_ALERT_DETAIL_URL,
                String.format("%s/#/alert/detail/%s", rootUrl, event.getAlertId()));
        alertContext.put(PublishConstants.ALERT_EMAIL_POLICY_DETAIL_URL,
                String.format("%s/#/policy/detail/%s", rootUrl, event.getPolicyId()));
    }
    alertContext.put(PublishConstants.ALERT_EMAIL_HOME_URL, rootUrl);
    return alertContext;
}

From source file:org.apache.ode.axis2.util.UrlReplacementTransformer.java

/**
 * @param baseUri - the base uri template containing part names enclosed within single curly braces
 * @param values  - a map<String, Element>, the key is a part name (without curly braces), the value the replacement value for the part name. If the value is not a simple type, it will be skipped.
 * @return the encoded uri/*from w  ww.j  av  a2  s  . c o m*/
 * @throws java.lang.IllegalArgumentException
 *          if a replacement value is null in the map or if a part pattern is found more than once
 */
public String transform(String baseUri, Map<String, Element> values) {
    // the list containing the final split result
    List<String> result = new ArrayList<String>();

    // initial value
    result.add(baseUri);

    // replace each part exactly once
    for (Map.Entry<String, Element> e : values.entrySet()) {

        String partName = e.getKey();
        String replacementValue;
        {
            Element value = e.getValue();
            if (DOMUtils.isEmptyElement(value)) {
                replacementValue = "";
            } else {
                /*
                The expected part value could be a simple type
                or an element of a simple type.
                So if a element is there, take its text content
                else take the text content of the part element itself
                */
                Element childElement = DOMUtils.getFirstChildElement(value);
                if (childElement != null) {
                    replacementValue = DOMUtils.getTextContent(childElement);
                } else {
                    replacementValue = DOMUtils.getTextContent(value);
                }
            }
        }

        // if it is not a simple type, skip it
        if (replacementValue != null) {
            try {
                replacementValue = URIUtil.encodeWithinQuery(replacementValue);
            } catch (URIException urie) {
                // this exception is never thrown by the code of httpclient
                if (log.isWarnEnabled())
                    log.warn(urie.getMessage(), urie);
            }

            // first, search for parentheses
            String partPattern = "\\(" + partName + "\\)";
            if (!replace(result, partPattern, replacementValue)) {
                // if parentheses not found, try braces
                partPattern = "\\{" + partName + "\\}";
                replace(result, partPattern, replacementValue);
            }
        }
    }

    // join all the array elements to form the final url
    StringBuilder sb = new StringBuilder(128);
    for (String aResult : result)
        sb.append(aResult);
    return sb.toString();
}

From source file:org.apache.webdav.ant.CollectionScanner.java

protected void addResource(String href, boolean isCollection) throws ScanException {
    try {/*  w ww .  jav a2  s . c o  m*/
        String path = (Utils.createHttpURL(getBaseURL(), href)).getPath();
        String relPath = path.substring(getBaseURL().getPath().length());
        if (relPath.startsWith(SEPARATOR)) {
            relPath = relPath.substring(1);
        }
        if (isCollection) {
            if (isIncluded(relPath)) {
                if (isExcluded(relPath)) {
                    dirsExcluded.add(relPath);
                } else {
                    dirsIncluded.add(relPath);
                }
            } else {
                dirsNotIncluded.add(relPath);
            }
        } else {
            if (isIncluded(relPath)) {
                if (isExcluded(relPath)) {
                    filesExcluded.add(relPath);
                } else {
                    filesIncluded.add(relPath);
                }
            } else {
                filesNotIncluded.add(relPath);
            }
        }
    } catch (URIException e) {
        throw new ScanException("The XML response returned an invalid URL: " + e.getMessage(), e);
    }
}

From source file:org.apache.webdav.lib.WebdavFile.java

public URL toURL() throws MalformedURLException {
    if (relPath != null)
        return null;
    try {//from   w  ww . ja v  a2s  .c om
        return new URL(httpUrl.getURI());
    } catch (URIException e) {
        throw new MalformedURLException(e.getMessage());
    }
}

From source file:org.apache.wink.itest.CookieParamTest.java

/**
 * Tests that a cookie parameter is retrieved.
 *///  w ww  . j av a  2 s .c  o  m
public void testCookieParam() {

    try {
        PutMethod httpMethod = new PutMethod();
        httpMethod.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
        httpMethod.setURI(new URI(BASE_URI, false));
        System.out.println("Request headers:");
        System.out.println(Arrays.asList(httpMethod.getRequestHeaders()));
        httpclient = new HttpClient();

        try {
            int result = httpclient.executeMethod(httpMethod);
            System.out.println("Response status code: " + result);
            System.out.println("Response body: ");
            String responseBody = httpMethod.getResponseBodyAsString();
            System.out.println(responseBody);
            System.out.println("Response headers:");
            System.out.println(Arrays.asList(httpMethod.getResponseHeaders()));
            assertEquals(200, result);
            assertEquals("swiped:" + 0, responseBody);
        } catch (IOException ioe) {
            ioe.printStackTrace();
            fail(ioe.getMessage());
        } finally {
            httpMethod.releaseConnection();
        }

        System.out.println("---");

        httpMethod = new PutMethod();
        httpMethod.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
        httpMethod.setURI(new URI(BASE_URI, false));
        httpMethod.setRequestHeader("Cookie", "jar=1");
        System.out.println("Request headers:");
        System.out.println(Arrays.asList(httpMethod.getRequestHeaders()));
        httpclient = new HttpClient();
        try {
            int result = httpclient.executeMethod(httpMethod);
            System.out.println("Response status code: " + result);
            System.out.println("Response body: ");
            String responseBody = httpMethod.getResponseBodyAsString();
            System.out.println(responseBody);
            System.out.println("Response headers:");
            System.out.println(Arrays.asList(httpMethod.getResponseHeaders()));
            assertEquals(200, result);
            assertEquals("swiped:" + 1, responseBody);
        } catch (IOException ioe) {
            ioe.printStackTrace();
            fail(ioe.getMessage());
        } finally {
            httpMethod.releaseConnection();
        }
    } catch (URIException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}