List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString
public String toString()
From source file:org.flowable.content.rest.service.api.content.ContentItemResourceTest.java
public void testUpdateContentItem() throws Exception { String contentItemId = createContentItem("test.pdf", "application/pdf", null, "12345", null, null, "test", "test2"); ContentItem contentItem = contentService.createContentItemQuery().singleResult(); try {/*from w w w. j a v a 2 s .c o m*/ ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("name", "test2.txt"); requestNode.put("mimeType", "application/txt"); requestNode.put("createdBy", "testb"); requestNode.put("lastModifiedBy", "testc"); HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + ContentRestUrls.createRelativeResourceUrl(ContentRestUrls.URL_CONTENT_ITEM, contentItemId)); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertEquals(contentItem.getId(), responseNode.get("id").asText()); assertEquals("test2.txt", responseNode.get("name").asText()); assertEquals("application/txt", responseNode.get("mimeType").asText()); assertTrue(responseNode.get("taskId").isNull()); assertEquals(contentItem.getProcessInstanceId(), responseNode.get("processInstanceId").asText()); assertEquals("", responseNode.get("tenantId").asText()); assertEquals("testb", responseNode.get("createdBy").asText()); assertEquals("testc", responseNode.get("lastModifiedBy").asText()); assertEquals(contentItem.getCreated(), getDateFromISOString(responseNode.get("created").asText())); assertEquals(contentItem.getLastModified(), getDateFromISOString(responseNode.get("lastModified").asText())); } finally { contentService.deleteContentItem(contentItemId); } }
From source file:io.gs2.auth.Gs2AuthClient.java
/** * ??????<br>/*from w ww .ja v a2 s. co m*/ * <br> * * @param request * @return ? */ public CreateOnceOnetimeTokenResult createOnceOnetimeToken(CreateOnceOnetimeTokenRequest request) { ObjectNode body = JsonNodeFactory.instance.objectNode().put("scriptName", request.getScriptName()); if (request.getGrant() != null) body.put("grant", request.getGrant()); if (request.getArgs() != null) body.put("args", request.getArgs()); HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/onetime/once/token", credential, ENDPOINT, CreateOnceOnetimeTokenRequest.Constant.MODULE, CreateOnceOnetimeTokenRequest.Constant.FUNCTION, body.toString()); if (request.getRequestId() != null) { post.setHeader("X-GS2-REQUEST-ID", request.getRequestId()); } return doRequest(post, CreateOnceOnetimeTokenResult.class); }
From source file:org.flowable.rest.service.api.runtime.ProcessInstanceVariableResourceTest.java
/** * Test updating a single process variable, including "not found" check. * /*from ww w. j ava 2 s . c o m*/ * PUT runtime/process-instances/{processInstanceId}/variables/{variableName} */ @Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" }) public void testUpdateProcessVariable() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", Collections.singletonMap("overlappingVariable", (Object) "processValue")); runtimeService.setVariable(processInstance.getId(), "myVar", "value"); // Update variable ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("name", "myVar"); requestNode.put("value", "updatedValue"); requestNode.put("type", "string"); HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "myVar")); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertEquals("updatedValue", responseNode.get("value").asText()); // Try updating with mismatch between URL and body variableName requestNode.put("name", "unexistingVariable"); httpPut.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST)); // Try updating unexisting property requestNode.put("name", "unexistingVariable"); httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "unexistingVariable")); httpPut.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND)); }
From source file:easyrpc.server.serialization.jsonrpc.JSONCallee.java
@Override public byte[] matchMethod(Object object, byte[] callInfo) { try {//w w w.jav a2 s . c o m Object returnedObject = null; ObjectNode call = (ObjectNode) MAPPER.readTree(callInfo); String jsonrpc = call.get("jsonrpc").textValue(); if (jsonrpc == null || !"2.0".equals(jsonrpc)) { throw new SerializationException( "'jsonrpc' value must be '2.0' and actually is: '" + jsonrpc + "'"); } String methodName = call.get("method").textValue(); if (methodName == null) throw new SerializationException("The 'method' field must not be null: " + call.toString()); Class iface = object.getClass(); for (Method m : iface.getMethods()) { if (methodName.equals(m.getName())) { ArrayNode jsParams = (ArrayNode) call.get("params"); if (jsParams == null || jsParams.size() == 0) { try { returnedObject = m.invoke(object); // System.out.println("returnedObject = " + returnedObject); } catch (Exception e) { e.printStackTrace(); return returnJsonRpcError(call.get("id"), e); } } else { // System.out.println("methodName = " + methodName); Object[] params = new Object[jsParams.size()]; for (int i = 0; i < params.length; i++) { params[i] = MAPPER.convertValue(jsParams.get(i), m.getParameters()[i].getType()); // System.out.println("params[i] = " + params[i] + "("+ params[i].getClass().getName() +")"); } try { returnedObject = m.invoke(object, params); // System.out.println("returnedObject = " + returnedObject); } catch (Exception e) { e.printStackTrace(); return returnJsonRpcError(call.get("id"), e); } } break; } } ObjectNode jsret = JsonNodeFactory.instance.objectNode(); jsret.put("jsonrpc", "2.0"); jsret.put("id", call.get("id").toString()); if (returnedObject != null) { addResult(jsret, returnedObject); } // System.out.println("jsret.toString() = " + jsret.toString()); return jsret.toString().getBytes(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.bimserver.servlets.UploadServlet.java
private void sendException(HttpServletResponse response, Exception exception) { try {/*from w w w.ja v a 2 s. com*/ ObjectNode responseObject = OBJECT_MAPPER.createObjectNode(); ObjectNode exceptionJson = OBJECT_MAPPER.createObjectNode(); exceptionJson.put("__type", exception.getClass().getSimpleName()); if (exception.getMessage() == null) { exceptionJson.put("message", "Unknown exception"); } else { exceptionJson.put("message", exception.getMessage()); } responseObject.set("exception", exceptionJson); response.getWriter().write(responseObject.toString()); } catch (IOException e) { } }
From source file:org.onosproject.sse.SseTopologyResource.java
@Path("/geoloc") @GET//from w ww . j a v a2s. c o m @Produces("application/json") public Response getGeoLocations() { ObjectNode rootNode = mapper.createObjectNode(); ArrayNode devices = mapper.createArrayNode(); ArrayNode hosts = mapper.createArrayNode(); Map<String, ObjectNode> metaUi = SseTopologyViewMessages.getMetaUi(); for (String id : metaUi.keySet()) { ObjectNode memento = metaUi.get(id); if (id.charAt(17) == '/') { addGeoData(hosts, "id", id, memento); } else { addGeoData(devices, "uri", id, memento); } } rootNode.set("devices", devices); rootNode.set("hosts", hosts); return Response.ok(rootNode.toString()).build(); }
From source file:org.activiti.rest.service.api.runtime.ProcessInstanceVariableResourceTest.java
/** * Test updating a single process variable, including "not found" check. * /*from w ww. ja v a 2 s . c o m*/ * PUT runtime/process-instances/{processInstanceId}/variables/{variableName} */ @Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" }) public void testUpdateProcessVariable() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", Collections.singletonMap("overlappingVariable", (Object) "processValue")); runtimeService.setVariable(processInstance.getId(), "myVar", "value"); // Update variable ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("name", "myVar"); requestNode.put("value", "updatedValue"); requestNode.put("type", "string"); HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "myVar")); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertEquals("updatedValue", responseNode.get("value").asText()); // Try updating with mismatch between URL and body variableName requestNode.put("name", "unexistingVariable"); httpPut.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST)); // Try updating unexisting property requestNode.put("name", "unexistingVariable"); httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "unexistingVariable")); httpPut.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND)); }
From source file:org.flowable.content.rest.service.api.content.ContentItemCollectionResourceTest.java
public void testCreateContentItemNoName() throws Exception { ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("mimeType", "application/pdf"); // Post JSON without name HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + ContentRestUrls.createRelativeResourceUrl(ContentRestUrls.URL_CONTENT_ITEM_COLLECTION)); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST)); }
From source file:org.apache.geode.tools.pulse.internal.data.DataBrowser.java
/** * generateQueryKey method stores queries in query history file. * /*from www .j av a 2 s . c o m*/ * @return Boolean true is operation is successful, false otherwise */ private boolean storeQueriesInFile(ObjectNode queries) { boolean operationStatus = false; FileOutputStream fileOut = null; File file = new File(Repository.get().getPulseConfig().getQueryHistoryFileName()); try { fileOut = new FileOutputStream(file); // if file does not exists, then create it if (!file.exists()) { file.createNewFile(); } // get the content in bytes byte[] contentInBytes = queries.toString().getBytes(); fileOut.write(contentInBytes); fileOut.flush(); operationStatus = true; } catch (FileNotFoundException e) { logger.debug(resourceBundle.getString("LOG_MSG_DATA_BROWSER_QUERY_HISTORY_FILE_NOT_FOUND"), e.getMessage()); } catch (IOException e) { logger.info(e); } finally { if (fileOut != null) { try { fileOut.close(); } catch (IOException e) { logger.info(e); } } } return operationStatus; }
From source file:org.activiti.rest.service.api.identity.UserCollectionResourceTest.java
public void testCreateUser() throws Exception { try {//from ww w . j a va2s.c o m ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("id", "testuser"); requestNode.put("firstName", "Frederik"); requestNode.put("lastName", "Heremans"); requestNode.put("password", "test"); requestNode.put("email", "no-reply@activiti.org"); HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION, "testuser")); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertEquals("testuser", responseNode.get("id").textValue()); assertEquals("Frederik", responseNode.get("firstName").textValue()); assertEquals("Heremans", responseNode.get("lastName").textValue()); assertEquals("no-reply@activiti.org", responseNode.get("email").textValue()); assertTrue(responseNode.get("url").textValue() .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, "testuser"))); assertNotNull(identityService.createUserQuery().userId("testuser").singleResult()); } finally { try { identityService.deleteUser("testuser"); } catch (Throwable t) { // Ignore, user might not have been created by test } } }