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.devbliss.doctest.httpfactory.PutWithoutRedirectImpl.java

public HttpPut createPutRequest(URI uri, Object payload) throws IOException {
    HttpPut httpPut = new HttpPut(uri);
    HttpParams params = new BasicHttpParams();
    params.setParameter(HANDLE_REDIRECTS, false);
    httpPut.setParams(params);//from  w w  w  .  java  2  s .  c  o  m

    if (payload != null) {
        httpPut.setEntity(entityBuilder.buildEntity(payload));
    }

    return httpPut;
}

From source file:org.dasein.cloud.aws.storage.GlacierAction.java

public HttpRequestBase getMethod(String url) throws InternalException {

    switch (GlacierAction.this) {
    case DELETE_VAULT:
    case DELETE_ARCHIVE:
        return new HttpDelete(url);
    case LIST_VAULTS:
    case DESCRIBE_VAULT:
    case DESCRIBE_JOB:
    case LIST_JOBS:
    case GET_JOB_OUTPUT:
        return new HttpGet(url);
    case CREATE_VAULT:
        return new HttpPut(url);
    case CREATE_ARCHIVE:
    case CREATE_JOB:
        return new HttpPost(url);
    }/*from  w  ww  .j av  a  2s.  co  m*/
    throw new InternalException("failed to build method");
}

From source file:io.liveoak.container.ParamsServerTest.java

@Test
public void testServer() throws Exception {

    Header header = new BasicHeader("Accept", "application/json");

    HttpGet getRequest = null;/*www  .  j  a va  2s  .co m*/
    HttpPost postRequest = null;
    HttpPut putRequest = null;
    CloseableHttpResponse response = null;

    // create people collection with direct PUT
    System.err.println("CREATE /people collection");

    putRequest = new HttpPut("http://localhost:8080/testApp/memory/people");
    putRequest.setEntity(new StringEntity("{ \"type\": \"collection\" }"));
    putRequest.setHeader("Content-Type", "application/json");
    response = this.httpClient.execute(putRequest);
    System.err.println("response: " + response);
    assertThat(response).isNotNull();
    assertThat(response.getStatusLine().getStatusCode()).isEqualTo(201);

    response.close();

    System.err.println("PREPARE 2 people ...");
    // Post a person

    postRequest = new HttpPost("http://localhost:8080/testApp/memory/people");
    postRequest.setEntity(new StringEntity("{ \"name\": \"bob\" }"));
    postRequest.setHeader("Content-Type", "application/json");

    response = httpClient.execute(postRequest);
    assertThat(response).isNotNull();
    assertThat(response.getStatusLine().getStatusCode()).isEqualTo(201);

    ResourceState bobState = decode(response);
    assertThat(bobState).isNotNull();

    assertThat(bobState.id()).isNotNull();
    assertThat(bobState.getProperty("name")).isEqualTo("bob");

    response.close();

    postRequest = new HttpPost("http://localhost:8080/testApp/memory/people");
    postRequest.setEntity(new StringEntity("{ \"name\": \"krusty\" }"));
    postRequest.setHeader("Content-Type", "application/json");

    response = httpClient.execute(postRequest);
    assertThat(response).isNotNull();
    assertThat(response.getStatusLine().getStatusCode()).isEqualTo(201);

    ResourceState krustyState = (ResourceState) decode(response);
    assertThat(krustyState).isNotNull();

    //assertThat(krustyState.getProperty(LiveOak.ID)).isNotNull();
    assertThat(krustyState.id()).isNotNull();
    assertThat(krustyState.getProperty("name")).isEqualTo("krusty");

    response.close();

    System.err.println("TEST #1");
    // test pagination

    // now that we have two people we can do paging requests

    // Retrieve first people resource, ensuring only the first one is returned
    // Assumption: unsorted GET on collection returns items in the order they were added to collection
    getRequest = new HttpGet("http://localhost:8080/testApp/memory/people?limit=1");
    getRequest.addHeader(header);
    response = httpClient.execute(getRequest);

    assertThat(response).isNotNull();
    assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);

    ResourceState state = decode(response);
    assertThat(state).isNotNull();
    List<ResourceState> members = state.members();

    assertThat(members.size()).isEqualTo(1);

    ResourceState memberState = members.get(0);
    assertThat(memberState).isInstanceOf(ResourceState.class);

    ResourceState member = (ResourceState) memberState;
    assertThat(member.id()).isEqualTo(bobState.id());

    response.close();

    // Retrieve second people resource, ensuring only the second one is returned
    // Assumption: unsorted GET on collection returns items in the order they were added to collection
    getRequest = new HttpGet("http://localhost:8080/testApp/memory/people?offset=1&limit=1");
    getRequest.addHeader(header);
    response = httpClient.execute(getRequest);

    assertThat(response).isNotNull();
    assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);

    state = decode(response);
    assertThat(state).isNotNull();

    members = state.members();
    assertThat(members.size()).isEqualTo(1);

    memberState = members.get(0);
    assertThat(memberState).isInstanceOf(ResourceState.class);

    member = (ResourceState) memberState;
    assertThat(member.id()).isEqualTo(krustyState.id());

    response.close();

    // Retrieve the people resource with a limit of 0 (eg do not return any members)
    getRequest = new HttpGet("http://localhost:8080/testApp/memory/people?limit=0");
    getRequest.addHeader(header);
    response = httpClient.execute(getRequest);

    assertThat(response).isNotNull();
    assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);

    state = decode(response);
    assertThat(state).isNotNull();

    members = state.members();
    assertThat(members.size()).isEqualTo(0);

    response.close();

    System.err.println("TEST #2");
    // test specifying fields to return

    getRequest = new HttpGet("http://localhost:8080/testApp/memory/people/" + krustyState.id() + "?fields=id");
    getRequest.addHeader(header);
    response = httpClient.execute(getRequest);

    assertThat(response).isNotNull();
    assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);

    state = decode(response);
    assertThat(state).isNotNull();
    assertThat(state).isInstanceOf(ResourceState.class);

    HashSet fields = new HashSet();
    /*
    ((CollectionResourceState) state).members().forEach((f) -> {
    fields.add(f.id());
    });
    */
    // TODO: uncomment when _self, and id encoding takes ReturnFields into account
    //assertThat(fields.size()).isEqualTo(1);
    //assertThat(fields.contains("id")).isTrue();
    //assertThat(fields.contains("name")).isFalse();
}

From source file:org.apache.vysper.xmpp.extension.xep0124.inttests.MethodsNotAllowedIntegrationTest.java

@Test
public void doNotAllowPut() throws Exception {
    HttpResponse response = httpclient.execute(new HttpPut(getServerUrl()));

    Assert.assertEquals(405, response.getStatusLine().getStatusCode());
}

From source file:com.arrow.acn.client.api.CoreEventApi.java

public StatusModel putFailed(String hid, String error) {
    String method = "putFailed";
    try {/*from  w  w  w.  j av a 2s. co m*/
        URI uri = buildUri(PUT_FAILED_URL.replace("{hid}", hid));
        StatusModel result = execute(new HttpPut(uri),
                JsonUtils.toJson(Collections.singletonMap("error", error)), StatusModel.class);
        log(method, result);
        return result;
    } catch (Throwable e) {
        logError(method, e);
        throw new AcnClientException(method, e);
    }
}

From source file:org.dasein.cloud.aws.platform.CloudFrontAction.java

public HttpRequestBase getMethod(String url) {
    switch (this) {
    case DELETE_DISTRIBUTION:
        return new HttpDelete(url);
    case LIST_DISTRIBUTIONS:
    case GET_DISTRIBUTION:
        return new HttpGet(url);
    case CREATE_DISTRIBUTION:
        return new HttpPost(url);
    case UPDATE_DISTRIBUTION:
        return new HttpPut(url);
    }//from  w  w  w  .jav  a2s .  c om
    return null;
}

From source file:com.woonoz.proxy.servlet.HttpPutRequestHandler.java

@Override
protected HttpEntityEnclosingRequestBase createHttpRequestBase(URI targetUri) {
    return new HttpPut(targetUri);
}

From source file:ca.uhn.fhir.rest.method.HttpPutClientInvocation.java

@Override
protected HttpRequestBase createRequest(StringBuilder theUrl, AbstractHttpEntity theEntity) {
    HttpPut retVal = new HttpPut(theUrl.toString());
    retVal.setEntity(theEntity);//from  www .  j a  v a 2 s . c o m
    return retVal;
}

From source file:org.osmsurround.ae.osmrequest.OsmUpdateRequest.java

@Override
protected HttpRequestBase createRequest(OsmBasicType amenity, int changesetId) throws Exception {
    ByteArrayOutputStream baos = marshallIntoBaos(amenity, changesetId);
    HttpEntityEnclosingRequestBase request = new HttpPut(
            osmApiBaseUrl + "/api/0.6/" + OsmBasicTypeMap.get(amenity.getClass()) + "/" + amenity.getId());
    request.setEntity(new ByteArrayEntity(baos.toByteArray()));
    return request;
}