List of usage examples for com.fasterxml.jackson.databind.node ArrayNode toString
public String toString()
From source file:org.wisdom.wamp.WampController.java
private void handleCallMessage(String id, Map.Entry<String, WampClient> entry, ArrayNode message) { if (entry == null) { LOGGER.error("Invalid CALL message, cannot identify the client {}", id); return;//from w ww. j ava 2 s . c o m } if (message.get(1) == null || message.get(1).asText() == null) { LOGGER.error("Invalid CALL message, callId not defined in the CALL message {}", message.toString()); sendOnWebSocket(new RPCError("0", new IllegalArgumentException("callId not defined in CALL message"), errorPrefix).toJson(json), entry.getValue()); return; } String callId = message.get(1).asText(); if (message.get(2) == null || message.get(2).asText() == null) { LOGGER.error("Invalid CALL message, procId not defined in the CALL message {}", message.toString()); sendOnWebSocket(new RPCError(callId, new IllegalArgumentException("procId not defined in CALL message"), errorPrefix).toJson(json), entry.getValue()); return; } String procId = message.get(2).asText(); List<JsonNode> args = new ArrayList<>(); for (int i = 3; i < message.size(); i++) { args.add(message.get(i)); } // Get full url from the potential compacted url (prefixed) String url = entry.getValue().getUri(procId); // Extract the service object identifier int index = url.indexOf("#"); if (index == -1) { LOGGER.error("Invalid CALL message, malformed procId in the CALL message {}", message.toString()); sendOnWebSocket( new RPCError(callId, new IllegalArgumentException("Malformed procId " + procId), errorPrefix) .toJson(json), entry.getValue()); return; } String regId = url.substring(0, index); String method = url.substring(index + 1); ExportedService service; synchronized (this) { service = registry.get(regId); } if (service == null) { LOGGER.error("Invalid CALL message, cannot find service {} from message {}", regId, message.toString()); sendOnWebSocket( new RPCError(callId, new IllegalArgumentException("Service object " + regId + " not found"), errorPrefix).toJson(json), entry.getValue()); return; } if (method.isEmpty()) { LOGGER.error("Invalid CALL message, broken method name in message {}", message.toString()); sendOnWebSocket(new RPCError(callId, new IllegalArgumentException("Malformed method name in " + procId), errorPrefix).toJson(json), entry.getValue()); return; } // invocation handleRPCInvocation(entry.getValue(), callId, service, method, args); }
From source file:org.activiti.rest.service.api.runtime.ProcessInstanceVariablesCollectionResourceTest.java
/** * Test creating a single process variable. POST runtime/process-instance/{processInstanceId}/variables */// ww w . ja va 2s. co m @Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" }) public void testCreateSingleProcessInstanceVariable() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); ArrayNode requestNode = objectMapper.createArrayNode(); ObjectNode variableNode = requestNode.addObject(); variableNode.put("name", "myVariable"); variableNode.put("value", "simple string value"); variableNode.put("type", "string"); // Create a new local variable HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()).get(0); closeResponse(response); assertNotNull(responseNode); assertEquals("myVariable", responseNode.get("name").asText()); assertEquals("simple string value", responseNode.get("value").asText()); assertEquals("local", responseNode.get("scope").asText()); assertEquals("string", responseNode.get("type").asText()); assertNull(responseNode.get("valueUrl")); assertTrue(runtimeService.hasVariableLocal(processInstance.getId(), "myVariable")); assertEquals("simple string value", runtimeService.getVariableLocal(processInstance.getId(), "myVariable")); }
From source file:org.flowable.rest.service.api.runtime.ProcessInstanceVariablesCollectionResourceTest.java
/** * Test creating a single process variable. POST runtime/process-instance/{processInstanceId}/variables *//*from w w w. j ava 2 s .c o m*/ @Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" }) public void testCreateSingleProcessInstanceVariable() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); ArrayNode requestNode = objectMapper.createArrayNode(); ObjectNode variableNode = requestNode.addObject(); variableNode.put("name", "myVariable"); variableNode.put("value", "simple string value"); variableNode.put("type", "string"); // Create a new local variable HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()).get(0); closeResponse(response); assertNotNull(responseNode); assertEquals("myVariable", responseNode.get("name").asText()); assertEquals("simple string value", responseNode.get("value").asText()); assertEquals("local", responseNode.get("scope").asText()); assertEquals("string", responseNode.get("type").asText()); assertNull(responseNode.get("valueUrl")); assertTrue(runtimeService.hasVariableLocal(processInstance.getId(), "myVariable")); assertEquals("simple string value", runtimeService.getVariableLocal(processInstance.getId(), "myVariable")); }
From source file:pl.edu.pwr.iiar.zak.thermalKit.deserializers.HeaterUnitDeserializerTest.java
@Test public void testDeserializeThermalInstances() throws Exception { Method method = HeaterUnitDeserializer.class.getDeclaredMethod("deserializeThermalInstances", ArrayNode.class); method.setAccessible(true);//from w ww . java 2 s .c o m JsonNodeFactory factory = JsonNodeFactory.instance; ArrayNode instanceArrayNode = new ArrayNode(factory); ObjectNode instanceNode = new ObjectNode(factory); instanceArrayNode.add(instanceNode); instanceNode.put("name", "upper"); instanceNode.put("primitiveType", "SLICEL"); ArrayNode attributeArrayNode = new ArrayNode(factory); instanceNode.put("attributes", attributeArrayNode); ObjectNode attributeNode = new ObjectNode(factory); attributeArrayNode.add(attributeNode); attributeNode.put("physicalName", "phyName1"); attributeNode.put("logicalName", "logName1"); attributeNode.put("value", "value1"); ArrayNode enablePinsNode = new ArrayNode(factory); instanceNode.put("enablePins", enablePinsNode); ObjectNode enablePinNode = new ObjectNode(factory); enablePinsNode.add(enablePinNode); enablePinNode.put("isOutputPin", false); enablePinNode.put("name", "D3"); System.out.print(instanceArrayNode.toString()); ArrayList<ThermalInstance> heaterInstances = (ArrayList<ThermalInstance>) method .invoke(new HeaterUnitDeserializer(), instanceArrayNode); ThermalInstance heaterInstance = heaterInstances.get(0); Assert.assertEquals(heaterInstance.getName(), "upper"); Assert.assertEquals(heaterInstance.getType().toString(), "SLICEL"); }
From source file:org.activiti.rest.service.api.runtime.TaskVariablesCollectionResourceTest.java
/** * Test creating a single task variable, testing default types when omitted. POST runtime/tasks/{taskId}/variables *//*from w w w . j ava2 s. c o m*/ public void testCreateSingleTaskVariableDefaultTypes() throws Exception { try { Task task = taskService.newTask(); taskService.saveTask(task); // String type detection ArrayNode requestNode = objectMapper.createArrayNode(); ObjectNode varNode = requestNode.addObject(); varNode.put("name", "stringVar"); varNode.put("value", "String value"); varNode.put("scope", "local"); HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED)); assertEquals("String value", taskService.getVariable(task.getId(), "stringVar")); // Integer type detection varNode.put("name", "integerVar"); varNode.put("value", 123); varNode.put("scope", "local"); httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED)); assertEquals(123, taskService.getVariable(task.getId(), "integerVar")); // Double type detection varNode.put("name", "doubleVar"); varNode.put("value", 123.456); varNode.put("scope", "local"); httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED)); assertEquals(123.456, taskService.getVariable(task.getId(), "doubleVar")); // Boolean type detection varNode.put("name", "booleanVar"); varNode.put("value", Boolean.TRUE); varNode.put("scope", "local"); httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED)); assertEquals(Boolean.TRUE, taskService.getVariable(task.getId(), "booleanVar")); } finally { // Clean adhoc-tasks even if test fails List<Task> tasks = taskService.createTaskQuery().list(); for (Task task : tasks) { taskService.deleteTask(task.getId(), true); } } }
From source file:org.activiti.rest.service.api.runtime.TaskVariablesCollectionResourceTest.java
/** * Test creating a single task variable, testing edge case exceptions. POST runtime/tasks/{taskId}/variables *//*ww w . j a v a 2 s . co m*/ public void testCreateSingleTaskVariableEdgeCases() throws Exception { try { // Test adding variable to unexisting task ArrayNode requestNode = objectMapper.createArrayNode(); ObjectNode variableNode = requestNode.addObject(); variableNode.put("name", "existingVariable"); variableNode.put("value", "simple string value"); variableNode.put("scope", "local"); variableNode.put("type", "string"); HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, "unexisting")); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_NOT_FOUND)); // Test trying to create already existing variable Task task = taskService.newTask(); taskService.saveTask(task); taskService.setVariable(task.getId(), "existingVariable", "Value 1"); httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CONFLICT)); // Test setting global variable on standalone task variableNode.put("name", "myVariable"); variableNode.put("value", "simple string value"); variableNode.put("scope", "global"); variableNode.put("type", "string"); httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_BAD_REQUEST)); // Test creating nameless variable variableNode.removeAll(); variableNode.put("value", "simple string value"); httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_BAD_REQUEST)); // Test passing in empty array requestNode.removeAll(); httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_BAD_REQUEST)); // Test passing in object instead of array httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId())); httpPost.setEntity(new StringEntity(objectMapper.createObjectNode().toString())); closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_BAD_REQUEST)); } finally { // Clean adhoc-tasks even if test fails List<Task> tasks = taskService.createTaskQuery().list(); for (Task task : tasks) { taskService.deleteTask(task.getId(), true); } } }
From source file:org.activiti.rest.service.api.runtime.TaskVariablesCollectionResourceTest.java
/** * Test creating a single task variable. POST runtime/tasks/{taskId}/variables *///w w w . ja v a 2 s . co m @Deployment public void testCreateSingleTaskVariable() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); ArrayNode requestNode = objectMapper.createArrayNode(); ObjectNode variableNode = requestNode.addObject(); variableNode.put("name", "myVariable"); variableNode.put("value", "simple string value"); variableNode.put("scope", "local"); variableNode.put("type", "string"); // Create a new local variable HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()).get(0); closeResponse(response); assertNotNull(responseNode); assertEquals("myVariable", responseNode.get("name").asText()); assertEquals("simple string value", responseNode.get("value").asText()); assertEquals("local", responseNode.get("scope").asText()); assertEquals("string", responseNode.get("type").asText()); assertNull(responseNode.get("valueUrl")); assertTrue(taskService.hasVariableLocal(task.getId(), "myVariable")); assertEquals("simple string value", taskService.getVariableLocal(task.getId(), "myVariable")); // Create a new global variable variableNode.put("name", "myVariable"); variableNode.put("value", "Another simple string value"); variableNode.put("scope", "global"); variableNode.put("type", "string"); httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); response = executeRequest(httpPost, HttpStatus.SC_CREATED); responseNode = objectMapper.readTree(response.getEntity().getContent()).get(0); closeResponse(response); assertNotNull(responseNode); assertEquals("myVariable", responseNode.get("name").asText()); assertEquals("Another simple string value", responseNode.get("value").asText()); assertEquals("global", responseNode.get("scope").asText()); assertEquals("string", responseNode.get("type").asText()); assertNull(responseNode.get("valueUrl")); assertTrue(runtimeService.hasVariable(task.getExecutionId(), "myVariable")); // Create a new scope-less variable, which defaults to local variables variableNode.removeAll(); variableNode.put("name", "scopelessVariable"); variableNode.put("value", "simple string value"); variableNode.put("type", "string"); httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId())); httpPost.setEntity(new StringEntity(requestNode.toString())); response = executeRequest(httpPost, HttpStatus.SC_CREATED); responseNode = objectMapper.readTree(response.getEntity().getContent()).get(0); closeResponse(response); assertNotNull(responseNode); assertEquals("scopelessVariable", responseNode.get("name").asText()); assertEquals("simple string value", responseNode.get("value").asText()); assertEquals("local", responseNode.get("scope").asText()); assertEquals("string", responseNode.get("type").asText()); assertNull(responseNode.get("valueUrl")); assertTrue(taskService.hasVariableLocal(task.getId(), "scopelessVariable")); assertEquals("simple string value", taskService.getVariableLocal(task.getId(), "scopelessVariable")); }
From source file:org.activiti.rest.service.api.runtime.ProcessInstanceVariablesCollectionResourceTest.java
/** * Test creating multiple process variables in a single call. POST runtime/process-instance/{processInstanceId}/variables?override=true *//*from ww w. j a v a 2 s . c o m*/ @Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" }) public void testCreateMultipleProcessVariablesWithOverride() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); runtimeService.setVariable(processInstance.getId(), "stringVariable", "initialValue"); ArrayNode requestNode = objectMapper.createArrayNode(); // String variable ObjectNode stringVarNode = requestNode.addObject(); stringVarNode.put("name", "stringVariable"); stringVarNode.put("value", "simple string value"); stringVarNode.put("type", "string"); ObjectNode anotherVariable = requestNode.addObject(); anotherVariable.put("name", "stringVariable2"); anotherVariable.put("value", "another string value"); anotherVariable.put("type", "string"); // Create local variables with a single request HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId())); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertTrue(responseNode.isArray()); assertEquals(2, responseNode.size()); // Check if engine has correct variables set Map<String, Object> variables = runtimeService.getVariablesLocal(processInstance.getId()); assertEquals(2, variables.size()); assertEquals("simple string value", variables.get("stringVariable")); assertEquals("another string value", variables.get("stringVariable2")); }
From source file:org.flowable.rest.service.api.runtime.ProcessInstanceVariablesCollectionResourceTest.java
/** * Test creating multiple process variables in a single call. POST runtime/process-instance/{processInstanceId}/variables?override=true *//*w ww .jav a 2 s. co m*/ @Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" }) public void testCreateMultipleProcessVariablesWithOverride() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); runtimeService.setVariable(processInstance.getId(), "stringVariable", "initialValue"); ArrayNode requestNode = objectMapper.createArrayNode(); // String variable ObjectNode stringVarNode = requestNode.addObject(); stringVarNode.put("name", "stringVariable"); stringVarNode.put("value", "simple string value"); stringVarNode.put("type", "string"); ObjectNode anotherVariable = requestNode.addObject(); anotherVariable.put("name", "stringVariable2"); anotherVariable.put("value", "another string value"); anotherVariable.put("type", "string"); // Create local variables with a single request HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId())); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertTrue(responseNode.isArray()); assertEquals(2, responseNode.size()); // Check if engine has correct variables set Map<String, Object> variables = runtimeService.getVariablesLocal(processInstance.getId()); assertEquals(2, variables.size()); assertEquals("simple string value", variables.get("stringVariable")); assertEquals("another string value", variables.get("stringVariable2")); }
From source file:org.talend.dataprep.api.service.command.transformation.SuggestLookupActions.java
/** * @param dataSetId the current dataset id. * @return the function that aggregates the SuggestColumnActions with the lookups. */// ww w . ja va2 s . c om private BiFunction<HttpRequestBase, HttpResponse, InputStream> process(String dataSetId) { return (request, response) -> { // read suggested actions from previous command ArrayNode suggestedActions; try { suggestedActions = (ArrayNode) objectMapper.readerFor(new TypeReference<Action>() { }).readTree(getInput()); // list datasets from this command's response List<DataSetMetadata> dataSets = objectMapper.readValue(response.getEntity().getContent(), new TypeReference<List<DataSetMetadata>>() { }); // create and add all the possible lookup to the suggested actions for (DataSetMetadata dataset : dataSets) { // exclude current dataset from possible lookup sources if (StringUtils.equals(dataSetId, dataset.getId())) { continue; } final Lookup lookup = new Lookup(); lookup.adapt(dataset); final JsonNode jsonNode = objectMapper.valueToTree(lookup); suggestedActions.add(jsonNode); } // write the merged actions to the output streams return new ReleasableInputStream( // IOUtils.toInputStream(suggestedActions.toString(), "UTF-8"), // request::releaseConnection); } catch (IOException e) { throw new TDPException(APIErrorCodes.UNABLE_TO_RETRIEVE_SUGGESTED_ACTIONS, e); } }; }