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.uploader.Vimeo.java

public VimeoResponse addVideoPrivacyDomain(String videoEndpoint, String domain)
        throws ClientProtocolException, UnsupportedEncodingException, IOException {
    return apiRequest(new StringBuffer(videoEndpoint).append("/privacy/domains/")
            .append(URLEncoder.encode(domain, "UTF-8")).toString(), HttpPut.METHOD_NAME, null, null);
}

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

@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    if (!request.containsHeader("Accept")) {
        request.addHeader("Accept",
                "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
    }/*from w  ww. j  a v  a 2 s .c  o  m*/

    if (!request.containsHeader("Content-Type")) {
        request.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
    }

    //      request.addHeader("Accept-Language", "zh-CN,zh;q=0.8,ja;q=0.6,en;q=0.4");
    request.addHeader("Cache-Control", "no-cache");
    request.addHeader("Pragma", "no-cache");

    if (request.containsHeader("X-Requested-With")) {

        String method = ((HttpUriRequest) request).getMethod();

        if (HttpPost.METHOD_NAME.equals(method) || HttpPut.METHOD_NAME.equals(method)
                || HttpPatch.METHOD_NAME.equals(method)) {
            //            request.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
            request.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        }

        request.addHeader("Origin", hostConfig.getHostUrl());
    }

    if (!request.containsHeader("Referer") && hostConfig.getReferer() != null) {
        request.addHeader("Referer", hostConfig.getReferer());
    }

    request.setHeader("User-Agent", hostConfig.getUserAgent() != null ? hostConfig.getUserAgent() : userAgent);

    copyAndSet(sortKeyList, request);
}

From source file:org.deviceconnect.message.http.impl.factory.AbstractHttpMessageFactory.java

/**
 * HTTP 1???dConnect??./*from www .  j  av  a2 s .  c  o  m*/
 * @param message HTTP
 * @return dConnect
 */
protected DConnectMessage parseFirstLine(final M message) {
    mLogger.entering(getClass().getName(), "parseFirstLine", message);
    DConnectMessage dmessage = null;

    if (message instanceof HttpRequest) {

        // put action
        String method = ((HttpRequest) message).getRequestLine().getMethod();
        mLogger.fine("HTTP request method: " + method);

        DConnectRequestMessage drequest = new DConnectRequestMessage();
        if (HttpGet.METHOD_NAME.equals(method)) {
            drequest.setMethod(DConnectRequestMessage.METHOD_GET);
        } else if (HttpPut.METHOD_NAME.equals(method)) {
            drequest.setMethod(DConnectRequestMessage.METHOD_PUT);
        } else if (HttpPost.METHOD_NAME.equals(method)) {
            drequest.setMethod(DConnectRequestMessage.METHOD_POST);
        } else if (HttpDelete.METHOD_NAME.equals(method)) {
            drequest.setMethod(DConnectRequestMessage.METHOD_DELETE);
        } else {
            throw new IllegalArgumentException("invalid http request mehtod: " + method);
        }

        dmessage = drequest;
    } else if (message instanceof HttpResponse) {
        dmessage = new DConnectResponseMessage();
    } else {
        throw new IllegalArgumentException(
                "unkown http message class instance: " + message.getClass().getName());
    }

    mLogger.exiting(getClass().getName(), "parseFirstLine", dmessage);
    return dmessage;
}

From source file:retsys.client.http.HttpHelper.java

public String executeHttpRequest(HttpClient client, HttpUriRequest req) throws IOException {
    String response = null;//from   ww w  .j  a  va 2s  . com
    HttpResponse httpResponse = client.execute(req);
    int httpStatus = httpResponse.getStatusLine().getStatusCode();
    if (httpStatus >= 200 && httpStatus < 300) {
        if (!HttpDelete.METHOD_NAME.equals(req.getMethod()) && !HttpPut.METHOD_NAME.equals(req.getMethod())) {
            response = readFromStream(httpResponse.getEntity().getContent());
        }
    } else if (httpStatus == 409) {
        response = readFromStream(httpResponse.getEntity().getContent());
        System.out.println("response:  " + response);
        response = "!ERROR!";
    } else {
        response = "!ERROR!";
    }

    return response;
}

From source file:org.apache.edgent.connectors.http.runtime.HttpRequester.java

@Override
public R apply(T t) {

    if (client == null)
        client = clientCreator.get();//ww w  .ja  v  a  2s  .  c  o  m

    String m = method.apply(t);
    String uri = url.apply(t);
    HttpUriRequest request;

    switch (m) {

    case HttpGet.METHOD_NAME:
        request = new HttpGet(uri);
        break;
    case HttpDelete.METHOD_NAME:
        request = new HttpDelete(uri);
        break;
    case HttpPost.METHOD_NAME:
        request = new HttpPost(uri);
        break;
    case HttpPut.METHOD_NAME:
        request = new HttpPut(uri);
        break;

    default:
        throw new IllegalArgumentException();
    }

    // If entity is not null means http request should have a body
    if (entity != null) {

        HttpEntity body = entity.apply(t);

        if (request instanceof HttpEntityEnclosingRequest == false) {
            throw new IllegalArgumentException("Http request does not support body");
        }

        ((HttpEntityEnclosingRequest) request).setEntity(body);
    }

    try {
        try (CloseableHttpResponse response = client.execute(request)) {
            return responseProcessor.apply(t, response);
        }

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.metamodel.elasticsearch.rest.ElasticSearchRestClient.java

private static Request putMapping(final PutMappingRequest putMappingRequest) {
    final String endpoint = "/" + putMappingRequest.indices()[0] + "/_mapping/" + putMappingRequest.type();
    final ByteArrayEntity entity = new ByteArrayEntity(putMappingRequest.source().getBytes(),
            ContentType.APPLICATION_JSON);
    return new Request(HttpPut.METHOD_NAME, endpoint, Collections.emptyMap(), entity);
}

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

@Test
public void testBuildHttpRequest_Put() throws IOException {
    byte[] data = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };
    RequestTemplate template = new RequestTemplate().method("put").append("/path").body(data, null);
    HttpUriRequest request = RequestUtil.buildHttpRequest("http://host", template.request());

    assertEquals("http://host/path", request.getURI().toString());
    assertEquals(HttpPut.METHOD_NAME, request.getMethod());

    HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request;
    assertArrayEquals(data, EntityUtils.toByteArray(entityRequest.getEntity()));
}

From source file:org.camunda.connect.httpclient.impl.AbstractHttpRequest.java

public Q put() {
    return method(HttpPut.METHOD_NAME);
}

From source file:org.camunda.connect.httpclient.impl.AbstractHttpConnector.java

@SuppressWarnings("unchecked")
protected <T extends HttpRequestBase> T createHttpRequestBase(Q request) {
    String url = request.getUrl();
    if (url != null && !url.trim().isEmpty()) {
        String method = request.getMethod();
        if (HttpGet.METHOD_NAME.equals(method)) {
            return (T) new HttpGet(url);
        } else if (HttpPost.METHOD_NAME.equals(method)) {
            return (T) new HttpPost(url);
        } else if (HttpPut.METHOD_NAME.equals(method)) {
            return (T) new HttpPut(url);
        } else if (HttpDelete.METHOD_NAME.equals(method)) {
            return (T) new HttpDelete(url);
        } else if (HttpPatch.METHOD_NAME.equals(method)) {
            return (T) new HttpPatch(url);
        } else if (HttpHead.METHOD_NAME.equals(method)) {
            return (T) new HttpHead(url);
        } else if (HttpOptions.METHOD_NAME.equals(method)) {
            return (T) new HttpOptions(url);
        } else if (HttpTrace.METHOD_NAME.equals(method)) {
            return (T) new HttpTrace(url);
        } else {//from  w  ww . ja  va 2  s  .  c  o  m
            throw LOG.unknownHttpMethod(method);
        }
    } else {
        throw LOG.requestUrlRequired();
    }
}

From source file:org.apache.edgent.test.connectors.http.HttpTest.java

@Test
public void testPut() throws Exception {
    DirectProvider ep = new DirectProvider();

    Topology topology = ep.newTopology();

    String url = "http://httpbin.org/put";

    TStream<String> stream = topology.strings(url);
    TStream<String> rc = HttpStreams.<String, String>requestsWithBody(stream, HttpClients::noAuthentication,
            t -> HttpPut.METHOD_NAME, t -> t, t -> new ByteArrayEntity(t.getBytes()),
            HttpResponders.inputOn200());

    Tester tester = topology.getTester();

    Condition<List<String>> endCondition = tester.streamContents(rc, url);

    tester.complete(ep, new JsonObject(), endCondition, 10, TimeUnit.SECONDS);

    assertTrue(endCondition.valid());//from   ww  w.  j  av  a  2 s.c  o m
}