Example usage for com.fasterxml.jackson.databind.node ObjectNode toString

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ObjectNode toString.

Prototype

public String toString() 

Source Link

Usage

From source file:org.activiti.rest.service.api.runtime.ProcessInstanceCollectionResourceTest.java

/**
 * Test starting a process instance using procDefinitionId, key procDefinitionKey business-key.
 *///from   w  w  w  . j  a  v  a  2s. c  o m
@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testStartProcess() throws Exception {
    ObjectNode requestNode = objectMapper.createObjectNode();

    // Start using process definition key
    requestNode.put("processDefinitionKey", "processOne");

    HttpPost httpPost = new HttpPost(
            SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);

    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertNotNull(processInstance);

    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
            .processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(historicProcessInstance);
    assertEquals("kermit", historicProcessInstance.getStartUserId());

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertTrue(responseNode.get("businessKey").isNull());
    assertFalse(responseNode.get("suspended").booleanValue());

    assertTrue(responseNode.get("url").asText().endsWith(
            RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId())));
    assertTrue(responseNode.get("processDefinitionUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId())));
    runtimeService.deleteProcessInstance(processInstance.getId(), "testing");

    // Start using process definition id
    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionId", repositoryService.createProcessDefinitionQuery()
            .processDefinitionKey("processOne").singleResult().getId());
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPost, HttpStatus.SC_CREATED);

    processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertNotNull(processInstance);

    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertTrue(responseNode.get("businessKey").isNull());
    assertFalse(responseNode.get("suspended").booleanValue());

    assertTrue(responseNode.get("url").asText().endsWith(
            RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId())));
    assertTrue(responseNode.get("processDefinitionUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId())));
    runtimeService.deleteProcessInstance(processInstance.getId(), "testing");

    // Start using message
    requestNode = objectMapper.createObjectNode();
    requestNode.put("message", "newInvoiceMessage");
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPost, HttpStatus.SC_CREATED);

    processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertNotNull(processInstance);

    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertTrue(responseNode.get("businessKey").isNull());
    assertFalse(responseNode.get("suspended").booleanValue());

    assertTrue(responseNode.get("url").asText().endsWith(
            RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId())));
    assertTrue(responseNode.get("processDefinitionUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId())));

    // Start using process definition id and business key
    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionId", repositoryService.createProcessDefinitionQuery()
            .processDefinitionKey("processOne").singleResult().getId());
    requestNode.put("businessKey", "myBusinessKey");
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPost, HttpStatus.SC_CREATED);

    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("myBusinessKey", responseNode.get("businessKey").textValue());
}

From source file:org.flowable.rest.service.api.runtime.ProcessInstanceCollectionResourceTest.java

/**
 * Test starting a process instance using procDefinitionId, key procDefinitionKey business-key.
 */// w  w w .  ja va  2  s.  c  om
@Deployment(resources = {
        "org/flowable/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testStartProcess() throws Exception {
    ObjectNode requestNode = objectMapper.createObjectNode();

    // Start using process definition key
    requestNode.put("processDefinitionKey", "processOne");

    HttpPost httpPost = new HttpPost(
            SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);

    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertNotNull(processInstance);

    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
            .processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(historicProcessInstance);
    assertEquals("kermit", historicProcessInstance.getStartUserId());

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertTrue(responseNode.get("businessKey").isNull());
    assertFalse(responseNode.get("suspended").booleanValue());

    assertTrue(responseNode.get("url").asText().endsWith(
            RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId())));
    assertTrue(responseNode.get("processDefinitionUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId())));
    runtimeService.deleteProcessInstance(processInstance.getId(), "testing");

    // Start using process definition id
    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionId", repositoryService.createProcessDefinitionQuery()
            .processDefinitionKey("processOne").singleResult().getId());
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPost, HttpStatus.SC_CREATED);

    processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertNotNull(processInstance);

    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertTrue(responseNode.get("businessKey").isNull());
    assertFalse(responseNode.get("suspended").booleanValue());

    assertTrue(responseNode.get("url").asText().endsWith(
            RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId())));
    assertTrue(responseNode.get("processDefinitionUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId())));
    runtimeService.deleteProcessInstance(processInstance.getId(), "testing");

    // Start using message
    requestNode = objectMapper.createObjectNode();
    requestNode.put("message", "newInvoiceMessage");
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPost, HttpStatus.SC_CREATED);

    processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertNotNull(processInstance);

    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertTrue(responseNode.get("businessKey").isNull());
    assertFalse(responseNode.get("suspended").booleanValue());

    assertTrue(responseNode.get("url").asText().endsWith(
            RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId())));
    assertTrue(responseNode.get("processDefinitionUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId())));

    // Start using process definition id and business key
    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionId", repositoryService.createProcessDefinitionQuery()
            .processDefinitionKey("processOne").singleResult().getId());
    requestNode.put("businessKey", "myBusinessKey");
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPost, HttpStatus.SC_CREATED);

    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("myBusinessKey", responseNode.get("businessKey").textValue());
}

From source file:org.activiti.rest.service.api.runtime.TaskResourceTest.java

/**
 * Test resolving a single task and all exceptional cases related to resolution. POST runtime/tasks/{taskId}
 *//*from   w w w .  j av  a2  s .c om*/
public void testResolveTask() throws Exception {
    try {
        Task task = taskService.newTask();
        task.setAssignee("initialAssignee");
        taskService.saveTask(task);
        taskService.delegateTask(task.getId(), "anotherUser");
        String taskId = task.getId();

        // Resolve the task and check result
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("action", "resolve");
        HttpPost httpPost = new HttpPost(
                SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));

        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        assertNotNull(task);
        assertEquals("initialAssignee", task.getAssignee());
        assertEquals("initialAssignee", task.getOwner());
        assertEquals(DelegationState.RESOLVED, task.getDelegationState());

        // Resolving again shouldn't cause an exception
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        assertNotNull(task);
        assertEquals("initialAssignee", task.getAssignee());
        assertEquals("initialAssignee", task.getOwner());
        assertEquals(DelegationState.RESOLVED, task.getDelegationState());

    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}

From source file:org.activiti.rest.service.api.repository.ModelResourceTest.java

@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testUpdateModelOverrideWithNull() throws Exception {
    Model model = null;//from  w  ww  .j  a v  a  2s .  c  om
    try {
        Calendar createTime = Calendar.getInstance();
        createTime.set(Calendar.MILLISECOND, 0);
        processEngineConfiguration.getClock().setCurrentTime(createTime.getTime());

        model = repositoryService.newModel();
        model.setCategory("Model category");
        model.setKey("Model key");
        model.setMetaInfo("Model metainfo");
        model.setName("Model name");
        model.setTenantId("myTenant");
        model.setVersion(2);
        repositoryService.saveModel(model);

        Calendar updateTime = Calendar.getInstance();
        updateTime.set(Calendar.MILLISECOND, 0);
        processEngineConfiguration.getClock().setCurrentTime(updateTime.getTime());

        // Create update request
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("name", (String) null);
        requestNode.put("category", (String) null);
        requestNode.put("key", (String) null);
        requestNode.put("metaInfo", (String) null);
        requestNode.put("deploymentId", (String) null);
        requestNode.put("version", (String) null);
        requestNode.put("tenantId", (String) null);

        HttpPut httpPut = new HttpPut(
                SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
        httpPut.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertNull(responseNode.get("name").textValue());
        assertNull(responseNode.get("key").textValue());
        assertNull(responseNode.get("category").textValue());
        assertNull(responseNode.get("version").textValue());
        assertNull(responseNode.get("metaInfo").textValue());
        assertNull(responseNode.get("deploymentId").textValue());
        assertNull(responseNode.get("tenantId").textValue());
        assertEquals(model.getId(), responseNode.get("id").textValue());

        assertEquals(createTime.getTime().getTime(),
                getDateFromISOString(responseNode.get("createTime").textValue()).getTime());
        assertEquals(updateTime.getTime().getTime(),
                getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime());

        assertTrue(responseNode.get("url").textValue()
                .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId())));

        model = repositoryService.getModel(model.getId());
        assertNull(model.getName());
        assertNull(model.getKey());
        assertNull(model.getCategory());
        assertNull(model.getMetaInfo());
        assertNull(model.getDeploymentId());
        assertEquals("", model.getTenantId());

    } finally {
        try {
            repositoryService.deleteModel(model.getId());
        } catch (Throwable ignore) {
            // Ignore, model might not be created
        }
    }
}

From source file:org.flowable.rest.service.api.repository.ModelResourceTest.java

@Deployment(resources = { "org/flowable/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testUpdateModelOverrideWithNull() throws Exception {
    Model model = null;//from  w ww. jav a2s. c o m
    try {
        Calendar createTime = Calendar.getInstance();
        createTime.set(Calendar.MILLISECOND, 0);
        processEngineConfiguration.getClock().setCurrentTime(createTime.getTime());

        model = repositoryService.newModel();
        model.setCategory("Model category");
        model.setKey("Model key");
        model.setMetaInfo("Model metainfo");
        model.setName("Model name");
        model.setTenantId("myTenant");
        model.setVersion(2);
        repositoryService.saveModel(model);

        Calendar updateTime = Calendar.getInstance();
        updateTime.set(Calendar.MILLISECOND, 0);
        processEngineConfiguration.getClock().setCurrentTime(updateTime.getTime());

        // Create update request
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("name", (String) null);
        requestNode.put("category", (String) null);
        requestNode.put("key", (String) null);
        requestNode.put("metaInfo", (String) null);
        requestNode.put("deploymentId", (String) null);
        requestNode.put("version", (String) null);
        requestNode.put("tenantId", (String) null);

        HttpPut httpPut = new HttpPut(
                SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
        httpPut.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertNull(responseNode.get("name").textValue());
        assertNull(responseNode.get("key").textValue());
        assertNull(responseNode.get("category").textValue());
        assertNull(responseNode.get("version").textValue());
        assertNull(responseNode.get("metaInfo").textValue());
        assertNull(responseNode.get("deploymentId").textValue());
        assertNull(responseNode.get("tenantId").textValue());
        assertEquals(model.getId(), responseNode.get("id").textValue());

        assertEquals(createTime.getTime().getTime(),
                getDateFromISOString(responseNode.get("createTime").textValue()).getTime());
        assertEquals(updateTime.getTime().getTime(),
                getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime());

        assertTrue(responseNode.get("url").textValue()
                .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId())));

        model = repositoryService.getModel(model.getId());
        assertNull(model.getName());
        assertNull(model.getKey());
        assertNull(model.getCategory());
        assertNull(model.getMetaInfo());
        assertNull(model.getDeploymentId());
        assertEquals("", model.getTenantId());

    } finally {
        try {
            repositoryService.deleteModel(model.getId());
        } catch (Throwable ignore) {
            // Ignore, model might not be created
        }
    }
}

From source file:org.activiti.rest.service.api.runtime.TaskResourceTest.java

/**
 * Test delegating a single task and all exceptional cases related to delegation. POST runtime/tasks/{taskId}
 *//*w  w  w  .  j  a v a 2s .  co m*/
public void testDelegateTask() throws Exception {
    try {

        Task task = taskService.newTask();
        task.setAssignee("initialAssignee");
        taskService.saveTask(task);
        String taskId = task.getId();

        // Delegating without assignee fails
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("action", "delegate");
        HttpPost httpPost = new HttpPost(
                SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));

        // Delegate the task and check result
        requestNode.put("assignee", "newAssignee");
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        assertNotNull(task);
        assertEquals("newAssignee", task.getAssignee());
        assertEquals("initialAssignee", task.getOwner());
        assertEquals(DelegationState.PENDING, task.getDelegationState());

        // Delegating again shouldn't cause an exception and should delegate
        // to user without affecting initial delegator (owner)
        requestNode.put("assignee", "anotherAssignee");
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        assertNotNull(task);
        assertEquals("anotherAssignee", task.getAssignee());
        assertEquals("initialAssignee", task.getOwner());
        assertEquals(DelegationState.PENDING, task.getDelegationState());

    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}

From source file:org.flowable.ui.modeler.service.FlowableModelQueryService.java

public ModelRepresentation importCaseModel(HttpServletRequest request, MultipartFile file) {

    String fileName = file.getOriginalFilename();
    if (fileName != null && (fileName.endsWith(".cmmn") || fileName.endsWith(".cmmn.xml"))) {
        try {/* w  ww  . ja v a2  s . c om*/
            XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
            InputStreamReader xmlIn = new InputStreamReader(file.getInputStream(), "UTF-8");
            XMLStreamReader xtr = xif.createXMLStreamReader(xmlIn);
            CmmnModel cmmnModel = cmmnXmlConverter.convertToCmmnModel(xtr);
            if (CollectionUtils.isEmpty(cmmnModel.getCases())) {
                throw new BadRequestException("No cases found in definition " + fileName);
            }

            if (cmmnModel.getLocationMap().size() == 0) {
                throw new BadRequestException("No CMMN DI found in definition " + fileName);
            }

            ObjectNode modelNode = cmmnJsonConverter.convertToJson(cmmnModel);

            Case caseModel = cmmnModel.getPrimaryCase();
            String name = caseModel.getId();
            if (StringUtils.isNotEmpty(caseModel.getName())) {
                name = caseModel.getName();
            }
            String description = caseModel.getDocumentation();

            ModelRepresentation model = new ModelRepresentation();
            model.setKey(caseModel.getId());
            model.setName(name);
            model.setDescription(description);
            model.setModelType(AbstractModel.MODEL_TYPE_CMMN);
            Model newModel = modelService.createModel(model, modelNode.toString(),
                    SecurityUtils.getCurrentUserObject());
            return new ModelRepresentation(newModel);

        } catch (BadRequestException e) {
            throw e;

        } catch (Exception e) {
            LOGGER.error("Import failed for {}", fileName, e);
            throw new BadRequestException(
                    "Import failed for " + fileName + ", error message " + e.getMessage());
        }
    } else {
        throw new BadRequestException(
                "Invalid file name, only .cmmn and .cmmn.xml files are supported not " + fileName);
    }
}

From source file:io.gs2.identifier.Gs2IdentifierClient.java

/**
 * GSI?????<br>/* w  w w  . j  ava 2 s .  co  m*/
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public CreateIdentifierResult createIdentifier(CreateIdentifierRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode();

    HttpPost post = createHttpPost(
            Gs2Constant.ENDPOINT_HOST + "/user/"
                    + (request.getUserName() == null || request.getUserName().equals("") ? "null"
                            : request.getUserName())
                    + "/identifier",
            credential, ENDPOINT, CreateIdentifierRequest.Constant.MODULE,
            CreateIdentifierRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(post, CreateIdentifierResult.class);

}

From source file:com.chap.memo.memoNodes.MemoNode.java

/**
 * Return the subgraph below this node as a JSON object suitable for the chap network
 * viewer.//from www . ja v a2s.  c om
 * 
 * @see <a href="http://almende.github.com/chap-links-library/network.html">CHAP network viewer</a>
 * @param depth maximum depth of the subgraph to retrieve. (set to 0 for unlimited =dangerous)
 */
public String toJSONString(int depth) {
    //TODO: prevent loops
    JSONTuple tuple = new JSONTuple();
    this.toJSON(depth, tuple);
    ObjectNode node = om.createObjectNode();
    node.put("nodes", tuple.getNodes());
    node.put("links", tuple.getLinks());
    return node.toString();
}

From source file:io.gs2.identifier.Gs2IdentifierClient.java

/**
 * ????<br>//  ww  w.  j  a v  a 2 s.c om
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public UpdateSecurityPolicyResult updateSecurityPolicy(UpdateSecurityPolicyRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("policy", request.getPolicy());
    HttpPut put = createHttpPut(Gs2Constant.ENDPOINT_HOST + "/securityPolicy/"
            + (request.getSecurityPolicyName() == null || request.getSecurityPolicyName().equals("") ? "null"
                    : request.getSecurityPolicyName())
            + "", credential, ENDPOINT, UpdateSecurityPolicyRequest.Constant.MODULE,
            UpdateSecurityPolicyRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        put.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(put, UpdateSecurityPolicyResult.class);

}