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:org.flowable.rest.service.api.runtime.ProcessInstanceVariableResourceTest.java

/**
 * Test updating a single process variable using a binary stream. PUT runtime/process-instances/{processInstanceId}/variables/{variableName}
 *//* w  w w  .  j  av a2  s  . com*/
@Deployment(resources = {
        "org/flowable/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" })
public void testUpdateBinaryProcessVariable() throws Exception {

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess",
            Collections.singletonMap("overlappingVariable", (Object) "processValue"));
    runtimeService.setVariable(processInstance.getId(), "binaryVariable", "Initial binary value".getBytes());

    InputStream binaryContent = new ByteArrayInputStream("This is binary content".getBytes());

    // Add name and type
    Map<String, String> additionalFields = new HashMap<String, String>();
    additionalFields.put("name", "binaryVariable");
    additionalFields.put("type", "binary");

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "binaryVariable"));
    httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("value", "application/octet-stream", binaryContent,
            additionalFields));
    CloseableHttpResponse response = executeBinaryRequest(httpPut, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("binaryVariable", responseNode.get("name").asText());
    assertTrue(responseNode.get("value").isNull());
    assertEquals("binary", responseNode.get("type").asText());
    assertNotNull(responseNode.get("valueUrl").isNull());
    assertTrue(responseNode.get("valueUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_INSTANCE_VARIABLE_DATA, processInstance.getId(), "binaryVariable")));

    // Check actual value of variable in engine
    Object variableValue = runtimeService.getVariableLocal(processInstance.getId(), "binaryVariable");
    assertNotNull(variableValue);
    assertTrue(variableValue instanceof byte[]);
    assertEquals("This is binary content", new String((byte[]) variableValue));
}

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

/**
 * Poll the source configuration for new versions
 * @param properties Runtime properties to pass to the source configuration
 * @throws IOException// www .  j  a v a 2 s .  c om
 * @throws JSONException
 */
public void importComponentVersions(String componentName, Map<String, String> properties)
        throws IOException, JSONException {
    JSONObject jsonToSend = new JSONObject();

    jsonToSend.put("component", componentName);

    JSONObject propertiesObject = new JSONObject();
    if (properties != null && !properties.isEmpty()) {
        for (Entry<String, String> ent : properties.entrySet()) {
            propertiesObject.put(ent.getKey(), ent.getValue());
        }
    }

    jsonToSend.put("properties", propertiesObject);
    String uri = url + "/cli/component/integrate";
    HttpPut method = new HttpPut(uri);
    method.setEntity(getStringEntity(jsonToSend));

    HttpResponse response = invokeMethod(method);
}

From source file:com.esri.geoportal.commons.gpt.client.Client.java

/**
 * Publishes a document.// w w  w.  j a v a 2s.com
 *
 * @param data data to publish
 * @param forceAdd <code>true</code> to force add.
 * @return response information
 * @throws IOException if reading response fails
 * @throws URISyntaxException if URL has invalid syntax
 */
public PublishResponse publish(PublishRequest data, boolean forceAdd) throws IOException, URISyntaxException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    String json = mapper.writeValueAsString(data);
    StringEntity entity = new StringEntity(json);

    List<String> ids = !forceAdd ? queryIds(data.src_uri_s) : Collections.emptyList();
    HttpRequestBase request;
    switch (ids.size()) {
    case 0: {
        HttpPut put = new HttpPut(url.toURI().resolve(REST_ITEM_URL));
        put.setConfig(DEFAULT_REQUEST_CONFIG);
        put.setEntity(entity);
        put.setHeader("Content-Type", "application/json");
        request = put;
    }
        break;
    case 1: {
        HttpPut put = new HttpPut(url.toURI().resolve(REST_ITEM_URL + "/" + ids.get(0)));
        put.setConfig(DEFAULT_REQUEST_CONFIG);
        put.setEntity(entity);
        put.setHeader("Content-Type", "application/json");
        request = put;
    }
        break;
    default:
        throw new IOException(String.format("Error updating item: %s", data.src_uri_s));
    }

    try (CloseableHttpResponse httpResponse = execute(request);
            InputStream contentStream = httpResponse.getEntity().getContent();) {
        if (httpResponse.getStatusLine().getStatusCode() >= 400) {
            throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(),
                    httpResponse.getStatusLine().getReasonPhrase());
        }
        String reasonMessage = httpResponse.getStatusLine().getReasonPhrase();
        String responseContent = IOUtils.toString(contentStream, "UTF-8");
        LOG.trace(String.format("RESPONSE: %s, %s", responseContent, reasonMessage));
        return mapper.readValue(responseContent, PublishResponse.class);
    }
}

From source file:ca.ualberta.app.ESmanager.AuthorMapManager.java

/**
 * Update an exist author//from  ww  w  . j av a2s  .c  om
 * 
 * @param author
 *            The author.
 */
public void updateAuthor(Author author) {
    HttpClient httpClient = new DefaultHttpClient();

    try {
        HttpPut updateRequest = new HttpPut(RESOURCE_URL + author.getUserId());

        StringEntity stringEntity = new StringEntity(gson.toJson(author));
        updateRequest.setEntity(stringEntity);
        updateRequest.setHeader("Accept", "application/json");
        HttpResponse response = httpClient.execute(updateRequest);
        String status = response.getStatusLine().toString();

        Log.i(TAG, status);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

/**
 * Test signalling a single execution, without signal name.
 */// w w w . ja v  a 2  s  .c o  m
@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-signal.bpmn20.xml" })
public void testSignalExecution() throws Exception {
    runtimeService.startProcessInstanceByKey("processOne");

    Execution signalExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
    assertNotNull(signalExecution);
    assertEquals("waitState", signalExecution.getActivityId());

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "signal");

    // Signalling one causes process to move on to second signal and
    // execution is not finished yet
    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, signalExecution.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertEquals("anotherWaitState", responseNode.get("activityId").textValue());
    assertEquals("anotherWaitState", runtimeService.createExecutionQuery().executionId(signalExecution.getId())
            .singleResult().getActivityId());

    // Signalling again causes process to end
    response = executeRequest(httpPut, HttpStatus.SC_NO_CONTENT);
    closeResponse(response);

    // Check if process is actually ended
    assertNull(runtimeService.createExecutionQuery().executionId(signalExecution.getId()).singleResult());
}

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

/**
 * Test signalling a single execution, without signal event and variables.
 *//*w  w w .  j ava 2s  .c o  m*/
@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-message-event.bpmn20.xml" })
public void testMessageEventExecution() throws Exception {
    Execution execution = runtimeService.startProcessInstanceByKey("processOne");
    assertNotNull(execution);

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "messageEventReceived");
    requestNode.put("messageName", "unexisting");
    Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
    assertNotNull(waitingExecution);

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, waitingExecution.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_INTERNAL_SERVER_ERROR);
    closeResponse(response);

    requestNode.put("messageName", "paymentMessage");

    // Sending signal event causes the execution to end (scope-execution for
    // the catching event)
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_OK);
    closeResponse(response);

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

From source file:org.dspace.identifier.ezid.EZIDRequest.java

/**
 * Create an identifier with a given name. The name is the end of the
 * request path. Note: to "reserve" a given identifier, include "_status =
 * reserved" in {@link metadata}./*www .  j  a v a  2s .  c o m*/
 *
 * @param metadata ANVL-encoded key/value pairs.
 * @return
 */
public EZIDResponse create(String name, Map<String, String> metadata)
        throws IOException, IdentifierException, URISyntaxException {
    // PUT path [+metadata]
    HttpPut request;
    URI uri = new URI(scheme, host, ID_PATH + authority + '/' + name, null);
    log.debug("EZID create {}", uri.toASCIIString());
    request = new HttpPut(uri);
    if (null != metadata) {
        try {
            request.setEntity(new StringEntity(formatMetadata(metadata), UTF_8));
        } catch (UnsupportedEncodingException ex) {
            /* SNH */ }
    }
    HttpResponse response = client.execute(request);
    return new EZIDResponse(response);
}

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

/**
 * Test signalling a single execution, without signal name.
 *//*  w ww  .j  a v a2 s  .  c o  m*/
@Deployment(resources = {
        "org/flowable/rest/service/api/runtime/ExecutionResourceTest.process-with-signal.bpmn20.xml" })
public void testSignalExecution() throws Exception {
    runtimeService.startProcessInstanceByKey("processOne");

    Execution signalExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
    assertNotNull(signalExecution);
    assertEquals("waitState", signalExecution.getActivityId());

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "signal");

    // Signalling one causes process to move on to second signal and
    // execution is not finished yet
    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, signalExecution.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertEquals("anotherWaitState", responseNode.get("activityId").textValue());
    assertEquals("anotherWaitState", runtimeService.createExecutionQuery().executionId(signalExecution.getId())
            .singleResult().getActivityId());

    // Signalling again causes process to end
    response = executeRequest(httpPut, HttpStatus.SC_NO_CONTENT);
    closeResponse(response);

    // Check if process is actually ended
    assertNull(runtimeService.createExecutionQuery().executionId(signalExecution.getId()).singleResult());
}

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

/**
 * Test signalling a single execution, without signal event and variables.
 *//*from w  ww. ja v a  2s  .co  m*/
@Deployment(resources = {
        "org/flowable/rest/service/api/runtime/ExecutionResourceTest.process-with-message-event.bpmn20.xml" })
public void testMessageEventExecution() throws Exception {
    Execution execution = runtimeService.startProcessInstanceByKey("processOne");
    assertNotNull(execution);

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "messageEventReceived");
    requestNode.put("messageName", "unexisting");
    Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
    assertNotNull(waitingExecution);

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, waitingExecution.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_INTERNAL_SERVER_ERROR);
    closeResponse(response);

    requestNode.put("messageName", "paymentMessage");

    // Sending signal event causes the execution to end (scope-execution for
    // the catching event)
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_OK);
    closeResponse(response);

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

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

/**
 * Test signalling a single execution, without signal name.
 *///from   ww  w. j av a 2  s .  c o m
@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" })
public void testSignalEventExecution() throws Exception {
    Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne");
    assertNotNull(signalExecution);

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

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

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, waitingExecution.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_INTERNAL_SERVER_ERROR);
    closeResponse(response);

    requestNode.put("signalName", "alert");

    // Sending signal event causes the execution to end (scope-execution for
    // the catching event)
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_OK);
    closeResponse(response);

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

}