當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjectNode.toString方法代碼示例

本文整理匯總了Java中org.codehaus.jackson.node.ObjectNode.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectNode.toString方法的具體用法?Java ObjectNode.toString怎麽用?Java ObjectNode.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.codehaus.jackson.node.ObjectNode的用法示例。


在下文中一共展示了ObjectNode.toString方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: deserialize

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
@Override
public Directive deserialize(JsonParser jp, DeserializationContext ctx)
        throws IOException {
    ObjectReader reader = ObjectMapperUtil.instance().getObjectReader();
    ObjectNode obj = (ObjectNode) reader.readTree(jp);
    Iterator<Map.Entry<String, JsonNode>> elementsIterator = obj.getFields();

    String rawMessage = obj.toString();
    DialogRequestIdHeader header = null;
    JsonNode payloadNode = null;
    ObjectReader headerReader =
            ObjectMapperUtil.instance().getObjectReader(DialogRequestIdHeader.class);
    while (elementsIterator.hasNext()) {
        Map.Entry<String, JsonNode> element = elementsIterator.next();
        if (element.getKey().equals("header")) {
            header = headerReader.readValue(element.getValue());
        }
        if (element.getKey().equals("payload")) {
            payloadNode = element.getValue();
        }
    }
    if (header == null) {
        throw ctx.mappingException("Missing header");
    }
    if (payloadNode == null) {
        throw ctx.mappingException("Missing payload");
    }

    return createDirective(header, payloadNode, rawMessage);
}
 
開發者ID:dueros,項目名稱:dcs-sdk-java,代碼行數:31,代碼來源:Directive.java

示例2: createAuthLinkResponse

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
public static String createAuthLinkResponse(){

        JsonNodeFactory f = JsonNodeFactory.instance ;
        ObjectNode loginResponse = f.objectNode();
        loginResponse.put("text","Authorization for SkyGiraffe to use Slack details is required.");
        ArrayNode attachments = loginResponse.putArray("attachments");
        ObjectNode att = f.objectNode();
        att.put("fallback", "Please authorize SkyGiraffe to access to your Slack details ...");
        att.put("pretext", "");
        att.put("title", "Please authorize..");
        att.put("title_link", Config.getPropertyValue("SLACK_AUTH_URL_DEV"));
        att.put("text","Once authorized and logged into SkyGiraffe try '/sg help' to see all commands");
        att.put("color", "#7CD197");

        attachments.add(att);
        return loginResponse.toString();

    }
 
開發者ID:skygiraffe,項目名稱:skygiraffe-slackbot,代碼行數:19,代碼來源:JsonUtil.java

示例3: createLoginLinkResponse

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
/**
 * {
 "attachments": [
 {
 "fallback": "Please login into SkyGiraffe to continue ...",
 "pretext": "SkyGiraffe Login",
 "title": "Please login into SkyGiraffe to continue ...",
 "title_link": "https://sgbot-mobilityai.rhcloud.com/SGbot-1.0/skyg/login?key=",
 "text": "Once logged in try '/sg help' to see all commands",
 "color": "#7CD197"
 }
 ]
 }
 * @return
 */
public static String createLoginLinkResponse(String slackUserId, String email, String teamId){

    JsonNodeFactory f = JsonNodeFactory.instance ;
    ObjectNode loginResponse = f.objectNode();
    loginResponse.put("text","Login to SkyGiraffe is required.");
    ArrayNode attachments = loginResponse.putArray("attachments");
    ObjectNode att = f.objectNode();
    att.put("fallback", "Please login into SkyGiraffe to continue ...");
    att.put("pretext", "");
    att.put("title", "Please login..");
    att.put("title_link", Config.getPropertyValue("SGDS_LOGIN_URL_DEV")+slackUserId+"&EMAIL="+email+"&TEAMID="+teamId);
    att.put("text","Once logged in try '/sg help' to see all commands");
    att.put("color", "#7CD197");

    attachments.add(att);

    return loginResponse.toString();

}
 
開發者ID:skygiraffe,項目名稱:skygiraffe-slackbot,代碼行數:35,代碼來源:JsonUtil.java

示例4: authenticate

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
public static String authenticate(String userName, String password) throws IOException {
    if (userName == null || userName.isEmpty())
        userName = SGSlackConstants.DEFAULT_USER;
    if (password == null || password.isEmpty())
        password = SGSlackConstants.PASSWORD;

    ObjectMapper m = new ObjectMapper();
    ObjectNode o = m.createObjectNode();
    o.put("UserName",userName);
    o.put("Password",password);
    o.put("OS","webapp");
    o.put("Version","4006000");

    StringEntity input = new StringEntity(o.toString());

    SGDSAuthRes ss = new SGDSAuthRes();
    ss = m.readValue(postSGDS("Authenticate",input), ss.getClass());

    logger.debug("Session id on authentication="+ss.getSessionID());
    return ss.getSessionID();
}
 
開發者ID:skygiraffe,項目名稱:skygiraffe-slackbot,代碼行數:22,代碼來源:SGDSClient.java

示例5: postRealTimeData

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
public static boolean postRealTimeData(HttpClient client, String url, String deviceToken) throws ParseException, IOException {
  HttpPost post = new HttpPost(url);
  post.addHeader("Cookie", Constants.X_SMS_AUTH_TOKEN + "=" + deviceToken);

  long MINS_AHEAD = 1000 * 60 * 30;   // Pretend we have 30 minutes of print time left
  int jobsInQueue = 6;                // and 6 jobs left in the queue
  String status = "DS_PRINTING";      // and we're currently printing

  Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
  Timestamp printCompleteTime = new Timestamp(cal.getTime().getTime() + MINS_AHEAD);
  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
  String date = format.format(printCompleteTime.getTime());

  ObjectMapper mapper = new org.codehaus.jackson.map.ObjectMapper();
  ObjectNode jsonNode = mapper.createObjectNode();

  jsonNode.put("deviceStatus", status);
  jsonNode.put("totalJobs", jobsInQueue);
  jsonNode.put("printTimeComplete", date);

  StringEntity entity = new StringEntity(jsonNode.toString());
  post.setEntity(entity);

  HttpResponse response = HttpClientWrapper.executeHttpCommand(client, post);
  if (response != null) {
    if (response.getStatusLine().getStatusCode() != 204) {
      HttpClientWrapper.logErrorResponse(response, "Failed To post data");
      return false;
    } else {
      EntityUtils.consumeQuietly(response.getEntity());
      log.info("Sucessfully posted data");
      System.out.println("Successfully posted data.");
      return false;
    }
  } else {
    log.error("No response returned from post data");
    return false;
  }
}
 
開發者ID:HPInc,項目名稱:printos-device-api-example-java,代碼行數:40,代碼來源:Device.java

示例6: loginAndGetToken

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
public static String loginAndGetToken(HttpClient client, String url, String login, String password)
  throws ParseException, IOException
{
  String token = null;
  HttpPost loginPost = new HttpPost(url);

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

  jsonNode.put("login", login);
  jsonNode.put("password", password);

  StringEntity entity = new StringEntity(jsonNode.toString());
  loginPost.setEntity(entity);

  HttpResponse response = HttpClientWrapper.executeHttpCommand(client, loginPost);
  if (response != null)
  {
    if(response.getStatusLine().getStatusCode() == 200)
    {
      token = HttpClientWrapper.getTokenFromResponse(response);
      EntityUtils.consumeQuietly(response.getEntity());
    }
    else {
      HttpClientWrapper.logErrorResponse(response, "Failed To login");
    }
  }else {
    log.error("No response returned from login call");
  }

  return token;
}
 
開發者ID:HPInc,項目名稱:printos-device-api-example-java,代碼行數:33,代碼來源:User.java

示例7: getAppList

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
public static String getAppList(String sessionId) throws IOException {

        if (sessionId == null || sessionId.isEmpty())
            throw new IllegalArgumentException("Session Id is empty. Please login.");

        ObjectMapper m = new ObjectMapper();
        ObjectNode o = m.createObjectNode();
        o.put("SessionID",sessionId);
        StringEntity inputApps = new StringEntity(o.toString());
        return postSGDS("GetAppsList", inputApps);
    }
 
開發者ID:skygiraffe,項目名稱:skygiraffe-slackbot,代碼行數:12,代碼來源:SGDSClient.java

示例8: getLogSearch

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
@Path("dataTable/{index-name}/{search-handle}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getDataTableData
    (
        @PathParam("index-name") String indexName,
        @PathParam("search-handle") String searchHandle,
        @QueryParam("iDisplayStart") int iDisplayStart,
        @QueryParam("iDisplayLength") int iDisplayLength,
        @QueryParam("sEcho") String sEcho
    ) throws Exception
{
    LogSearch logSearch = getLogSearch(indexName);
    if ( logSearch == null )
    {
        return "{}";
    }
    ObjectNode          node;
    try
    {
        CachedSearch        cachedSearch = logSearch.getCachedSearch(searchHandle);
        DateFormat          dateFormatter = new SimpleDateFormat(DATE_FORMAT_STR);
        ArrayNode           dataTab = JsonNodeFactory.instance.arrayNode();
        for ( int i = iDisplayStart; i < (iDisplayStart + iDisplayLength); ++i )
        {
            if ( i < cachedSearch.getTotalHits() )
            {
                ObjectNode      data = JsonNodeFactory.instance.objectNode();
                int             docId = cachedSearch.getNthDocId(i);
                SearchItem      item = logSearch.toResult(docId);
                
                data.put("DT_RowId", "index-query-result-" + docId);
                data.put("0", getTypeName(EntryTypes.getFromId(item.getType())));
                data.put("1", dateFormatter.format(item.getDate()));
                data.put("2", trimPath(item.getPath()));

                dataTab.add(data);
            }
        }

        node = JsonNodeFactory.instance.objectNode();
        node.put("sEcho", sEcho);
        node.put("iTotalRecords", logSearch.getDocQty());
        node.put("iTotalDisplayRecords", cachedSearch.getTotalHits());
        node.put("aaData", dataTab);
    }
    finally
    {
        context.getExhibitor().getIndexCache().releaseLogSearch(logSearch.getFile());
    }

    return node.toString();
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:54,代碼來源:IndexResource.java

示例9: getNodeData

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
@GET
@Path("node-data")
@Produces("application/json")
public String   getNodeData(@QueryParam("key") String key) throws Exception
{
    ObjectNode node = JsonNodeFactory.instance.objectNode();
    try
    {
        Stat stat = context.getExhibitor().getLocalConnection().checkExists().forPath(key);
        byte[]          bytes = context.getExhibitor().getLocalConnection().getData().storingStatIn(stat).forPath(key);

        if (bytes != null) {
            node.put("bytes", bytesToString(bytes));
            node.put("str", new String(bytes, "UTF-8"));
        } else {
            node.put("bytes", "");
            node.put("str", "");
        }
        node.put("stat", reflectToString(stat));
    }
    catch ( KeeperException.NoNodeException dummy )
    {
        node.put("bytes", "");
        node.put("str", "");
        node.put("stat", "* not found * ");
    }
    catch ( Throwable e )
    {
        node.put("bytes", "");
        node.put("str", "Exception");
        node.put("stat", e.getMessage());
    }
    return node.toString();
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:35,代碼來源:ExplorerResource.java

示例10: create

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
public static DeviceInfo create(String aaaPrefix, HttpClient client, String userToken,
                              Properties settings, Properties credentials) throws ParseException, IOException {
  String url = aaaPrefix + "/organizations/devices";
  String pspPassword = credentials.getProperty("psp_password");
  HttpPost post = new HttpPost(url);
  post.addHeader("Cookie", Constants.X_SMS_AUTH_TOKEN + "=" + userToken);

  // Device model and type must match correctly; see etc/devicelist.csv for a list of currently supported
  // combinations.  Note that serial number must be unique, or the same device will get replaced.

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

  String serialNumber = getSerialNumber(settings.getProperty("serial_number"));
  jsonNode.put("name", settings.getProperty("device_name"));
  jsonNode.put("description", settings.getProperty("device_description"));
  jsonNode.put("serialNumber", serialNumber);
  jsonNode.put("model", settings.getProperty("device_model"));
  jsonNode.put("type", settings.getProperty("device_type"));
  jsonNode.put("securityPassword", pspPassword);

  StringEntity entity = new StringEntity(jsonNode.toString());
  post.setEntity(entity);

  HttpResponse response = HttpClientWrapper.executeHttpCommand(client, post);
  if (response != null) {
    String resp = EntityUtils.toString(response.getEntity());

    if (response.getStatusLine().getStatusCode() == 200) {
      JsonParser jp = mapper.getJsonFactory().createJsonParser(resp);
      JsonNode rootNode = mapper.readTree(jp);
      JsonNode node = rootNode.findValue("credentials");
      JsonNode node2 = rootNode.findValue("device");
      String deviceId = node2.findValue("deviceId").getTextValue();

      String deviceLogin = null;
      String devicePassword = null;
      if (node == null || node.findValue("login") == null) {
        System.out.println("Device is marked as non-provisionable, no login/password will be returned.");
      } else {
        deviceLogin = node.findValue("login").getTextValue();
        devicePassword = node.findValue("password").getTextValue();
        System.out.println("device_login=" + deviceLogin);
        System.out.println("device_password=" + devicePassword);
      }

      System.out.println("device_id=" + deviceId);
      System.out.println("Device created successfully.  Remember these values, this is the only time they'll be shown.");
      EntityUtils.consumeQuietly(response.getEntity());
      return new DeviceInfo(deviceLogin, devicePassword, deviceId, serialNumber);

    } else {
      System.out.println("Error executing command.  Does that device already exist?");
      EntityUtils.consumeQuietly(response.getEntity());
      return null;
    }

  } else {
    System.out.println("No response returned from create device");
    return null;
  }
}
 
開發者ID:HPInc,項目名稱:printos-device-api-example-java,代碼行數:63,代碼來源:Device.java

示例11: getParameterList

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
public static String getParameterList(String sessionId, String appId, String repId, String repUpId) throws IOException {

        //
        if (sessionId == null || sessionId.isEmpty())
            throw new IllegalArgumentException("Session Id is empty. Please login.");

        HttpPost postRequest = new HttpPost("https://wspublisherv2https.skygiraffe.com/WSPublisherV2.svc/GetReport_ParametersMainScreen4");

        // add header
        postRequest.setHeader("Content-Type", "application/json");

        JsonNodeFactory f = JsonNodeFactory.instance;

        ObjectNode o = f.objectNode();

        o.put("ApplicationID", appId);
        o.put("ReportID", repId);
        o.put("TabID","");

        ArrayNode diuId = f.arrayNode();
        diuId = o.putArray("DataItemUpdateIDs");
        o.put("ReportUpdateID",repUpId);
        o.put("RequestID",sessionId);

        o.put("SessionID",sessionId);

        StringEntity inputApps = new StringEntity(o.toString());

        inputApps.setContentType("application/json");
        postRequest.setEntity(inputApps);

        CloseableHttpResponse responseParams = getHttpClient().execute(postRequest);
        String paramStr = "";
        try {
            HttpEntity entityApps = responseParams.getEntity();
            paramStr = EntityUtils.toString(entityApps, "UTF-8");
            EntityUtils.consume(entityApps);
        }finally{
            responseParams.close();
        }
        logger.debug("Params = "+paramStr);
        return paramStr;
    }
 
開發者ID:skygiraffe,項目名稱:skygiraffe-slackbot,代碼行數:44,代碼來源:SGDSClient.java


注:本文中的org.codehaus.jackson.node.ObjectNode.toString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。