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

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

Introduction

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

Prototype

public void setPassword(String paramString) throws URIException 

Source Link

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. */// ww w.j  a v a2 s  . com
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:org.apache.cocoon.components.source.impl.WebDAVSource.java

/**
 * Default constructor./*  w ww  . j  av  a2  s  . co m*/
 */
private WebDAVSource(HttpURL url, String protocol) throws URIException {
    this.protocol = protocol;
    this.url = url;

    String qs = url.getQuery();
    if (qs != null) {
        final SourceParameters sp = new SourceParameters(qs);

        // parse optional start depth and start action qs parameters
        this.depth = sp.getParameterAsInteger("cocoon:webdav-depth", DepthSupport.DEPTH_1);
        this.action = sp.getParameterAsInteger("cocoon:webdav-action", WebdavResource.NOACTION);

        // [UH] FIXME: Why this alternative way of passing in credentials?
        String principal = url.getUser();
        String password = url.getPassword();
        if (principal == null || password == null) {
            principal = sp.getParameter("cocoon:webdav-principal", principal);
            password = sp.getParameter("cocoon:webdav-password", password);
            if (principal != null) {
                url.setUser(principal);
                url.setPassword(password);
            }
        }

        sp.removeParameter("cocoon:webdav-depth");
        sp.removeParameter("cocoon:webdav-action");
        sp.removeParameter("cocoon:webdav-principal");
        sp.removeParameter("cocoon:webdav-password");

        // set the qs without WebdavSource specific parameters
        url.setQuery(sp.getQueryString());
    }
}