Example usage for org.apache.http.client.methods RequestBuilder getVersion

List of usage examples for org.apache.http.client.methods RequestBuilder getVersion

Introduction

In this page you can find the example usage for org.apache.http.client.methods RequestBuilder getVersion.

Prototype

public ProtocolVersion getVersion() 

Source Link

Usage

From source file:com.wudaosoft.net.httpclient.ParameterRequestBuilder.java

public static HttpUriRequest build(RequestBuilder builder) {

    final HttpRequestBase result;
    URI uriNotNull = builder.getUri() != null ? builder.getUri() : URI.create("/");
    Charset charset = builder.getCharset();
    charset = charset != null ? charset : HTTP.DEF_CONTENT_CHARSET;
    String method = builder.getMethod();
    List<NameValuePair> parameters = builder.getParameters();
    HttpEntity entityCopy = builder.getEntity();

    if (parameters != null && !parameters.isEmpty()) {
        if (entityCopy == null && (HttpPost.METHOD_NAME.equalsIgnoreCase(method)
                || HttpPut.METHOD_NAME.equalsIgnoreCase(method)
                || HttpPatch.METHOD_NAME.equalsIgnoreCase(method))) {
            entityCopy = new UrlEncodedFormEntity(parameters, charset);
        } else {/*  w  ww  . j ava 2 s  .co  m*/
            try {
                uriNotNull = new URIBuilder(uriNotNull).setCharset(charset).addParameters(parameters).build();
            } catch (final URISyntaxException ex) {
                // should never happen
            }
        }
    }

    if (entityCopy == null) {
        result = new InternalRequest(method);
    } else {
        final InternalEntityEclosingRequest request = new InternalEntityEclosingRequest(method);
        request.setEntity(entityCopy);
        result = request;
    }
    result.setProtocolVersion(builder.getVersion());
    result.setURI(uriNotNull);
    // if (builder.headergroup != null) {
    // result.setHeaders(builder.headergroup.getAllHeaders());
    // }
    result.setConfig(builder.getConfig());
    return result;
}