Example usage for org.apache.commons.httpclient.methods MultipartPostMethod getParams

List of usage examples for org.apache.commons.httpclient.methods MultipartPostMethod getParams

Introduction

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

Prototype

@Override
public HttpMethodParams getParams() 

Source Link

Document

Returns HttpMethodParams HTTP protocol parameters associated with this method.

Usage

From source file:org.bibsonomy.rest.client.worker.impl.PostWorker.java

public Reader perform(final String url, final File file) throws ErrorPerformingRequestException {
    LOGGER.debug("POST Multipart: URL: " + url);

    if (this.proxyHost != null) {
        this.getHttpClient().getHostConfiguration().setProxy(this.proxyHost, this.proxyPort);
    }//from  ww  w  .  j a  va  2s  .  c o  m

    // TODO: remove deprecated method
    final MultipartPostMethod post = new MultipartPostMethod(url);

    post.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
    post.addRequestHeader(HeaderUtils.HEADER_AUTHORIZATION,
            HeaderUtils.encodeForAuthorization(this.username, this.apiKey));
    post.addRequestHeader("Content-Type", "multipart/form-data");

    try {
        post.addParameter("file", file);

        this.getHttpClient().getHttpConnectionManager().getParams().setConnectionTimeout(5000);

        this.httpResult = this.getHttpClient().executeMethod(post);
        LOGGER.debug("HTTP result: " + this.httpResult);
        LOGGER.debug("response:\n" + post.getResponseBodyAsString());
        LOGGER.debug("===================================================");
        return new StringReader(post.getResponseBodyAsString());
    } catch (final IOException e) {
        LOGGER.debug(e.getMessage(), e);
        throw new ErrorPerformingRequestException(e);
    } finally {
        post.releaseConnection();
    }
}