List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString
public String toString()
From source file:org.activiti.rest.service.api.identity.UserInfoResourceTest.java
/** * Test deleting the info for a user who doesn't have that info set *///from w w w . j ava2 s . c o m public void testUpdateUnexistingInfo() throws Exception { User savedUser = null; try { User newUser = identityService.newUser("testuser"); newUser.setFirstName("Fred"); newUser.setLastName("McDonald"); newUser.setEmail("no-reply@activiti.org"); identityService.saveUser(newUser); savedUser = newUser; ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("value", "Updated value"); HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, "testuser", "key1")); httpPut.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND)); } finally { // Delete user after test passes or fails if (savedUser != null) { identityService.deleteUser(savedUser.getId()); } } }
From source file:edu.nwpu.gemfire.monitor.controllers.PulseController.java
@RequestMapping(value = "/pulseProductSupport", method = RequestMethod.GET) public void getConfiguredPulseProduct(HttpServletRequest request, HttpServletResponse response) throws IOException { ObjectNode responseJSON = mapper.createObjectNode(); try {/*from w w w. j a va 2 s . co m*/ responseJSON.put("product", pulseProductSupport); // Send json response response.getOutputStream().write(responseJSON.toString().getBytes()); } catch (Exception e) { if (LOGGER.fineEnabled()) { LOGGER.fine("Exception Occurred : " + e.getMessage()); } } }
From source file:com.glaf.core.web.rest.MxSystemParamResource.java
@GET @POST// w ww . jav a 2 s.com @Path("/view") @ResponseBody @Produces({ MediaType.APPLICATION_OCTET_STREAM }) public byte[] view(@Context HttpServletRequest request, @Context UriInfo uriInfo) { String systemParamId = request.getParameter("systemParamId"); SystemParam systemParam = null; if (StringUtils.isNotEmpty(systemParamId)) { systemParam = systemParamService.getSystemParam(systemParamId); } ObjectNode responseJSON = new ObjectMapper().createObjectNode(); if (systemParam != null) { // Map<String, UserProfile> userMap = // MxIdentityFactory.getUserProfileMap(); responseJSON = systemParam.toObjectNode(); } try { return responseJSON.toString().getBytes("UTF-8"); } catch (IOException e) { return responseJSON.toString().getBytes(); } }
From source file:org.attribyte.api.pubsub.impl.server.BroadcastServlet.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { long startNanos = System.nanoTime(); byte[] broadcastContent = ByteStreams.toByteArray(request.getInputStream()); long endNanos = System.nanoTime(); String topicURL = request.getPathInfo(); if (maxBodyBytes > 0 && broadcastContent.length > maxBodyBytes) { logNotification(request, topicURL, NOTIFICATION_TOO_LARGE.statusCode, null); Bridge.sendServletResponse(NOTIFICATION_TOO_LARGE, response); return;/*from w w w . j a va2s . com*/ } Response endpointResponse; if (topicURL != null) { if (filters.size() > 0) { String checkHeader = request.getHeader(BasicAuthScheme.AUTH_HEADER); for (BasicAuthFilter filter : filters) { if (filter.reject(topicURL, checkHeader)) { logNotification(request, topicURL, Response.Code.UNAUTHORIZED, broadcastContent); response.sendError(Response.Code.UNAUTHORIZED, "Unauthorized"); return; } } } try { Topic topic = topicCache != null ? topicCache.getIfPresent(topicURL) : null; if (topic == null) { topic = datastore.getTopic(topicURL, autocreateTopics); if (topicCache != null && topic != null) { topicCache.put(topicURL, topic); } } if (topic != null) { NotificationMetrics globalMetrics = endpoint.getGlobalNotificationMetrics(); NotificationMetrics metrics = endpoint.getNotificationMetrics(topic.getId()); metrics.notificationSize.update(broadcastContent.length); globalMetrics.notificationSize.update(broadcastContent.length); long acceptTimeNanos = endNanos - startNanos; metrics.notifications.update(acceptTimeNanos, TimeUnit.NANOSECONDS); globalMetrics.notifications.update(acceptTimeNanos, TimeUnit.NANOSECONDS); Notification notification = new Notification(topic, null, broadcastContent); //No custom headers... final boolean queued = endpoint.enqueueNotification(notification); if (queued) { if (replicationTopic != null) { final boolean replicationQueued = endpoint .enqueueNotification(new Notification(replicationTopic, Collections.singleton( new Header(REPLICATION_TOPIC_HEADER, topic.getURL())), broadcastContent)); if (!replicationQueued) { //What to do? logger.error("Replication failure due to notification capacity limits!"); } } if (!jsonEnabled) { endpointResponse = ACCEPTED_RESPONSE; } else { ResponseBuilder builder = new ResponseBuilder(); builder.setStatusCode(ACCEPTED_RESPONSE.statusCode); builder.addHeader("Content-Type", ServerUtil.JSON_CONTENT_TYPE); ObjectNode responseNode = JsonNodeFactory.instance.objectNode(); ArrayNode idsNode = responseNode.putArray("messageIds"); idsNode.add(Long.toString(notification.getCreateTimestampMicros())); builder.setBody(responseNode.toString().getBytes(Charsets.UTF_8)); endpointResponse = builder.create(); } } else { endpointResponse = CAPACITY_ERROR_RESPONSE; } } else { endpointResponse = UNKNOWN_TOPIC_RESPONSE; } } catch (DatastoreException de) { logger.error("Problem selecting topic", de); endpointResponse = INTERNAL_ERROR_RESPONSE; } } else { endpointResponse = NO_TOPIC_RESPONSE; } logNotification(request, topicURL, endpointResponse.statusCode, broadcastContent); Bridge.sendServletResponse(endpointResponse, response); }
From source file:com.msopentech.odatajclient.testservice.utils.JSONUtilities.java
@Override protected InputStream addLinks(final String entitySetName, final String entitykey, final InputStream is, final Set<String> links) throws Exception { final ObjectMapper mapper = new ObjectMapper(); final ObjectNode srcNode = (ObjectNode) mapper.readTree(is); IOUtils.closeQuietly(is);/*from w w w . ja v a 2s .co m*/ for (String link : links) { srcNode.set(link + JSON_NAVIGATION_SUFFIX, new TextNode(Commons.getLinksURI(version, entitySetName, entitykey, link))); } return IOUtils.toInputStream(srcNode.toString()); }
From source file:com.funtl.framework.smoke.core.modules.act.service.ActProcessService.java
/** * ??/* w w w . j ava2 s. c o m*/ * * @param procDefId * @throws UnsupportedEncodingException * @throws XMLStreamException */ @Transactional(readOnly = false) public org.activiti.engine.repository.Model convertToModel(String procDefId) throws UnsupportedEncodingException, XMLStreamException { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery() .processDefinitionId(procDefId).singleResult(); InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName()); XMLInputFactory xif = XMLInputFactory.newInstance(); InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(in); BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr); BpmnJsonConverter converter = new BpmnJsonConverter(); ObjectNode modelNode = converter.convertToJson(bpmnModel); org.activiti.engine.repository.Model modelData = repositoryService.newModel(); modelData.setKey(processDefinition.getKey()); modelData.setName(processDefinition.getResourceName()); modelData.setCategory(processDefinition.getCategory());//.getDeploymentId()); modelData.setDeploymentId(processDefinition.getDeploymentId()); modelData.setVersion(Integer.parseInt( String.valueOf(repositoryService.createModelQuery().modelKey(modelData.getKey()).count() + 1))); ObjectNode modelObjectNode = new ObjectMapper().createObjectNode(); modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processDefinition.getName()); modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, modelData.getVersion()); modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, processDefinition.getDescription()); modelData.setMetaInfo(modelObjectNode.toString()); repositoryService.saveModel(modelData); repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8")); return modelData; }
From source file:org.activiti.rest.service.api.runtime.ExecutionResourceTest.java
/** * Test signalling a single execution, without signal name. *///from w w w.j a v a2 s . c o m @Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-signal.bpmn20.xml" }) public void testSignalExecution() throws Exception { runtimeService.startProcessInstanceByKey("processOne"); Execution signalExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult(); assertNotNull(signalExecution); assertEquals("waitState", signalExecution.getActivityId()); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("action", "signal"); // Signalling one causes process to move on to second signal and // execution is not finished yet HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, signalExecution.getId())); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertEquals("anotherWaitState", responseNode.get("activityId").textValue()); assertEquals("anotherWaitState", runtimeService.createExecutionQuery().executionId(signalExecution.getId()) .singleResult().getActivityId()); // Signalling again causes process to end response = executeRequest(httpPut, HttpStatus.SC_NO_CONTENT); closeResponse(response); // Check if process is actually ended assertNull(runtimeService.createExecutionQuery().executionId(signalExecution.getId()).singleResult()); }
From source file:org.flowable.rest.service.api.runtime.ExecutionResourceTest.java
/** * Test signalling a single execution, without signal name. *///from ww w . ja v a 2 s . c o m @Deployment(resources = { "org/flowable/rest/service/api/runtime/ExecutionResourceTest.process-with-signal.bpmn20.xml" }) public void testSignalExecution() throws Exception { runtimeService.startProcessInstanceByKey("processOne"); Execution signalExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult(); assertNotNull(signalExecution); assertEquals("waitState", signalExecution.getActivityId()); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("action", "signal"); // Signalling one causes process to move on to second signal and // execution is not finished yet HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, signalExecution.getId())); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertEquals("anotherWaitState", responseNode.get("activityId").textValue()); assertEquals("anotherWaitState", runtimeService.createExecutionQuery().executionId(signalExecution.getId()) .singleResult().getActivityId()); // Signalling again causes process to end response = executeRequest(httpPut, HttpStatus.SC_NO_CONTENT); closeResponse(response); // Check if process is actually ended assertNull(runtimeService.createExecutionQuery().executionId(signalExecution.getId()).singleResult()); }
From source file:org.onosproject.maven.OnosSwaggerMojo.java
private void genCatalog(ObjectNode root) { File swaggerCfg = new File(dstDirectory, JSON_FILE); if (dstDirectory.exists() || dstDirectory.mkdirs()) { try (FileWriter fw = new FileWriter(swaggerCfg); PrintWriter pw = new PrintWriter(fw)) { pw.println(root.toString()); } catch (IOException e) { getLog().warn("Unable to write " + JSON_FILE); }/* w ww .j a v a 2s .c o m*/ } else { getLog().warn("Unable to create " + dstDirectory); } }
From source file:edu.nwpu.gemfire.monitor.controllers.PulseController.java
@RequestMapping(value = "/authenticateUser", method = RequestMethod.GET) public void authenticateUser(HttpServletRequest request, HttpServletResponse response) throws IOException { // json object to be sent as response ObjectNode responseJSON = mapper.createObjectNode(); try {/*from ww w .j a v a 2s . co m*/ responseJSON.put("isUserLoggedIn", this.isUserLoggedIn(request)); // Send json response response.getOutputStream().write(responseJSON.toString().getBytes()); } catch (Exception e) { if (LOGGER.fineEnabled()) { LOGGER.fine("Exception Occurred : " + e.getMessage()); } } }