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:co.cask.cdap.client.rest.RestStreamClient.java

@Override
public void create(String stream) throws IOException {
    HttpPut putRequest = new HttpPut(
            restClient.getBaseURL().resolve(String.format("/%s/streams/%s", restClient.getVersion(), stream)));
    CloseableHttpResponse httpResponse = restClient.execute(putRequest);
    try {/*w w  w .jav a  2s.c  om*/
        LOG.debug("Create Stream Response Code : {}", httpResponse.getStatusLine().getStatusCode());
        RestClient.responseCodeAnalysis(httpResponse);
    } finally {
        httpResponse.close();
    }
}

From source file:jp.co.gui.aruga.watch.ClockHttpRequest.java

public boolean update(Todo todo) throws IOException {
    if (todo.getId() == null)
        throw new UnsupportedOperationException();

    HttpPut request = new HttpPut(url + "/json/" + todo.getId());

    String json = om.writeValueAsString(todo);
    StringEntity se = new StringEntity(json, encode);
    request.addHeader("Content-type", "application/json");
    request.setEntity(se);//from w  ww.j a  v  a  2s  . co m
    HttpResponse hr = httpClient.execute(request);
    String a = EntityUtils.toString(hr.getEntity());
    if (a != null && hr.getStatusLine().getStatusCode() < 400) {
        return true;
    } else {
        return false;
    }
}

From source file:com.urbancode.ud.client.ApplicationClient.java

public String addComponentToApplication(String appName, String compName) throws IOException {
    String result = null;/*from   www . j  a  v a  2s . c  o  m*/

    String uri = url + "/cli/application/addComponentToApp?application=" + encodePath(appName) + "&component="
            + encodePath(compName);

    HttpPut method = new HttpPut(uri);
    HttpResponse response = invokeMethod(method);
    result = getBody(response);
    return result;
}

From source file:org.stem.api.ClusterManagerClient.java

public StemResponse initCluster(String clusterName, int vBuckets, int rf, String partitioner) {
    URI uri = getURI(RESTConstants.Api.Cluster.Init.URI);
    HttpPut request = new HttpPut(uri);

    // Initialize with local Cassandra cluster, RF = 1
    CreateClusterRequest initRequest = new CreateClusterRequest(clusterName, vBuckets, rf, partitioner,
            new MetaStoreConfiguration());

    return send(request, initRequest, StemResponse.class);
}

From source file:org.sharetask.controller.WorkspaceControllerIT.java

@Test
public void testUpdateWorkspace() throws IOException {
    //given/*w  w  w.ja  v  a  2  s. com*/
    final HttpPut httpPut = new HttpPut(URL_WORKSPACE);
    httpPut.addHeader(new BasicHeader("Content-Type", "application/json"));
    final StringEntity httpEntity = new StringEntity(
            "{\"id\":7," + "\"title\":\"Test Title\"," + "\"owner\":{\"username\":\"dev1@shareta.sk\"}" + "}");
    httpPut.setEntity(httpEntity);

    //when
    final HttpResponse response = getClient().execute(httpPut);

    //then
    Assert.assertEquals(HttpStatus.OK.value(), response.getStatusLine().getStatusCode());
    final String responseData = EntityUtils.toString(response.getEntity());
    Assert.assertTrue(responseData.contains("\"title\":\"Test Title\""));
}

From source file:org.elasticsearch.shell.command.HttpPutCommand.java

@SuppressWarnings("unused")
public HttpCommandResponse execute(String url, HttpParameters parameters) throws IOException {
    HttpPut httpPut = new HttpPut(url);
    httpPut.setEntity(new UrlEncodedFormEntity(parameters));
    return new HttpCommandResponse(shellHttpClient.getHttpClient().execute(httpPut));
}

From source file:org.gradle.cache.tasks.http.HttpTaskOutputCache.java

@Override
public void store(TaskCacheKey key, final TaskOutputWriter output) throws IOException {
    CloseableHttpClient httpClient = HttpClients.createDefault();
    try {//from  www . j  a v a2  s. c o m
        final URI uri = root.resolve(key.getHashCode());
        HttpPut httpPut = new HttpPut(uri);
        httpPut.setEntity(new AbstractHttpEntity() {
            @Override
            public boolean isRepeatable() {
                return true;
            }

            @Override
            public long getContentLength() {
                return -1;
            }

            @Override
            public InputStream getContent() throws IOException, UnsupportedOperationException {
                throw new UnsupportedOperationException();
            }

            @Override
            public void writeTo(OutputStream outstream) throws IOException {
                output.writeTo(outstream);
            }

            @Override
            public boolean isStreaming() {
                return false;
            }
        });
        CloseableHttpResponse response = httpClient.execute(httpPut);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Response for PUT {}: {}", uri, response.getStatusLine());
        }
    } finally {
        httpClient.close();
    }
}

From source file:org.sonatype.spice.zapper.client.hc4.Hc4Client.java

@Override
public State upload(final Payload payload, final Hc4Track track) throws IOException {
    final String url = getRemoteUrl() + payload.getPath().stringValue();
    final HttpPut put = new HttpPut(url);
    if (payload instanceof SegmentPayload) {
        put.setEntity(new ZapperEntity(payload, getParameters().getCodecSelector()
                .selectCodecs(SegmentPayload.class.cast(payload).getSegment().getZFile())));
    } else {/*from  ww w .j av a  2  s  .c  om*/
        put.setEntity(new ZapperEntity(payload));
    }
    put.addHeader("X-Zapper-Transfer-ID", payload.getTransferIdentifier().stringValue());
    if (track != null) {
        put.addHeader("X-Zapper-Track-ID", track.getIdentifier().stringValue());
    }
    final HttpClientContext context = new HttpClientContext();
    if (preemptiveCredentialsProvider != null) {
        context.setCredentialsProvider(preemptiveCredentialsProvider);
        context.setAuthCache(new BasicAuthCache());
        context.getAuthCache().put(
                new HttpHost(put.getURI().getHost(), put.getURI().getPort(), put.getURI().getScheme()),
                new BasicScheme());
    }
    final HttpResponse response = httpClient.execute(put, context);
    final StatusLine statusLine = response.getStatusLine();
    EntityUtils.consume(response.getEntity());
    if (!(statusLine.getStatusCode() > 199 && statusLine.getStatusCode() < 299)) {
        throw new IOException(String.format("Unexpected server response: %s %s", statusLine.getStatusCode(),
                statusLine.getReasonPhrase()));
    }
    return State.SUCCESS;
}

From source file:com.urbancode.ud.client.EnvironmentClient.java

public void addEnvironmentBaseResource(String application, String environment, String resource)
        throws IOException {
    String uri = url + "/cli/environment/addBaseResource?environment=" + encodePath(environment) + "&resource="
            + encodePath(resource);/*from  w  w w . j a v a2 s.  c  o m*/
    if (!StringUtils.isEmpty(application)) {
        uri = uri + "&application=" + encodePath(application);
    }
    HttpPut method = new HttpPut(uri);
    invokeMethod(method);
}