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

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

Introduction

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

Prototype

public void setIntParameter(String paramString, int paramInt) 

Source Link

Usage

From source file:com.ibm.stocator.fs.swift.SwiftAPIDirect.java

/**
 * GET object//ww w.j  a  v  a  2  s  .c om
 *
 * @param path path to object
 * @param authToken authentication token
 * @param bytesFrom from from
 * @param bytesTo bytes to
 * @return SwiftGETResponse that includes input stream and length
 * @throws IOException if network errors
 */
public static SwiftGETResponse getObject(Path path, String authToken, long bytesFrom, long bytesTo)
        throws IOException {
    GetMethod method = new GetMethod(path.toString());
    method.addRequestHeader(new Header("X-Auth-Token", authToken));
    if (bytesTo > 0) {
        final String rangeValue = String.format("bytes=%d-%d", bytesFrom, bytesTo);
        method.addRequestHeader(new Header(Constants.RANGES_HTTP_HEADER, rangeValue));
    }
    HttpMethodParams methodParams = method.getParams();
    methodParams.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    methodParams.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 15000);
    methodParams.setSoTimeout(60000);
    method.addRequestHeader(Constants.USER_AGENT_HTTP_HEADER, Constants.STOCATOR_USER_AGENT);
    final HttpClient client = new HttpClient();
    int statusCode = client.executeMethod(method);
    SwiftInputStreamWrapper httpStream = new SwiftInputStreamWrapper(method);
    SwiftGETResponse getResponse = new SwiftGETResponse(httpStream, method.getResponseContentLength());
    return getResponse;
}

From source file:fr.cls.atoll.motu.processor.wps.framework.WPSFactory.java

/**
 * Post async.//www  .  j a v a  2s .co  m
 * 
 * @param url the url
 * @param postBody the post body
 * @param headers the headers
 * 
 * @return the int
 * 
 * @throws HttpException the http exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static int postAsync(String url, InputStream postBody, Map<String, String> headers)
        throws HttpException, IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("postAsync(String, InputStream, Map<String,String>) - entering");
    }

    // TODO no proxies used
    HttpClient client = new HttpClient();
    HttpMethodParams httpMethodParams = new HttpMethodParams();
    httpMethodParams.setIntParameter(HttpMethodParams.SO_TIMEOUT, 1);

    PostMethod post = new PostMethod(url);
    post.setRequestEntity(new InputStreamRequestEntity(postBody));
    post.setParams(httpMethodParams);

    for (String key : headers.keySet()) {
        post.setRequestHeader(key, headers.get(key));
    }
    int retcode = -1;
    try {
        retcode = client.executeMethod(post);
    } catch (SocketTimeoutException e) {
        LOG.error("postAsync(String, InputStream, Map<String,String>)", e);

        // do nothing
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("postAsync(String, InputStream, Map<String,String>) - exiting");
    }
    return retcode;
}

From source file:org.apache.maven.wagon.providers.webdav.HttpMethodConfiguration.java

private void fillParams(HttpMethodParams p) {
    if (!hasParams()) {
        return;//from  w ww .j a v  a2  s  . c o m
    }

    if (connectionTimeout > 0) {
        p.setSoTimeout(connectionTimeout);
    }

    if (params != null) {
        Pattern coercePattern = Pattern.compile(COERCE_PATTERN);

        for (Map.Entry<Object, Object> entry : params.entrySet()) {
            String key = (String) entry.getKey();
            String value = (String) entry.getValue();

            Matcher matcher = coercePattern.matcher(value);
            if (matcher.matches()) {
                char type = matcher.group(1).charAt(0);
                value = matcher.group(2);

                switch (type) {
                case 'i': {
                    p.setIntParameter(key, Integer.parseInt(value));
                    break;
                }
                case 'd': {
                    p.setDoubleParameter(key, Double.parseDouble(value));
                    break;
                }
                case 'l': {
                    p.setLongParameter(key, Long.parseLong(value));
                    break;
                }
                case 'b': {
                    p.setBooleanParameter(key, Boolean.valueOf(value).booleanValue());
                    break;
                }
                case 'c': {
                    String[] entries = value.split(",");
                    List<String> collection = new ArrayList<String>();
                    for (String e : entries) {
                        collection.add(e.trim());
                    }

                    p.setParameter(key, collection);
                    break;
                }
                case 'm': {
                    String[] entries = value.split(",");

                    Map<String, String> map = new LinkedHashMap<String, String>();
                    for (String e : entries) {
                        int idx = e.indexOf("=>");
                        if (idx < 1) {
                            break;
                        }

                        String mapKey = e.substring(0, idx);
                        String mapVal = e.substring(idx + 1, e.length());
                        map.put(mapKey.trim(), mapVal.trim());
                    }

                    p.setParameter(key, map);
                    break;
                }
                }
            } else {
                p.setParameter(key, value);
            }
        }
    }
}