Java Code Examples for io.vertx.core.json.JsonObject#encode()

The following examples show how to use io.vertx.core.json.JsonObject#encode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonRpcHttpServiceLoginTest.java    From besu with Apache License 2.0 6 votes vote down vote up
@Test
public void loginDoesntPopulateJWTPayloadWithPassword()
    throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
  final RequestBody body =
      RequestBody.create(JSON, "{\"username\":\"user\",\"password\":\"pegasys\"}");
  final Request request = new Request.Builder().post(body).url(baseUrl + "/login").build();
  try (final Response resp = client.newCall(request).execute()) {
    assertThat(resp.code()).isEqualTo(200);
    assertThat(resp.message()).isEqualTo("OK");
    assertThat(resp.body().contentType()).isNotNull();
    assertThat(resp.body().contentType().type()).isEqualTo("application");
    assertThat(resp.body().contentType().subtype()).isEqualTo("json");
    final String bodyString = resp.body().string();
    assertThat(bodyString).isNotNull();
    assertThat(bodyString).isNotBlank();

    final JsonObject respBody = new JsonObject(bodyString);
    final String token = respBody.getString("token");
    assertThat(token).isNotNull();

    final JsonObject jwtPayload = decodeJwtPayload(token);
    final String jwtPayloadString = jwtPayload.encode();
    assertThat(jwtPayloadString.contains("password")).isFalse();
    assertThat(jwtPayloadString.contains("pegasys")).isFalse();
  }
}
 
Example 2
Source File: SearchHitEndableWriteStreamToJsonLine.java    From sfs with Apache License 2.0 6 votes vote down vote up
protected void write0(SearchHit data) {
    try {
        JsonObject jsonObject = new JsonObject()
                .put("_index", data.getIndex())
                .put("_type", data.getType())
                .put("_id", data.getId())
                .put("_source", new JsonObject(data.getSource()));
        String source = jsonObject.encode();
        checkState(!source.contains("\n"), "Record contains newline");
        byte[] bytes = source.getBytes(charset);
        bufferStreamConsumer.write(
                buffer(bytes.length + delimiter.length)
                        .appendBytes(bytes)
                        .appendBytes(delimiter));
    } catch (Throwable e) {
        handleError(e);
    }
}
 
Example 3
Source File: GreeterController.java    From knative-tutorial with Apache License 2.0 5 votes vote down vote up
@PostMapping("/")
public @ResponseBody
String eventGreet(@RequestBody String cloudEventJson) {
    count++;
    String greeterHost = String.format(RESPONSE_STRING_FORMAT, ""," Event ", HOSTNAME, count);
    JsonObject response = new JsonObject(cloudEventJson)
                              .put("host",greeterHost.replace("\n","").trim())
                              .put("time",SDF.format(new Date()));
    LOGGER.info("Event Message Received \n {}",response.encodePrettily());
    return response.encode();
}
 
Example 4
Source File: GraphiQLHandlerImpl.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
private String replacement(RoutingContext rc) {
  JsonObject json = new JsonObject();
  if (options.getGraphQLUri() != null) {
    json.put("graphQLUri", options.getGraphQLUri());
  }
  MultiMap headers = MultiMap.caseInsensitiveMultiMap();
  Map<String, String> fixedHeaders = options.getHeaders();
  if (fixedHeaders != null) {
    fixedHeaders.forEach(headers::add);
  }
  Function<RoutingContext, MultiMap> rh;
  synchronized (this) {
    rh = this.graphiQLRequestHeadersFactory;
  }
  MultiMap dynamicHeaders = rh.apply(rc);
  if (dynamicHeaders != null) {
    headers.addAll(dynamicHeaders);
  }
  if (!headers.isEmpty()) {
    JsonObject headersJson = new JsonObject();
    headers.forEach(header -> headersJson.put(header.getKey(), header.getValue()));
    json.put("headers", headersJson);
  }
  if (options.getQuery() != null) {
    json.put("query", options.getQuery());
  }
  if (options.getVariables() != null) {
    json.put("parameters", options.getVariables());
  }
  return json.encode();
}
 
Example 5
Source File: RbacSecurityContext.java    From enmasse with Apache License 2.0 5 votes vote down vote up
public static Principal getUserPrincipal(String username, String uid) {
    return () -> {
        JsonObject object = new JsonObject();
        object.put("username", username);
        object.put("uid", uid);
        return object.encode();
    };
}
 
Example 6
Source File: PersistAccount.java    From sfs with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<Optional<PersistentAccount>> call(final TransientAccount transientAccount) {

    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

    final JsonObject source = transientAccount.toJsonObject();

    String encoded;

    if (LOGGER.isDebugEnabled()) {
        encoded = source.encodePrettily();
        LOGGER.debug(format("Index Request {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.accountIndex(), transientAccount.getId(), encoded));
    } else {
        encoded = source.encode();
    }

    IndexRequestBuilder request = elasticSearch.get()
            .prepareIndex(
                    elasticSearch.accountIndex(),
                    elasticSearch.defaultType(),
                    transientAccount.getId())
            .setCreate(true)
            .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10))
            .setSource(encoded);

    return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout())
            .map(indexResponse -> {
                if (indexResponse.isPresent()) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s} = %s", indexResponse.get().getType(), indexResponse.get().getIndex(), transientAccount.getId(), Jsonify.toString(indexResponse.get())));
                    }
                    return of(fromIndexResponse(indexResponse.get(), source));
                } else {
                    LOGGER.debug(format("Index Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.accountIndex(), transientAccount.getId(), "null"));
                    return absent();
                }
            });
}
 
Example 7
Source File: UpdateAccount.java    From sfs with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<Optional<PersistentAccount>> call(final PersistentAccount persistentAccount) {

    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

    final JsonObject source = persistentAccount.toJsonObject();

    String encoded;

    if (LOGGER.isDebugEnabled()) {
        encoded = source.encodePrettily();
        LOGGER.debug(format("Index Request {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.accountIndex(), persistentAccount.getId(), persistentAccount.getPersistentVersion(), encoded));
    } else {
        encoded = source.encode();
    }

    IndexRequestBuilder request = elasticSearch.get()
            .prepareIndex(
                    elasticSearch.accountIndex(),
                    elasticSearch.defaultType(),
                    persistentAccount.getId())
            .setVersion(persistentAccount.getPersistentVersion())
            .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10))
            .setSource(encoded);

    return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout())
            .map(indexResponse -> {
                if (indexResponse.isPresent()) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.accountIndex(), persistentAccount.getId(), persistentAccount.getPersistentVersion(), Jsonify.toString(indexResponse.get())));
                    }
                    return of(fromIndexResponse(indexResponse.get(), source));
                } else {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.accountIndex(), persistentAccount.getId(), persistentAccount.getPersistentVersion(), "null"));
                    }
                    return absent();
                }
            });
}
 
Example 8
Source File: UpdateMasterKey.java    From sfs with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<Optional<PersistentMasterKey>> call(PersistentMasterKey persistentMasterKey) {
    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

    final JsonObject document = persistentMasterKey.toJsonObject();

    String encoded = document.encode();

    IndexRequestBuilder request = elasticSearch.get()
            .prepareIndex(
                    elasticSearch.masterKeyTypeIndex(),
                    elasticSearch.defaultType(),
                    persistentMasterKey.getId())
            .setVersion(persistentMasterKey.getPersistentVersion())
            .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10))
            .setSource(encoded);

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Index Request {%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.masterKeyTypeIndex(), Jsonify.toString(request)));
    }

    return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout())
            .map(indexResponse -> {
                if (indexResponse.isPresent()) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.masterKeyTypeIndex(), persistentMasterKey.getId(), Jsonify.toString(indexResponse.get())));
                    }
                    return of(fromIndexResponse(indexResponse.get(), document));
                } else {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.masterKeyTypeIndex(), persistentMasterKey.getId(), "null"));
                    }
                    return absent();
                }
            });
}
 
Example 9
Source File: PersistMasterKey.java    From sfs with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<Optional<PersistentMasterKey>> call(TransientMasterKey transientMasterKey) {
    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

    final JsonObject document = transientMasterKey.toJsonObject();

    String encoded = document.encode();


    IndexRequestBuilder request = elasticSearch.get()
            .prepareIndex(
                    elasticSearch.masterKeyTypeIndex(),
                    elasticSearch.defaultType(),
                    transientMasterKey.getId())
            .setCreate(true) // put only if absent
            .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10))
            .setSource(encoded);

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Index Request {%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.masterKeyTypeIndex(), Jsonify.toString(request)));
    }

    return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout())
            .map(indexResponse -> {
                if (indexResponse.isPresent()) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.masterKeyTypeIndex(), transientMasterKey.getId(), Jsonify.toString(indexResponse.get())));
                    }
                    return of(fromIndexResponse(indexResponse.get(), document));
                } else {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.masterKeyTypeIndex(), transientMasterKey.getId(), "null"));
                    }
                    return absent();
                }
            });
}
 
Example 10
Source File: JsonObjectConverter.java    From vertx-jooq with MIT License 4 votes vote down vote up
@Override
public String to(JsonObject userObject) {
    return userObject==null?null:userObject.encode();
}
 
Example 11
Source File: ListContainerKeys.java    From sfs with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<PersistentContainerKey> call(PersistentContainer persistentContainer) {

    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

    final JsonObject source = persistentContainer.toJsonObject();

    String encoded;

    if (LOGGER.isDebugEnabled()) {
        encoded = source.encodePrettily();
        LOGGER.debug(format("Search Request {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerKeyIndex(), persistentContainer.getId(), persistentContainer.getPersistentVersion(), encoded));
    } else {
        encoded = source.encode();
    }

    SearchRequestBuilder request =
            elasticSearch.get()
                    .prepareSearch(elasticSearch.containerKeyIndex())
                    .setTypes(elasticSearch.defaultType())
                    .setVersion(true)
                    .setQuery(termQuery("container_id", persistentContainer.getId()))
                    .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10))
                    .setSource(encoded);

    return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout())
            .flatMap(oSearchResponse -> {
                if (oSearchResponse.isPresent()) {
                    SearchResponse searchResponse = oSearchResponse.get();
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Search Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), persistentContainer.getId(), persistentContainer.getPersistentVersion(), Jsonify.toString(searchResponse)));
                    }
                    return from(searchResponse.getHits());
                } else {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), persistentContainer.getId(), persistentContainer.getPersistentVersion(), "null"));
                    }
                    return empty();
                }
            })
            .map(searchHitFields -> fromSearchHit(persistentContainer, searchHitFields));
}
 
Example 12
Source File: UpdateContainer.java    From sfs with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<Optional<PersistentContainer>> call(final PersistentContainer persistentContainer) {

    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

    final JsonObject source = persistentContainer.toJsonObject();

    String encoded;

    if (LOGGER.isDebugEnabled()) {
        encoded = source.encodePrettily();
        LOGGER.debug(format("Index Request {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), persistentContainer.getId(), persistentContainer.getPersistentVersion(), encoded));
    } else {
        encoded = source.encode();
    }

    IndexRequestBuilder request =
            elasticSearch.get()
                    .prepareIndex(
                            elasticSearch.containerIndex(),
                            elasticSearch.defaultType(),
                            persistentContainer.getId())
                    .setVersion(persistentContainer.getPersistentVersion())
                    .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10))
                    .setSource(encoded);

    return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout())
            .map(indexResponse -> {
                if (indexResponse.isPresent()) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), persistentContainer.getId(), persistentContainer.getPersistentVersion(), Jsonify.toString(indexResponse.get())));
                    }
                    return of(fromIndexResponse(persistentContainer.getParent(), indexResponse.get(), source));
                } else {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), persistentContainer.getId(), persistentContainer.getPersistentVersion(), "null"));
                    }
                    return absent();
                }
            });
}
 
Example 13
Source File: PersistContainer.java    From sfs with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<Optional<PersistentContainer>> call(final TransientContainer transientContainer) {

    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

    final JsonObject source = transientContainer.toJsonObject();

    String encoded;

    if (LOGGER.isDebugEnabled()) {
        encoded = source.encodePrettily();
        LOGGER.debug(format("Index Request {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), transientContainer.getId(), encoded));
    } else {
        encoded = source.encode();
    }


    IndexRequestBuilder request =
            elasticSearch.get()
                    .prepareIndex(
                            elasticSearch.containerIndex(),
                            elasticSearch.defaultType(),
                            transientContainer.getId())
                    .setCreate(true)
                    .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10))
                    .setSource(encoded);

    return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout())
            .map(indexResponse -> {
                if (indexResponse.isPresent()) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), transientContainer.getId(), Jsonify.toString(indexResponse.get())));
                    }
                    return of(fromIndexResponse(transientContainer.getParent(), indexResponse.get(), source));
                } else {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), transientContainer.getId(), "null"));
                    }
                    return absent();
                }
            });
}
 
Example 14
Source File: WebhookNotifierServiceImpl.java    From gravitee-management-rest-api with Apache License 2.0 4 votes vote down vote up
private String toJson(final Hook hook, final Map<String, Object> params) {
    JsonObject content = new JsonObject();
    //hook
    content.put("event", hook.name());
    content.put("scope", hook.getScope().name());
    //api
    if (params.containsKey(PARAM_API)) {
        Object api = params.get(PARAM_API);
        if (api != null) {
            JsonObject jsonApi = new JsonObject();
            jsonApi.put("id", api instanceof ApiModelEntity ? ((ApiModelEntity) api).getId() : ((ApiEntity) api).getId());
            jsonApi.put("name", api instanceof ApiModelEntity ? ((ApiModelEntity) api).getName() : ((ApiEntity) api).getName());
            jsonApi.put("version", api instanceof ApiModelEntity ? ((ApiModelEntity) api).getVersion() : ((ApiEntity) api).getVersion());
            content.put("api", jsonApi);
        }
    }
    // application
    if (params.containsKey(PARAM_APPLICATION)) {
        ApplicationEntity application = (ApplicationEntity )params.get(PARAM_APPLICATION);
        if (application != null) {
            JsonObject jsonApplication = new JsonObject();
            jsonApplication.put("id", application.getId());
            jsonApplication.put("name", application.getName());
            /*
            if (application.getType() != null) {
                jsonApplication.put("type", application.getType());
            }
            */
            content.put("application", jsonApplication);
        }
    }
    // owner
    if (params.containsKey(PARAM_OWNER)) {
        PrimaryOwnerEntity owner = (PrimaryOwnerEntity) params.get(PARAM_OWNER);
        if (owner != null) {
            JsonObject jsonOwner = new JsonObject();
            jsonOwner.put("id", owner.getId());
            jsonOwner.put("username", owner.getDisplayName());
            content.put("owner", jsonOwner);
        }
    }
    // plan
    if (params.containsKey(PARAM_PLAN)) {
        PlanEntity plan = (PlanEntity)params.get(PARAM_PLAN);
        if (plan != null) {
            JsonObject jsonPlan = new JsonObject();
            jsonPlan.put("id", plan.getId());
            jsonPlan.put("name", plan.getName());
            jsonPlan.put("security", plan.getSecurity());
            content.put("plan", jsonPlan);
        }
    }
    // subscription
    if (params.containsKey(PARAM_SUBSCRIPTION)) {
        SubscriptionEntity subscription = (SubscriptionEntity) params.get(PARAM_SUBSCRIPTION);
        if (subscription != null) {
            JsonObject jsonSubscription = new JsonObject();
            jsonSubscription.put("id", subscription.getId());
            jsonSubscription.put("status", subscription.getStatus());
            content.put("subscription", jsonSubscription);
        }
    }

    return content.encode();
}
 
Example 15
Source File: PersistObject.java    From sfs with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<Optional<PersistentObject>> call(TransientObject transientObject) {

    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

    PersistentContainer container = transientObject.getParent();

    String objectIndex = elasticSearch.objectIndex(container.getName());

    final JsonObject source = transientObject.toJsonObject();

    String encoded;

    if (LOGGER.isDebugEnabled()) {
        encoded = source.encodePrettily();
        LOGGER.debug(format("Index Request {%s,%s,%s} = %s", elasticSearch.defaultType(), objectIndex, transientObject.getId(), encoded));
    } else {
        encoded = source.encode();
    }

    IndexRequestBuilder request = elasticSearch.get()
            .prepareIndex(
                    objectIndex,
                    elasticSearch.defaultType(),
                    transientObject.getId())
            .setCreate(true)
            .setSource(encoded)
            .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10));

    return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout())
            .map(indexResponse -> {
                if (indexResponse.isPresent()) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s} = %s", elasticSearch.defaultType(), objectIndex, transientObject.getId(), Jsonify.toString(indexResponse.get())));
                    }
                    return of(fromIndexResponse(transientObject.getParent(), indexResponse.get(), source));
                } else {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s} = %s", elasticSearch.defaultType(), objectIndex, transientObject.getId(), "null"));
                    }
                    return absent();
                }
            });
}
 
Example 16
Source File: UpdateContainerKey.java    From sfs with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<Holder2<PersistentContainerKey, Optional<PersistentContainerKey>>> call(final PersistentContainerKey persistentContainerKey) {
    final JsonObject source = persistentContainerKey.toJsonObject();

    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

    String encoded;

    if (LOGGER.isDebugEnabled()) {
        encoded = source.encodePrettily();
        LOGGER.debug(format("Index Request {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerKeyIndex(), persistentContainerKey.getId(), persistentContainerKey.getPersistentVersion(), encoded));
    } else {
        encoded = source.encode();
    }

    IndexRequestBuilder request =
            elasticSearch.get()
                    .prepareIndex(
                            elasticSearch.containerKeyIndex(),
                            elasticSearch.defaultType(),
                            persistentContainerKey.getId())
                    .setVersion(persistentContainerKey.getPersistentVersion())
                    .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10))
                    .setSource(encoded);

    return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout())
            .map(indexResponse -> {
                Holder2<PersistentContainerKey, Optional<PersistentContainerKey>> output = new Holder2<>();
                output.value0 = persistentContainerKey;
                if (indexResponse.isPresent()) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerKeyIndex(), persistentContainerKey.getId(), persistentContainerKey.getPersistentVersion(), Jsonify.toString(indexResponse.get())));
                    }
                    output.value1 = of(fromIndexResponse(persistentContainerKey.getPersistentContainer(), indexResponse.get(), source));
                } else {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Index Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerKeyIndex(), persistentContainerKey.getId(), persistentContainerKey.getPersistentVersion(), "null"));
                    }
                    output.value1 = absent();
                }
                return output;
            });
}
 
Example 17
Source File: JsObject.java    From vertx-codetrans with Apache License 2.0 4 votes vote down vote up
@CodeTranslate
public void encode() throws Exception {
  JsonObject obj = new JsonObject().put("foo", "foo_value");
  JsonTest.o = obj.encode();
}
 
Example 18
Source File: UpdateServiceDef.java    From sfs with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<Optional<PersistentServiceDef>> call(final PersistentServiceDef persistentServiceDef) {

    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

    final String id = persistentServiceDef.getId();

    final JsonObject source = persistentServiceDef.toJsonObject();

    String encoded;

    if (LOGGER.isDebugEnabled()) {
        encoded = source.encodePrettily();
        LOGGER.debug(format("Request {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.serviceDefTypeIndex(), id, encoded));
    } else {
        encoded = source.encode();
    }


    IndexRequestBuilder request =
            elasticSearch.get()
                    .prepareIndex(
                            elasticSearch.serviceDefTypeIndex(),
                            elasticSearch.defaultType(),
                            id)
                    .setSource(encoded)
                    .setTTL(ttl)
                    .setVersion(persistentServiceDef.getVersion())
                    .setCreate(false)
                    .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10));

    return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout())
            .map(new Func1<Optional<IndexResponse>, Optional<PersistentServiceDef>>() {
                @Override
                public Optional<PersistentServiceDef> call(Optional<IndexResponse> oIndexResponse) {
                    if (oIndexResponse.isPresent()) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug(format("Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.serviceDefTypeIndex(), id, Jsonify.toString(oIndexResponse.get())));
                        }
                        return fromNullable(fromIndexResponse(oIndexResponse.get(), source));
                    } else {
                        LOGGER.debug(format("Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.serviceDefTypeIndex(), id, "null"));
                        return absent();
                    }
                }
            });
}
 
Example 19
Source File: PersistServiceDef.java    From sfs with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<Optional<PersistentServiceDef>> call(final TransientServiceDef transientServiceDef) {

    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

    final String id = transientServiceDef.getId();

    final JsonObject source = transientServiceDef.toJsonObject();

    String encoded;

    if (LOGGER.isDebugEnabled()) {
        encoded = source.encodePrettily();
        LOGGER.debug(format("Request {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.serviceDefTypeIndex(), id, encoded));
    } else {
        encoded = source.encode();
    }


    IndexRequestBuilder request =
            elasticSearch.get()
                    .prepareIndex(
                            elasticSearch.serviceDefTypeIndex(),
                            elasticSearch.defaultType(),
                            id)
                    .setSource(encoded)
                    .setTTL(ttl)
                    .setCreate(true)
                    .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10));

    return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout())
            .map(new Func1<Optional<IndexResponse>, Optional<PersistentServiceDef>>() {
                @Override
                public Optional<PersistentServiceDef> call(Optional<IndexResponse> oIndexResponse) {
                    if (oIndexResponse.isPresent()) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug(format("Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.serviceDefTypeIndex(), id, Jsonify.toString(oIndexResponse.get())));
                        }
                        return fromNullable(fromIndexResponse(oIndexResponse.get(), source));
                    } else {
                        LOGGER.debug(format("Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.serviceDefTypeIndex(), id, "null"));
                        return absent();
                    }
                }
            });
}
 
Example 20
Source File: ObjectToJsonObjectBinding.java    From vertx-jooq with MIT License 4 votes vote down vote up
@Override
public Object to(JsonObject u) {
    return u == null ? null : u.encode();
}