Example usage for org.apache.http.client.methods HttpPut METHOD_NAME

List of usage examples for org.apache.http.client.methods HttpPut METHOD_NAME

Introduction

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

Prototype

String METHOD_NAME

To view the source code for org.apache.http.client.methods HttpPut METHOD_NAME.

Click 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 {/*from   ww w.j  a va 2  s .  c om*/
            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;
}

From source file:com.blacklocus.jres.request.mapping.JresPutMapping.java

@Override
public String getHttpMethod() {
    return HttpPut.METHOD_NAME;
}

From source file:org.fcrepo.camel.HttpMethodsTest.java

@Test
public void testMethods() {
    assertEquals(HttpMethods.DELETE.toString(), HttpDelete.METHOD_NAME);
    assertEquals(HttpMethods.GET.toString(), HttpGet.METHOD_NAME);
    assertEquals(HttpMethods.HEAD.toString(), HttpHead.METHOD_NAME);
    assertEquals(HttpMethods.OPTIONS.toString(), HttpOptions.METHOD_NAME);
    assertEquals(HttpMethods.PATCH.toString(), HttpPatch.METHOD_NAME);
    assertEquals(HttpMethods.POST.toString(), HttpPost.METHOD_NAME);
    assertEquals(HttpMethods.PUT.toString(), HttpPut.METHOD_NAME);
}

From source file:ch.cyberduck.core.dav.DAVRedirectStrategy.java

@Override
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context)
        throws ProtocolException {
    final String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase(HttpPut.METHOD_NAME)) {
        return this.copyEntity(new HttpPut(this.getLocationURI(request, response, context)), request);
    }/*w w  w  .  j  a  va  2  s .  c  o  m*/
    return super.getRedirect(request, response, context);
}

From source file:io.wcm.caravan.io.http.impl.RequestUtil.java

/**
 * @param urlPrefix URL prefix//from   ww  w .j a  v a  2  s  .c  o  m
 * @param request Requset
 * @return HTTP client request object
 */
public static HttpUriRequest buildHttpRequest(String urlPrefix, Request request) {
    String url = urlPrefix + request.url();

    // http method
    HttpUriRequest httpRequest;
    String method = StringUtils.upperCase(request.method());
    switch (method) {
    case HttpGet.METHOD_NAME:
        httpRequest = new HttpGet(url);
        break;
    case HttpPost.METHOD_NAME:
        httpRequest = new HttpPost(url);
        break;
    case HttpPut.METHOD_NAME:
        httpRequest = new HttpPut(url);
        break;
    case HttpDelete.METHOD_NAME:
        httpRequest = new HttpDelete(url);
        break;
    default:
        throw new IllegalArgumentException("Unsupported HTTP method type: " + request.method());
    }

    // headers
    for (Entry<String, Collection<String>> entry : request.headers().entrySet()) {
        Streams.of(entry.getValue()).forEach(value -> httpRequest.addHeader(entry.getKey(), value));
    }

    // body
    if ((httpRequest instanceof HttpEntityEnclosingRequest) && request.body() != null) {
        HttpEntityEnclosingRequest entityHttpRequest = (HttpEntityEnclosingRequest) httpRequest;
        if (request.charset() != null) {
            entityHttpRequest.setEntity(
                    new StringEntity(new String(request.body(), request.charset()), request.charset()));
        } else {
            entityHttpRequest.setEntity(new ByteArrayEntity(request.body()));
        }
    }

    return httpRequest;
}

From source file:org.gradle.internal.resource.transport.http.AlwaysRedirectRedirectStrategy.java

public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context)
        throws ProtocolException {
    URI uri = this.getLocationURI(request, response, context);
    String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
        return new HttpHead(uri);
    } else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
        return this.copyEntity(new HttpPost(uri), request);
    } else if (method.equalsIgnoreCase(HttpPut.METHOD_NAME)) {
        return this.copyEntity(new HttpPut(uri), request);
    } else if (method.equalsIgnoreCase(HttpDelete.METHOD_NAME)) {
        return new HttpDelete(uri);
    } else if (method.equalsIgnoreCase(HttpTrace.METHOD_NAME)) {
        return new HttpTrace(uri);
    } else if (method.equalsIgnoreCase(HttpOptions.METHOD_NAME)) {
        return new HttpOptions(uri);
    } else if (method.equalsIgnoreCase(HttpPatch.METHOD_NAME)) {
        return this.copyEntity(new HttpPatch(uri), request);
    } else {/*from w ww  . j a va  2s .  co  m*/
        return new HttpGet(uri);
    }
}

From source file:org.camunda.connect.httpclient.HttpRequestTest.java

@Test
public void setHttpMethod() {
    HttpRequest request = connector.createRequest().get();
    assertThat(request.getMethod()).isEqualTo(HttpGet.METHOD_NAME);

    request = connector.createRequest().post();
    assertThat(request.getMethod()).isEqualTo(HttpPost.METHOD_NAME);

    request = connector.createRequest().put();
    assertThat(request.getMethod()).isEqualTo(HttpPut.METHOD_NAME);

    request = connector.createRequest().delete();
    assertThat(request.getMethod()).isEqualTo(HttpDelete.METHOD_NAME);

    request = connector.createRequest().patch();
    assertThat(request.getMethod()).isEqualTo(HttpPatch.METHOD_NAME);

    request = connector.createRequest().head();
    assertThat(request.getMethod()).isEqualTo(HttpHead.METHOD_NAME);

    request = connector.createRequest().options();
    assertThat(request.getMethod()).isEqualTo(HttpOptions.METHOD_NAME);

    request = connector.createRequest().trace();
    assertThat(request.getMethod()).isEqualTo(HttpTrace.METHOD_NAME);
}

From source file:org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApi.java

/**
 * Returns the supported http methods given the rest parameters provided
 *//*from  w  ww. j a  v  a 2 s  . co  m*/
public List<String> getSupportedMethods(Set<String> restParams) {
    //we try to avoid hardcoded mappings but the index api is the exception
    if ("index".equals(name) || "create".equals(name)) {
        List<String> indexMethods = new ArrayList<>();
        for (String method : methods) {
            if (restParams.contains("id")) {
                //PUT when the id is provided
                if (HttpPut.METHOD_NAME.equals(method)) {
                    indexMethods.add(method);
                }
            } else {
                //POST without id
                if (HttpPost.METHOD_NAME.equals(method)) {
                    indexMethods.add(method);
                }
            }
        }
        return indexMethods;
    }

    return methods;
}

From source file:org.elasticsearch.test.rest.spec.RestApi.java

/**
 * Returns the supported http methods given the rest parameters provided
 *//*from w w w .j  a  v a2s  . c om*/
public List<String> getSupportedMethods(Set<String> restParams) {
    //we try to avoid hardcoded mappings but the index api is the exception
    if ("index".equals(name) || "create".equals(name)) {
        List<String> indexMethods = Lists.newArrayList();
        for (String method : methods) {
            if (restParams.contains("id")) {
                //PUT when the id is provided
                if (HttpPut.METHOD_NAME.equals(method)) {
                    indexMethods.add(method);
                }
            } else {
                //POST without id
                if (HttpPost.METHOD_NAME.equals(method)) {
                    indexMethods.add(method);
                }
            }
        }
        return indexMethods;
    }

    return methods;
}