Example usage for org.apache.commons.httpclient.params HttpMethodParams CREDENTIAL_CHARSET

List of usage examples for org.apache.commons.httpclient.params HttpMethodParams CREDENTIAL_CHARSET

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.params HttpMethodParams CREDENTIAL_CHARSET.

Prototype

String CREDENTIAL_CHARSET

To view the source code for org.apache.commons.httpclient.params HttpMethodParams CREDENTIAL_CHARSET.

Click Source Link

Usage

From source file:edu.ucsd.xmlrpc.xmlrpc.client.XmlRpcCommonsTransport.java

protected void setCredentials(XmlRpcHttpClientConfig pConfig) throws XmlRpcClientException {
    String userName = pConfig.getBasicUserName();
    if (userName != null) {
        String enc = pConfig.getBasicEncoding();
        if (enc == null) {
            enc = XmlRpcStreamConfig.UTF8_ENCODING;
        }/* www . ja v a2 s .com*/
        client.getParams().setParameter(HttpMethodParams.CREDENTIAL_CHARSET, enc);
        Credentials creds = new UsernamePasswordCredentials(userName, pConfig.getBasicPassword());
        AuthScope scope = new AuthScope(null, AuthScope.ANY_PORT, null, AuthScope.ANY_SCHEME);
        client.getState().setCredentials(scope, creds);
        client.getParams().setAuthenticationPreemptive(true);
    }
}

From source file:ch.cyberduck.core.http.HTTP3Session.java

protected HostConfiguration getHostConfiguration(Host host) {
    int port = host.getPort();
    final HostConfiguration configuration = new StickyHostConfiguration();
    if ("https".equals(host.getProtocol().getScheme())) {
        if (-1 == port) {
            port = 443;//from ww  w  .j a va  2 s . c o  m
        }
        // Configuration with custom socket factory using the trust manager
        configuration.setHost(host.getHostname(), port,
                new org.apache.commons.httpclient.protocol.Protocol(host.getProtocol().getScheme(),
                        new SSLSocketFactory(this.getTrustManager(host.getHostname())), port));
        if (Preferences.instance().getBoolean("connection.proxy.enable")) {
            final Proxy proxy = ProxyFactory.instance();
            if (proxy.isHTTPSProxyEnabled(host)) {
                configuration.setProxy(proxy.getHTTPSProxyHost(host), proxy.getHTTPSProxyPort(host));
            }
        }
    } else if ("http".equals(host.getProtocol().getScheme())) {
        if (-1 == port) {
            port = 80;
        }
        configuration.setHost(host.getHostname(), port, new org.apache.commons.httpclient.protocol.Protocol(
                host.getProtocol().getScheme(), new DefaultProtocolSocketFactory(), port));
        if (Preferences.instance().getBoolean("connection.proxy.enable")) {
            final Proxy proxy = ProxyFactory.instance();
            if (proxy.isHTTPProxyEnabled(host)) {
                configuration.setProxy(proxy.getHTTPProxyHost(host), proxy.getHTTPProxyPort(host));
            }
        }
    }
    final HostParams parameters = configuration.getParams();
    parameters.setParameter(HttpMethodParams.USER_AGENT, this.getUserAgent());
    parameters.setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    parameters.setParameter(HttpMethodParams.SO_TIMEOUT, this.timeout());
    parameters.setParameter(HttpMethodParams.CREDENTIAL_CHARSET, "ISO-8859-1");
    parameters.setParameter(HttpClientParams.MAX_REDIRECTS, 10);
    return configuration;
}

From source file:com.hp.alm.ali.rest.client.AliRestClient.java

@Override
public synchronized void login() {
    // exclude the NTLM authentication scheme (requires NTCredentials we don't supply)
    List<String> authPrefs = new ArrayList<String>(2);
    authPrefs.add(AuthPolicy.DIGEST);//from  w w w  . j  a  v  a  2 s.  c  o  m
    authPrefs.add(AuthPolicy.BASIC);
    httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);

    // first try Apollo style login
    String authPoint = pathJoin("/", location, "/authentication-point/alm-authenticate");
    String authXml = createAuthXml();
    PostMethod post = initPostMethod(authPoint, authXml);
    ResultInfo resultInfo = ResultInfo.create(null);
    executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet());

    if (resultInfo.getHttpStatus() == HttpStatus.SC_NOT_FOUND) {
        // try Maya style login
        Credentials cred = new UsernamePasswordCredentials(userName, password);
        AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
        httpClient.getParams().setParameter(HttpMethodParams.CREDENTIAL_CHARSET, "UTF-8");
        httpClient.getState().setCredentials(scope, cred);

        authPoint = pathJoin("/", location, "/authentication-point/authenticate");
        GetMethod get = new GetMethod(authPoint);
        resultInfo = ResultInfo.create(null);
        executeAndWriteResponse(get, resultInfo, Collections.<Integer>emptySet());
    }
    HttpStatusBasedException.throwForError(resultInfo);
    if (resultInfo.getHttpStatus() != 200) {
        // during login we only accept 200 status (to avoid redirects and such as seemingly correct login)
        throw new AuthenticationFailureException(resultInfo);
    }

    Cookie[] cookies = httpClient.getState().getCookies();
    Cookie ssoCookie = getSessionCookieByName(cookies, COOKIE_SSO_NAME);
    addTenantCookie(ssoCookie);

    //Since ALM 12.00 it is required explicitly ask for QCSession calling "/rest/site-session"
    //For all the rest of HP ALM / AGM versions it is optional
    String siteSessionPoint = pathJoin("/", location, "/rest/site-session");
    String sessionParamXml = createRestSessionXml();
    post = initPostMethod(siteSessionPoint, sessionParamXml);
    resultInfo = ResultInfo.create(null);
    executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet());
    //AGM throws 403
    if (resultInfo.getHttpStatus() != HttpStatus.SC_FORBIDDEN) {
        HttpStatusBasedException.throwForError(resultInfo);
    }

    cookies = httpClient.getState().getCookies();
    Cookie qcCookie = getSessionCookieByName(cookies, COOKIE_SESSION_NAME);
    sessionContext = new SessionContext(location, ssoCookie, qcCookie);
}