List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString
public String toString()
From source file:com.evrythng.java.wrapper.mapping.GeoJsonDeserializerImpl.java
@Override public GeoJson deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectCodec codec = jp.getCodec();//from ww w. ja v a2 s. co m ObjectMapper mapper = (ObjectMapper) codec; ObjectNode root = (ObjectNode) mapper.readTree(jp); JsonNode type = root.get(getTypeFieldName()); if (type == null) { throw new IllegalArgumentException(this.getValueClass().getSimpleName() + " type cannot be empty."); } String sType = type.textValue(); if (sType == null || sType.isEmpty()) { throw new IllegalArgumentException(this.getValueClass().getSimpleName() + " type cannot be empty."); } Class<GeoJson> clazz = (Class<GeoJson>) resolveClass(sType); GeoJson obj = codec.treeToValue(root, clazz); if (obj == null) { throw new IllegalArgumentException( this.getValueClass().getSimpleName() + " type deserialised as null: " + root.toString()); } return obj; }
From source file:io.gs2.identifier.Gs2IdentifierClient.java
/** * ?????<br>/*from w ww.j a v a 2s . co m*/ * <br> * * @param request * @return ? */ public CreateUserResult createUser(CreateUserRequest request) { ObjectNode body = JsonNodeFactory.instance.objectNode().put("name", request.getName()); HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/user", credential, ENDPOINT, CreateUserRequest.Constant.MODULE, CreateUserRequest.Constant.FUNCTION, body.toString()); if (request.getRequestId() != null) { post.setHeader("X-GS2-REQUEST-ID", request.getRequestId()); } return doRequest(post, CreateUserResult.class); }
From source file:com.baasbox.Global.java
@Override public F.Promise<SimpleResult> onError(RequestHeader request, Throwable throwable) { error("INTERNAL SERVER ERROR: " + request.method() + " " + request); ObjectNode result = prepareError(request, ExceptionUtils.getMessage(throwable)); result.put("http_code", 500); result.put("stacktrace", ExceptionUtils.getFullStackTrace(throwable)); error(ExceptionUtils.getFullStackTrace(throwable)); SimpleResult resultToReturn = internalServerError(result); try {//ww w . jav a 2 s . c o m if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("Global.onBadRequest:\n + result: \n" + result.toString() + "\n --> Body:\n" + new String(JavaResultExtractor.getBody(resultToReturn), "UTF-8")); } finally { return F.Promise.pure(resultToReturn); } }
From source file:cf.client.DefaultCloudController.java
@Override public UUID createServiceInstance(Token token, String name, UUID planGuid, UUID spaceGuid) { try {/*from w w w . j a v a 2s . co m*/ final ObjectNode json = mapper.createObjectNode(); json.put("name", name); json.put("service_plan_guid", planGuid.toString()); json.put("space_guid", spaceGuid.toString()); final HttpPost post = new HttpPost(target.resolve(V2_SERVICE_INSTANCES)); post.addHeader(token.toAuthorizationHeader()); post.setEntity(new StringEntity(json.toString(), ContentType.APPLICATION_JSON)); final HttpResponse response = httpClient.execute(post); try { validateResponse(response, 201); final JsonNode jsonResponse = mapper.readTree(response.getEntity().getContent()); return UUID.fromString(jsonResponse.get("metadata").get("guid").asText()); } finally { HttpClientUtils.closeQuietly(response); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.activiti.service.activiti.ProcessInstanceService.java
public JsonNode listProcesInstancesForProcessDefinition(ObjectNode bodyNode, ServerConfig serverConfig) { JsonNode resultNode = null;//w w w .j a v a 2 s .c o m try { URIBuilder builder = new URIBuilder("query/historic-process-instances"); builder.addParameter("size", DEFAULT_PROCESSINSTANCE_SIZE); builder.addParameter("sort", "startTime"); builder.addParameter("order", "desc"); String uri = clientUtil.getUriWithPagingAndOrderParameters(builder, bodyNode); HttpPost post = clientUtil.createPost(uri, serverConfig); post.setEntity(clientUtil.createStringEntity(bodyNode.toString())); resultNode = clientUtil.executeRequest(post, serverConfig); } catch (Exception e) { throw new ActivitiServiceException(e.getMessage(), e); } return resultNode; }
From source file:org.activiti.rest.service.api.runtime.ExecutionCollectionResourceTest.java
/** * Test signalling all executions//w w 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 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 va2s .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.flowable.rest.dmn.service.api.decision.DmnRuleServiceResourceTest.java
@DmnDeploymentAnnotation(resources = { "org/flowable/rest/dmn/service/api/decision/multi-hit.dmn" }) public void testExecutionDecision() throws Exception { // Add decision key ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("decisionKey", "decision1"); // add input variable ArrayNode variablesNode = objectMapper.createArrayNode(); ObjectNode variableNode = objectMapper.createObjectNode(); variableNode.put("name", "inputVariable1"); variableNode.put("type", "integer"); variableNode.put("value", 5); variablesNode.add(variableNode);//from www .j a v a2s. com requestNode.set("inputVariables", variablesNode); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_RULE_SERVICE_EXECUTE)); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); // Check response JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); ArrayNode resultVariables = (ArrayNode) responseNode.get("resultVariables"); assertEquals(3, resultVariables.size()); }
From source file:org.jetbrains.webdemo.sessions.MyHttpSession.java
private void sendAddProjectResult() { try {//from w ww .j av a2 s. com String content = request.getParameter("content"); if (content != null) { try { currentProject = objectMapper.readValue(content, Project.class); currentProject.name = request.getParameter("args"); //when user calls save as we must change project name ExamplesUtils.addHiddenFilesToProject(currentProject); String publicId = MySqlConnector.getInstance().addProject(sessionInfo.getUserInfo(), currentProject, "USER_PROJECT"); ObjectNode result = new ObjectNode(JsonNodeFactory.instance); result.put("publicId", publicId); Project project = MySqlConnector.getInstance().getProjectContent(publicId); result.put("content", objectMapper.writeValueAsString(project)); writeResponse(result.toString(), HttpServletResponse.SC_OK); } catch (IOException e) { writeResponse("Can't parse file", HttpServletResponse.SC_BAD_REQUEST); } } else { String name = request.getParameter("name"); String publicIds = MySqlConnector.getInstance().addProject(sessionInfo.getUserInfo(), name, "USER_PROJECT"); writeResponse(publicIds, HttpServletResponse.SC_OK); } } catch (NullPointerException e) { writeResponse("Can't get parameters", HttpServletResponse.SC_BAD_REQUEST); } catch (DatabaseOperationException e) { writeResponse(e.getMessage(), HttpServletResponse.SC_FORBIDDEN); } }
From source file:org.flowable.rest.dmn.service.api.decision.DmnRuleServiceResourceTest.java
@DmnDeploymentAnnotation(resources = { "org/flowable/rest/dmn/service/api/decision/multi-hit.dmn" }) public void testExecutionDecisionSingleResultViolated() throws Exception { // Add decision key ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("decisionKey", "decision1"); // add input variable ArrayNode variablesNode = objectMapper.createArrayNode(); ObjectNode variableNode = objectMapper.createObjectNode(); variableNode.put("name", "inputVariable1"); variableNode.put("type", "integer"); variableNode.put("value", 5); variablesNode.add(variableNode);// ww w . java 2s.c o m requestNode.set("inputVariables", variablesNode); HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_RULE_SERVICE_EXECUTE_SINGLE_RESULT)); httpPost.setEntity(new StringEntity(requestNode.toString())); executeRequest(httpPost, HttpStatus.SC_INTERNAL_SERVER_ERROR); }