Example usage for org.apache.commons.httpclient HttpURL toString

List of usage examples for org.apache.commons.httpclient HttpURL toString

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpURL toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.zimbra.common.util.HttpUtil.java

/** Strips any userinfo (username/password) data from the passed-in URL
 *  and returns the result. *//*from w  w  w.  j  a va  2  s  . co m*/
public static String sanitizeURL(String url) {
    if (url != null && url.indexOf('@') != -1) {
        try {
            HttpURL httpurl = (url.indexOf("https:") == 0) ? new HttpsURL(url) : new HttpURL(url);
            if (httpurl.getPassword() != null) {
                httpurl.setPassword("");
                return httpurl.toString();
            }
        } catch (org.apache.commons.httpclient.URIException urie) {
        }
    }
    return url;
}

From source file:com.apatar.webdav.WebDavNode.java

protected String convertHttpToString(HttpURL url) {
    return url.toString().replace("%20", " ");
}

From source file:org.apache.cocoon.generation.HttpProxyGenerator.java

/**
 * Setup this <code>Generator</code> with its runtime configurations and parameters
 * specified in the sitemap, and prepare it for generation.
 *
 * @param sourceResolver The <code>SourceResolver</code> instance resolving sources by
 *                       system identifiers.
 * @param objectModel The Cocoon "object model" <code>Map</code>
 * @param parameters The runtime <code>Parameters</code> instance.
 * @throws ProcessingException If this instance could not be setup.
 * @throws SAXException If a SAX error occurred during setup.
 * @throws IOException If an I/O error occurred during setup.
 * @see #recycle()/*from  w  w w  .  j a va 2  s . co  m*/
 */
public void setup(SourceResolver sourceResolver, Map objectModel, String source, Parameters parameters)
        throws ProcessingException, SAXException, IOException {
    /* Do the usual stuff */
    super.setup(sourceResolver, objectModel, source, parameters);

    /*
     * Parameter handling: In case the method is a POST method, query
     * parameters and request parameters will be two different arrays
     * (one for the body, one for the query string, otherwise it's going
     * to be the same one, as all parameters are passed on the query string
     */
    ArrayList req = new ArrayList();
    ArrayList qry = req;
    if (this.method instanceof PostMethod)
        qry = new ArrayList();
    req.addAll(this.reqParams);
    qry.addAll(this.qryParams);

    /*
     * Parameter handling: complete or override the configured parameters with
     * those specified in the pipeline.
     */
    String names[] = parameters.getNames();
    for (int x = 0; x < names.length; x++) {
        String name = names[x];
        String value = parameters.getParameter(name, null);
        if (value == null)
            continue;

        if (name.startsWith("query:")) {
            name = name.substring("query:".length());
            qry.add(new NameValuePair(name, value));
        } else if (name.startsWith("param:")) {
            name = name.substring("param:".length());
            req.add(new NameValuePair(name, value));
        } else if (name.startsWith("query-override:")) {
            name = name.substring("query-override:".length());
            qry = overrideParams(qry, name, value);
        } else if (name.startsWith("param-override:")) {
            name = name.substring("param-override:".length());
            req = overrideParams(req, name, value);
        }
    }

    /* Process the current source URL in relation to the configured one */
    HttpURL src = (super.source == null ? null : new HttpURL(super.source));
    if (this.url != null)
        src = (src == null ? this.url : new HttpURL(this.url, src));
    if (src == null)
        throw new ProcessingException("No URL specified");
    if (src.isRelativeURI()) {
        throw new ProcessingException("Invalid URL \"" + src.toString() + "\"");
    }

    /* Configure the method with the resolved URL */
    HostConfiguration hc = new HostConfiguration();
    hc.setHost(src);
    this.method.setHostConfiguration(hc);
    this.method.setPath(src.getPath());
    this.method.setQueryString(src.getQuery());

    /* And now process the query string (from the parameters above) */
    if (qry.size() > 0) {
        String qs = this.method.getQueryString();
        NameValuePair nvpa[] = new NameValuePair[qry.size()];
        this.method.setQueryString((NameValuePair[]) qry.toArray(nvpa));
        if (qs != null) {
            this.method.setQueryString(qs + "&" + this.method.getQueryString());
        }
    }

    /* Finally process the body parameters */
    if ((this.method instanceof PostMethod) && (req.size() > 0)) {
        PostMethod post = (PostMethod) this.method;
        NameValuePair nvpa[] = new NameValuePair[req.size()];
        post.setRequestBody((NameValuePair[]) req.toArray(nvpa));
    }

    /* Check the debugging flag */
    this.debug = parameters.getParameterAsBoolean("debug", false);
}

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

public ResourceTypeProperty getResourceType(HttpURL baseUrl, String relative) throws URIException {
    HttpURL url = Utils.createHttpURL(baseUrl, relative);
    return getResourceType(url.toString());
}

From source file:org.apache.webdav.ant.taskdefs.Get.java

protected void downloadFile(HttpURL url, String relativePath, CollectionScanner scanner) throws IOException {
    File target = new File(this.toDir, relativePath);

    long lastMod = scanner.getProperties().getLastModified(url.toString());

    if (shallWeGetIt(target, lastMod)) {
        getAndStoreResource(url, target, lastMod, relativePath);
    } else {//from  ww w.  j  a v  a  2s  . com
        log("Omitted: " + relativePath + " (uptodate)", ifVerbose());
        this.countOmittedFiles++;
    }
}

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

public static InputStream getFile(HttpClient client, HttpURL url) throws IOException, HttpException {
    GetMethod get = new GetMethod(url.toString());
    get.setFollowRedirects(true);//from   w  w w  .j  a va 2  s . co m
    int status = client.executeMethod(get);

    switch (status) {
    case WebdavStatus.SC_OK:
        return get.getResponseBodyAsStream();
    default:
        HttpException ex = new HttpException();
        ex.setReason(get.getStatusText());
        ex.setReasonCode(status);
        throw ex;
    }

}

From source file:org.jahia.modules.jahiademo.filter.StockWidgetFilter.java

/**
 *
 * @param path//ww w . j a  va2s.c  om
 * @param params
 * @return
 * @throws RepositoryException
 */
private JSONObject queryGoogleFinanceAPI(final String path, final String... params) throws RepositoryException {
    try {
        final HttpClient httpClient = new HttpClient();
        final HttpURL url = new HttpURL(API_URL, -1, path);

        final Map<String, String> m = new LinkedHashMap<String, String>();
        for (int i = 0; i < params.length; i += 2) {
            m.put(params[i], params[i + 1]);
        }

        url.setQuery(m.keySet().toArray(new String[m.size()]), m.values().toArray(new String[m.size()]));
        final long l = System.currentTimeMillis();
        LOGGER.debug("Start request : " + url);
        final GetMethod httpMethod = new GetMethod(url.toString());
        try {
            httpClient.getParams().setSoTimeout(1000);
            httpClient.executeMethod(httpMethod);
            return new JSONObject(httpMethod.getResponseBodyAsString());
        } finally {
            httpMethod.releaseConnection();
            LOGGER.debug("Request " + url + " done in " + (System.currentTimeMillis() - l) + "ms");
        }
    } catch (java.net.SocketTimeoutException te) {
        LOGGER.warn("Timeout Exception on request to Google Finance API");
        return null;
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        return null;
    }
}