List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString
public String toString()
From source file:org.activiti.rest.service.api.identity.UserCollectionResourceTest.java
public void testCreateUserExceptions() throws Exception { // Create without ID ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("firstName", "Frederik"); requestNode.put("lastName", "Heremans"); requestNode.put("email", "no-reply@activiti.org"); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION, "unexisting")); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST)); // Create when user already exists // Create without ID requestNode = objectMapper.createObjectNode(); requestNode.put("id", "kermit"); requestNode.put("firstName", "Frederik"); requestNode.put("lastName", "Heremans"); requestNode.put("email", "no-reply@activiti.org"); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_CONFLICT)); }
From source file:org.osiam.resources.helper.AttributesRemovalHelper.java
private SCIMSearchResult<User> getUserJsonResponseWithAdditionalFields(SCIMSearchResult<User> scimSearchResult, Map<String, Object> parameterMap) { ObjectMapper mapper = new ObjectMapper(); String[] fieldsToReturn = (String[]) parameterMap.get("attributes"); if (fieldsToReturn.length == 0) { return scimSearchResult; }//from w w w .jav a 2s .co m for (int i = 0; i < fieldsToReturn.length; i++) { fieldsToReturn[i] = fieldsToReturn[i].trim(); } ObjectWriter writer = getObjectWriter(mapper, fieldsToReturn); try { List<User> users = scimSearchResult.getResources(); users = filterUserSchemas(users, fieldsToReturn); String resourcesString = writer.writeValueAsString(users); JsonNode resourcesNode = mapper.readTree(resourcesString); String schemasString = writer.writeValueAsString(scimSearchResult.getSchemas()); JsonNode schemasNode = mapper.readTree(schemasString); ObjectNode rootNode = mapper.createObjectNode(); rootNode.put("totalResults", scimSearchResult.getTotalResults()); rootNode.put("itemsPerPage", scimSearchResult.getItemsPerPage()); rootNode.put("startIndex", scimSearchResult.getStartIndex()); rootNode.put("schemas", schemasNode); rootNode.put("Resources", resourcesNode); return mapper.readValue(rootNode.toString(), SCIMSearchResult.class); } catch (IOException e) { LOGGER.warn("Unable to serialize search result", e); throw new OsiamBackendFailureException(); } }
From source file:dk.dbc.rawrepo.oai.ResumptionTokenTest.java
@Test public void testXml() throws Exception { ObjectNode jsonOriginal = (ObjectNode) new ObjectMapper().readTree("{\"foo\":\"bar\"}"); ResumptionTokenType token = ResumptionToken.toToken(jsonOriginal, 1); OAIPMH oaipmh = OBJECT_FACTORY.createOAIPMH(); ListRecordsType getRecord = OBJECT_FACTORY.createListRecordsType(); oaipmh.setListRecords(getRecord);/*from ww w.j av a2s. c om*/ getRecord.setResumptionToken(token); ObjectNode json = ResumptionToken.decode(token.getValue()); assertEquals(jsonOriginal.toString(), json.toString()); }
From source file:org.osiam.resource_server.resources.helper.AttributesRemovalHelper.java
private SCIMSearchResult<User> getUserJsonResponseWithAdditionalFields(SCIMSearchResult<User> scimSearchResult, Map<String, Object> parameterMap) { ObjectMapper mapper = new ObjectMapper(); String[] fieldsToReturn = (String[]) parameterMap.get("attributes"); if (fieldsToReturn.length == 0) { return scimSearchResult; }//from w w w . j a v a 2 s . c om for (int i = 0; i < fieldsToReturn.length; i++) { fieldsToReturn[i] = fieldsToReturn[i].trim(); } ObjectWriter writer = getObjectWriter(mapper, fieldsToReturn); try { List<User> users = scimSearchResult.getResources(); users = filterUserSchemas(users, fieldsToReturn); String resourcesString = writer.writeValueAsString(users); JsonNode resourcesNode = mapper.readTree(resourcesString); String schemasString = writer.writeValueAsString(scimSearchResult.getSchemas()); JsonNode schemasNode = mapper.readTree(schemasString); ObjectNode rootNode = mapper.createObjectNode(); rootNode.put("totalResults", scimSearchResult.getTotalResults()); rootNode.put("itemsPerPage", scimSearchResult.getItemsPerPage()); rootNode.put("startIndex", scimSearchResult.getStartIndex()); rootNode.put("schemas", schemasNode); rootNode.put("Resources", resourcesNode); return mapper.readValue(rootNode.toString(), SCIMSearchResult.class); } catch (IOException e) { throw new IllegalArgumentException(e); } }
From source file:org.bimserver.client.BimServerClient.java
public long query(Query query, long roid, long serializerOid) throws ServerException, UserException, PublicInterfaceNotFoundException { ObjectNode queryNode = new JsonQueryObjectModelConverter(query.getPackageMetaData()).toJson(query); Long topicId = getServiceInterface().download(Collections.singleton(roid), queryNode.toString(), serializerOid, false);/*from ww w . jav a 2 s . c o m*/ return topicId; }
From source file:org.activiti.rest.service.api.runtime.ExecutionResourceTest.java
/** * Test executing an illegal action on an execution. *//* w ww .jav a 2s. c o m*/ @Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" }) public void testIllegalExecutionAction() throws Exception { Execution execution = runtimeService.startProcessInstanceByKey("processOne"); assertNotNull(execution); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("action", "badaction"); HttpPut httpPut = new HttpPut( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, execution.getId())); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST); closeResponse(response); }
From source file:org.flowable.rest.service.api.runtime.ExecutionResourceTest.java
/** * Test executing an illegal action on an execution. *//*from ww w . j a v a 2 s. c om*/ @Deployment(resources = { "org/flowable/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" }) public void testIllegalExecutionAction() throws Exception { Execution execution = runtimeService.startProcessInstanceByKey("processOne"); assertNotNull(execution); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("action", "badaction"); HttpPut httpPut = new HttpPut( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, execution.getId())); httpPut.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST); closeResponse(response); }
From source file:org.flowable.app.rest.service.BaseSpringRestTestCase.java
/** * Checks if the rest operation returns an error as expected *//* ww w.java 2 s. co m*/ protected void assertErrorResult(String url, ObjectNode body, int statusCode) throws IOException { // Do the actual call HttpPost post = new HttpPost(SERVER_URL_PREFIX + url); post.setEntity(new StringEntity(body.toString())); closeResponse(executeRequest(post, statusCode)); }
From source file:org.flowable.rest.service.api.runtime.SignalsResourceTest.java
@Deployment(resources = { "org/flowable/rest/service/api/runtime/SignalsResourceTest.process-signal-start.bpmn20.xml" }) public void testSignalEventReceivedAsync() throws Exception { org.flowable.engine.repository.Deployment tenantDeployment = repositoryService.createDeployment() .addClasspathResource(//from www. ja v a 2s . c o m "org/flowable/rest/service/api/runtime/SignalsResourceTest.process-signal-start.bpmn20.xml") .tenantId("my tenant").deploy(); try { // Signal without vars, without tenant ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("signalName", "The Signal"); requestNode.put("async", true); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_SIGNALS)); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_ACCEPTED)); // Check if job is queued as a result of the signal without tenant ID set assertEquals(1, managementService.createJobQuery().jobWithoutTenantId().count()); // Signal with tenant requestNode.put("tenantId", "my tenant"); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_ACCEPTED)); // Check if job is queued as a result of the signal, in the right tenant assertEquals(1, managementService.createJobQuery().jobTenantId("my tenant").count()); // Signal with variables and async, should fail as it's not supported ArrayNode vars = requestNode.putArray("variables"); ObjectNode var = vars.addObject(); var.put("name", "testVar"); var.put("value", "test"); httpPost.setEntity(new StringEntity(requestNode.toString())); closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST)); } finally { // Clean up tenant-specific deployment if (tenantDeployment != null) { repositoryService.deleteDeployment(tenantDeployment.getId(), true); } // Clear jobs List<Job> jobs = managementService.createJobQuery().list(); for (Job job : jobs) { managementService.deleteJob(job.getId()); } } }
From source file:io.gs2.auth.Gs2AuthClient.java
/** * GS2-Account??????????<br>/*from w w w . j a v a 2s . c om*/ * <br> * * @param request * @return ? */ public LoginWithSignResult loginWithSign(LoginWithSignRequest request) { ObjectNode body = JsonNodeFactory.instance.objectNode().put("serviceId", request.getServiceId()) .put("userId", request.getUserId()).put("keyName", request.getKeyName()) .put("sign", request.getSign()); HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/login/signed", credential, ENDPOINT, LoginWithSignRequest.Constant.MODULE, LoginWithSignRequest.Constant.FUNCTION, body.toString()); if (request.getRequestId() != null) { post.setHeader("X-GS2-REQUEST-ID", request.getRequestId()); } return doRequest(post, LoginWithSignResult.class); }