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

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

Introduction

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

Prototype

public HttpMethodParams() 

Source Link

Usage

From source file:com.taobao.diamond.client.impl.DefaultDiamondSubscriber.java

/**
 * DiamondServerDataID/*from  w w w  . j ava 2  s  .  c  o m*/
 * 
 * @param timeout
 * @return
 */
Set<String> checkUpdateDataIds(long timeout) {
    if (!isRun) {
        throw new RuntimeException("DiamondSubscriberDataID");
    }
    // ==============================================
    if (MockServer.isTestMode()) {
        return testData();
    }
    // ==========================================================
    long waitTime = 0;

    // Set<String> localModifySet = getLocalUpdateDataIds();
    String probeUpdateString = getProbeUpdateString();
    if (StringUtils.isBlank(probeUpdateString)) {
        return null;
    }

    while (0 == timeout || timeout > waitTime) {
        // 
        long onceTimeOut = getOnceTimeOut(waitTime, timeout);
        waitTime += onceTimeOut;

        PostMethod postMethod = new PostMethod(Constants.HTTP_URI_FILE);

        postMethod.addParameter(Constants.PROBE_MODIFY_REQUEST, probeUpdateString);

        // HttpMethod
        HttpMethodParams params = new HttpMethodParams();
        params.setSoTimeout((int) onceTimeOut);
        // ///////////////////////
        postMethod.setParams(params);

        try {
            httpClient.getHostConfiguration().setHost(
                    diamondConfigure.getDomainNameList().get(this.domainNamePos.get()),
                    this.diamondConfigure.getPort());

            int httpStatus = httpClient.executeMethod(postMethod);

            switch (httpStatus) {
            case SC_OK: {
                Set<String> result = getUpdateDataIds(postMethod);
                return result;
            }

            case SC_SERVICE_UNAVAILABLE: {
                rotateToNextDomain();
            }
                break;

            default: {
                log.warn("DataIDHTTP State: " + httpStatus);
                rotateToNextDomain();
            }
            }
        } catch (HttpException e) {
            log.error("Http", e);
            rotateToNextDomain();
        } catch (IOException e) {
            log.error("IO", e);
            rotateToNextDomain();
        } catch (Exception e) {
            log.error("", e);
            rotateToNextDomain();
        } finally {
            postMethod.releaseConnection();
        }
    }
    throw new RuntimeException("DataID "
            + diamondConfigure.getDomainNameList().get(this.domainNamePos.get()) + ", " + timeout);
}

From source file:cn.leancloud.diamond.client.impl.DefaultDiamondSubscriber.java

/**
 * DiamondServer??DataID/*from   w ww  . j ava  2s  .  c  o  m*/
 * 
 * @param timeout
 * @return
 */
Set<String> checkUpdateDataIds(long timeout) {
    if (!isRun) {
        throw new RuntimeException(
                "DiamondSubscriber????DataID");
    }
    // =======================?=======================
    if (MockServer.isTestMode()) {
        return testData();
    }
    // ==========================================================
    long waitTime = 0;

    // Set<String> localModifySet = getLocalUpdateDataIds();
    String probeUpdateString = getProbeUpdateString();
    if (StringUtils.isBlank(probeUpdateString)) {
        return null;
    }

    while (0 == timeout || timeout > waitTime) {
        // 
        long onceTimeOut = getOnceTimeOut(waitTime, timeout);
        waitTime += onceTimeOut;

        PostMethod postMethod = new PostMethod(Constants.HTTP_URI_FILE);

        postMethod.addParameter(Constants.PROBE_MODIFY_REQUEST, probeUpdateString);

        // HttpMethod?
        HttpMethodParams params = new HttpMethodParams();
        params.setSoTimeout((int) onceTimeOut);
        // ///////////////////////
        postMethod.setParams(params);

        try {
            httpClient.getHostConfiguration().setHost(
                    diamondConfigure.getDomainNameList().get(this.domainNamePos.get()),
                    this.diamondConfigure.getPort());

            int httpStatus = httpClient.executeMethod(postMethod);

            log.info(httpStatus);

            switch (httpStatus) {
            case SC_OK: {
                Set<String> result = getUpdateDataIds(postMethod);
                return result;
            }

            case SC_SERVICE_UNAVAILABLE: {
                rotateToNextDomain();
            }
                break;

            default: {
                log.warn("?DataIDHTTP State: " + httpStatus);
                rotateToNextDomain();
            }
            }
        } catch (HttpException e) {
            log.error("???Http", e);
            rotateToNextDomain();
        } catch (IOException e) {
            log.error("???IO", e);
            rotateToNextDomain();
        } catch (Exception e) {
            log.error("", e);
            rotateToNextDomain();
        } finally {
            postMethod.releaseConnection();
        }
    }
    throw new RuntimeException("?DataID "
            + diamondConfigure.getDomainNameList().get(this.domainNamePos.get()) + ", "
            + timeout);
}

From source file:com.mengka.diamond.client.impl.DefaultDiamondSubscriber.java

/**
 * DiamondServer??DataID/*from w w  w .  j  ava  2 s .  co m*/
 * 
 * @param timeout
 * @return
 */
Set<String> checkUpdateDataIds(long timeout) {
    if (!isRun) {
        throw new RuntimeException(
                "DiamondSubscriber????DataID");
    }
    // =======================?=======================
    if (MockServer.isTestMode()) {
        return testData();
    }
    // ==========================================================
    long waitTime = 0;

    // Set<String> localModifySet = getLocalUpdateDataIds();
    String probeUpdateString = getProbeUpdateString();
    if (StringUtils.isBlank(probeUpdateString)) {
        return null;
    }

    while (0 == timeout || timeout > waitTime) {
        // 
        long onceTimeOut = getOnceTimeOut(waitTime, timeout);
        waitTime += onceTimeOut;

        PostMethod postMethod = new PostMethod(Constants.CONFIG_HTTP_URI_FILE);

        postMethod.addParameter(Constants.PROBE_MODIFY_REQUEST, probeUpdateString);

        // HttpMethod?
        HttpMethodParams params = new HttpMethodParams();
        params.setSoTimeout((int) onceTimeOut);
        // ///////////////////////
        postMethod.setParams(params);

        try {
            httpClient.getHostConfiguration().setHost(
                    diamondConfigure.getDomainNameList().get(this.domainNamePos.get()),
                    this.diamondConfigure.getPort());

            int httpStatus = httpClient.executeMethod(postMethod);

            switch (httpStatus) {
            case SC_OK: {
                Set<String> result = getUpdateDataIds(postMethod);
                return result;
            }

            case SC_SERVICE_UNAVAILABLE: {
                rotateToNextDomain();
            }
                break;

            default: {
                log.warn("?DataIDHTTP State: " + httpStatus);
                rotateToNextDomain();
            }
            }
        } catch (HttpException e) {
            log.error("???Http", e);
            rotateToNextDomain();
        } catch (IOException e) {
            log.error("???IO", e);
            rotateToNextDomain();
        } catch (Exception e) {
            log.error("", e);
            rotateToNextDomain();
        } finally {
            postMethod.releaseConnection();
        }
    }
    throw new RuntimeException("?DataID "
            + diamondConfigure.getDomainNameList().get(this.domainNamePos.get()) + ", "
            + timeout);
}

From source file:com.starit.diamond.client.impl.DefaultDiamondSubscriber.java

private void configureHttpMethod(boolean skipContentCache, CacheData cacheData, long onceTimeOut,
        HttpMethod httpMethod) {//from w ww. java  2s. com
    if (skipContentCache && null != cacheData) {
        if (null != cacheData.getLastModifiedHeader() && Constants.NULL != cacheData.getLastModifiedHeader()) {
            httpMethod.addRequestHeader(Constants.IF_MODIFIED_SINCE, cacheData.getLastModifiedHeader());
        }
        if (null != cacheData.getMd5() && Constants.NULL != cacheData.getMd5()) {
            httpMethod.addRequestHeader(Constants.CONTENT_MD5, cacheData.getMd5());
        }
    }
    // appName
    if (null != this.appName) {
        httpMethod.addRequestHeader(Constants.APPNAME, this.appName);
    }
    httpMethod.addRequestHeader(Constants.CLIENT_VERSION_HEADER, Constants.CLIENT_VERSION);

    httpMethod.addRequestHeader(Constants.ACCEPT_ENCODING, "gzip,deflate");

    // HttpMethod?
    HttpMethodParams params = new HttpMethodParams();
    params.setSoTimeout((int) onceTimeOut);
    // ///////////////////////
    httpMethod.setParams(params);
    httpClient.getHostConfiguration().setHost(
            diamondConfigure.getDomainNameList().get(this.domainNamePos.get()), diamondConfigure.getPort());
}

From source file:com.starit.diamond.client.impl.DefaultDiamondSubscriber.java

/**
 * DiamondServer??DataID/* ww w  .j  a  va  2  s.  c  o  m*/
 * 
 * @param timeout
 * @return
 */
Set<String> checkUpdateDataIds(long timeout) {
    if (!isRun) {
        throw new RuntimeException(
                "DiamondSubscriber????DataID");
    }
    // =======================?=======================
    if (MockServer.isTestMode()) {
        return testData();
    }
    // ==========================================================
    long waitTime = 0;

    String probeUpdateString = getProbeUpdateString();
    if (StringUtils.isBlank(probeUpdateString)) {
        return null;
    }

    while (0 == timeout || timeout > waitTime) {
        // 
        long onceTimeOut = getOnceTimeOut(waitTime, timeout);
        waitTime += onceTimeOut;

        PostMethod postMethod = new PostMethod(Constants.CONFIG_HTTP_URI_FILE);

        postMethod.addParameter(Constants.PROBE_MODIFY_REQUEST, probeUpdateString);

        if (null != this.appName) {
            postMethod.addRequestHeader(Constants.APPNAME, this.appName);
        }
        postMethod.addRequestHeader(Constants.CLIENT_VERSION_HEADER, Constants.CLIENT_VERSION);
        // HttpMethod?
        HttpMethodParams params = new HttpMethodParams();
        params.setSoTimeout((int) onceTimeOut);
        // ///////////////////////
        postMethod.setParams(params);

        try {
            httpClient.getHostConfiguration().setHost(
                    diamondConfigure.getDomainNameList().get(this.domainNamePos.get()),
                    this.diamondConfigure.getPort());

            int httpStatus = httpClient.executeMethod(postMethod);

            switch (httpStatus) {
            case SC_OK: {

                Set<String> result = getUpdateDataIds(postMethod);
                return result;
            }

            case SC_SERVICE_UNAVAILABLE: {
                rotateToNextDomain();
            }
                break;

            default: {
                log.warn("?DataIDHTTP State: " + httpStatus);
                rotateToNextDomain();
            }
            }
        } catch (HttpException e) {
            log.error("???Http" + e);
            rotateToNextDomain();
        } catch (IOException e) {
            log.error("???IO" + e);
            rotateToNextDomain();
        } catch (Exception e) {
            log.error("", e);
            rotateToNextDomain();
        } finally {
            postMethod.releaseConnection();
        }
    }
    throw new RuntimeException("?DataID "
            + diamondConfigure.getDomainNameList().get(this.domainNamePos.get()) + ", "
            + timeout);
}

From source file:com.starit.diamond.client.impl.DefaultDiamondSubscriber.java

private void configureAckHttpMethod(HttpMethod httpMethod, long onceTimeOut) {
    // appName/*from w ww. ja  v  a2 s. co m*/
    if (null != this.appName) {
        httpMethod.addRequestHeader(Constants.APPNAME, this.appName);
    }
    httpMethod.addRequestHeader(Constants.CLIENT_VERSION_HEADER, Constants.CLIENT_VERSION);

    // HttpMethod?
    HttpMethodParams params = new HttpMethodParams();
    params.setSoTimeout((int) onceTimeOut);

    httpMethod.setParams(params);
    httpClient.getHostConfiguration().setHost(
            diamondConfigure.getDomainNameList().get(this.domainNamePos.get()), diamondConfigure.getPort());
}

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

/**
 * Post async./*from w w w .  ja va2s  .  c o 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:nz.co.jsrsolutions.ds3.provider.EodDataEodDataProvider.java

public EodDataEodDataProvider(String url, String username, String password, long timeout)
        throws EodDataProviderException {

    this.url = url;
    this.username = username;
    this.password = password;
    this.timeout = timeout;

    try {/*from  w  w w  .j  a  va 2  s.c om*/

        HttpMethodParams methodParams = new HttpMethodParams();
        DefaultHttpMethodRetryHandler retryHandler = new DefaultHttpMethodRetryHandler(3, false);
        methodParams.setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler);

        eodDataStub = new DataStub(url);
        eodDataStub._getServiceClient().getOptions().setTimeOutInMilliSeconds(timeout);
        eodDataStub._getServiceClient().getOptions().setProperty(HTTPConstants.HTTP_METHOD_PARAMS,
                methodParams);

        DataStub.Login loginRequest = new DataStub.Login();
        loginRequest.setUsername(username);
        loginRequest.setPassword(password);

        // Login
        DataStub.LoginResponse0 loginResponse0 = eodDataStub.login(loginRequest);
        DataStub.LOGINRESPONSE loginResponse = loginResponse0.getLoginResult();

        if (loginResponse == null) {
            throw new EodDataProviderException("Failed to authenticate with EOD Data web service.");
        }

        token = loginResponse.getToken();

        if (token == null || token.isEmpty()) {
            throw new EodDataProviderException("Failed to authenticate with EOD Data web service.");
        }

        logger.info(loginResponse.getMessage());
        logger.info(token);
        logger.info(loginResponse.getDataFormat());
    } catch (org.apache.axis2.AxisFault afe) {

        logger.error(afe.toString());
        EodDataProviderException edpe = new EodDataProviderException("Unable to construct EodDataDataProvider");
        edpe.initCause(afe);

        throw edpe;

    } catch (java.rmi.RemoteException re) {

        logger.error(re.toString());
        EodDataProviderException edpe = new EodDataProviderException("Unable to construct EodDataDataProvider");
        edpe.initCause(re);

        throw edpe;

    }

}

From source file:org.activiti.rest.HttpMultipartRepresentation.java

public void processStreamAndSetMediaType(final String fileName, InputStream fileStream,
        Map<String, String> additionalFormFields) throws IOException {
    // Copy the stream in a bytearray to get the length
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    IOUtils.copy(fileStream, output);/*from  w w w  . j  a v a  2  s  .  c o  m*/

    final int length = output.toByteArray().length;
    final InputStream stream = new ByteArrayInputStream(output.toByteArray());

    List<Part> parts = new ArrayList<Part>();

    // Filepart is based on in-memory stream an file-name rather than an actual file
    FilePart filePart = new FilePart(fileName, new PartSource() {
        @Override
        public long getLength() {
            return length;
        }

        @Override
        public String getFileName() {
            return fileName;
        }

        @Override
        public InputStream createInputStream() throws IOException {
            return stream;
        }
    });
    parts.add(filePart);

    if (additionalFormFields != null && !additionalFormFields.isEmpty()) {
        for (Entry<String, String> field : additionalFormFields.entrySet()) {
            parts.add(new StringPart(field.getKey(), field.getValue()));
        }
    }

    MultipartRequestEntity entity = new MultipartRequestEntity(parts.toArray(new Part[] {}),
            new HttpMethodParams());

    // Let the entity write the raw multipart to a bytearray, which is used as a source
    // for the input-stream returned by this Representation
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    entity.writeRequest(os);
    setMediaType(new MediaType(entity.getContentType()));
    setStream(new ByteArrayInputStream(os.toByteArray()));
}

From source file:org.alfresco.repo.web.scripts.custommodel.CustomModelImportTest.java

public PostRequest buildMultipartPostRequest(File file) throws IOException {
    Part[] parts = { new FilePart("filedata", file.getName(), file, "application/zip", null) };

    MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(parts, new HttpMethodParams());

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    multipartRequestEntity.writeRequest(os);

    PostRequest postReq = new PostRequest(UPLOAD_URL, os.toByteArray(),
            multipartRequestEntity.getContentType());
    return postReq;
}