public static void addToObject(final String key, final Object param, final JsonObjectBuilder jsonObjectBuilder) { if (param instanceof Integer) { jsonObjectBuilder.add(key, (Integer) param); } else if (param instanceof Long) { jsonObjectBuilder.add(key, (Long) param); } else if (param instanceof Double) { jsonObjectBuilder.add(key, (Double) param); } else if (param instanceof String) { jsonObjectBuilder.add(key, (String) param); } else if (param instanceof Boolean) { jsonObjectBuilder.add(key, (Boolean) param); } else if (param instanceof Map) { JsonObject mapObject = toJsonObject((Map<String, Object>) param); jsonObjectBuilder.add(key, mapObject); } else if (param instanceof Short) { jsonObjectBuilder.add(key, (Short) param); } else if (param instanceof Byte) { jsonObjectBuilder.add(key, ((Byte) param).shortValue()); } else if (param instanceof SimpleString) { jsonObjectBuilder.add(key, param.toString()); } else if (param == null) { jsonObjectBuilder.addNull(key); } else if (param instanceof byte[]) { JsonArrayBuilder byteArrayObject = toJsonArrayBuilder((byte[]) param); jsonObjectBuilder.add(key, byteArrayObject); } else { throw ActiveMQClientMessageBundle.BUNDLE.invalidManagementParam(param.getClass().getName()); } }
public static Map<String, String> readJsonProperties(String jsonString) { Map<String, String> properties = new HashMap<>(); if (jsonString != null) { JsonUtil.readJsonObject(jsonString).forEach((k, v) -> properties.put(k, v.toString())); } return properties; }
JsonArray objectArray = toJSONArray((Object[]) val); jsonObject.add(key, objectArray); } else { addToObject(key, val, jsonObject); jsonArray.add(jsonObject); } else { jsonArray.add(toJSONArray(innerArray)); addToArray(parameter, jsonArray);
/** * Returns the result of an operation invocation or an attribute value. * <br> * If an error occurred on the server, {@link #hasOperationSucceeded(Message)} will return {@code false}. * and the result will be a String corresponding to the server exception. */ public static Object[] getResults(final ICoreMessage message) throws Exception { SimpleString sstring = message.getReadOnlyBodyBuffer().readNullableSimpleString(); String jsonString = (sstring == null) ? null : sstring.toString(); if (jsonString != null) { JsonArray jsonArray = JsonUtil.readJsonArray(jsonString); return JsonUtil.fromJsonArray(jsonArray); } else { return null; } }
public JsonObject toJson() { return JsonLoader.createObjectBuilder().add("name", name).add("factoryClassName", factoryClassName).add("params", JsonUtil.toJsonObject(params)).add("extraProps", JsonUtil.toJsonObject(extraProps)).build(); }
public static JsonObject toJsonObject(Map<String, ?> map) { JsonObjectBuilder jsonObjectBuilder = JsonLoader.createObjectBuilder(); if (map != null) { for (Map.Entry<String, ?> entry : map.entrySet()) { addToObject(entry.getKey(), entry.getValue(), jsonObjectBuilder); } } return jsonObjectBuilder.build(); }
/** * Returns the result of an operation invocation or an attribute value. * <br> * If an error occurred on the server, {@link #hasOperationSucceeded(Message)} will return {@code false}. * and the result will be a String corresponding to the server exception. */ public static Object getResult(final ICoreMessage message, Class desiredType) throws Exception { Object[] res = ManagementHelper.getResults(message); if (res != null) { return JsonUtil.convertJsonValue(res[0], desiredType); } else { return null; } }
/** * Used by ActiveMQ Artemis management service. */ public static void storeResult(final CoreMessage message, final Object result) throws Exception { String resultString; if (result != null) { // Result is stored in body, also encoded as JSON array of length 1 JsonArray jsonArray = JsonUtil.toJSONArray(new Object[]{result}); resultString = jsonArray.toString(); } else { resultString = null; } message.getBodyBuffer().writeNullableSimpleString(SimpleString.toSimpleString(resultString)); }
Object[] inner = fromJsonArray((JsonArray) val); innerVal = fromJsonArray(((JsonArray) innerVal)); } else if (innerVal instanceof JsonString) { innerVal = ((JsonString) innerVal).getString(); CompositeData[] cds = new CompositeData[data.length]; for (int i1 = 0; i1 < data.length; i1++) { String dataConverted = convertJsonValue(data[i1], String.class).toString(); try (ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(new ByteArrayInputStream(Base64.decode(dataConverted)))) { ois.setWhiteList("java.util,java.lang,javax.management");
/** * Returns an array of RoleInfo corresponding to the JSON serialization returned * by {@link AddressControl#getRolesAsJSON()}. */ public static RoleInfo[] from(final String jsonString) throws Exception { JsonArray array = JsonUtil.readJsonArray(jsonString); RoleInfo[] roles = new RoleInfo[array.size()]; for (int i = 0; i < array.size(); i++) { JsonObject r = array.getJsonObject(i); RoleInfo role = new RoleInfo(r.getString("name"), r.getBoolean("send"), r.getBoolean("consume"), r.getBoolean("createDurableQueue"), r.getBoolean("deleteDurableQueue"), r.getBoolean("createNonDurableQueue"), r.getBoolean("deleteNonDurableQueue"), r.getBoolean("manage"), r.getBoolean("browse"), r.getBoolean("createAddress")); roles[i] = role; } return roles; }
@Test public void testAddToArray() { JsonArrayBuilder jsonArrayBuilder = JsonLoader.createArrayBuilder(); JsonUtil.addToArray("hello", jsonArrayBuilder); JsonUtil.addToArray(null, jsonArrayBuilder); JsonArray jsonArray = jsonArrayBuilder.build(); Assert.assertEquals(2, jsonArray.size()); }
/** * Used by ActiveMQ Artemis management service. */ public static Object[] retrieveOperationParameters(final Message message) throws Exception { SimpleString sstring = message.toCore().getReadOnlyBodyBuffer().readNullableSimpleString(); String jsonString = (sstring == null) ? null : sstring.toString(); if (jsonString != null) { JsonArray jsonArray = JsonUtil.readJsonArray(jsonString); return JsonUtil.fromJsonArray(jsonArray); } else { return null; } }
public JsonObject toJson() { return JsonLoader.createObjectBuilder().add("name", name).add("factoryClassName", factoryClassName).add("params", JsonUtil.toJsonObject(params)).add("extraProps", JsonUtil.toJsonObject(extraProps)).build(); }
public static JsonObject toJsonObject(Map<String, ?> map) { JsonObjectBuilder jsonObjectBuilder = JsonLoader.createObjectBuilder(); if (map != null) { for (Map.Entry<String, ?> entry : map.entrySet()) { addToObject(String.valueOf(entry.getKey()), entry.getValue(), jsonObjectBuilder); } } return jsonObjectBuilder.build(); }
result[i] = convertJsonValue(array[i], desiredType);
/** * Stores an operation invocation in a message to invoke the corresponding operation the value from the server resource. * * @param message message * @param resourceName the name of the server resource * @param operationName the name of the operation to invoke on the server resource * @param parameters the parameters to use to invoke the server resource * @see ResourceNames */ public static void putOperationInvocation(final ICoreMessage message, final String resourceName, final String operationName, final Object... parameters) throws Exception { // store the name of the operation in the headers message.putStringProperty(ManagementHelper.HDR_RESOURCE_NAME, new SimpleString(resourceName)); message.putStringProperty(ManagementHelper.HDR_OPERATION_NAME, new SimpleString(operationName)); // and the params go in the body, since might be too large for header String paramString; if (parameters != null) { JsonArray jsonArray = JsonUtil.toJSONArray(parameters); paramString = jsonArray.toString(); } else { paramString = null; } message.getBodyBuffer().writeNullableSimpleString(SimpleString.toSimpleString(paramString)); }
protected long getFirstMessageId(final QueueControl queueControl) throws Exception { JsonArray array = JsonUtil.readJsonArray(queueControl.getFirstMessageAsJSON()); JsonObject object = (JsonObject) array.get(0); return object.getJsonNumber("messageID").longValue(); }
@Test public void testAddByteArrayToJsonArray() { JsonArrayBuilder jsonArrayBuilder = JsonLoader.createArrayBuilder(); byte[] bytes = {0x0a, 0x1b, 0x2c, 0x3d, 0x4e, 0x5f}; JsonUtil.addToArray(bytes, jsonArrayBuilder); JsonArray jsonArray = jsonArrayBuilder.build(); Assert.assertEquals(1, jsonArray.size()); } }
public static void addToArray(final Object param, final JsonArrayBuilder jsonArrayBuilder) { if (param instanceof Integer) { jsonArrayBuilder.add((Integer) param); } else if (param instanceof Long) { jsonArrayBuilder.add((Long) param); } else if (param instanceof Double) { jsonArrayBuilder.add((Double) param); } else if (param instanceof String) { jsonArrayBuilder.add((String) param); } else if (param instanceof Boolean) { jsonArrayBuilder.add((Boolean) param); } else if (param instanceof Map) { JsonObject mapObject = toJsonObject((Map<String, Object>) param); jsonArrayBuilder.add(mapObject); } else if (param instanceof Short) { jsonArrayBuilder.add((Short) param); } else if (param instanceof Byte) { jsonArrayBuilder.add(((Byte) param).shortValue()); } else if (param == null) { jsonArrayBuilder.addNull(); } else if (param instanceof byte[]) { JsonArrayBuilder byteArrayObject = toJsonArrayBuilder((byte[]) param); jsonArrayBuilder.add(byteArrayObject); } else { throw ActiveMQClientMessageBundle.BUNDLE.invalidManagementParam(param.getClass().getName()); } }
JsonArray objectArray = toJSONArray((Object[]) val); jsonObject.add(key, objectArray); } else { addToObject(key, val, jsonObject); jsonArray.add(jsonObject); } else { jsonArray.add(toJSONArray(innerArray)); addToArray(parameter, jsonArray);