List of usage examples for io.vertx.core.json JsonObject put
public JsonObject put(String key, Object value)
From source file:org.eclipse.hono.util.EventBusMessage.java
License:Open Source License
/** * Serializes a correlation identifier to JSON. * <p>/* w w w.j ava 2s. c om*/ * Supported types for AMQP 1.0 correlation IDs are * {@code String}, {@code UnsignedLong}, {@code UUID} and {@code Binary}. * * @param id The identifier to encode. * @return The JSON representation of the identifier. * @throws NullPointerException if the correlation id is {@code null}. * @throws IllegalArgumentException if the type is not supported. */ private static JsonObject encodeIdToJson(final Object id) { Objects.requireNonNull(id); final JsonObject json = new JsonObject(); if (id instanceof String) { json.put(FIELD_CORRELATION_ID_TYPE, "string"); json.put(FIELD_CORRELATION_ID, id); } else if (id instanceof UnsignedLong) { json.put(FIELD_CORRELATION_ID_TYPE, "ulong"); json.put(FIELD_CORRELATION_ID, id.toString()); } else if (id instanceof UUID) { json.put(FIELD_CORRELATION_ID_TYPE, "uuid"); json.put(FIELD_CORRELATION_ID, id.toString()); } else if (id instanceof Binary) { json.put(FIELD_CORRELATION_ID_TYPE, "binary"); final Binary binary = (Binary) id; json.put(FIELD_CORRELATION_ID, Base64.getEncoder().encodeToString(binary.getArray())); } else { throw new IllegalArgumentException("type " + id.getClass().getName() + " is not supported"); } return json; }
From source file:org.eclipse.hono.util.MessageHelper.java
License:Open Source License
/** * Encodes the given ID object to JSON representation. Supported types for AMQP 1.0 correlation/messageIds are * String, UnsignedLong, UUID and Binary. * @param id the id to encode to JSON/*from w ww . j a v a2 s . co m*/ * @return a JsonObject containing the JSON represenatation * @throws IllegalArgumentException if the type is not supported */ public static JsonObject encodeIdToJson(final Object id) { final JsonObject json = new JsonObject(); if (id instanceof String) { json.put("type", "string"); json.put("id", id); } else if (id instanceof UnsignedLong) { json.put("type", "ulong"); json.put("id", id.toString()); } else if (id instanceof UUID) { json.put("type", "uuid"); json.put("id", id.toString()); } else if (id instanceof Binary) { json.put("type", "binary"); final Binary binary = (Binary) id; json.put("id", Base64.getEncoder().encodeToString(binary.getArray())); } else { throw new IllegalArgumentException("type " + id.getClass().getName() + " is not supported"); } return json; }
From source file:org.eclipse.hono.util.RequestResponseApiConstants.java
License:Open Source License
/** * Build a Json object as a reply for internal communication via the vert.x event bus. * Services use this object to build their response when replying to a request that was received for processing. * * @param status The status from the service that processed the message. * @param tenantId The tenant for which the message was processed. * @param deviceId The device that the message relates to. * @param payload The payload of the message reply as json object. * @return JsonObject The json reply object that is to be sent back via the vert.x event bus. *///from w w w .java2 s . c o m public static final JsonObject getServiceReplyAsJson(final int status, final String tenantId, final String deviceId, final JsonObject payload) { final JsonObject jsonObject = new JsonObject(); jsonObject.put(FIELD_TENANT_ID, tenantId); if (deviceId != null) { jsonObject.put(FIELD_DEVICE_ID, deviceId); } jsonObject.put(MessageHelper.APP_PROPERTY_STATUS, Integer.toString(status)); if (payload != null) { jsonObject.put(FIELD_PAYLOAD, payload); } return jsonObject; }
From source file:org.eclipse.hono.util.RequestResponseApiConstants.java
License:Open Source License
/** * Build a Json object as a reply for internal communication via the vert.x event bus. * Services use this object to build their response when replying to a request that was received for processing. * * @param operation The operation that shall be processed by the service. * @param tenantId The tenant for which the message was processed. * @param deviceId The device that the message relates to. Maybe null - then no deviceId will be contained. * @param valueForKeyProperty The value for the application property {@link #APP_PROPERTY_KEY}. * If null, the key will not be set. * @param payload The payload from the request that is passed to the processing service. * @return JsonObject The json object for the request that is to be sent via the vert.x event bus. *///from w w w . j a v a 2s . co m public static final JsonObject getServiceRequestAsJson(final String operation, final String tenantId, final String deviceId, final String valueForKeyProperty, final JsonObject payload) { final JsonObject msg = new JsonObject(); msg.put(MessageHelper.SYS_PROPERTY_SUBJECT, operation); if (deviceId != null) { msg.put(FIELD_DEVICE_ID, deviceId); } msg.put(FIELD_TENANT_ID, tenantId); if (valueForKeyProperty != null) { msg.put(RegistrationConstants.APP_PROPERTY_KEY, valueForKeyProperty); } if (payload != null) { msg.put(RegistrationConstants.FIELD_PAYLOAD, payload); } return msg; }
From source file:org.eclipse.hono.util.TenantObject.java
License:Open Source License
/** * Sets the trusted certificate authority to use for authenticating * devices of this tenant.//from w ww .j a v a 2s . co m * * @param publicKey The CA's public key. * @param subjectDn The CA's subject DN. * @return This tenant for command chaining. * @throws NullPointerException if any of the parameters is {@code null}. */ @JsonIgnore public TenantObject setTrustAnchor(final PublicKey publicKey, final X500Principal subjectDn) { Objects.requireNonNull(publicKey); Objects.requireNonNull(subjectDn); final JsonObject trustedCa = new JsonObject(); trustedCa.put(TenantConstants.FIELD_PAYLOAD_SUBJECT_DN, subjectDn.getName(X500Principal.RFC2253)); trustedCa.put(TenantConstants.FIELD_PAYLOAD_PUBLIC_KEY, publicKey.getEncoded()); setProperty(TenantConstants.FIELD_PAYLOAD_TRUSTED_CA, trustedCa); return this; }
From source file:org.entcore.archive.services.impl.FileSystemExportService.java
License:Open Source License
private void sendExportEmail(final String exportId, final String locale, final String status, final String host) { final String userId = getUserId(exportId); String query = "MATCH (u:User {id : {userId}}) RETURN u.email as email "; JsonObject params = new JsonObject().put("userId", userId); Neo4j.getInstance().execute(query, params, new Handler<Message<JsonObject>>() { @Override//from ww w .j a va 2s . c om public void handle(Message<JsonObject> event) { JsonArray res = event.body().getJsonArray("result"); if ("ok".equals(event.body().getString("status")) && res != null && res.size() == 1) { JsonObject e = res.getJsonObject(0); String email = e.getString("email"); if (email != null && !email.trim().isEmpty()) { HttpServerRequest r = new JsonHttpServerRequest( new JsonObject().put("headers", new JsonObject().put("Accept-Language", locale))); String subject, template; JsonObject p = new JsonObject(); if ("ok".equals(status)) { subject = "email.export.ok"; template = "email/export.ok.html"; p.put("download", host + "/archive/export/" + exportId); if (log.isDebugEnabled()) { log.debug(host + "/archive/export/" + exportId); } } else { subject = "email.export.ko"; template = "email/export.ko.html"; } notification.sendEmail(r, email, null, null, subject, template, p, true, handlerToAsyncHandler(new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { if (event == null || !"ok".equals(event.body().getString("status"))) { log.error("Error sending export email for user " + userId); } } })); } else { log.info("User " + userId + " hasn't email."); } } else if (res != null) { log.warn("User " + userId + " not found."); } else { log.error("Error finding user " + userId + " email : " + event.body().getString("message")); } } }); }
From source file:org.entcore.auth.adapter.UserInfoAdapterV1_0Json.java
License:Open Source License
protected JsonObject getCommonFilteredInfos(JsonObject info, String clientId) { JsonObject filteredInfos = info.copy(); String type = Utils.getOrElse(types.get(info.getString("type", "")), ""); filteredInfos.put("type", type); filteredInfos.remove("cache"); if (filteredInfos.getString("level") == null) { filteredInfos.put("level", ""); } else if (filteredInfos.getString("level").contains("$")) { String[] level = filteredInfos.getString("level").split("\\$"); filteredInfos.put("level", level[level.length - 1]); }/*from www. java 2 s. co m*/ if (clientId != null && !clientId.trim().isEmpty()) { JsonArray classNames = filteredInfos.getJsonArray("classNames"); filteredInfos.remove("classNames"); JsonArray structureNames = filteredInfos.getJsonArray("structureNames"); filteredInfos.remove("structureNames"); filteredInfos.remove("federated"); if (classNames != null && classNames.size() > 0) { filteredInfos.put("classId", classNames.getString(0)); } if (structureNames != null && structureNames.size() > 0) { filteredInfos.put("schoolName", structureNames.getString(0)); } filteredInfos.remove("functions"); filteredInfos.remove("groupsIds"); filteredInfos.remove("structures"); filteredInfos.remove("classes"); filteredInfos.remove("apps"); filteredInfos.remove("authorizedActions"); filteredInfos.remove("children"); JsonArray authorizedActions = new fr.wseduc.webutils.collections.JsonArray(); for (Object o : info.getJsonArray("authorizedActions")) { JsonObject j = (JsonObject) o; String name = j.getString("name"); if (name != null && name.startsWith(clientId + "|")) { authorizedActions.add(j); } } if (authorizedActions.size() > 0) { filteredInfos.put("authorizedActions", authorizedActions); } } return filteredInfos; }
From source file:org.entcore.auth.controllers.AbstractFederateController.java
License:Open Source License
private void activateUser(final String activationCode, final String login, String email, String mobile, final String sessionIndex, final String nameId, final HttpServerRequest request) { userAuthAccount.activateAccount(login, activationCode, UUID.randomUUID().toString(), email, mobile, null, request, new Handler<Either<String, String>>() { @Override//from w w w. j a va2 s .c om public void handle(Either<String, String> activated) { if (activated.isRight() && activated.right().getValue() != null) { log.info("Activation du compte utilisateur " + login); eventStore.createAndStoreEvent(AuthController.AuthEvent.ACTIVATION.name(), login); createSession(activated.right().getValue(), sessionIndex, nameId, request); } else { log.info("Echec de l'activation : compte utilisateur " + login + " introuvable ou dj activ."); JsonObject error = new JsonObject().put("error", new JsonObject().put("message", I18n.getInstance().translate(activated.left().getValue(), getHost(request), I18n.acceptLanguage(request)))); error.put("activationCode", activationCode); renderJson(request, error); } } }); }
From source file:org.entcore.auth.controllers.AuthController.java
License:Open Source License
private void loginResult(final HttpServerRequest request, String error, String callBack) { final JsonObject context = new JsonObject(); if (callBack != null && !callBack.trim().isEmpty()) { try {/* w ww. ja v a 2s. com*/ context.put("callBack", URLEncoder.encode(callBack, "UTF-8")); } catch (UnsupportedEncodingException e) { log.error(e.getMessage(), e); } } if (error != null && !error.trim().isEmpty()) { context.put("error", new JsonObject().put("message", I18n.getInstance().translate(error, getHost(request), I18n.acceptLanguage(request)))); } UserUtils.getUserInfos(eb, request, new io.vertx.core.Handler<UserInfos>() { @Override public void handle(UserInfos user) { context.put("notLoggedIn", user == null); renderView(request, context, "login.html", null); } }); }
From source file:org.entcore.auth.controllers.AuthController.java
License:Open Source License
@Get("/context") public void context(final HttpServerRequest request) { final JsonObject context = new JsonObject(); context.put("callBack", config.getJsonObject("authenticationServer").getString("loginCallback")); context.put("cgu", config.getBoolean("cgu", true)); context.put("passwordRegex", passwordPattern.toString()); context.put("mandatory", config.getJsonObject("mandatory", new JsonObject())); renderJson(request, context);//from w ww .j a v a 2 s . c om }