Example usage for org.apache.commons.httpclient HttpMethod getParams

List of usage examples for org.apache.commons.httpclient HttpMethod getParams

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpMethod getParams.

Prototype

public abstract HttpMethodParams getParams();

Source Link

Usage

From source file:com.gs.jrpip.client.FastServletProxyInvocationHandler.java

protected void setMethodTimeout(HttpMethod httpMethod, Method methodToCall) {
    int timeout = this.timeout;
    Integer methodTimeout = this.methodResolver.getMethodTimeout(methodToCall);
    if (methodTimeout != null) {
        timeout = methodTimeout.intValue();
    }/* w w  w.j av  a  2s.  c o m*/

    if (timeout > 0) {
        httpMethod.getParams().setSoTimeout(timeout);
    }
}

From source file:com.zimbra.qa.unittest.prov.ldap.TestProvIDN.java

@Test
public void testBasicAuth() throws Exception {

    Names.IDNName domainName = new Names.IDNName(makeTestDomainName("basicAuthTest."));
    Domain domain = createDomain(domainName.uName(), domainName.uName());

    Names.IDNName acctName = new Names.IDNName("acct", domainName.uName());
    Account acct = (Account) createTest(EntryType.ACCOUNT, NameType.UNAME, acctName);

    HttpState initialState = new HttpState();

    /*/*from  w w  w  .j  a va2 s .  c  om*/
    Cookie authCookie = new Cookie(restURL.getURL().getHost(), "ZM_AUTH_TOKEN", mAuthToken, "/", null, false);
    Cookie sessionCookie = new Cookie(restURL.getURL().getHost(), "JSESSIONID", mSessionId, "/zimbra", null, false);
    initialState.addCookie(authCookie);
    initialState.addCookie(sessionCookie);
    */

    String guestName = acct.getUnicodeName();
    String guestPassword = "test123";

    Credentials loginCredentials = new UsernamePasswordCredentials(guestName, guestPassword);
    initialState.setCredentials(AuthScope.ANY, loginCredentials);

    HttpClient client = new HttpClient();
    client.setState(initialState);

    String url = UserServlet.getRestUrl(acct) + "/Calendar";
    System.out.println("REST URL: " + url);
    HttpMethod method = new GetMethod(url);
    HttpMethodParams methodParams = method.getParams();
    methodParams.setCredentialCharset("UTF-8");

    try {
        int respCode = HttpClientUtil.executeMethod(client, method);

        if (respCode != HttpStatus.SC_OK) {
            System.out.println("failed, respCode=" + respCode);
        } else {

            boolean chunked = false;
            boolean textContent = false;

            /*
            System.out.println("Headers:");
            System.out.println("--------");
            for (Header header : method.getRequestHeaders()) {
             System.out.print("    " + header.toString());
            }
            System.out.println();
                    
            System.out.println("Body:");
            System.out.println("-----");
            String respBody = method.getResponseBodyAsString();
            System.out.println(respBody);
            */
        }
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
}

From source file:com.zenkey.net.prowser.Tab.java

/**************************************************************************
 * Configures the HttpMethod object before use.
 * //  w ww.j a  v a 2  s.co m
 * @param httpMethod
 *        The HTTP method object.
 * @param request
 *        The request object.
 * @param ioTimeout
 *        The timeout value to use for I/O operations (like making
 *        connections and socket reads). This value should be 1 second
 *        longer than the actual timeout used for the request, in order to
 *        allow the request to timeout cleanly without having an I/O
 *        exception get in the way.
 * @param httpMethodRetryHandler
 *        The retry handler object.
 * @throws ProtocolException
 *         If the HTTP version in the request object is invalid.
 */
private static void prepareHttpMethod(HttpMethod httpMethod, Request request,
        HttpMethodRetryHandler httpMethodRetryHandler) throws ProtocolException {

    httpMethod.setFollowRedirects(false);

    httpMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, httpMethodRetryHandler);

    String httpVersion = null;
    if ((httpVersion = request.getHttpVersion()) != null)
        httpMethod.getParams().setVersion(HttpVersion.parse("HTTP/" + httpVersion));

    String userAgent = null;
    if ((userAgent = request.getUserAgent()) != null)
        httpMethod.getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent);
}

From source file:it.intecs.pisa.openCatalogue.solr.SolrHandler.java

public SaxonDocument search(HashMap<String, String> request)
        throws UnsupportedEncodingException, IOException, SaxonApiException, Exception {
    HttpClient client = new HttpClient();
    HttpMethod method;
    String urlStr = prepareUrl(request);
    Log.debug("The following search is goint to be executed:" + urlStr);
    // Create a method instance.
    method = new GetMethod(urlStr);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    // Execute the method.
    int statusCode = client.executeMethod(method);
    SaxonDocument solrResponse = new SaxonDocument(method.getResponseBodyAsString());
    //Log.debug(solrResponse.getXMLDocumentString());

    if (statusCode != HttpStatus.SC_OK) {
        Log.error("Method failed: " + method.getStatusLine());
        String errorMessage = (String) solrResponse.evaluatePath("//lst[@name='error']/str[@name='msg']/text()",
                XPathConstants.STRING);
        throw new Exception(errorMessage);
    }//from   w  ww.  ja  v a2s  . c  o  m

    return solrResponse;
}

From source file:com.esri.gpt.framework.http.HttpClientRequest.java

/**
 * Adds an retry handler to an HTTP method.
 * @param method the HttpMethod to be executed
 *//*w  ww.j  av  a  2  s.  c  om*/
private void addRetryHandler(HttpMethod method) {
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));
}

From source file:it.greenvulcano.gvesb.http.ntlm.JCIFS_NTLMScheme.java

@Override
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
    if (this.state == UNINITIATED) {
        throw new IllegalStateException("NTLM authentication process has not been initiated");
    }//from  w w w  .  j a v  a 2  s.com

    NTCredentials ntcredentials = null;
    try {
        ntcredentials = (NTCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException(
                "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName());
    }

    NTLM ntlm = new NTLM();
    ntlm.setCredentialCharset(method.getParams().getCredentialCharset());

    String response = null;
    if ((this.state == INITIATED) || (this.state == FAILED)) {
        response = ntlm.generateType1Msg(ntcredentials.getHost(), ntcredentials.getDomain());
        this.state = TYPE1_MSG_GENERATED;
    } else {
        response = ntlm.generateType3Msg(ntcredentials.getUserName(), ntcredentials.getPassword(),
                ntcredentials.getHost(), ntcredentials.getDomain(), this.ntlmchallenge);
        this.state = TYPE3_MSG_GENERATED;
    }

    return "NTLM " + response;
}

From source file:it.intecs.pisa.openCatalogue.solr.SolrHandler.java

public int postDocument(InputStream stream) throws IOException, Exception {
    HttpClient client = new HttpClient();
    HttpMethod method;
    String urlStr = solrHost + "/update?commit=true";
    Log.debug("Ingesting a new document to: " + urlStr);
    method = new PostMethod(urlStr);
    RequestEntity entity = new InputStreamRequestEntity(stream);
    ((PostMethod) method).setRequestEntity(entity);
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));
    method.setRequestHeader("Content-Type", "text/xml");
    method.setRequestHeader("charset", "utf-8");

    // Execute the method.
    int statusCode = client.executeMethod(method);
    SaxonDocument solrResponse = new SaxonDocument(method.getResponseBodyAsStream());

    Log.debug(solrResponse.getXMLDocumentString());
    if (statusCode != HttpStatus.SC_OK) {
        Log.error("Method failed: " + method.getStatusLine());
        Log.error(solrResponse.getXMLDocumentString());
    } else//from w  ww. j a  v a2  s  .c  o  m
        Log.debug(solrResponse.getXMLDocumentString());
    return statusCode;
}

From source file:com.owncloud.android.oc_framework.network.BearerAuthScheme.java

/**
 * Produces bearer authorization string for the given set of {@link Credentials}.
 * //from w w  w  . j  a va  2 s.  c om
 * @param   credentials                     The set of credentials to be used for authentication
 * @param   method                          The method being authenticated
 * @throws  InvalidCredentialsException     If authentication credentials are not valid or not applicable for this authentication 
 *                                          scheme.
 * @throws AuthenticationException         If authorization string cannot be generated due to an authentication failure.
 * 
 * @return a basic authorization string
 */
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
    Log.d(TAG, "enter BearerScheme.authenticate(Credentials, HttpMethod)");

    if (method == null) {
        throw new IllegalArgumentException("Method may not be null");
    }
    BearerCredentials bearer = null;
    try {
        bearer = (BearerCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException(
                "Credentials cannot be used for bearer authentication: " + credentials.getClass().getName());
    }
    return BearerAuthScheme.authenticate(bearer, method.getParams().getCredentialCharset());
}

From source file:fedora.client.test.PerformanceTests.java

private HttpMethod getHttpMethod(String pid) {
    String url = "http://" + host + ":" + port + "/" + context + "/get/" + pid + "/" + "MDS1";
    HttpMethod httpMethod = new GetMethod(url);
    httpMethod.setDoAuthentication(true);
    httpMethod.getParams().setParameter("Connection", "Keep-Alive");
    return httpMethod;
}

From source file:com.cerema.cloud2.lib.common.network.BearerAuthScheme.java

/**
 * Produces bearer authorization string for the given set of {@link Credentials}.
 * //from ww w  .jav a 2 s. co  m
 * @param   credentials                     The set of credentials to be used for authentication
 * @param   method                          The method being authenticated
 * @throws  InvalidCredentialsException     If authentication credentials are not valid or not applicable for this authentication 
 *                                          scheme.
 * @throws AuthenticationException         If authorization string cannot be generated due to an authentication failure.
 * 
 * @return a basic authorization string
 */
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
    Log_OC.d(TAG, "enter BearerScheme.authenticate(Credentials, HttpMethod)");

    if (method == null) {
        throw new IllegalArgumentException("Method may not be null");
    }
    BearerCredentials bearer = null;
    try {
        bearer = (BearerCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException(
                "Credentials cannot be used for bearer authentication: " + credentials.getClass().getName());
    }
    return BearerAuthScheme.authenticate(bearer, method.getParams().getCredentialCharset());
}