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.ambientdynamix.core.WebListener.java

/**
 * {@inheritDoc}//from   w  w  w . j a  v  a2s.com
 */
@Override
public void onContextEvent(ContextEvent event) throws RemoteException {
    //String pojoBuilder = "";

    try {
        // Setup a SimpleDateFormat for UTC-based ISO 8601 date/time formatting
        SimpleDateFormat timeFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
        TimeZone tz = TimeZone.getTimeZone("UTC");
        timeFormatter.setTimeZone(tz);
        // Create a root node and basic event properties
        ObjectNode jNode = mapper.createObjectNode();
        jNode.put("sourcePluginId", event.getEventSource().getPluginId());
        jNode.put("responseId", event.getResponseId() == null ? "" : event.getResponseId());
        jNode.put("contextType", event.getContextType());
        jNode.put("implementingClassname", event.getIContextInfo().getImplementingClassname());
        jNode.put("timeStamp", timeFormatter.format(event.getTimeStamp()));
        jNode.put("expires", event.expires());
        jNode.put("expireTime", timeFormatter.format(event.getExpireTime()));

        /*
         * Now add the properties from the IContextInfo. First, handle automatic web encoding, if requested. If the
         * IContextInfo uses JavaBean standards, it can be automatically encoded into JSON. If no automatic web
         * encoding is requested, then we use the
         */
        JsonNode encodedNode;
        if (event.autoWebEncode()) {
            encodedNode = mapper.valueToTree(event.getIContextInfo());
            jNode.put("hasPojoData", true);
        } else {
            jNode.put("hasPojoData", false);
            if (!event.getWebEncodingFormat().equalsIgnoreCase(PluginConstants.NO_WEB_ENCODING)) {
                ObjectNode tmp = mapper.createObjectNode();
                tmp.put("encodedDataType", event.getWebEncodingFormat());
                tmp.put("encodedData", event.getStringRepresentation(event.getWebEncodingFormat()));
                encodedNode = tmp;
            } else {
                // This object cannot be sent via web serialization
                Log.w(TAG, "Event is configured with NO_WEB_ENCODING... ignoring");
                return;
            }
        }
        // Iterate through the IContextInfo fields, adding them to the event
        Iterator<String> itr = encodedNode.fieldNames();
        while (itr.hasNext()) {
            String field = itr.next();
            jNode.put(field, encodedNode.get(field));
        }

        String tmp = jNode.toString();//.textValue();
        // Send the event
        try {
            connector.sendEvent(this.token,
                    "javascript:try{Dynamix.onContextEvent(" + jNode.toString() + ");}catch(e){};");
        } catch (Exception e) {
            Log.w(TAG, "onContextEvent: " + e);
        }
        // Create the JavaScript reply
        // StringBuilder params = new StringBuilder();
        // params.append("javascript:try{Dynamix.onContextEvent('");
        // // To keep things lightweight, we are only sending plug-in id for context events
        // params.append(event.getEventSource().getPluginId());
        // params.append("','");
        // params.append(event.getContextType());
        // params.append("','");
        // params.append(event.getIContextInfo().getImplementingClassname());
        // params.append("','");
        // params.append(timeFormatter.format(event.getTimeStamp()));
        // params.append("','");
        // params.append(event.expires());
        // params.append("','");
        // params.append(timeFormatter.format(event.getExpireTime()));
        // params.append("','");
        // params.append(event.getResponseId() == null ? "" : event.getResponseId());
        // params.append("','");
        // params.append(encodedData);
        // params.append("','");
        // params.append(event.getAutoWebEncodingFormat());
        // params.append("','");
        // params.append(pojoBuilder);
        // params.append("');}catch(e){};");
        // connector.sendEvent(this.token, params.toString());
    } catch (Exception e) {
        Log.w(TAG, "onContextEvent: " + e);
    }
}

From source file:com.glaf.activiti.web.springmvc.ActivitiTreeController.java

@ResponseBody
@RequestMapping("/historyProcessInstances")
public byte[] historyProcessInstances(HttpServletRequest request) {
    ObjectNode responseJSON = new ObjectMapper().createObjectNode();
    ArrayNode arrayJSON = new ObjectMapper().createArrayNode();
    Map<String, Object> params = RequestUtils.getParameterMap(request);
    params.put("orderByProcessInstanceStartTime", "1");
    params.put("orderDesc", "1");

    logger.debug("params:" + params);
    int pageNo = ParamUtils.getInt(params, "page");
    int limit = ParamUtils.getInt(params, "rows");
    if (limit <= 0) {
        limit = 15;/*ww  w  .j a v a  2 s  .c  o m*/
    }
    if (pageNo <= 0) {
        pageNo = 1;
    }
    int start = (pageNo - 1) * limit;
    long total = activitiProcessQueryService.getHistoricProcessInstanceCount(params);
    responseJSON.put("start", start);
    responseJSON.put("limit", limit);
    if (total > 0) {
        responseJSON.put("total", total);
        List<HistoricProcessInstance> list = activitiProcessQueryService.getHistoricProcessInstances(start,
                limit, params);
        if (list != null && !list.isEmpty()) {
            for (HistoricProcessInstance processInstance : list) {
                ObjectNode row = new ObjectMapper().createObjectNode();
                row.put("sortNo", ++start);
                row.put("id", processInstance.getId());
                row.put("processInstanceId", processInstance.getId());
                row.put("processDefinitionId", processInstance.getProcessDefinitionId());
                row.put("businessKey", processInstance.getBusinessKey());
                row.put("startTime", DateUtils.getDateTime(processInstance.getStartTime()));
                row.put("endTime", DateUtils.getDateTime(processInstance.getEndTime()));
                row.put("startUserId", processInstance.getStartUserId());
                row.put("startDate", DateUtils.getDate(processInstance.getStartTime()));
                row.put("endDate", DateUtils.getDate(processInstance.getEndTime()));
                row.put("startDateTime", DateUtils.getDateTime(processInstance.getStartTime()));
                row.put("endDateTime", DateUtils.getDateTime(processInstance.getEndTime()));
                row.put("durationInMillis", processInstance.getDurationInMillis());
                row.put("processDefinitionId", processInstance.getProcessDefinitionId());
                arrayJSON.add(row);
            }
            responseJSON.set("rows", arrayJSON);
        }
    } else {
        responseJSON.set("rows", arrayJSON);
    }
    try {
        // logger.debug(responseJSON.toString());
        return responseJSON.toString().getBytes("UTF-8");
    } catch (IOException e) {
        return responseJSON.toString().getBytes();
    }
}

From source file:com.hrm.controller.RegisterController.java

@RequestMapping("stuRegister")
@ResponseBody// w w  w  .  j a v a2  s  .c  om
public void StuRegister(@ModelAttribute StuModel stuRegisterModel, HttpSession session,
        HttpServletRequest request, HttpServletResponse response) throws IOException {
    /*???*/
    response.setContentType("application/json");
    int checkAmount = 0;
    PrintWriter out = response.getWriter();
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode register = mapper.createObjectNode();
    String StuAccount = request.getParameter("username");
    String agentId = request.getParameter("agentId");
    String StuPassword = string2MD5(request.getParameter("password"));
    String username = VerifyCodeUtil.getRandomString(16);
    String method = request.getParameter("method");
    String stuMsg = request.getParameter("stuMsg");
    if (agentId == null || agentId.equals("")) {
        agentId = "0";
    }
    if (method != null) {
        if (stuMsg != null) {
            if (session.getAttribute("telephoneCodeSession") != null
                    && session.getAttribute("telephoneSession") != null) {
                System.out.println(session.getAttribute("telephoneCodeSession"));
                System.out.println(session.getAttribute("telephoneSession"));
                if (session.getAttribute("telephoneCodeSession").equals(stuMsg)
                        && session.getAttribute("telephoneSession").equals(StuAccount)) {
                    checkAmount = IComServiceImplRegister.accountCheckService(
                            StuAccount);/*??checkAmount1??*/
                    if (checkAmount == 0) {
                        System.out.print("agentId:" + agentId);
                        stuRegisterModel = StuService.saveStuInfo(StuAccount, StuPassword, username, agentId);
                        if (stuRegisterModel != null) {
                            stuRegisterModel.setPassword(null);
                            session.setAttribute("loginInfoSession", stuRegisterModel);
                            register.put("status", "??");
                            /*out.write(mapper.writeValueAsString(stuRegisterModel));*//*?*/
                            out.write(register.toString());
                        } else {
                            register.put("status", "??");
                            out.write(register.toString());
                        }
                    } else {
                        register.put("status", "?");
                        out.write(register.toString());/*?*/
                    }
                } else {
                    register.put("status", "???");
                    out.write(register.toString());
                }
            } else {
                register.put("status", "??????");
                out.write(register.toString());
            }
        } else {
            register.put("status", "???");
            out.write(register.toString());
        }
    } else {/*PC*/
        checkAmount = IComServiceImplRegister.accountCheckService(
                StuAccount);/*??checkAmount1??*/
        if (checkAmount == 0) {
            System.out.print("agentId:" + agentId);
            if (session.getAttribute("telephoneCodeSession").equals(stuMsg)
                    && session.getAttribute("telephoneSession").equals(StuAccount)) {
                stuRegisterModel = StuService.saveStuInfo(StuAccount, StuPassword, username, agentId);//
                if (stuRegisterModel != null) {
                    stuRegisterModel.setPassword(null);
                    session.setAttribute("loginInfoSession", stuRegisterModel);
                    session.setAttribute("accountLableInfoSession", "stu");
                    System.out.println(JSONObject.fromObject(stuRegisterModel));
                    register.put("registerStatus", "1");
                    register.put("accountClass", "stu");
                    out.write(register.toString());/*?*/
                } else {
                    System.out.print("??");
                    register.put("registerStatus", "0");
                    out.write(register.toString());/*?*/
                }
            } else {
                System.out.print("?????");
                register.put("registerStatus", "2");
                out.write(register.toString());/*?*/
            }
        } else {
            System.out.print("?");
            register.put("registerStatus", "-1");
            out.write(register.toString());/*?*/
        }
    }
}

From source file:com.marklogic.client.functionaltest.TestBiTemporal.java

private JacksonDatabindHandle<ObjectNode> getJSONDocumentHandle(String startValidTime, String endValidTime,
        String address, String uri) throws Exception {

    // Setup for JSON document
    /**//w  w  w . j  a v a 2s . c  o  m
     * 
     { "System": { systemStartERIName : "", systemEndERIName : "", }, "Valid":
     * { validStartERIName: "2001-01-01T00:00:00", validEndERIName:
     * "2011-12-31T23:59:59" }, "Address": "999 Skyway Park", "uri":
     * "javaSingleDoc1.json" }
     */

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode rootNode = mapper.createObjectNode();

    // Set system time values
    ObjectNode system = mapper.createObjectNode();

    system.put(systemStartERIName, "");
    system.put(systemEndERIName, "");
    rootNode.set(systemNodeName, system);

    // Set valid time values
    ObjectNode valid = mapper.createObjectNode();

    valid.put(validStartERIName, startValidTime);
    valid.put(validEndERIName, endValidTime);
    rootNode.set(validNodeName, valid);

    // Set Address
    rootNode.put(addressNodeName, address);

    // Set uri
    rootNode.put(uriNodeName, uri);

    System.out.println(rootNode.toString());

    JacksonDatabindHandle<ObjectNode> handle = new JacksonDatabindHandle<ObjectNode>(ObjectNode.class)
            .withFormat(Format.JSON);
    handle.set(rootNode);

    return handle;
}

From source file:io.gs2.matchmaking.Gs2MatchmakingClient.java

/**
 * ??????<br>/*ww w.j  a  va2s. co  m*/
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public CreateMatchmakingResult createMatchmaking(CreateMatchmakingRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("name", request.getName())
            .put("serviceClass", request.getServiceClass()).put("type", request.getType())
            .put("maxPlayer", request.getMaxPlayer());
    if (request.getDescription() != null)
        body.put("description", request.getDescription());
    if (request.getGatheringPoolName() != null)
        body.put("gatheringPoolName", request.getGatheringPoolName());
    if (request.getCallback() != null)
        body.put("callback", request.getCallback());
    if (request.getNotificationGameName() != null)
        body.put("notificationGameName", request.getNotificationGameName());
    if (request.getCreateGatheringTriggerScript() != null)
        body.put("createGatheringTriggerScript", request.getCreateGatheringTriggerScript());
    if (request.getCreateGatheringDoneTriggerScript() != null)
        body.put("createGatheringDoneTriggerScript", request.getCreateGatheringDoneTriggerScript());
    if (request.getJoinGatheringTriggerScript() != null)
        body.put("joinGatheringTriggerScript", request.getJoinGatheringTriggerScript());
    if (request.getJoinGatheringDoneTriggerScript() != null)
        body.put("joinGatheringDoneTriggerScript", request.getJoinGatheringDoneTriggerScript());
    if (request.getLeaveGatheringTriggerScript() != null)
        body.put("leaveGatheringTriggerScript", request.getLeaveGatheringTriggerScript());
    if (request.getLeaveGatheringDoneTriggerScript() != null)
        body.put("leaveGatheringDoneTriggerScript", request.getLeaveGatheringDoneTriggerScript());
    if (request.getBreakupGatheringTriggerScript() != null)
        body.put("breakupGatheringTriggerScript", request.getBreakupGatheringTriggerScript());
    if (request.getMatchmakingCompleteTriggerScript() != null)
        body.put("matchmakingCompleteTriggerScript", request.getMatchmakingCompleteTriggerScript());

    HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/matchmaking", credential, ENDPOINT,
            CreateMatchmakingRequest.Constant.MODULE, CreateMatchmakingRequest.Constant.FUNCTION,
            body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(post, CreateMatchmakingResult.class);

}

From source file:com.glaf.mail.web.rest.MailTaskResource.java

@GET
@POST/* w  w  w .  ja v  a  2 s . c  o  m*/
@Path("/list")
@ResponseBody
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
public byte[] list(@Context HttpServletRequest request) {
    Map<String, Object> params = RequestUtils.getParameterMap(request);
    MailTaskQuery query = new MailTaskQuery();
    Tools.populate(query, params);

    logger.debug("params:" + params);

    String gridType = ParamUtils.getString(params, "gridType");
    if (gridType == null) {
        gridType = "easyui";
    }
    int start = 0;
    int limit = 10;
    String orderName = null;
    String order = null;
    if ("easyui".equals(gridType)) {
        int pageNo = ParamUtils.getInt(params, "page");
        limit = ParamUtils.getInt(params, "rows");
        start = (pageNo - 1) * limit;
        orderName = ParamUtils.getString(params, "sort");
        order = ParamUtils.getString(params, "order");
    } else if ("extjs".equals(gridType)) {
        start = ParamUtils.getInt(params, "start");
        limit = ParamUtils.getInt(params, "limit");
        orderName = ParamUtils.getString(params, "sort");
        order = ParamUtils.getString(params, "dir");
    } else if ("yui".equals(gridType)) {
        start = ParamUtils.getInt(params, "startIndex");
        limit = ParamUtils.getInt(params, "results");
        orderName = ParamUtils.getString(params, "sort");
        order = ParamUtils.getString(params, "dir");
    }

    if (start < 0) {
        start = 0;
    }

    if (limit <= 0) {
        limit = Paging.DEFAULT_PAGE_SIZE;
    }

    query.createBy(RequestUtils.getActorId(request));

    ObjectNode responseJSON = new ObjectMapper().createObjectNode();
    int total = mailTaskService.getMailTaskCountByQueryCriteria(query);
    if (total > 0) {
        responseJSON.put("total", total);
        responseJSON.put("totalCount", total);
        responseJSON.put("totalRecords", total);
        responseJSON.put("start", start);
        responseJSON.put("startIndex", start);
        responseJSON.put("limit", limit);
        responseJSON.put("pageSize", limit);

        if (StringUtils.isNotEmpty(orderName)) {
            query.setSortOrder(orderName);
            if (StringUtils.equals(order, "desc")) {
                query.setSortOrder("desc");
            }
        }

        List<MailTask> list = mailTaskService.getMailTasksByQueryCriteria(start, limit, query);

        if (list != null && !list.isEmpty()) {
            ArrayNode rowsJSON = new ObjectMapper().createArrayNode();
            if ("yui".equals(gridType)) {
                responseJSON.set("records", rowsJSON);
            } else {
                responseJSON.set("rows", rowsJSON);
            }

            for (MailTask mailTask : list) {
                ObjectNode rowJSON = new ObjectMapper().createObjectNode();
                rowJSON.put("id", mailTask.getId());
                rowJSON.put("taskId", mailTask.getId());

                if (mailTask.getSubject() != null) {
                    rowJSON.put("subject", mailTask.getSubject());
                }

                if (mailTask.getCallbackUrl() != null) {
                    rowJSON.put("callbackUrl", mailTask.getCallbackUrl());
                }

                rowJSON.put("threadSize", mailTask.getThreadSize());

                rowJSON.put("locked", mailTask.getLocked());

                rowJSON.put("delayTime", mailTask.getDelayTime());

                if (mailTask.getStartDate() != null) {
                    rowJSON.put("startDate", DateUtils.getDateTime(mailTask.getStartDate()));
                }

                if (mailTask.getEndDate() != null) {
                    rowJSON.put("endDate", DateUtils.getDateTime(mailTask.getEndDate()));
                }

                rowJSON.put("isHtml", mailTask.isHtml());

                rowJSON.put("isBack", mailTask.isBack());

                rowJSON.put("isUnSubscribe", mailTask.isUnSubscribe());

                rowsJSON.add(rowJSON);
            }

        }
    }
    try {
        return responseJSON.toString().getBytes("UTF-8");
    } catch (IOException e) {
        return responseJSON.toString().getBytes();
    }
}

From source file:io.gs2.matchmaking.Gs2MatchmakingClient.java

/**
 * ????<br>//from w  w w  . jav  a  2  s.  c  om
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public UpdateMatchmakingResult updateMatchmaking(UpdateMatchmakingRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("serviceClass", request.getServiceClass());
    if (request.getDescription() != null)
        body.put("description", request.getDescription());
    if (request.getGatheringPoolName() != null)
        body.put("gatheringPoolName", request.getGatheringPoolName());
    if (request.getCallback() != null)
        body.put("callback", request.getCallback());
    if (request.getNotificationGameName() != null)
        body.put("notificationGameName", request.getNotificationGameName());
    if (request.getCreateGatheringTriggerScript() != null)
        body.put("createGatheringTriggerScript", request.getCreateGatheringTriggerScript());
    if (request.getCreateGatheringDoneTriggerScript() != null)
        body.put("createGatheringDoneTriggerScript", request.getCreateGatheringDoneTriggerScript());
    if (request.getJoinGatheringTriggerScript() != null)
        body.put("joinGatheringTriggerScript", request.getJoinGatheringTriggerScript());
    if (request.getJoinGatheringDoneTriggerScript() != null)
        body.put("joinGatheringDoneTriggerScript", request.getJoinGatheringDoneTriggerScript());
    if (request.getLeaveGatheringTriggerScript() != null)
        body.put("leaveGatheringTriggerScript", request.getLeaveGatheringTriggerScript());
    if (request.getLeaveGatheringDoneTriggerScript() != null)
        body.put("leaveGatheringDoneTriggerScript", request.getLeaveGatheringDoneTriggerScript());
    if (request.getBreakupGatheringTriggerScript() != null)
        body.put("breakupGatheringTriggerScript", request.getBreakupGatheringTriggerScript());
    if (request.getMatchmakingCompleteTriggerScript() != null)
        body.put("matchmakingCompleteTriggerScript", request.getMatchmakingCompleteTriggerScript());
    HttpPut put = createHttpPut(
            Gs2Constant.ENDPOINT_HOST + "/matchmaking/"
                    + (request.getMatchmakingName() == null || request.getMatchmakingName().equals("") ? "null"
                            : request.getMatchmakingName())
                    + "",
            credential, ENDPOINT, UpdateMatchmakingRequest.Constant.MODULE,
            UpdateMatchmakingRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        put.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(put, UpdateMatchmakingResult.class);

}

From source file:com.glaf.dts.web.rest.MxTableResource.java

@GET
@POST/* w w w.  ja  v a2 s.  c o m*/
@Path("/list")
@ResponseBody
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
public byte[] list(@Context HttpServletRequest request, @Context UriInfo uriInfo) {
    Map<String, Object> params = RequestUtils.getParameterMap(request);
    TableDefinitionQuery query = new TableDefinitionQuery();
    Tools.populate(query, params);
    query.setType(Constants.DTS_TASK_TYPE);
    List<TableDefinition> tables = tableDefinitionService.list(query);
    ObjectNode responseJSON = new ObjectMapper().createObjectNode();

    ArrayNode tablesJSON = new ObjectMapper().createArrayNode();
    responseJSON.set("tables", tablesJSON);

    for (TableDefinition table : tables) {
        ObjectNode tableJSON = new ObjectMapper().createObjectNode();
        tableJSON.put("tableName", table.getTableName());
        tableJSON.put("tableName_enc", RequestUtils.encodeString(table.getTableName()));
        tableJSON.put("title", table.getTitle());
        if (table.getDescription() != null) {
            tableJSON.put("description", table.getDescription());
        }
        tableJSON.put("locked", table.getLocked());
        tableJSON.put("revision", table.getRevision());
        if (table.getCreateBy() != null) {
            tableJSON.put("createBy", table.getCreateBy());
        }
        tableJSON.put("createTime", DateUtils.getDateTime(table.getCreateTime()));
        tablesJSON.add(tableJSON);

        table = tableDefinitionService.getTableDefinition(table.getTableName());

        ArrayNode columnsJSON = new ObjectMapper().createArrayNode();

        for (ColumnDefinition column : table.getColumns()) {
            ObjectNode columnJSON = new ObjectMapper().createObjectNode();
            columnJSON.put("columnName", column.getColumnName());
            if (column.getTitle() != null) {
                columnJSON.put("title", column.getTitle());
            }
            if (column.getValueExpression() != null) {
                columnJSON.put("valueExpression", column.getValueExpression());
            }
            if (column.getFormula() != null) {
                columnJSON.put("formula", column.getFormula());
            }
            if (column.getJavaType() != null) {
                columnJSON.put("javaType", column.getJavaType());
            }
            if (column.getTranslator() != null) {
                columnJSON.put("translator", column.getTranslator());
            }
            if (column.getName() != null) {
                columnJSON.put("name", column.getName());
            }
            if (column.getRegex() != null) {
                columnJSON.put("regex", column.getRegex());
            }
            columnJSON.put("length", column.getLength());
            columnJSON.put("ordinal", column.getOrdinal());
            columnJSON.put("precision", column.getPrecision());
            columnJSON.put("scale", column.getScale());
            columnsJSON.add(columnJSON);
        }

        tableJSON.set("columns", columnsJSON);
    }

    try {
        return responseJSON.toString().getBytes("UTF-8");
    } catch (IOException e) {
        return responseJSON.toString().getBytes();
    }
}

From source file:io.gs2.matchmaking.Gs2MatchmakingClient.java

/**
 * ????<br>/*from ww  w  . ja v a 2 s.  co m*/
 * <br>
 * ??5????????<br>
 * ?????5??????????????????????<br>
 * <br>
 * ????????? done ? true ???<br>
 * done ? true ???????? item ????????????<br>
 * <br>
 * done ? false ???????????????????<br>
 * ????searchContext ????????<br>
 * ??????????API??????????????????<br>
 * <br>
 * ???????????????????????? done ? true ???<br>
 * <br>
 * - : 10<br>
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public CustomAutoDoMatchmakingResult customAutoDoMatchmaking(CustomAutoDoMatchmakingRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode();
    if (request.getAttribute1() != null)
        body.put("attribute1", request.getAttribute1());
    if (request.getAttribute2() != null)
        body.put("attribute2", request.getAttribute2());
    if (request.getAttribute3() != null)
        body.put("attribute3", request.getAttribute3());
    if (request.getAttribute4() != null)
        body.put("attribute4", request.getAttribute4());
    if (request.getAttribute5() != null)
        body.put("attribute5", request.getAttribute5());
    if (request.getSearchAttribute1Min() != null)
        body.put("searchAttribute1Min", request.getSearchAttribute1Min());
    if (request.getSearchAttribute2Min() != null)
        body.put("searchAttribute2Min", request.getSearchAttribute2Min());
    if (request.getSearchAttribute3Min() != null)
        body.put("searchAttribute3Min", request.getSearchAttribute3Min());
    if (request.getSearchAttribute4Min() != null)
        body.put("searchAttribute4Min", request.getSearchAttribute4Min());
    if (request.getSearchAttribute5Min() != null)
        body.put("searchAttribute5Min", request.getSearchAttribute5Min());
    if (request.getSearchAttribute1Max() != null)
        body.put("searchAttribute1Max", request.getSearchAttribute1Max());
    if (request.getSearchAttribute2Max() != null)
        body.put("searchAttribute2Max", request.getSearchAttribute2Max());
    if (request.getSearchAttribute3Max() != null)
        body.put("searchAttribute3Max", request.getSearchAttribute3Max());
    if (request.getSearchAttribute4Max() != null)
        body.put("searchAttribute4Max", request.getSearchAttribute4Max());
    if (request.getSearchAttribute5Max() != null)
        body.put("searchAttribute5Max", request.getSearchAttribute5Max());
    if (request.getSearchContext() != null)
        body.put("searchContext", request.getSearchContext());

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

    post.setHeader("X-GS2-ACCESS-TOKEN", request.getAccessToken());

    return doRequest(post, CustomAutoDoMatchmakingResult.class);

}

From source file:com.glaf.mail.web.rest.MailStorageResource.java

@GET
@POST/*from w w  w  . j ava  2 s .  co m*/
@Path("/list")
@ResponseBody
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
public byte[] list(@Context HttpServletRequest request) {
    Map<String, Object> params = RequestUtils.getParameterMap(request);
    MailStorageQuery query = new MailStorageQuery();
    Tools.populate(query, params);

    String gridType = ParamUtils.getString(params, "gridType");
    if (gridType == null) {
        gridType = "easyui";
    }
    int start = 0;
    int limit = 10;
    String orderName = null;
    String order = null;
    if ("easyui".equals(gridType)) {
        int pageNo = ParamUtils.getInt(params, "page");
        limit = ParamUtils.getInt(params, "rows");
        start = (pageNo - 1) * limit;
        orderName = ParamUtils.getString(params, "sort");
        order = ParamUtils.getString(params, "order");
    } else if ("extjs".equals(gridType)) {
        start = ParamUtils.getInt(params, "start");
        limit = ParamUtils.getInt(params, "limit");
        orderName = ParamUtils.getString(params, "sort");
        order = ParamUtils.getString(params, "dir");
    } else if ("yui".equals(gridType)) {
        start = ParamUtils.getInt(params, "startIndex");
        limit = ParamUtils.getInt(params, "results");
        orderName = ParamUtils.getString(params, "sort");
        order = ParamUtils.getString(params, "dir");
    }

    if (start < 0) {
        start = 0;
    }

    if (limit <= 0) {
        limit = Paging.DEFAULT_PAGE_SIZE;
    }

    ObjectNode responseJSON = new ObjectMapper().createObjectNode();
    int total = mailStorageService.getMailStorageCountByQueryCriteria(query);
    if (total > 0) {
        responseJSON.put("total", total);
        responseJSON.put("totalCount", total);
        responseJSON.put("totalRecords", total);
        responseJSON.put("start", start);
        responseJSON.put("startIndex", start);
        responseJSON.put("limit", limit);
        responseJSON.put("pageSize", limit);

        if (StringUtils.isNotEmpty(orderName)) {
            query.setSortOrder(orderName);
            if (StringUtils.equals(order, "desc")) {
                query.setSortOrder("desc");
            }
        }

        List<MailStorage> list = mailStorageService.getMailStoragesByQueryCriteria(start, limit, query);

        if (list != null && !list.isEmpty()) {
            ArrayNode rowsJSON = new ObjectMapper().createArrayNode();
            if ("yui".equals(gridType)) {
                responseJSON.set("records", rowsJSON);
            } else {
                responseJSON.set("rows", rowsJSON);
            }

            for (MailStorage mailStorage : list) {
                ObjectNode rowJSON = new ObjectMapper().createObjectNode();
                rowJSON.put("id", mailStorage.getId());
                rowJSON.put("mailStorageId", mailStorage.getId());

                if (mailStorage.getSubject() != null) {
                    rowJSON.put("subject", mailStorage.getSubject());
                }
                if (mailStorage.getDataSpace() != null) {
                    rowJSON.put("dataSpace", mailStorage.getDataSpace());
                }
                if (mailStorage.getDataTable() != null) {
                    rowJSON.put("dataTable", mailStorage.getDataTable());
                }
                if (mailStorage.getStorageType() != null) {
                    rowJSON.put("storageType", mailStorage.getStorageType());
                }
                if (mailStorage.getHost() != null) {
                    rowJSON.put("host", mailStorage.getHost());
                }
                rowJSON.put("port", mailStorage.getPort());
                if (mailStorage.getUsername() != null) {
                    rowJSON.put("username", mailStorage.getUsername());
                }
                if (mailStorage.getPassword() != null) {
                    rowJSON.put("password", mailStorage.getPassword());
                }
                if (mailStorage.getStatus() != null) {
                    rowJSON.put("status ", mailStorage.getStatus());
                }
                if (mailStorage.getCreateBy() != null) {
                    rowJSON.put("createBy", mailStorage.getCreateBy());
                }
                if (mailStorage.getCreateDate() != null) {
                    rowJSON.put("createDate", DateUtils.getDateTime(mailStorage.getCreateDate()));
                }
                rowsJSON.add(rowJSON);
            }

        }
    }
    try {
        return responseJSON.toString().getBytes("UTF-8");
    } catch (IOException e) {
        return responseJSON.toString().getBytes();
    }
}