use of org.apache.http.entity.StringEntity in project Activiti by Activiti.
the class ProcessDefinitionResourceTest method testActivateAlreadyActiveProcessDefinition.
/**
* Test activating already active process definition.
* POST repository/process-definitions/{processDefinitionId}
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testActivateAlreadyActiveProcessDefinition() throws Exception {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
assertFalse(processDefinition.isSuspended());
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "activate");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_CONFLICT);
closeResponse(response);
}
use of org.apache.http.entity.StringEntity in project Activiti by Activiti.
the class ProcessDefinitionResourceTest method testSuspendAlreadySuspendedProcessDefinition.
/**
* Test suspending already suspended process definition.
* POST repository/process-definitions/{processDefinitionId}
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testSuspendAlreadySuspendedProcessDefinition() throws Exception {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
repositoryService.suspendProcessDefinitionById(processDefinition.getId());
processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
assertTrue(processDefinition.isSuspended());
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "suspend");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_CONFLICT);
closeResponse(response);
}
use of org.apache.http.entity.StringEntity in project Activiti by Activiti.
the class ProcessInstanceCollectionResourceTest method testStartProcessWithVariables.
/**
* Test starting a process instance passing in variables to set.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testStartProcessWithVariables() throws Exception {
ArrayNode variablesNode = objectMapper.createArrayNode();
// String variable
ObjectNode stringVarNode = variablesNode.addObject();
stringVarNode.put("name", "stringVariable");
stringVarNode.put("value", "simple string value");
stringVarNode.put("type", "string");
ObjectNode integerVarNode = variablesNode.addObject();
integerVarNode.put("name", "integerVariable");
integerVarNode.put("value", 1234);
integerVarNode.put("type", "integer");
ObjectNode shortVarNode = variablesNode.addObject();
shortVarNode.put("name", "shortVariable");
shortVarNode.put("value", 123);
shortVarNode.put("type", "short");
ObjectNode longVarNode = variablesNode.addObject();
longVarNode.put("name", "longVariable");
longVarNode.put("value", 4567890L);
longVarNode.put("type", "long");
ObjectNode doubleVarNode = variablesNode.addObject();
doubleVarNode.put("name", "doubleVariable");
doubleVarNode.put("value", 123.456);
doubleVarNode.put("type", "double");
ObjectNode booleanVarNode = variablesNode.addObject();
booleanVarNode.put("name", "booleanVariable");
booleanVarNode.put("value", Boolean.TRUE);
booleanVarNode.put("type", "boolean");
// Date
Calendar varCal = Calendar.getInstance();
String isoString = getISODateString(varCal.getTime());
ObjectNode dateVarNode = variablesNode.addObject();
dateVarNode.put("name", "dateVariable");
dateVarNode.put("value", isoString);
dateVarNode.put("type", "date");
ObjectNode requestNode = objectMapper.createObjectNode();
// Start using process definition key, passing in variables
requestNode.put("processDefinitionKey", "processOne");
requestNode.put("variables", variablesNode);
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION));
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertEquals("processTask", responseNode.get("activityId").asText());
assertEquals(false, responseNode.get("ended").asBoolean());
JsonNode variablesArrayNode = responseNode.get("variables");
assertEquals(0, variablesArrayNode.size());
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
assertNotNull(processInstance);
// Check if engine has correct variables set
Map<String, Object> processVariables = runtimeService.getVariables(processInstance.getId());
assertEquals(7, processVariables.size());
assertEquals("simple string value", processVariables.get("stringVariable"));
assertEquals(1234, processVariables.get("integerVariable"));
assertEquals((short) 123, processVariables.get("shortVariable"));
assertEquals(4567890L, processVariables.get("longVariable"));
assertEquals(123.456, processVariables.get("doubleVariable"));
assertEquals(Boolean.TRUE, processVariables.get("booleanVariable"));
assertEquals(dateFormat.parse(isoString), processVariables.get("dateVariable"));
}
use of org.apache.http.entity.StringEntity in project Activiti by Activiti.
the class ModelResourceTest method testUpdateUnexistingModel.
public void testUpdateUnexistingModel() throws Exception {
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, "unexisting"));
httpPut.setEntity(new StringEntity(objectMapper.createObjectNode().toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND));
}
use of org.apache.http.entity.StringEntity in project SeaStar by 13120241790.
the class SyncHttpClient method postRestful.
/**
* 支持post提交Restful风格的json字符串
* post
* @param context
* @param url
* @param params
* @param jsonContent
* @return
* @throws HttpException
*/
public String postRestful(Context context, String url, RequestParams params, String jsonContent) throws HttpException {
StringEntity entity = null;
StringBuilder urlBilder = new StringBuilder(url);
try {
//拼装公共参数
if (params != null) {
String paramString = params.getParamString();
if (paramString != null && !"".equals(paramString)) {
urlBilder.append("?").append(paramString);
url = urlBilder.toString();
}
}
//post提交的Json内容
if (jsonContent != null && !"".equals(jsonContent)) {
NLog.e(tag, "jsonContent: " + jsonContent);
entity = new StringEntity(jsonContent, ENCODE_UTF8);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return post(context, url, entity, "application/json");
}
Aggregations