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

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

Introduction

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

Prototype

public void setEntity(final HttpEntity entity) 

Source Link

Usage

From source file:com.teradata.tempto.internal.hadoop.hdfs.WebHDFSClient.java

private void saveFile(String path, String username, HttpEntity entity) {
    Pair<String, String> params = Pair.of("overwrite", "true");
    String writeRedirectUri = executeAndGetRedirectUri(new HttpPut(buildUri(path, username, "CREATE", params)));
    HttpPut writeRequest = new HttpPut(writeRedirectUri);
    writeRequest.setEntity(entity);

    try (CloseableHttpResponse response = httpClient.execute(writeRequest)) {
        if (response.getStatusLine().getStatusCode() != SC_CREATED) {
            throw invalidStatusException("CREATE", path, username, writeRequest, response);
        }/* www  .  ja va  2 s.  co  m*/
        long length = waitForFileSavedAndReturnLength(path, username);
        logger.debug("Saved file {} - username: {}, size: {}", path, username, byteCountToDisplaySize(length));
    } catch (IOException e) {
        throw new RuntimeException("Could not save file " + path + " in hdfs, user: " + username, e);
    }
}

From source file:org.activiti.rest.service.api.repository.ModelResourceSourceTest.java

public void testSetModelSourceExtraUnexistingModel() throws Exception {
    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE_EXTRA, "unexisting"));
    httpPut.setEntity(new StringEntity(""));
    closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NOT_FOUND));
}

From source file:xyz.cloudbans.client.DefaultClient.java

@Override
public Future<BanResponse> updateBan(BanRequest request) {
    HttpPut httpRequest = new HttpPut(buildSafe(createUri("/ban/" + request.getId())));
    initHeaders(httpRequest);/*from   w  w  w.  j a v  a2  s . c  om*/
    httpRequest.setEntity(createEntity(request));

    return client.execute(new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), BanResponse.class),
            DeafFutureCallback.<BanResponse>instance());
}

From source file:org.activiti.rest.service.api.runtime.ExecutionCollectionResourceTest.java

/**
 * Test signalling all executions//from   w  w w  .  j  av  a2  s.c  o  m
 */
@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" })
public void testSignalEventExecutions() throws Exception {
    Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne");
    assertNotNull(signalExecution);

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "signalEventReceived");
    requestNode.put("signalName", "alert");

    Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
    assertNotNull(waitingExecution);

    // Sending signal event causes the execution to end (scope-execution for
    // the catching event)
    HttpPut httpPut = new HttpPut(
            SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_NO_CONTENT));

    // Check if process is moved on to the other wait-state
    waitingExecution = runtimeService.createExecutionQuery().activityId("anotherWaitState").singleResult();
    assertNotNull(waitingExecution);
}

From source file:org.flowable.rest.service.api.runtime.ExecutionCollectionResourceTest.java

/**
 * Test signalling all executions//from w w  w .ja v  a  2  s .c  o  m
 */
@Deployment(resources = {
        "org/flowable/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" })
public void testSignalEventExecutions() throws Exception {
    Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne");
    assertNotNull(signalExecution);

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "signalEventReceived");
    requestNode.put("signalName", "alert");

    Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
    assertNotNull(waitingExecution);

    // Sending signal event causes the execution to end (scope-execution for
    // the catching event)
    HttpPut httpPut = new HttpPut(
            SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_NO_CONTENT));

    // Check if process is moved on to the other wait-state
    waitingExecution = runtimeService.createExecutionQuery().activityId("anotherWaitState").singleResult();
    assertNotNull(waitingExecution);
}

From source file:org.jboss.pull.player.LabelProcessor.java

private void setLabels(final String issueUrl, final Collection<String> labels) {
    // Build a list of the new labels
    final StringBuilder sb = new StringBuilder(32).append('[');
    final int size = labels.size();
    int counter = 0;
    for (String label : labels) {
        sb.append('"').append(label).append('"');
        if (++counter < size) {
            sb.append(',');
        }/*from w  w w. ja  v a2 s. co  m*/
    }
    sb.append(']');
    try {
        final HttpPut put = new HttpPut(issueUrl + "/labels");
        GitHubApi.addDefaultHeaders(put);
        put.setEntity(new StringEntity(sb.toString()));
        execute(put, HttpURLConnection.HTTP_OK);
    } catch (Exception e) {
        e.printStackTrace(err);
    }

}

From source file:org.apache.camel.component.cxf.jaxrs.CxfRsConvertBodyToTest.java

@Test
public void testPutConsumer() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);//from w  w w.  j a va  2  s .c  o m
    mock.message(0).body().isInstanceOf(Customer.class);

    HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/customers");
    StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
    entity.setContentType("text/xml; charset=ISO-8859-1");
    put.addHeader("test", "header1;header2");
    put.setEntity(entity);
    HttpClient httpclient = new DefaultHttpClient();

    try {
        HttpResponse response = httpclient.execute(put);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("", EntityUtils.toString(response.getEntity()));
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:xyz.cloudbans.client.DefaultClient.java

@Override
public Future<NoticeResponse> updateNotice(NoticeRequest request) {
    HttpPut httpRequest = new HttpPut(buildSafe(createUri("/notice/" + request.getId())));
    initHeaders(httpRequest);//from  www  . j a  v  a2 s .  c o m
    httpRequest.setEntity(createEntity(request));

    return client.execute(new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), NoticeResponse.class),
            DeafFutureCallback.<NoticeResponse>instance());
}

From source file:com.citruspay.mobile.payment.client.rest.RESTClient.java

public JSONObject put(URI path, Collection<Header> headers, JSONObject json)
        throws ProtocolException, RESTException {
    // create request + entity
    HttpPut put = new HttpPut(uri.resolve(path));
    put.addHeader("Content-Type", "application/json");
    try {/*from  w w  w.j  a v  a2  s  .c o  m*/
        put.setEntity(new StringEntity(json.toString()));
    } catch (UnsupportedEncodingException uex) {
        throw new RuntimeException(uex);
    }

    // execute request
    return execute(put, headers);
}

From source file:com.codota.uploader.Uploader.java

private void uploadFile(File file, String uploadUrl) throws IOException {
    HttpPut putRequest = new HttpPut(uploadUrl);
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    builder.addPart("code", new FileBody(file));
    final HttpEntity entity = builder.build();
    putRequest.setEntity(entity);

    putRequest.setHeader("enctype", "multipart/form-data");
    putRequest.setHeader("authorization", "bearer " + token);
    httpClient.execute(putRequest, new UploadResponseHandler());
}