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

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

Introduction

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

Prototype

String RETRY_HANDLER

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

Click Source Link

Usage

From source file:eu.eco2clouds.scheduler.accounting.client.AccountingClientHC.java

private String postMethod(String url, String payload, String bonfireUserId, String bonfireGroupId,
        Boolean exception) {/*from  ww w.j  a va2 s.c  o  m*/
    // Create an instance of HttpClient.
    HttpClient client = getHttpClient();

    logger.debug("Connecting to: " + url);
    // Create a method instance.
    PostMethod method = new PostMethod(url);
    setHeaders(method, bonfireGroupId, bonfireUserId);
    //method.addRequestHeader("Content-Type", SchedulerDictionary.CONTENT_TYPE_ECO2CLOUDS_XML);

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

    String response = "";

    try {
        // We set the payload
        StringRequestEntity payloadEntity = new StringRequestEntity(payload,
                SchedulerDictionary.CONTENT_TYPE_ECO2CLOUDS_XML, "UTF-8");
        method.setRequestEntity(payloadEntity);

        // Execute the method.
        int statusCode = client.executeMethod(method);
        logger.debug("Status Code: " + statusCode);

        if (statusCode >= 200 && statusCode > 300) { //TODO test for this case... 
            logger.warn("Get host information of testbeds: " + url + " failed: " + method.getStatusLine());
        } else {
            // Read the response body.
            byte[] responseBody = method.getResponseBody();
            response = new String(responseBody);
        }

    } catch (HttpException e) {
        logger.warn("Fatal protocol violation: " + e.getMessage());
        e.printStackTrace();
        exception = true;
    } catch (IOException e) {
        logger.warn("Fatal transport error: " + e.getMessage());
        e.printStackTrace();
        exception = true;
    } finally {
        // Release the connection.
        method.releaseConnection();
    }

    return response;
}

From source file:com.xmlcalabash.library.ApacheHttpRequest.java

private GetMethod doGet() {
    GetMethod method = new GetMethod(requestURI.toASCIIString());

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

    for (Header header : headers) {
        method.addRequestHeader(header);
    }/*from   w w  w.  j a v  a  2 s  .  c om*/

    return method;
}

From source file:edu.utah.further.core.ws.HttpUtil.java

/**
 * @param url//from   w  ww  .  j  av a  2 s. c  o m
 * @return
 */
private static HttpMethod newGetMethod(final String url) {
    final HttpMethod method = new GetMethod(url);

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

From source file:com.xmlcalabash.library.ApacheHttpRequest.java

private HeadMethod doHead() {
    HeadMethod method = new HeadMethod(requestURI.toASCIIString());

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

    for (Header header : headers) {
        method.addRequestHeader(header);
    }//from   w w  w.ja  v  a2 s.c om

    return method;
}

From source file:com.cubeia.backoffice.operator.client.OperatorServiceClientHTTP.java

private HttpMethodBase prepareMethod(HttpMethodBase method) {
    method.setRequestHeader("content-type", "application/json;charset=UTF-8;");
    // Provide custom retry handler
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(NUMBER_OF_RETRIES, false));
    return method;
}

From source file:com.xmlcalabash.library.ApacheHttpRequest.java

private void doPutOrPost(EntityEnclosingMethod method, XdmNode body) {
    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    for (Header header : headers) {
        method.addRequestHeader(header);
    }//from   www  .  j  ava  2 s.  c om

    contentType = body.getAttributeValue(_content_type);
    if (contentType == null) {
        throw new XProcException("Content-type on c:body is required.");
    }

    // FIXME: This sucks rocks. I want to write the data to be posted, not provide some way to read it
    String postContent = null;
    try {
        if (xmlContentType(contentType)) {
            Serializer serializer = makeSerializer();

            Vector<XdmNode> content = new Vector<XdmNode>();
            XdmSequenceIterator iter = body.axisIterator(Axis.CHILD);
            while (iter.hasNext()) {
                XdmNode node = (XdmNode) iter.next();
                content.add(node);
            }

            // FIXME: set serializer properties appropriately!
            StringWriter writer = new StringWriter();
            serializer.setOutputWriter(writer);
            S9apiUtils.serialize(runtime, content, serializer);
            writer.close();
            postContent = writer.toString();
        } else {
            StringWriter writer = new StringWriter();
            XdmSequenceIterator iter = body.axisIterator(Axis.CHILD);
            while (iter.hasNext()) {
                XdmNode node = (XdmNode) iter.next();
                writer.write(node.getStringValue());
            }
            writer.close();
            postContent = writer.toString();
        }

        StringRequestEntity requestEntity = new StringRequestEntity(postContent, contentType, "UTF-8");
        method.setRequestEntity(requestEntity);

    } catch (IOException ioe) {
        throw new XProcException(ioe);
    } catch (SaxonApiException sae) {
        throw new XProcException(sae);
    }
}

From source file:com.kaltura.client.KalturaClientBase.java

private PostMethod createPostMethod(KalturaParams kparams, KalturaFiles kfiles, String url) {
    PostMethod method = new PostMethod(url);
    method.setRequestHeader("Accept", "text/xml,application/xml,*/*");
    method.setRequestHeader("Accept-Charset", "utf-8,ISO-8859-1;q=0.7,*;q=0.5");

    if (!kfiles.isEmpty()) {
        method = this.getPostMultiPartWithFiles(method, kparams, kfiles);
    } else {/*from   w  w w.ja  v  a  2 s  . com*/
        method = this.addParams(method, kparams);
    }

    if (isAcceptGzipEncoding()) {
        method.addRequestHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
    }

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

From source file:com.borhan.client.BorhanClientBase.java

private PostMethod createPostMethod(BorhanParams kparams, BorhanFiles kfiles, String url)
        throws UnsupportedEncodingException {
    PostMethod method = new PostMethod(url);
    method.setRequestHeader("Accept", "text/xml,application/xml,*/*");
    method.setRequestHeader("Accept-Charset", "utf-8,ISO-8859-1;q=0.7,*;q=0.5");

    if (!kfiles.isEmpty()) {
        method = this.getPostMultiPartWithFiles(method, kparams, kfiles);
    } else {//from ww  w.  j  a  va 2  s .  c o m
        method = this.addParams(method, kparams);
    }

    if (isAcceptGzipEncoding()) {
        method.addRequestHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
    }

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

From source file:de.ingrid.portal.interfaces.impl.WMSInterfaceImpl.java

public String getWMCDocument(String sessionId) {
    String response = null;//  w ww .  java2s .  com

    try {
        String urlStr = config.getString("interface_url",
                "http://localhost/mapbender/php/mod_portalCommunication_gt.php");
        if (urlStr.indexOf("?") > 0) {
            urlStr = urlStr.concat("&PREQUEST=getWMC").concat("&PHPSESSID=" + sessionId);
        } else {
            urlStr = urlStr.concat("?PREQUEST=getWMC").concat("&PHPSESSID=" + sessionId);
        }

        if (log.isDebugEnabled()) {
            log.debug("MapBender Server Request: " + urlStr);
        }

        //          Create an instance of HttpClient.
        HttpClient client = new HttpClient();

        // Create a method instance.
        GetMethod method = new GetMethod(urlStr);

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

        try {
            // Execute the method.
            int statusCode = client.executeMethod(method);

            if (statusCode != HttpStatus.SC_OK) {
                log.error("Requesting WMC faild for URL: " + urlStr);
            }

            // Read the response body.
            byte[] responseBody = method.getResponseBody();

            response = new String(responseBody);

        } catch (HttpException e) {
            log.error("Fatal protocol violation: " + e.getMessage(), e);
        } catch (IOException e) {
            log.error("Fatal transport error: " + e.getMessage(), e);
        } finally {
            // Release the connection.
            method.releaseConnection();
        }

        if (log.isDebugEnabled()) {
            log.debug("MapBender Server Response: " + response);
        }

        Document document = DocumentHelper.parseText(response);
        // check for valid server response
        String error = document.valueOf("//portal_communication/error");
        if (error != null && error.length() > 0) {
            throw new Exception("MapBender Server Error: " + error);
        }

        String sessionMapBender = document.valueOf("//portal_communication/session");
        if (sessionMapBender != null && !sessionMapBender.equals(sessionId)) {
            throw new Exception(
                    "MapBender Server Error: session Id (" + sessionId + ") from request and session Id ("
                            + sessionMapBender + ") from MapBender are not the same.");
        }

        String urlEncodedWmc = document.valueOf("//portal_communication/wmc");
        return urlEncodedWmc;

    } catch (Exception e) {
        log.error(e.toString());
    }
    return null;
}

From source file:eu.eco2clouds.scheduler.accounting.client.AccountingClientHC.java

private String putMethod(String url, String payload, String bonfireUserId, String bonfireGroupId,
        Boolean exception) {//from  w  ww  .j a  v  a  2 s. c  o m
    // Create an instance of HttpClient.
    HttpClient client = getHttpClient();

    logger.debug("Connecting to: " + url);
    // Create a method instance.
    PutMethod method = new PutMethod(url);
    setHeaders(method, bonfireGroupId, bonfireUserId);
    //method.addRequestHeader("Content-Type", SchedulerDictionary.CONTENT_TYPE_ECO2CLOUDS_XML);

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

    String response = "";

    try {
        // We set the payload
        StringRequestEntity payloadEntity = new StringRequestEntity(payload,
                SchedulerDictionary.CONTENT_TYPE_ECO2CLOUDS_XML, "UTF-8");
        method.setRequestEntity(payloadEntity);

        // Execute the method.
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) { //TODO test for this case... 
            logger.warn("Get host information of testbeds: " + url + " failed: " + method.getStatusLine());
        } else {
            // Read the response body.
            byte[] responseBody = method.getResponseBody();
            response = new String(responseBody);
        }

    } catch (HttpException e) {
        logger.warn("Fatal protocol violation: " + e.getMessage());
        e.printStackTrace();
        exception = true;
    } catch (IOException e) {
        logger.warn("Fatal transport error: " + e.getMessage());
        e.printStackTrace();
        exception = true;
    } finally {
        // Release the connection.
        method.releaseConnection();
    }

    return response;
}