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

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

Introduction

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

Prototype

public HttpPut(final String uri) 

Source Link

Usage

From source file:com.aliyun.android.oss.task.PutBucketAclTask.java

@Override
protected HttpUriRequest generateHttpRequest() {
    HttpPut httpPut = new HttpPut(this.getOSSEndPoint() + httpTool.generateCanonicalizedResource("/"));

    String resource = httpTool.generateCanonicalizedResource("/" + bucketName + "/");
    String dateStr = Helper.getGMTDate();
    String content = "PUT\n\n\n" + dateStr + "\n" + X_OSS_ACL + ":" + accessLevel.toString() + "\n" + resource;
    String authorization = OSSHttpTool.generateAuthorization(accessId, accessKey, content);
    httpPut.setHeader("Authorization", authorization);
    httpPut.setHeader(X_OSS_ACL, accessLevel.toString());
    httpPut.setHeader("Date", dateStr);

    return httpPut;
}

From source file:tech.beshu.ror.integration.FiltersAndFieldsSecurityTests.java

private static void insertDoc(String docName, RestClient restClient, String idx, String field) {
    if (adminClient == null) {
        adminClient = restClient;/* w  w w  .  j  ava 2  s .c om*/
    }

    String path = "/" + IDX_PREFIX + idx + "/documents/doc-" + docName + String.valueOf(Math.random());
    try {

        HttpPut request = new HttpPut(restClient.from(path));
        request.setHeader("Content-Type", "application/json");
        request.setHeader("refresh", "true");
        request.setHeader("timeout", "50s");
        request.setEntity(new StringEntity("{\"" + field + "\": \"" + docName + "\", \"dummy\": true}"));
        System.out.println(body(restClient.execute(request)));

    } catch (Exception e) {
        e.printStackTrace();
        throw new IllegalStateException("Test problem", e);
    }

    // Polling phase.. #TODO is there a better way?
    try {
        HttpResponse response;
        do {
            HttpHead request = new HttpHead(restClient.from(path));
            request.setHeader("x-api-key", "p");
            response = restClient.execute(request);
            System.out.println(
                    "polling for " + docName + ".. result: " + response.getStatusLine().getReasonPhrase());
            Thread.sleep(200);
        } while (response.getStatusLine().getStatusCode() != 200);
    } catch (Exception e) {
        e.printStackTrace();
        throw new IllegalStateException("Cannot configure test case", e);
    }
}

From source file:com.messagemedia.restapi.client.v1.internal.RestRequest.java

/**
 * Builds an apache http request//  w w w  . j a v a  2s.  com
 *
 * @return the apache http request
 */
HttpUriRequest getHttpRequest() {
    HttpUriRequest request;
    switch (method) {
    case GET:
        request = new HttpGet(url);
        break;
    case DELETE:
        request = new HttpDelete(url);
        break;
    case HEAD:
        request = new HttpHead(url);
        break;
    case POST:
        HttpPost post = new HttpPost(url);
        post.setEntity(new ByteArrayEntity(body));
        request = post;
        break;
    case PUT:
        HttpPut put = new HttpPut(url);
        put.setEntity(new ByteArrayEntity(body));
        request = put;
        break;
    case PATCH:
        HttpPatch patch = new HttpPatch(url);
        patch.setEntity(new ByteArrayEntity(body));
        request = patch;
        break;
    default:
        throw new RuntimeException("Method not supported");
    }

    addHeaders(request);

    return request;
}

From source file:org.commonjava.maven.galley.transport.htcli.internal.HttpPublish.java

@Override
public HttpPublish call() {
    //            logger.info( "Trying: {}", url );
    final HttpPut put = new HttpPut(url);
    put.setEntity(new InputStreamEntity(stream, length, ContentType.create(contentType)));

    request = put;/*w  ww. ja  v a 2  s .  c  o  m*/

    try {
        success = executeHttp();
    } catch (final TransferException e) {
        this.error = e;
    } finally {
        cleanup();
    }

    return this;
}

From source file:org.talend.dataprep.api.service.command.preparation.PreparationCopyStepsFrom.java

private HttpRequestBase onExecute(final String to, final String from) {
    try {/*ww  w  . j  a  v a2s  . co m*/
        URIBuilder builder = new URIBuilder(preparationServiceUrl + "/preparations/" + to + "/steps/copy");
        builder.addParameter("from", from);
        return new HttpPut(builder.build());
    } catch (URISyntaxException e) {
        throw new TDPException(UNEXPECTED_EXCEPTION, e);
    }
}

From source file:com.sepgil.ral.CreateNodeTask.java

@Override
public HttpRequestBase getHttpRequest(String url) {
    HttpPut put = new HttpPut(url);

    try {//  w ww.j  a va 2s . c  om
        StringEntity enity = new StringEntity(mNode.getJSON());
        put.setEntity(enity);
    } catch (JSONException e) {
        mListener.onError(ErrorState.ERROR_PARSE);
    } catch (UnsupportedEncodingException e) {
        mListener.onError(ErrorState.ERROR_PARSE);
    }
    return put;
}

From source file:org.fcrepo.integration.generator.AbstractResourceIT.java

protected static HttpPut putDSMethod(final String pid, final String ds) {
    return new HttpPut(serverAddress + pid + "/" + ds + "?mixin=" + FedoraJcrTypes.FEDORA_DATASTREAM);
}

From source file:functionaltests.RestSchedulerTest.java

@Test
public void testStartScheduler() throws Exception {
    Scheduler scheduler = getScheduler();
    scheduler.stop();//  w  w  w.  j  a  v  a2  s .c o  m
    String resourceUrl = getResourceUrl("start");
    HttpPut httpPut = new HttpPut(resourceUrl);
    setSessionHeader(httpPut);
    HttpResponse response = executeUriRequest(httpPut);
    assertHttpStatusOK(response);
    assertTrue(Boolean.valueOf(getContent(response)));
    assertTrue(SchedulerStatus.STARTED.equals(scheduler.getStatus()));
}

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

/**
 * @param urlPrefix URL prefix/*w w  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;
}