예제 #1
0
 public void testEchoJson() {
   JsonObject obj = new JsonObject();
   obj.putString("foo", "bar");
   obj.putNumber("num", 12124);
   obj.putBoolean("x", true);
   obj.putBoolean("y", false);
   Handler<Message<JsonObject>> handler = echoHandler(obj);
   eb.send(ECHO_ADDRESS, obj, handler);
 }
예제 #2
0
 private JsonObject setDefaults(JsonObject config) {
   config = config.copy();
   // Set the defaults
   if (config.getNumber("session_timeout") == null) {
     config.putNumber("session_timeout", 5l * 1000);
   }
   if (config.getBoolean("insert_JSESSIONID") == null) {
     config.putBoolean("insert_JSESSIONID", true);
   }
   if (config.getNumber("heartbeat_period") == null) {
     config.putNumber("heartbeat_period", 25l * 1000);
   }
   if (config.getNumber("max_bytes_streaming") == null) {
     config.putNumber("max_bytes_streaming", 128 * 1024);
   }
   if (config.getString("prefix") == null) {
     config.putString("prefix", "/");
   }
   if (config.getString("library_url") == null) {
     config.putString("library_url", "http://cdn.sockjs.org/sockjs-0.2.1.min.js");
   }
   if (config.getArray("disabled_transports") == null) {
     config.putArray("disabled_transports", new JsonArray());
   }
   return config;
 }
예제 #3
0
  public void act(HashMap<String, Object> cmd) {
    if (cmd == null) return;

    JsonObject notif = new JsonObject();

    for (String key : cmd.keySet()) {
      Object value = cmd.get(key);

      if (value != null) {
        if (value instanceof byte[]) notif.putBinary(key, (byte[]) value);
        else if (value instanceof Boolean) notif.putBoolean(key, (Boolean) value);
        else if (value instanceof Number) notif.putNumber(key, (Number) value);
        else if (value instanceof String) notif.putString(key, (String) value);
        else if (value instanceof JsonArray) notif.putArray(key, (JsonArray) value);
      }
    }
    System.out.println("sent: \n" + notif.encode());
    push(notif);
  }