List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString
public String toString()
From source file:org.activiti.rest.service.api.runtime.ExecutionResourceTest.java
/** * Test messaging a single execution with variables. */// w w w. ja v a 2 s .c om @Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-message-event.bpmn20.xml" }) public void testMessageEventExecutionWithvariables() throws Exception { Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne"); assertNotNull(signalExecution); ArrayNode variables = objectMapper.createArrayNode(); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("action", "messageEventReceived"); requestNode.put("messageName", "paymentMessage"); requestNode.put("variables", variables); ObjectNode varNode = objectMapper.createObjectNode(); variables.add(varNode); varNode.put("name", "myVar"); varNode.put("value", "Variable set when signal event is receieved"); 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, waitingExecution.getId())); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse 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); Map<String, Object> vars = runtimeService.getVariables(waitingExecution.getId()); assertEquals(1, vars.size()); assertEquals("Variable set when signal event is receieved", vars.get("myVar")); }
From source file:io.gs2.inbox.Gs2InboxClient.java
/** * ????<br>//from w w w . j a va2 s .c om * <br> * - : 10<br> * <br> * * @param request * @return ? */ public SendMessageResult sendMessage(SendMessageRequest request) { ObjectNode body = JsonNodeFactory.instance.objectNode().put("userId", request.getUserId()).put("message", request.getMessage()); if (request.getCooperation() != null) body.put("cooperation", request.getCooperation()); HttpPost post = createHttpPost( Gs2Constant.ENDPOINT_HOST + "/inbox/" + (request.getInboxName() == null || request.getInboxName().equals("") ? "null" : request.getInboxName()) + "/message", credential, ENDPOINT, SendMessageRequest.Constant.MODULE, SendMessageRequest.Constant.FUNCTION, body.toString()); if (request.getRequestId() != null) { post.setHeader("X-GS2-REQUEST-ID", request.getRequestId()); } return doRequest(post, SendMessageResult.class); }
From source file:org.activiti.app.rest.editor.ModelsResource.java
@RequestMapping(value = "/rest/models/{modelId}/clone", method = RequestMethod.POST, produces = "application/json") public ModelRepresentation duplicateModel(@PathVariable String modelId, @RequestBody ModelRepresentation modelRepresentation) { String json = null;//from w w w . j a v a 2s. co m Model model = null; if (modelId != null) { model = modelService.getModel(modelId); json = model.getModelEditorJson(); } if (model == null) { throw new InternalServerErrorException("Error duplicating model : Unknown original model"); } if (modelRepresentation.getModelType() != null && modelRepresentation.getModelType().equals(AbstractModel.MODEL_TYPE_FORM)) { // noting to do special for forms (just clone the json) } else if (modelRepresentation.getModelType() != null && modelRepresentation.getModelType().equals(AbstractModel.MODEL_TYPE_APP)) { // noting to do special for applications (just clone the json) } else { // BPMN model ObjectNode editorNode = null; try { ObjectNode editorJsonNode = (ObjectNode) objectMapper.readTree(json); editorNode = deleteEmbededReferencesFromBPMNModel(editorJsonNode); ObjectNode propertiesNode = (ObjectNode) editorNode.get("properties"); String processId = model.getName().replaceAll(" ", ""); propertiesNode.put("process_id", processId); propertiesNode.put("name", model.getName()); if (StringUtils.isNotEmpty(model.getDescription())) { propertiesNode.put("documentation", model.getDescription()); } editorNode.put("properties", propertiesNode); } catch (IOException e) { e.printStackTrace(); } if (editorNode != null) { json = editorNode.toString(); } } // create the new model Model newModel = modelService.createModel(modelRepresentation, json, SecurityUtils.getCurrentUserObject()); // copy also the thumbnail byte[] imageBytes = model.getThumbnail(); newModel = modelService.saveModel(newModel, newModel.getModelEditorJson(), imageBytes, false, newModel.getComment(), SecurityUtils.getCurrentUserObject()); return new ModelRepresentation(newModel); }
From source file:org.flowable.app.rest.editor.ModelsResource.java
@RequestMapping(value = "/rest/models/{modelId}/clone", method = RequestMethod.POST, produces = "application/json") public ModelRepresentation duplicateModel(@PathVariable String modelId, @RequestBody ModelRepresentation modelRepresentation) { String json = null;/* w w w. j a v a2s . c om*/ Model model = null; if (modelId != null) { model = modelService.getModel(modelId); json = model.getModelEditorJson(); } if (model == null) { throw new InternalServerErrorException("Error duplicating model : Unknown original model"); } if (modelRepresentation.getModelType() != null && modelRepresentation.getModelType().equals(AbstractModel.MODEL_TYPE_FORM)) { // noting to do special for forms (just clone the json) } else if (modelRepresentation.getModelType() != null && modelRepresentation.getModelType().equals(AbstractModel.MODEL_TYPE_APP)) { // noting to do special for applications (just clone the json) } else { // BPMN model ObjectNode editorNode = null; try { ObjectNode editorJsonNode = (ObjectNode) objectMapper.readTree(json); editorNode = deleteEmbededReferencesFromBPMNModel(editorJsonNode); ObjectNode propertiesNode = (ObjectNode) editorNode.get("properties"); String processId = model.getName().replaceAll(" ", ""); propertiesNode.put("process_id", processId); propertiesNode.put("name", model.getName()); if (StringUtils.isNotEmpty(model.getDescription())) { propertiesNode.put("documentation", model.getDescription()); } editorNode.set("properties", propertiesNode); } catch (IOException e) { e.printStackTrace(); } if (editorNode != null) { json = editorNode.toString(); } } // create the new model Model newModel = modelService.createModel(modelRepresentation, json, SecurityUtils.getCurrentUserObject()); // copy also the thumbnail byte[] imageBytes = model.getThumbnail(); newModel = modelService.saveModel(newModel, newModel.getModelEditorJson(), imageBytes, false, newModel.getComment(), SecurityUtils.getCurrentUserObject()); return new ModelRepresentation(newModel); }
From source file:io.gs2.ranking.Gs2RankingClient.java
/** * ???<br>/*from w ww. ja v a 2 s .co m*/ * <br> * * @param request * @return ? */ public PutScoreResult putScore(PutScoreRequest request) { ObjectNode body = JsonNodeFactory.instance.objectNode().put("score", request.getScore()); if (request.getMeta() != null) body.put("meta", request.getMeta()); HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/ranking/" + (request.getRankingTableName() == null || request.getRankingTableName().equals("") ? "null" : request.getRankingTableName()) + "/mode/" + (request.getGameMode() == null || request.getGameMode().equals("") ? "null" : request.getGameMode()) + "/ranking", credential, ENDPOINT, PutScoreRequest.Constant.MODULE, PutScoreRequest.Constant.FUNCTION, body.toString()); if (request.getRequestId() != null) { post.setHeader("X-GS2-REQUEST-ID", request.getRequestId()); } post.setHeader("X-GS2-ACCESS-TOKEN", request.getAccessToken()); return doRequest(post, PutScoreResult.class); }
From source file:com.googlecode.jsonrpc4j.JsonRpcServer.java
/** * Handles the given {@link ObjectNode} and writes the * responses to the given {@link OutputStream}. * * @param node the {@link JsonNode}/*from w w w . jav a 2s . com*/ * @param ops the {@link OutputStream} * @throws IOException on error */ public void handleObject(ObjectNode node, OutputStream ops) throws IOException { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Request: " + node.toString()); } // validate request if (!backwardsComaptible && !node.has("jsonrpc") || !node.has("method")) { writeAndFlushValue(ops, createErrorResponse("2.0", "null", -32600, "Invalid Request", null)); return; } // get nodes JsonNode jsonPrcNode = node.get("jsonrpc"); JsonNode methodNode = node.get("method"); JsonNode idNode = node.get("id"); JsonNode paramsNode = node.get("params"); // get node values String jsonRpc = (jsonPrcNode != null && !jsonPrcNode.isNull()) ? jsonPrcNode.asText() : "2.0"; String methodName = getMethodName(methodNode); String serviceName = getServiceName(methodNode); Object id = parseId(idNode); // find methods Set<Method> methods = new HashSet<Method>(); methods.addAll(findMethods(getHandlerInterfaces(serviceName), methodName)); if (methods.isEmpty()) { writeAndFlushValue(ops, createErrorResponse(jsonRpc, id, -32601, "Method not found", null)); return; } // choose a method MethodAndArgs methodArgs = findBestMethodByParamsNode(methods, paramsNode); if (methodArgs == null) { writeAndFlushValue(ops, createErrorResponse(jsonRpc, id, -32602, "Invalid method parameters", null)); return; } // invoke the method JsonNode result = null; Throwable thrown = null; long beforeMs = System.currentTimeMillis(); if (invocationListener != null) { invocationListener.willInvoke(methodArgs.method, methodArgs.arguments); } try { result = invoke(getHandler(serviceName), methodArgs.method, methodArgs.arguments); } catch (Throwable e) { thrown = e; } if (invocationListener != null) { invocationListener.didInvoke(methodArgs.method, methodArgs.arguments, result, thrown, System.currentTimeMillis() - beforeMs); } // respond if it's not a notification request if (id != null) { // attempt to resolve the error JsonError error = null; if (thrown != null) { // get cause of exception Throwable e = thrown; if (InvocationTargetException.class.isInstance(e)) { e = InvocationTargetException.class.cast(e).getTargetException(); } // resolve error if (errorResolver != null) { error = errorResolver.resolveError(e, methodArgs.method, methodArgs.arguments); } else { error = DEFAULT_ERRROR_RESOLVER.resolveError(e, methodArgs.method, methodArgs.arguments); } // make sure we have a JsonError if (error == null) { error = new JsonError(0, e.getMessage(), e.getClass().getName()); } } // the resoponse object ObjectNode response = null; // build error if (error != null) { response = createErrorResponse(jsonRpc, id, error.getCode(), error.getMessage(), error.getData()); // build success } else { response = createSuccessResponse(jsonRpc, id, result); } // write it writeAndFlushValue(ops, response); } // log and potentially re-throw errors if (thrown != null) { if (LOGGER.isLoggable(exceptionLogLevel)) { LOGGER.log(exceptionLogLevel, "Error in JSON-RPC Service", thrown); } if (rethrowExceptions) { throw new RuntimeException(thrown); } } }
From source file:com.redhat.lightblue.query.ArrayUpdateExpressionTest.java
/** * Test of fromJson method, of class ArrayUpdateExpression. *//* w w w . j av a2 s. c o m*/ @Test public void testFromJson() throws IOException { ObjectNode node = (ObjectNode) JsonUtils.json("{ \"$append\" : { \"path\" : \"rvalue_expression\" } } "); ArrayUpdateExpression expResult = ArrayAddExpression.fromJson(node); ArrayUpdateExpression result = ArrayUpdateExpression.fromJson(node); assertEquals(expResult, result); node = (ObjectNode) JsonUtils.json("{ \"$insert\" : { \"path\" : \"$all\"} } "); expResult = ArrayAddExpression.fromJson(node); result = ArrayUpdateExpression.fromJson(node); assertEquals(expResult, result); node = (ObjectNode) JsonUtils.json("{ \"$foreach\" : { \"path\" : \"$all\" ,\"$update\" : \"$remove\"} } "); expResult = ForEachExpression.fromJson(node); result = ArrayUpdateExpression.fromJson(node); assertEquals(expResult, result); boolean error = false; try { node = (ObjectNode) JsonUtils .json("{ \"$missing\" : { \"path\" : { \"path\" : \"rvalue_expression\" } }}"); result = ArrayUpdateExpression.fromJson(node); } catch (Error e) { error = true; assertEquals(Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString()).toString(), e.toString()); } assertTrue("It didn't thrown an expection as it was expected", error); }
From source file:edu.nwpu.gemfire.monitor.controllers.PulseController.java
@RequestMapping(value = "/dataBrowserRegions", method = RequestMethod.GET) public void dataBrowserRegions(HttpServletRequest request, HttpServletResponse response) throws IOException { // get cluster object Cluster cluster = Repository.get().getCluster(); // json object to be sent as response ObjectNode responseJSON = mapper.createObjectNode(); ArrayNode regionsData = mapper.createArrayNode(); try {//ww w . j ava 2 s . c o m // getting cluster's Regions responseJSON.put("clusterName", cluster.getServerName()); regionsData = getRegionsJson(cluster); responseJSON.put("clusterRegions", regionsData); responseJSON.put("connectedFlag", cluster.isConnectedFlag()); responseJSON.put("connectedErrorMsg", cluster.getConnectionErrorMsg()); } catch (Exception e) { if (LOGGER.fineEnabled()) { LOGGER.fine("Exception Occured : " + e.getMessage()); } } // Send json response response.getOutputStream().write(responseJSON.toString().getBytes()); }