This closes #640
This commit is contained in:
commit
110158bb86
28
LICENSE
28
LICENSE
|
@ -201,34 +201,6 @@
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
===============================================================
|
||||
= For json processor files. =
|
||||
= See: src/main/java/org/apache/activemq/utils/json =
|
||||
===============================================================
|
||||
|
||||
Copyright (c) 2002 JSON.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
The Software shall be used for Good, not Evil.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
===============================================================
|
||||
= For Base64.java file =
|
||||
===============================================================
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.activemq.artemis.utils;
|
||||
|
||||
public abstract class StringEscapeUtils {
|
||||
/**
|
||||
* Adapted from commons lang StringEscapeUtils, escapes a string
|
||||
*
|
||||
* @param str
|
||||
* @return an escaped version of the input string.
|
||||
*/
|
||||
public static String escapeString(String str) {
|
||||
if (str == null) {
|
||||
return str;
|
||||
}
|
||||
int sz = str.length();
|
||||
StringBuilder stringBuilder = new StringBuilder(str.length());
|
||||
for (int i = 0; i < sz; i++) {
|
||||
char ch = str.charAt(i);
|
||||
|
||||
// handle unicode
|
||||
if (ch > 0xfff) {
|
||||
stringBuilder.append("\\u").append(hex(ch));
|
||||
}
|
||||
else if (ch > 0xff) {
|
||||
stringBuilder.append("\\u0").append(hex(ch));
|
||||
}
|
||||
else if (ch > 0x7f) {
|
||||
stringBuilder.append("\\u00").append(hex(ch));
|
||||
}
|
||||
else if (ch < 32) {
|
||||
switch (ch) {
|
||||
case '\b':
|
||||
stringBuilder.append('\\').append('b');
|
||||
break;
|
||||
case '\n':
|
||||
stringBuilder.append('\\').append('n');
|
||||
break;
|
||||
case '\t':
|
||||
stringBuilder.append('\\').append('t');
|
||||
break;
|
||||
case '\f':
|
||||
stringBuilder.append('\\').append('f');
|
||||
break;
|
||||
case '\r':
|
||||
stringBuilder.append('\\').append('r');
|
||||
break;
|
||||
default :
|
||||
if (ch > 0xf) {
|
||||
stringBuilder.append("\\u00").append(hex(ch));
|
||||
}
|
||||
else {
|
||||
stringBuilder.append("\\u000").append(hex(ch));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (ch) {
|
||||
case '\'':
|
||||
stringBuilder.append('\\').append('\'');
|
||||
break;
|
||||
case '"':
|
||||
stringBuilder.append('\\').append('"');
|
||||
break;
|
||||
case '\\':
|
||||
stringBuilder.append('\\').append('\\');
|
||||
break;
|
||||
case '/':
|
||||
stringBuilder.append('\\').append('/');
|
||||
break;
|
||||
default :
|
||||
stringBuilder.append(ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns an upper case hexadecimal <code>String</code> for the given
|
||||
* character.</p>
|
||||
*
|
||||
* @param ch The character to convert.
|
||||
* @return An upper case hexadecimal <code>String</code>
|
||||
*/
|
||||
private static String hex(char ch) {
|
||||
return Integer.toHexString(ch).toUpperCase();
|
||||
}
|
||||
}
|
|
@ -68,6 +68,14 @@
|
|||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-json_1.0_spec</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.johnzon</groupId>
|
||||
<artifactId>johnzon-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
|
|
|
@ -0,0 +1,306 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.artemis.api.core;
|
||||
|
||||
import org.apache.activemq.artemis.core.client.ActiveMQClientMessageBundle;
|
||||
import org.apache.activemq.artemis.utils.Base64;
|
||||
import org.apache.activemq.artemis.utils.StringEscapeUtils;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonNumber;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
import javax.json.JsonString;
|
||||
import javax.json.JsonValue;
|
||||
import javax.management.openmbean.CompositeData;
|
||||
import javax.management.openmbean.CompositeDataSupport;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.StringReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public final class JsonUtil {
|
||||
public static JsonArray toJSONArray(final Object[] array) throws Exception {
|
||||
JsonArrayBuilder jsonArray = Json.createArrayBuilder();
|
||||
|
||||
for (Object parameter : array) {
|
||||
if (parameter instanceof Map) {
|
||||
Map<String, Object> map = (Map<String, Object>) parameter;
|
||||
|
||||
JsonObjectBuilder jsonObject = Json.createObjectBuilder();
|
||||
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
|
||||
Object val = entry.getValue();
|
||||
|
||||
if (val != null) {
|
||||
if (val.getClass().isArray()) {
|
||||
JsonArray objectArray = toJSONArray((Object[]) val);
|
||||
jsonObject.add(key, objectArray);
|
||||
}
|
||||
else {
|
||||
addToObject(key, val, jsonObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
jsonArray.add(jsonObject);
|
||||
}
|
||||
else {
|
||||
if (parameter != null) {
|
||||
Class<?> clz = parameter.getClass();
|
||||
|
||||
if (clz.isArray()) {
|
||||
Object[] innerArray = (Object[]) parameter;
|
||||
|
||||
if (innerArray instanceof CompositeData[]) {
|
||||
JsonArrayBuilder innerJsonArray = Json.createArrayBuilder();
|
||||
for (Object data : innerArray) {
|
||||
String s = Base64.encodeObject((CompositeDataSupport) data);
|
||||
innerJsonArray.add(s);
|
||||
}
|
||||
JsonObjectBuilder jsonObject = Json.createObjectBuilder();
|
||||
jsonObject.add(CompositeData.class.getName(), innerJsonArray);
|
||||
jsonArray.add(jsonObject);
|
||||
}
|
||||
else {
|
||||
jsonArray.add(toJSONArray(innerArray));
|
||||
}
|
||||
}
|
||||
else {
|
||||
addToArray(parameter, jsonArray);
|
||||
}
|
||||
}
|
||||
else {
|
||||
jsonArray.addNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
return jsonArray.build();
|
||||
}
|
||||
|
||||
public static Object[] fromJsonArray(final JsonArray jsonArray) throws Exception {
|
||||
Object[] array = new Object[jsonArray.size()];
|
||||
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
Object val = jsonArray.get(i);
|
||||
|
||||
if (val instanceof JsonArray) {
|
||||
Object[] inner = fromJsonArray((JsonArray) val);
|
||||
|
||||
array[i] = inner;
|
||||
}
|
||||
else if (val instanceof JsonObject) {
|
||||
JsonObject jsonObject = (JsonObject) val;
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
Set<String> keys = jsonObject.keySet();
|
||||
|
||||
for (String key : keys) {
|
||||
Object innerVal = jsonObject.get(key);
|
||||
|
||||
if (innerVal instanceof JsonArray) {
|
||||
innerVal = fromJsonArray(((JsonArray) innerVal));
|
||||
}
|
||||
else if (innerVal instanceof JsonObject) {
|
||||
Map<String, Object> innerMap = new HashMap<>();
|
||||
JsonObject o = (JsonObject) innerVal;
|
||||
Set<String> innerKeys = o.keySet();
|
||||
for (String k : innerKeys) {
|
||||
innerMap.put(k, o.get(k));
|
||||
}
|
||||
innerVal = innerMap;
|
||||
}
|
||||
else if (innerVal instanceof JsonNumber) {
|
||||
JsonNumber jsonNumber = (JsonNumber)innerVal;
|
||||
innerVal = jsonNumber.longValue();
|
||||
}
|
||||
if (CompositeData.class.getName().equals(key)) {
|
||||
Object[] data = (Object[]) innerVal;
|
||||
CompositeData[] cds = new CompositeData[data.length];
|
||||
for (int i1 = 0; i1 < data.length; i1++) {
|
||||
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(Base64.decode((data[i1].toString()))));
|
||||
cds[i1] = (CompositeDataSupport) ois.readObject();
|
||||
}
|
||||
innerVal = cds;
|
||||
}
|
||||
|
||||
map.put(key, innerVal);
|
||||
}
|
||||
|
||||
array[i] = map;
|
||||
}
|
||||
else {
|
||||
if (val == JsonObject.NULL) {
|
||||
array[i] = null;
|
||||
}
|
||||
else {
|
||||
array[i] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
public static JsonValue nullSafe(String input) {
|
||||
return new NullableJsonString(input);
|
||||
}
|
||||
|
||||
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) {
|
||||
//??
|
||||
}
|
||||
else if (param instanceof SimpleString) {
|
||||
jsonObjectBuilder.add(key, param.toString());
|
||||
}
|
||||
else {
|
||||
throw ActiveMQClientMessageBundle.BUNDLE.invalidManagementParam(param.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
//??
|
||||
}
|
||||
else {
|
||||
throw ActiveMQClientMessageBundle.BUNDLE.invalidManagementParam(param.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonArray toJsonArray(List<String> strings) {
|
||||
JsonArrayBuilder array = Json.createArrayBuilder();
|
||||
if (strings != null) {
|
||||
for (String connector : strings) {
|
||||
array.add(connector);
|
||||
}
|
||||
}
|
||||
return array.build();
|
||||
}
|
||||
|
||||
public static JsonObject toJsonObject(Map<String, Object> map) {
|
||||
JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
|
||||
if (map != null) {
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
addToObject(entry.getKey(), entry.getValue(), jsonObjectBuilder);
|
||||
}
|
||||
}
|
||||
return jsonObjectBuilder.build();
|
||||
}
|
||||
|
||||
public static JsonArray readJsonArray(String jsonString) {
|
||||
return Json.createReader(new StringReader(jsonString)).readArray();
|
||||
}
|
||||
|
||||
public static JsonObject readJsonObject(String jsonString) {
|
||||
return Json.createReader(new StringReader(jsonString)).readObject();
|
||||
}
|
||||
|
||||
private JsonUtil() {
|
||||
}
|
||||
|
||||
private static class NullableJsonString implements JsonValue, JsonString {
|
||||
private final String value;
|
||||
private String escape;
|
||||
|
||||
NullableJsonString(String value) {
|
||||
if (value == null || value.length() == 0) {
|
||||
this.value = null;
|
||||
}
|
||||
else {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueType getValueType() {
|
||||
return value == null ? ValueType.NULL : ValueType.STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getChars() {
|
||||
return getString();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (this.value == null) {
|
||||
return null;
|
||||
}
|
||||
String s = this.escape;
|
||||
if (s == null) {
|
||||
s = '\"' + StringEscapeUtils.escapeString(this.value) + '\"';
|
||||
this.escape = s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,6 +25,9 @@ import org.apache.activemq.artemis.core.remoting.impl.TransportConfigurationUtil
|
|||
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
|
||||
import org.apache.activemq.artemis.utils.UUIDGenerator;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonObject;
|
||||
|
||||
/**
|
||||
* A TransportConfiguration is used by a client to specify connections to a server and its backup if
|
||||
* one exists.
|
||||
|
@ -61,6 +64,15 @@ public class TransportConfiguration implements Serializable {
|
|||
|
||||
private static final byte TYPE_STRING = 3;
|
||||
|
||||
public JsonObject toJson() {
|
||||
return Json.createObjectBuilder()
|
||||
.add("name", name)
|
||||
.add("factoryClassName", factoryClassName)
|
||||
.add("params", JsonUtil.toJsonObject(params))
|
||||
.add("extraProps", JsonUtil.toJsonObject(extraProps))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method for splitting a comma separated list of hosts
|
||||
*
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.api.core.management;
|
||||
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
|
||||
import javax.json.JsonObject;
|
||||
|
||||
// XXX no javadocs
|
||||
public final class AddressSettingsInfo {
|
||||
|
@ -63,9 +65,21 @@ public final class AddressSettingsInfo {
|
|||
|
||||
// Static --------------------------------------------------------
|
||||
|
||||
public static AddressSettingsInfo from(final String jsonString) throws Exception {
|
||||
JSONObject object = new JSONObject(jsonString);
|
||||
return new AddressSettingsInfo(object.getString("addressFullMessagePolicy"), object.getLong("maxSizeBytes"), object.getInt("pageSizeBytes"), object.getInt("pageCacheMaxSize"), object.getInt("maxDeliveryAttempts"), object.getLong("redeliveryDelay"), object.getDouble("redeliveryMultiplier"), object.getLong("maxRedeliveryDelay"), object.getString("DLA"), object.getString("expiryAddress"), object.getBoolean("lastValueQueue"), object.getLong("redistributionDelay"), object.getBoolean("sendToDLAOnNoRoute"), object.getLong("slowConsumerThreshold"), object.getLong("slowConsumerCheckPeriod"), object.getString("slowConsumerPolicy"), object.getBoolean("autoCreateJmsQueues"), object.getBoolean("autoDeleteJmsQueues"), object.getBoolean("autoCreateJmsTopics"), object.getBoolean("autoDeleteJmsTopics"));
|
||||
public static AddressSettingsInfo from(final String jsonString) {
|
||||
JsonObject object = JsonUtil.readJsonObject(jsonString);
|
||||
return new AddressSettingsInfo(object.getString("addressFullMessagePolicy"),
|
||||
object.getJsonNumber("maxSizeBytes").longValue(), object.getInt("pageSizeBytes"), object.getInt("pageCacheMaxSize"),
|
||||
object.getInt("maxDeliveryAttempts"),
|
||||
object.getJsonNumber("redeliveryDelay").longValue(),
|
||||
object.getJsonNumber("redeliveryMultiplier").doubleValue(),
|
||||
object.getJsonNumber("maxRedeliveryDelay").longValue(),
|
||||
object.getString("DLA"), object.getString("expiryAddress"), object.getBoolean("lastValueQueue"),
|
||||
object.getJsonNumber("redistributionDelay").longValue(), object.getBoolean("sendToDLAOnNoRoute"),
|
||||
object.getJsonNumber("slowConsumerThreshold").longValue(),
|
||||
object.getJsonNumber("slowConsumerCheckPeriod").longValue(),
|
||||
object.getString("slowConsumerPolicy"), object.getBoolean("autoCreateJmsQueues"),
|
||||
object.getBoolean("autoDeleteJmsQueues"), object.getBoolean("autoCreateJmsTopics"),
|
||||
object.getBoolean("autoDeleteJmsTopics"));
|
||||
}
|
||||
|
||||
// Constructors --------------------------------------------------
|
||||
|
|
|
@ -16,11 +16,13 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.api.core.management;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONException;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
|
||||
/**
|
||||
* Helper class to create Java Objects from the
|
||||
|
@ -34,31 +36,35 @@ public final class DayCounterInfo {
|
|||
|
||||
// Static --------------------------------------------------------
|
||||
|
||||
public static String toJSON(final DayCounterInfo[] infos) throws JSONException {
|
||||
JSONObject json = new JSONObject();
|
||||
JSONArray counters = new JSONArray();
|
||||
public static String toJSON(final DayCounterInfo[] infos) {
|
||||
JsonObjectBuilder json = Json.createObjectBuilder();
|
||||
JsonArrayBuilder counters = Json.createArrayBuilder();
|
||||
for (DayCounterInfo info : infos) {
|
||||
JSONObject counter = new JSONObject();
|
||||
counter.put("date", info.getDate());
|
||||
counter.put("counters", Arrays.asList(info.getCounters()));
|
||||
counters.put(counter);
|
||||
JsonArrayBuilder counter = Json.createArrayBuilder();
|
||||
for (int c : info.getCounters()) {
|
||||
counter.add(c);
|
||||
}
|
||||
JsonObjectBuilder dci = Json.createObjectBuilder()
|
||||
.add("date", info.getDate())
|
||||
.add("counters", counter);
|
||||
counters.add(dci);
|
||||
}
|
||||
json.put("dayCounters", counters);
|
||||
return json.toString();
|
||||
json.add("dayCounters", counters);
|
||||
return json.build().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of RoleInfo corresponding to the JSON serialization returned
|
||||
* by {@link QueueControl#listMessageCounterHistory()}.
|
||||
*/
|
||||
public static DayCounterInfo[] fromJSON(final String jsonString) throws JSONException {
|
||||
JSONObject json = new JSONObject(jsonString);
|
||||
JSONArray dayCounters = json.getJSONArray("dayCounters");
|
||||
DayCounterInfo[] infos = new DayCounterInfo[dayCounters.length()];
|
||||
for (int i = 0; i < dayCounters.length(); i++) {
|
||||
public static DayCounterInfo[] fromJSON(final String jsonString) {
|
||||
JsonObject json = JsonUtil.readJsonObject(jsonString);
|
||||
JsonArray dayCounters = json.getJsonArray("dayCounters");
|
||||
DayCounterInfo[] infos = new DayCounterInfo[dayCounters.size()];
|
||||
for (int i = 0; i < dayCounters.size(); i++) {
|
||||
|
||||
JSONObject counter = (JSONObject) dayCounters.get(i);
|
||||
JSONArray hour = (JSONArray) counter.getJSONArray("counters").get(0);
|
||||
JsonObject counter = (JsonObject) dayCounters.get(i);
|
||||
JsonArray hour = counter.getJsonArray("counters");
|
||||
int[] hourCounters = new int[24];
|
||||
for (int j = 0; j < 24; j++) {
|
||||
hourCounters[j] = hour.getInt(j);
|
||||
|
|
|
@ -16,22 +16,11 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.api.core.management;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.api.core.Message;
|
||||
import org.apache.activemq.artemis.core.client.ActiveMQClientMessageBundle;
|
||||
import org.apache.activemq.artemis.utils.Base64;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
|
||||
import javax.management.openmbean.CompositeData;
|
||||
import javax.management.openmbean.CompositeDataSupport;
|
||||
import javax.json.JsonArray;
|
||||
|
||||
/**
|
||||
* Helper class to use ActiveMQ Artemis Core messages to manage server resources.
|
||||
|
@ -138,7 +127,7 @@ public final class ManagementHelper {
|
|||
String paramString;
|
||||
|
||||
if (parameters != null) {
|
||||
JSONArray jsonArray = ManagementHelper.toJSONArray(parameters);
|
||||
JsonArray jsonArray = JsonUtil.toJSONArray(parameters);
|
||||
|
||||
paramString = jsonArray.toString();
|
||||
}
|
||||
|
@ -149,151 +138,6 @@ public final class ManagementHelper {
|
|||
message.getBodyBuffer().writeNullableSimpleString(SimpleString.toSimpleString(paramString));
|
||||
}
|
||||
|
||||
private static JSONArray toJSONArray(final Object[] array) throws Exception {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
|
||||
for (Object parameter : array) {
|
||||
if (parameter instanceof Map) {
|
||||
Map<String, Object> map = (Map<String, Object>) parameter;
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
|
||||
Object val = entry.getValue();
|
||||
|
||||
if (val != null) {
|
||||
if (val.getClass().isArray()) {
|
||||
val = ManagementHelper.toJSONArray((Object[]) val);
|
||||
}
|
||||
else {
|
||||
ManagementHelper.checkType(val);
|
||||
}
|
||||
}
|
||||
|
||||
jsonObject.put(key, val);
|
||||
}
|
||||
|
||||
jsonArray.put(jsonObject);
|
||||
}
|
||||
else {
|
||||
if (parameter != null) {
|
||||
Class<?> clz = parameter.getClass();
|
||||
|
||||
if (clz.isArray()) {
|
||||
Object[] innerArray = (Object[]) parameter;
|
||||
|
||||
if (innerArray instanceof CompositeData[]) {
|
||||
JSONArray jsonArray1 = new JSONArray();
|
||||
for (Object data : innerArray) {
|
||||
String s = Base64.encodeObject((CompositeDataSupport)data);
|
||||
jsonArray1.put(s);
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put(CompositeData.class.getName(), jsonArray1);
|
||||
jsonArray.put(jsonObject);
|
||||
System.out.println("ManagementHelper.toJSONArray");
|
||||
}
|
||||
else {
|
||||
jsonArray.put(ManagementHelper.toJSONArray(innerArray));
|
||||
}
|
||||
}
|
||||
else {
|
||||
ManagementHelper.checkType(parameter);
|
||||
|
||||
jsonArray.put(parameter);
|
||||
}
|
||||
}
|
||||
else {
|
||||
jsonArray.put((Object) null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
private static Object[] fromJSONArray(final JSONArray jsonArray) throws Exception {
|
||||
Object[] array = new Object[jsonArray.length()];
|
||||
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
Object val = jsonArray.get(i);
|
||||
|
||||
if (val instanceof JSONArray) {
|
||||
Object[] inner = ManagementHelper.fromJSONArray((JSONArray) val);
|
||||
|
||||
array[i] = inner;
|
||||
}
|
||||
else if (val instanceof JSONObject) {
|
||||
JSONObject jsonObject = (JSONObject) val;
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
Iterator<String> iter = jsonObject.keys();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
String key = iter.next();
|
||||
|
||||
Object innerVal = jsonObject.get(key);
|
||||
|
||||
if (innerVal instanceof JSONArray) {
|
||||
innerVal = ManagementHelper.fromJSONArray(((JSONArray) innerVal));
|
||||
}
|
||||
else if (innerVal instanceof JSONObject) {
|
||||
Map<String, Object> innerMap = new HashMap<>();
|
||||
JSONObject o = (JSONObject) innerVal;
|
||||
Iterator it = o.keys();
|
||||
while (it.hasNext()) {
|
||||
String k = (String) it.next();
|
||||
innerMap.put(k, o.get(k));
|
||||
}
|
||||
innerVal = innerMap;
|
||||
}
|
||||
else if (innerVal instanceof Integer) {
|
||||
innerVal = ((Integer) innerVal).longValue();
|
||||
}
|
||||
|
||||
if (CompositeData.class.getName().equals(key)) {
|
||||
Object[] data = (Object[]) innerVal;
|
||||
CompositeData[] cds = new CompositeData[data.length];
|
||||
for (int i1 = 0; i1 < data.length; i1++) {
|
||||
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(Base64.decode((data[i1].toString()))));
|
||||
cds[i1] = (CompositeDataSupport) ois.readObject();
|
||||
}
|
||||
innerVal = cds;
|
||||
}
|
||||
|
||||
map.put(key, innerVal);
|
||||
}
|
||||
|
||||
array[i] = map;
|
||||
}
|
||||
else {
|
||||
if (val == JSONObject.NULL) {
|
||||
array[i] = null;
|
||||
}
|
||||
else {
|
||||
array[i] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
private static void checkType(final Object param) {
|
||||
if (param instanceof Integer == false && param instanceof Long == false &&
|
||||
param instanceof Double == false &&
|
||||
param instanceof String == false &&
|
||||
param instanceof Boolean == false &&
|
||||
param instanceof Map == false &&
|
||||
param instanceof Byte == false &&
|
||||
param instanceof Short == false) {
|
||||
throw ActiveMQClientMessageBundle.BUNDLE.invalidManagementParam(param.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by ActiveMQ Artemis management service.
|
||||
*/
|
||||
|
@ -302,9 +146,9 @@ public final class ManagementHelper {
|
|||
String jsonString = (sstring == null) ? null : sstring.toString();
|
||||
|
||||
if (jsonString != null) {
|
||||
JSONArray jsonArray = new JSONArray(jsonString);
|
||||
JsonArray jsonArray = JsonUtil.readJsonArray(jsonString);
|
||||
|
||||
return ManagementHelper.fromJSONArray(jsonArray);
|
||||
return JsonUtil.fromJsonArray(jsonArray);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
@ -334,7 +178,7 @@ public final class ManagementHelper {
|
|||
if (result != null) {
|
||||
// Result is stored in body, also encoded as JSON array of length 1
|
||||
|
||||
JSONArray jsonArray = ManagementHelper.toJSONArray(new Object[]{result});
|
||||
JsonArray jsonArray = JsonUtil.toJSONArray(new Object[]{result});
|
||||
|
||||
resultString = jsonArray.toString();
|
||||
}
|
||||
|
@ -356,11 +200,8 @@ public final class ManagementHelper {
|
|||
String jsonString = (sstring == null) ? null : sstring.toString();
|
||||
|
||||
if (jsonString != null) {
|
||||
JSONArray jsonArray = new JSONArray(jsonString);
|
||||
|
||||
Object[] res = ManagementHelper.fromJSONArray(jsonArray);
|
||||
|
||||
return res;
|
||||
JsonArray jsonArray = JsonUtil.readJsonArray(jsonString);
|
||||
return JsonUtil.fromJsonArray(jsonArray);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
@ -397,38 +238,6 @@ public final class ManagementHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by ActiveMQ Artemis management service.
|
||||
*/
|
||||
public static Map<String, Object> fromCommaSeparatedKeyValues(final String str) throws Exception {
|
||||
if (str == null || str.trim().length() == 0) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
// create a JSON array with 1 object:
|
||||
JSONArray array = new JSONArray("[{" + str + "}]");
|
||||
Map<String, Object> params = (Map<String, Object>) ManagementHelper.fromJSONArray(array)[0];
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by ActiveMQ Artemis management service.
|
||||
*/
|
||||
public static Object[] fromCommaSeparatedArrayOfCommaSeparatedKeyValues(final String str) throws Exception {
|
||||
if (str == null || str.trim().length() == 0) {
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
String s = str;
|
||||
|
||||
// if there is a single item, we wrap it in to make it a JSON object
|
||||
if (!s.trim().startsWith("{")) {
|
||||
s = "{" + s + "}";
|
||||
}
|
||||
JSONArray array = new JSONArray("[" + s + "]");
|
||||
return ManagementHelper.fromJSONArray(array);
|
||||
}
|
||||
|
||||
private ManagementHelper() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.api.core.management;
|
||||
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
|
||||
/**
|
||||
* Helper class to create Java Objects from the
|
||||
|
@ -48,11 +50,14 @@ public final class RoleInfo {
|
|||
* by {@link AddressControl#getRolesAsJSON()}.
|
||||
*/
|
||||
public static RoleInfo[] from(final String jsonString) throws Exception {
|
||||
JSONArray array = new JSONArray(jsonString);
|
||||
RoleInfo[] roles = new RoleInfo[array.length()];
|
||||
for (int i = 0; i < array.length(); 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"));
|
||||
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"));
|
||||
roles[i] = role;
|
||||
}
|
||||
return roles;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.core.security;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonObject;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
|
@ -43,6 +45,20 @@ public class Role implements Serializable {
|
|||
|
||||
private final boolean browse;
|
||||
|
||||
public JsonObject toJson() {
|
||||
return Json.createObjectBuilder()
|
||||
.add("name", name)
|
||||
.add("send", send)
|
||||
.add("consume", consume)
|
||||
.add("createDurableQueue", createDurableQueue)
|
||||
.add("deleteDurableQueue", deleteDurableQueue)
|
||||
.add("createNonDurableQueue", createNonDurableQueue)
|
||||
.add("deleteNonDurableQueue", deleteNonDurableQueue)
|
||||
.add("manage", manage)
|
||||
.add("browse", browse)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #Role(String, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean)}
|
||||
* @param name
|
||||
|
|
|
@ -1,931 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2002 JSON.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
The Software shall be used for Good, not Evil.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
package org.apache.activemq.artemis.utils.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A JSONArray is an ordered sequence of values. Its external text form is a
|
||||
* string wrapped in square brackets with commas separating the values. The
|
||||
* internal form is an object having <code>get</code> and <code>opt</code>
|
||||
* methods for accessing the values by index, and <code>put</code> methods for
|
||||
* adding or replacing values. The values can be any of these types:
|
||||
* <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>,
|
||||
* <code>Number</code>, {@code string}, or the
|
||||
* <code>JSONObject.NULL object</code>.
|
||||
* <p>
|
||||
* The constructor can convert a JSON text into a Java object. The
|
||||
* <code>toString</code> method converts to JSON text.
|
||||
* <p>
|
||||
* A <code>get</code> method returns a value if one can be found, and throws an
|
||||
* exception if one cannot be found. An <code>opt</code> method returns a
|
||||
* default value instead of throwing an exception, and so is useful for
|
||||
* obtaining optional values.
|
||||
* <p>
|
||||
* The generic <code>get()</code> and <code>opt()</code> methods return an
|
||||
* object which you can cast or query for type. There are also typed
|
||||
* <code>get</code> and <code>opt</code> methods that do type checking and type
|
||||
* coercion for you.
|
||||
* <p>
|
||||
* The texts produced by the <code>toString</code> methods strictly conform to
|
||||
* JSON syntax rules. The constructors are more forgiving in the texts they will
|
||||
* accept:
|
||||
* <ul>
|
||||
* <li>An extra <code>,</code> <small>(comma)</small> may appear just
|
||||
* before the closing bracket.</li>
|
||||
* <li>The {@code null} value will be inserted when there
|
||||
* is <code>,</code> <small>(comma)</small> elision.</li>
|
||||
* <li>Strings may be quoted with <code>'</code> <small>(single
|
||||
* quote)</small>.</li>
|
||||
* <li>Strings do not need to be quoted at all if they do not begin with a quote
|
||||
* or single quote, and if they do not contain leading or trailing spaces,
|
||||
* and if they do not contain any of these characters:
|
||||
* <code>{ } [ ] / \ : , = ; #</code> and if they do not look like numbers
|
||||
* and if they are not the reserved words <code>true</code>,
|
||||
* <code>false</code>, or {@code null}.</li>
|
||||
* <li>Values can be separated by <code>;</code> <small>(semicolon)</small> as
|
||||
* well as by <code>,</code> <small>(comma)</small>.</li>
|
||||
* <li>Numbers may have the <code>0-</code> <small>(octal)</small> or
|
||||
* <code>0x-</code> <small>(hex)</small> prefix.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class JSONArray {
|
||||
|
||||
/**
|
||||
* The arrayList where the JSONArray's properties are kept.
|
||||
*/
|
||||
private final ArrayList<Object> myArrayList;
|
||||
|
||||
/**
|
||||
* Construct an empty JSONArray.
|
||||
*/
|
||||
public JSONArray() {
|
||||
myArrayList = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a JSONArray from a JSONTokener.
|
||||
*
|
||||
* @param x A JSONTokener
|
||||
* @throws JSONException If there is a syntax error.
|
||||
*/
|
||||
public JSONArray(final JSONTokener x) throws JSONException {
|
||||
this();
|
||||
char c = x.nextClean();
|
||||
char q;
|
||||
if (c == '[') {
|
||||
q = ']';
|
||||
}
|
||||
else if (c == '(') {
|
||||
q = ')';
|
||||
}
|
||||
else {
|
||||
throw x.syntaxError("A JSONArray text must start with '['");
|
||||
}
|
||||
if (x.nextClean() == ']') {
|
||||
return;
|
||||
}
|
||||
x.back();
|
||||
for (;;) {
|
||||
if (x.nextClean() == ',') {
|
||||
x.back();
|
||||
myArrayList.add(null);
|
||||
}
|
||||
else {
|
||||
x.back();
|
||||
myArrayList.add(x.nextValue());
|
||||
}
|
||||
c = x.nextClean();
|
||||
switch (c) {
|
||||
case ';':
|
||||
case ',':
|
||||
if (x.nextClean() == ']') {
|
||||
return;
|
||||
}
|
||||
x.back();
|
||||
break;
|
||||
case ']':
|
||||
case ')':
|
||||
if (q != c) {
|
||||
throw x.syntaxError("Expected a '" + Character.valueOf(q) + "'");
|
||||
}
|
||||
return;
|
||||
default:
|
||||
throw x.syntaxError("Expected a ',' or ']'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a JSONArray from a source JSON text.
|
||||
*
|
||||
* @param source A string that begins with
|
||||
* <code>[</code> <small>(left bracket)</small>
|
||||
* and ends with <code>]</code> <small>(right bracket)</small>.
|
||||
* @throws JSONException If there is a syntax error.
|
||||
*/
|
||||
public JSONArray(final String source) throws JSONException {
|
||||
this(new JSONTokener(source));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a JSONArray from a Collection.
|
||||
*
|
||||
* @param collection A Collection.
|
||||
*/
|
||||
public JSONArray(final Collection collection) {
|
||||
myArrayList = collection == null ? new ArrayList<>() : new ArrayList<>(collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a JSONArray from a collection of beans.
|
||||
* The collection should have Java Beans.
|
||||
*/
|
||||
public JSONArray(final Collection collection, final boolean includeSuperClass) {
|
||||
myArrayList = collection == null ? new ArrayList<>() : new ArrayList<>(collection.size());
|
||||
if (collection != null) {
|
||||
Iterator<Object> iter = collection.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Object o = iter.next();
|
||||
if (o instanceof Map<?, ?>) {
|
||||
myArrayList.add(new JSONObject((Map<?, ?>) o, includeSuperClass));
|
||||
}
|
||||
else if (!JSONObject.isStandardProperty(o.getClass())) {
|
||||
myArrayList.add(new JSONObject(o, includeSuperClass));
|
||||
}
|
||||
else {
|
||||
myArrayList.add(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a JSONArray from an array
|
||||
*
|
||||
* @throws JSONException If not an array.
|
||||
*/
|
||||
public JSONArray(final Object array) throws JSONException {
|
||||
this();
|
||||
if (array.getClass().isArray()) {
|
||||
int length = Array.getLength(array);
|
||||
for (int i = 0; i < length; i += 1) {
|
||||
this.put(Array.get(array, i));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new JSONException("JSONArray initial value should be a string or collection or array.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a JSONArray from an array with a bean.
|
||||
* The array should have Java Beans.
|
||||
*
|
||||
* @throws JSONException If not an array.
|
||||
*/
|
||||
public JSONArray(final Object array, final boolean includeSuperClass) throws JSONException {
|
||||
this();
|
||||
if (array.getClass().isArray()) {
|
||||
int length = Array.getLength(array);
|
||||
for (int i = 0; i < length; i += 1) {
|
||||
Object o = Array.get(array, i);
|
||||
if (JSONObject.isStandardProperty(o.getClass())) {
|
||||
myArrayList.add(o);
|
||||
}
|
||||
else {
|
||||
myArrayList.add(new JSONObject(o, includeSuperClass));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new JSONException("JSONArray initial value should be a string or collection or array.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object value associated with an index.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return An object value.
|
||||
* @throws JSONException If there is no value for the index.
|
||||
*/
|
||||
public Object get(final int index) throws JSONException {
|
||||
Object o = opt(index);
|
||||
if (o == null) {
|
||||
throw new JSONException("JSONArray[" + index + "] not found.");
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the boolean value associated with an index.
|
||||
* The string values "true" and "false" are converted to boolean.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return The truth.
|
||||
* @throws JSONException If there is no value for the index or if the
|
||||
* value is not convertable to boolean.
|
||||
*/
|
||||
public boolean getBoolean(final int index) throws JSONException {
|
||||
Object o = get(index);
|
||||
if (o.equals(Boolean.FALSE) || o instanceof String && ((String) o).equalsIgnoreCase("false")) {
|
||||
return false;
|
||||
}
|
||||
else if (o.equals(Boolean.TRUE) || o instanceof String && ((String) o).equalsIgnoreCase("true")) {
|
||||
return true;
|
||||
}
|
||||
throw new JSONException("JSONArray[" + index + "] is not a Boolean.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the double value associated with an index.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return The value.
|
||||
* @throws JSONException If the key is not found or if the value cannot
|
||||
* be converted to a number.
|
||||
*/
|
||||
public double getDouble(final int index) throws JSONException {
|
||||
Object o = get(index);
|
||||
try {
|
||||
return o instanceof Number ? ((Number) o).doubleValue() : Double.valueOf((String) o).doubleValue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the int value associated with an index.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return The value.
|
||||
* @throws JSONException If the key is not found or if the value cannot
|
||||
* be converted to a number.
|
||||
* if the value cannot be converted to a number.
|
||||
*/
|
||||
public int getInt(final int index) throws JSONException {
|
||||
Object o = get(index);
|
||||
return o instanceof Number ? ((Number) o).intValue() : (int) getDouble(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the JSONArray associated with an index.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return A JSONArray value.
|
||||
* @throws JSONException If there is no value for the index. or if the
|
||||
* value is not a JSONArray
|
||||
*/
|
||||
public JSONArray getJSONArray(final int index) throws JSONException {
|
||||
Object o = get(index);
|
||||
if (o instanceof JSONArray) {
|
||||
return (JSONArray) o;
|
||||
}
|
||||
throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the JSONObject associated with an index.
|
||||
*
|
||||
* @param index subscript
|
||||
* @return A JSONObject value.
|
||||
* @throws JSONException If there is no value for the index or if the
|
||||
* value is not a JSONObject
|
||||
*/
|
||||
public JSONObject getJSONObject(final int index) throws JSONException {
|
||||
Object o = get(index);
|
||||
if (o instanceof JSONObject) {
|
||||
return (JSONObject) o;
|
||||
}
|
||||
throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the long value associated with an index.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return The value.
|
||||
* @throws JSONException If the key is not found or if the value cannot
|
||||
* be converted to a number.
|
||||
*/
|
||||
public long getLong(final int index) throws JSONException {
|
||||
Object o = get(index);
|
||||
return o instanceof Number ? ((Number) o).longValue() : (long) getDouble(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string associated with an index.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return A string value.
|
||||
* @throws JSONException If there is no value for the index.
|
||||
*/
|
||||
public String getString(final int index) throws JSONException {
|
||||
return get(index).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the value is null.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return true if the value at the index is null, or if there is no value.
|
||||
*/
|
||||
public boolean isNull(final int index) {
|
||||
return JSONObject.NULL.equals(opt(index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a string from the contents of this JSONArray. The
|
||||
* <code>separator</code> string is inserted between each element.
|
||||
* Warning: This method assumes that the data structure is acyclical.
|
||||
*
|
||||
* @param separator A string that will be inserted between the elements.
|
||||
* @return a string.
|
||||
* @throws JSONException If the array contains an invalid number.
|
||||
*/
|
||||
public String join(final String separator) throws JSONException {
|
||||
int len = length();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
for (int i = 0; i < len; i += 1) {
|
||||
if (i > 0) {
|
||||
sb.append(separator);
|
||||
}
|
||||
sb.append(JSONObject.valueToString(myArrayList.get(i)));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of elements in the JSONArray, included nulls.
|
||||
*
|
||||
* @return The length (or size).
|
||||
*/
|
||||
public int length() {
|
||||
return myArrayList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional object value associated with an index.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return An object value, or null if there is no
|
||||
* object at that index.
|
||||
*/
|
||||
public Object opt(final int index) {
|
||||
return index < 0 || index >= length() ? null : myArrayList.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional boolean value associated with an index.
|
||||
* It returns false if there is no value at that index,
|
||||
* or if the value is not Boolean.TRUE or the String "true".
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return The truth.
|
||||
*/
|
||||
public boolean optBoolean(final int index) {
|
||||
return optBoolean(index, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional boolean value associated with an index.
|
||||
* It returns the defaultValue if there is no value at that index or if
|
||||
* it is not a Boolean or the String "true" or "false" (case insensitive).
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @param defaultValue A boolean default.
|
||||
* @return The truth.
|
||||
*/
|
||||
public boolean optBoolean(final int index, final boolean defaultValue) {
|
||||
try {
|
||||
return getBoolean(index);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional double value associated with an index.
|
||||
* NaN is returned if there is no value for the index,
|
||||
* or if the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return The value.
|
||||
*/
|
||||
public double optDouble(final int index) {
|
||||
return optDouble(index, Double.NaN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional double value associated with an index.
|
||||
* The defaultValue is returned if there is no value for the index,
|
||||
* or if the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index subscript
|
||||
* @param defaultValue The default value.
|
||||
* @return The value.
|
||||
*/
|
||||
public double optDouble(final int index, final double defaultValue) {
|
||||
try {
|
||||
return getDouble(index);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional int value associated with an index.
|
||||
* Zero is returned if there is no value for the index,
|
||||
* or if the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return The value.
|
||||
*/
|
||||
public int optInt(final int index) {
|
||||
return optInt(index, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional int value associated with an index.
|
||||
* The defaultValue is returned if there is no value for the index,
|
||||
* or if the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @param defaultValue The default value.
|
||||
* @return The value.
|
||||
*/
|
||||
public int optInt(final int index, final int defaultValue) {
|
||||
try {
|
||||
return getInt(index);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional JSONArray associated with an index.
|
||||
*
|
||||
* @param index subscript
|
||||
* @return A JSONArray value, or null if the index has no value,
|
||||
* or if the value is not a JSONArray.
|
||||
*/
|
||||
public JSONArray optJSONArray(final int index) {
|
||||
Object o = opt(index);
|
||||
return o instanceof JSONArray ? (JSONArray) o : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional JSONObject associated with an index.
|
||||
* Null is returned if the key is not found, or null if the index has
|
||||
* no value, or if the value is not a JSONObject.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return A JSONObject value.
|
||||
*/
|
||||
public JSONObject optJSONObject(final int index) {
|
||||
Object o = opt(index);
|
||||
return o instanceof JSONObject ? (JSONObject) o : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional long value associated with an index.
|
||||
* Zero is returned if there is no value for the index,
|
||||
* or if the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return The value.
|
||||
*/
|
||||
public long optLong(final int index) {
|
||||
return optLong(index, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional long value associated with an index.
|
||||
* The defaultValue is returned if there is no value for the index,
|
||||
* or if the value is not a number and cannot be converted to a number.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @param defaultValue The default value.
|
||||
* @return The value.
|
||||
*/
|
||||
public long optLong(final int index, final long defaultValue) {
|
||||
try {
|
||||
return getLong(index);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional string value associated with an index. It returns an
|
||||
* empty string if there is no value at that index. If the value
|
||||
* is not a string and is not null, then it is converted to a string.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return A String value.
|
||||
*/
|
||||
public String optString(final int index) {
|
||||
return optString(index, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optional string associated with an index.
|
||||
* The defaultValue is returned if the key is not found.
|
||||
*
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @param defaultValue The default value.
|
||||
* @return A String value.
|
||||
*/
|
||||
public String optString(final int index, final String defaultValue) {
|
||||
Object o = opt(index);
|
||||
return o != null ? o.toString() : defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a boolean value. This increases the array's length by one.
|
||||
*
|
||||
* @param value A boolean value.
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(final boolean value) {
|
||||
put(value ? Boolean.TRUE : Boolean.FALSE);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a value in the JSONArray, where the value will be a
|
||||
* JSONArray which is produced from a Collection.
|
||||
*
|
||||
* @param value A Collection value.
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(final Collection value) {
|
||||
put(new JSONArray(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a double value. This increases the array's length by one.
|
||||
*
|
||||
* @param value A double value.
|
||||
* @return this.
|
||||
* @throws JSONException if the value is not finite.
|
||||
*/
|
||||
public JSONArray put(final double value) throws JSONException {
|
||||
Double d = Double.valueOf(value);
|
||||
JSONObject.testValidity(d);
|
||||
put(d);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append an int value. This increases the array's length by one.
|
||||
*
|
||||
* @param value An int value.
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(final int value) {
|
||||
put(Integer.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a long value. This increases the array's length by one.
|
||||
*
|
||||
* @param value A long value.
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(final long value) {
|
||||
put(Long.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a value in the JSONArray, where the value will be a
|
||||
* JSONObject which is produced from a Map.
|
||||
*
|
||||
* @param value A Map value.
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(final Map value) {
|
||||
put(new JSONObject(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append an object value. This increases the array's length by one.
|
||||
*
|
||||
* @param value An object value. The value should be a
|
||||
* Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
|
||||
* JSONObject.NULL object.
|
||||
* @return this.
|
||||
*/
|
||||
public JSONArray put(final Object value) {
|
||||
myArrayList.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put or replace a boolean value in the JSONArray. If the index is greater
|
||||
* than the length of the JSONArray, then null elements will be added as
|
||||
* necessary to pad it out.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value A boolean value.
|
||||
* @return this.
|
||||
* @throws JSONException If the index is negative.
|
||||
*/
|
||||
public JSONArray put(final int index, final boolean value) throws JSONException {
|
||||
put(index, value ? Boolean.TRUE : Boolean.FALSE);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a value in the JSONArray, where the value will be a
|
||||
* JSONArray which is produced from a Collection.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value A Collection value.
|
||||
* @return this.
|
||||
* @throws JSONException If the index is negative or if the value is
|
||||
* not finite.
|
||||
*/
|
||||
public JSONArray put(final int index, final Collection value) throws JSONException {
|
||||
put(index, new JSONArray(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put or replace a double value. If the index is greater than the length of
|
||||
* the JSONArray, then null elements will be added as necessary to pad
|
||||
* it out.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value A double value.
|
||||
* @return this.
|
||||
* @throws JSONException If the index is negative or if the value is
|
||||
* not finite.
|
||||
*/
|
||||
public JSONArray put(final int index, final double value) throws JSONException {
|
||||
put(index, Double.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put or replace an int value. If the index is greater than the length of
|
||||
* the JSONArray, then null elements will be added as necessary to pad
|
||||
* it out.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value An int value.
|
||||
* @return this.
|
||||
* @throws JSONException If the index is negative.
|
||||
*/
|
||||
public JSONArray put(final int index, final int value) throws JSONException {
|
||||
put(index, Integer.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put or replace a long value. If the index is greater than the length of
|
||||
* the JSONArray, then null elements will be added as necessary to pad
|
||||
* it out.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value A long value.
|
||||
* @return this.
|
||||
* @throws JSONException If the index is negative.
|
||||
*/
|
||||
public JSONArray put(final int index, final long value) throws JSONException {
|
||||
put(index, Long.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a value in the JSONArray, where the value will be a
|
||||
* JSONObject which is produced from a Map.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value The Map value.
|
||||
* @return this.
|
||||
* @throws JSONException If the index is negative or if the the value is
|
||||
* an invalid number.
|
||||
*/
|
||||
public JSONArray put(final int index, final Map value) throws JSONException {
|
||||
put(index, new JSONObject(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put or replace an object value in the JSONArray. If the index is greater
|
||||
* than the length of the JSONArray, then null elements will be added as
|
||||
* necessary to pad it out.
|
||||
*
|
||||
* @param index The subscript.
|
||||
* @param value The value to put into the array. The value should be a
|
||||
* Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
|
||||
* JSONObject.NULL object.
|
||||
* @return this.
|
||||
* @throws JSONException If the index is negative or if the the value is
|
||||
* an invalid number.
|
||||
*/
|
||||
public JSONArray put(final int index, final Object value) throws JSONException {
|
||||
JSONObject.testValidity(value);
|
||||
if (index < 0) {
|
||||
throw new JSONException("JSONArray[" + index + "] not found.");
|
||||
}
|
||||
if (index < length()) {
|
||||
myArrayList.set(index, value);
|
||||
}
|
||||
else {
|
||||
while (index != length()) {
|
||||
put(JSONObject.NULL);
|
||||
}
|
||||
put(value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an index and close the hole.
|
||||
*
|
||||
* @param index The index of the element to be removed.
|
||||
* @return The value that was associated with the index,
|
||||
* or null if there was no value.
|
||||
*/
|
||||
public Object remove(final int index) {
|
||||
Object o = opt(index);
|
||||
myArrayList.remove(index);
|
||||
return o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a JSONObject by combining a JSONArray of names with the values
|
||||
* of this JSONArray.
|
||||
*
|
||||
* @param names A JSONArray containing a list of key strings. These will be
|
||||
* paired with the values.
|
||||
* @return A JSONObject, or null if there are no names or if this JSONArray
|
||||
* has no values.
|
||||
* @throws JSONException If any of the names are null.
|
||||
*/
|
||||
public JSONObject toJSONObject(final JSONArray names) throws JSONException {
|
||||
if (names == null || names.length() == 0 || length() == 0) {
|
||||
return null;
|
||||
}
|
||||
JSONObject jo = new JSONObject();
|
||||
for (int i = 0; i < names.length(); i += 1) {
|
||||
jo.put(names.getString(i), opt(i));
|
||||
}
|
||||
return jo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a JSON text of this JSONArray. For compactness, no
|
||||
* unnecessary whitespace is added. If it is not possible to produce a
|
||||
* syntactically correct JSON text then null will be returned instead. This
|
||||
* could occur if the array contains an invalid number.
|
||||
* <p>
|
||||
* Warning: This method assumes that the data structure is acyclical.
|
||||
*
|
||||
* @return a printable, displayable, transmittable
|
||||
* representation of the array.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return '[' + join(",") + ']';
|
||||
}
|
||||
catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a pretty-printed JSON text of this JSONArray. Warning: This method assumes that the data
|
||||
* structure is acyclical.
|
||||
*
|
||||
* @param indentFactor The number of spaces to add to each level of indentation.
|
||||
* @return a printable, displayable, transmittable representation of the object, beginning with
|
||||
* <code>[</code> <small>(left bracket)</small> and ending with <code>]</code>
|
||||
* <small>(right bracket)</small>.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public String toString(final int indentFactor) throws JSONException {
|
||||
return toString(indentFactor, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a pretty-printed JSON text of this JSONArray. Warning: This method assumes that the data
|
||||
* structure is acyclical.
|
||||
*
|
||||
* @param indentFactor The number of spaces to add to each level of indentation.
|
||||
* @param indent The indention of the top level.
|
||||
* @return a printable, displayable, transmittable representation of the array.
|
||||
* @throws JSONException
|
||||
*/
|
||||
String toString(final int indentFactor, final int indent) throws JSONException {
|
||||
int len = length();
|
||||
if (len == 0) {
|
||||
return "[]";
|
||||
}
|
||||
int i;
|
||||
StringBuffer sb = new StringBuffer("[");
|
||||
if (len == 1) {
|
||||
sb.append(JSONObject.valueToString(myArrayList.get(0), indentFactor, indent));
|
||||
}
|
||||
else {
|
||||
int newindent = indent + indentFactor;
|
||||
sb.append('\n');
|
||||
for (i = 0; i < len; i += 1) {
|
||||
if (i > 0) {
|
||||
sb.append(",\n");
|
||||
}
|
||||
for (int j = 0; j < newindent; j += 1) {
|
||||
sb.append(' ');
|
||||
}
|
||||
sb.append(JSONObject.valueToString(myArrayList.get(i), indentFactor, newindent));
|
||||
}
|
||||
sb.append('\n');
|
||||
for (i = 0; i < indent; i += 1) {
|
||||
sb.append(' ');
|
||||
}
|
||||
}
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the contents of the JSONArray as JSON text to a writer.
|
||||
* For compactness, no whitespace is added.
|
||||
* <p>
|
||||
* Warning: This method assumes that the data structure is acyclical.
|
||||
*
|
||||
* @return The writer.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public Writer write(final Writer writer) throws JSONException {
|
||||
try {
|
||||
boolean b = false;
|
||||
int len = length();
|
||||
|
||||
writer.write('[');
|
||||
|
||||
for (int i = 0; i < len; i += 1) {
|
||||
if (b) {
|
||||
writer.write(',');
|
||||
}
|
||||
Object v = myArrayList.get(i);
|
||||
if (v instanceof JSONObject) {
|
||||
((JSONObject) v).write(writer);
|
||||
}
|
||||
else if (v instanceof JSONArray) {
|
||||
((JSONArray) v).write(writer);
|
||||
}
|
||||
else {
|
||||
writer.write(JSONObject.valueToString(v));
|
||||
}
|
||||
b = true;
|
||||
}
|
||||
writer.write(']');
|
||||
return writer;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new JSONException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2002 JSON.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
The Software shall be used for Good, not Evil.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
package org.apache.activemq.artemis.utils.json;
|
||||
|
||||
/**
|
||||
* The JSONException is thrown by the JSON.org classes then things are amiss.
|
||||
*/
|
||||
public class JSONException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3940674325153571604L;
|
||||
|
||||
private Throwable cause;
|
||||
|
||||
/**
|
||||
* Constructs a JSONException with an explanatory message.
|
||||
*
|
||||
* @param message Detail about the reason for the exception.
|
||||
*/
|
||||
public JSONException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JSONException(final Throwable t) {
|
||||
super(t.getMessage());
|
||||
cause = t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Throwable getCause() {
|
||||
return cause;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2002 JSON.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
The Software shall be used for Good, not Evil.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
package org.apache.activemq.artemis.utils.json;
|
||||
|
||||
/**
|
||||
* The <code>JSONString</code> interface allows a <code>toJSONString()</code>
|
||||
* method so that a class can change the behavior of
|
||||
* <code>JSONObject.toString()</code>, <code>JSONArray.toString()</code>,
|
||||
* and <code>JSONWriter.value(</code>Object<code>)</code>. The
|
||||
* <code>toJSONString</code> method will be used instead of the default behavior
|
||||
* of using the Object's <code>toString()</code> method and quoting the result.
|
||||
*/
|
||||
public interface JSONString {
|
||||
|
||||
/**
|
||||
* The <code>toJSONString</code> method allows a class to produce its own JSON
|
||||
* serialization.
|
||||
*
|
||||
* @return A strictly syntactically correct JSON text.
|
||||
*/
|
||||
String toJSONString();
|
||||
}
|
|
@ -1,414 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2002 JSON.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
The Software shall be used for Good, not Evil.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
package org.apache.activemq.artemis.utils.json;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
|
||||
/**
|
||||
* A JSONTokener takes a source string and extracts characters and tokens from
|
||||
* it. It is used by the JSONObject and JSONArray constructors to parse
|
||||
* JSON source strings.
|
||||
*/
|
||||
public class JSONTokener {
|
||||
|
||||
private int index;
|
||||
|
||||
private final Reader reader;
|
||||
|
||||
private char lastChar;
|
||||
|
||||
private boolean useLastChar;
|
||||
|
||||
/**
|
||||
* Construct a JSONTokener from a string.
|
||||
*
|
||||
* @param reader A reader.
|
||||
*/
|
||||
public JSONTokener(final Reader reader) {
|
||||
this.reader = reader.markSupported() ? reader : new BufferedReader(reader);
|
||||
useLastChar = false;
|
||||
index = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a JSONTokener from a string.
|
||||
*
|
||||
* @param s A source string.
|
||||
*/
|
||||
public JSONTokener(final String s) {
|
||||
this(new StringReader(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* Back up one character. This provides a sort of lookahead capability,
|
||||
* so that you can test for a digit or letter before attempting to parse
|
||||
* the next number or identifier.
|
||||
*/
|
||||
public void back() throws JSONException {
|
||||
if (useLastChar || index <= 0) {
|
||||
throw new JSONException("Stepping back two steps is not supported");
|
||||
}
|
||||
index -= 1;
|
||||
useLastChar = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hex value of a character (base16).
|
||||
*
|
||||
* @param c A character between '0' and '9' or between 'A' and 'F' or
|
||||
* between 'a' and 'f'.
|
||||
* @return An int between 0 and 15, or -1 if c was not a hex digit.
|
||||
*/
|
||||
public static int dehexchar(final char c) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
return c - '0';
|
||||
}
|
||||
if (c >= 'A' && c <= 'F') {
|
||||
return c - ('A' - 10);
|
||||
}
|
||||
if (c >= 'a' && c <= 'f') {
|
||||
return c - ('a' - 10);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the source string still contains characters that next()
|
||||
* can consume.
|
||||
*
|
||||
* @return true if not yet at the end of the source.
|
||||
*/
|
||||
public boolean more() throws JSONException {
|
||||
char nextChar = next();
|
||||
if (nextChar == 0) {
|
||||
return false;
|
||||
}
|
||||
back();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next character in the source string.
|
||||
*
|
||||
* @return The next character, or 0 if past the end of the source string.
|
||||
*/
|
||||
public char next() throws JSONException {
|
||||
if (useLastChar) {
|
||||
useLastChar = false;
|
||||
if (lastChar != 0) {
|
||||
index += 1;
|
||||
}
|
||||
return lastChar;
|
||||
}
|
||||
int c;
|
||||
try {
|
||||
c = reader.read();
|
||||
}
|
||||
catch (IOException exc) {
|
||||
throw new JSONException(exc);
|
||||
}
|
||||
|
||||
if (c <= 0) { // End of stream
|
||||
lastChar = 0;
|
||||
return 0;
|
||||
}
|
||||
index += 1;
|
||||
lastChar = (char) c;
|
||||
return lastChar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consume the next character, and check that it matches a specified
|
||||
* character.
|
||||
*
|
||||
* @param c The character to match.
|
||||
* @return The character.
|
||||
* @throws JSONException if the character does not match.
|
||||
*/
|
||||
public char next(final char c) throws JSONException {
|
||||
char n = next();
|
||||
if (n != c) {
|
||||
throw syntaxError("Expected '" + c + "' and instead saw '" + n + "'");
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next n characters.
|
||||
*
|
||||
* @param n The number of characters to take.
|
||||
* @return A string of n characters.
|
||||
* @throws JSONException Substring bounds error if there are not
|
||||
* n characters remaining in the source string.
|
||||
*/
|
||||
public String next(final int n) throws JSONException {
|
||||
if (n == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
char[] buffer = new char[n];
|
||||
int pos = 0;
|
||||
|
||||
if (useLastChar) {
|
||||
useLastChar = false;
|
||||
buffer[0] = lastChar;
|
||||
pos = 1;
|
||||
}
|
||||
|
||||
try {
|
||||
int len;
|
||||
while (pos < n && (len = reader.read(buffer, pos, n - pos)) != -1) {
|
||||
pos += len;
|
||||
}
|
||||
}
|
||||
catch (IOException exc) {
|
||||
throw new JSONException(exc);
|
||||
}
|
||||
index += pos;
|
||||
|
||||
if (pos < n) {
|
||||
throw syntaxError("Substring bounds error");
|
||||
}
|
||||
|
||||
lastChar = buffer[n - 1];
|
||||
return new String(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next char in the string, skipping whitespace.
|
||||
*
|
||||
* @return A character, or 0 if there are no more characters.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public char nextClean() throws JSONException {
|
||||
for (;;) {
|
||||
char c = next();
|
||||
if (c == 0 || c > ' ') {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the characters up to the next close quote character.
|
||||
* Backslash processing is done. The formal JSON format does not
|
||||
* allow strings in single quotes, but an implementation is allowed to
|
||||
* accept them.
|
||||
*
|
||||
* @param quote The quoting character, either
|
||||
* <code>"</code> <small>(double quote)</small> or
|
||||
* <code>'</code> <small>(single quote)</small>.
|
||||
* @return A String.
|
||||
* @throws JSONException Unterminated string.
|
||||
*/
|
||||
public String nextString(final char quote) throws JSONException {
|
||||
char c;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (;;) {
|
||||
c = next();
|
||||
switch (c) {
|
||||
case 0:
|
||||
case '\n':
|
||||
case '\r':
|
||||
throw syntaxError("Unterminated string");
|
||||
case '\\':
|
||||
c = next();
|
||||
switch (c) {
|
||||
case 'b':
|
||||
sb.append('\b');
|
||||
break;
|
||||
case 't':
|
||||
sb.append('\t');
|
||||
break;
|
||||
case 'n':
|
||||
sb.append('\n');
|
||||
break;
|
||||
case 'f':
|
||||
sb.append('\f');
|
||||
break;
|
||||
case 'r':
|
||||
sb.append('\r');
|
||||
break;
|
||||
case 'u':
|
||||
sb.append((char) Integer.parseInt(next(4), 16));
|
||||
break;
|
||||
case 'x':
|
||||
sb.append((char) Integer.parseInt(next(2), 16));
|
||||
break;
|
||||
default:
|
||||
sb.append(c);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (c == quote) {
|
||||
return sb.toString();
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text up but not including the specified character or the
|
||||
* end of line, whichever comes first.
|
||||
*
|
||||
* @param d A delimiter character.
|
||||
* @return A string.
|
||||
*/
|
||||
public String nextTo(final char d) throws JSONException {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (;;) {
|
||||
char c = next();
|
||||
if (c == d || c == 0 || c == '\n' || c == '\r') {
|
||||
if (c != 0) {
|
||||
back();
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text up but not including one of the specified delimiter
|
||||
* characters or the end of line, whichever comes first.
|
||||
*
|
||||
* @param delimiters A set of delimiter characters.
|
||||
* @return A string, trimmed.
|
||||
*/
|
||||
public String nextTo(final String delimiters) throws JSONException {
|
||||
char c;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (;;) {
|
||||
c = next();
|
||||
if (delimiters.indexOf(c) >= 0 || c == 0 || c == '\n' || c == '\r') {
|
||||
if (c != 0) {
|
||||
back();
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next value. The value can be a Boolean, Double, Integer,
|
||||
* JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
|
||||
*
|
||||
* @return An object.
|
||||
* @throws JSONException If syntax error.
|
||||
*/
|
||||
public Object nextValue() throws JSONException {
|
||||
char c = nextClean();
|
||||
String s;
|
||||
|
||||
switch (c) {
|
||||
case '"':
|
||||
case '\'':
|
||||
return nextString(c);
|
||||
case '{':
|
||||
back();
|
||||
return new JSONObject(this);
|
||||
case '[':
|
||||
case '(':
|
||||
back();
|
||||
return new JSONArray(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle unquoted text. This could be the values true, false, or
|
||||
* null, or it can be a number. An implementation (such as this one)
|
||||
* is allowed to also accept non-standard forms.
|
||||
*
|
||||
* Accumulate characters until we reach the end of the text or a
|
||||
* formatting character.
|
||||
*/
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
|
||||
sb.append(c);
|
||||
c = next();
|
||||
}
|
||||
back();
|
||||
|
||||
s = sb.toString().trim();
|
||||
if (s.equals("")) {
|
||||
throw syntaxError("Missing value");
|
||||
}
|
||||
return JSONObject.stringToValue(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip characters until the next character is the requested character.
|
||||
* If the requested character is not found, no characters are skipped.
|
||||
*
|
||||
* @param to A character to skip to.
|
||||
* @return The requested character, or zero if the requested character
|
||||
* is not found.
|
||||
*/
|
||||
public char skipTo(final char to) throws JSONException {
|
||||
char c;
|
||||
try {
|
||||
int startIndex = index;
|
||||
reader.mark(Integer.MAX_VALUE);
|
||||
do {
|
||||
c = next();
|
||||
if (c == 0) {
|
||||
reader.reset();
|
||||
index = startIndex;
|
||||
return c;
|
||||
}
|
||||
} while (c != to);
|
||||
}
|
||||
catch (IOException exc) {
|
||||
throw new JSONException(exc);
|
||||
}
|
||||
|
||||
back();
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a JSONException to signal a syntax error.
|
||||
*
|
||||
* @param message The error message.
|
||||
* @return A JSONException object, suitable for throwing
|
||||
*/
|
||||
public JSONException syntaxError(final String message) {
|
||||
return new JSONException(message + toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a printable string of this JSONTokener.
|
||||
*
|
||||
* @return " at character [this.index]"
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return " at character " + index;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.activemq.artemis.api.core.management;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class AddressSettingsInfoTest {
|
||||
|
||||
@Test
|
||||
public void shouldLoadFromJSON() {
|
||||
String json = "{\n" +
|
||||
"\"addressFullMessagePolicy\":\"fullPolicy\",\n" +
|
||||
"\"maxSizeBytes\":500,\n" +
|
||||
"\"pageSizeBytes\":200,\n" +
|
||||
"\"pageCacheMaxSize\":3,\n" +
|
||||
"\"maxDeliveryAttempts\":3,\n" +
|
||||
"\"redeliveryDelay\":70000,\n" +
|
||||
"\"redeliveryMultiplier\":1.5,\n" +
|
||||
"\"maxRedeliveryDelay\":100000,\n" +
|
||||
"\"DLA\":\"deadLettersGoHere\",\n" +
|
||||
"\"expiryAddress\":\"\",\n" +
|
||||
"\"lastValueQueue\":true,\n" +
|
||||
"\"redistributionDelay\":10004,\n" +
|
||||
"\"sendToDLAOnNoRoute\":true,\n" +
|
||||
"\"slowConsumerThreshold\":200,\n" +
|
||||
"\"slowConsumerCheckPeriod\":300,\n" +
|
||||
"\"slowConsumerPolicy\":\"retire\",\n" +
|
||||
"\"autoCreateJmsQueues\":true,\n" +
|
||||
"\"autoDeleteJmsQueues\":false,\n" +
|
||||
"\"autoCreateJmsTopics\":true,\n" +
|
||||
"\"autoDeleteJmsTopics\":false\n" +
|
||||
"}";
|
||||
AddressSettingsInfo addressSettingsInfo = AddressSettingsInfo.from(json);
|
||||
assertEquals("fullPolicy", addressSettingsInfo.getAddressFullMessagePolicy());
|
||||
assertEquals(500L, addressSettingsInfo.getMaxSizeBytes());
|
||||
assertEquals(200L, addressSettingsInfo.getPageSizeBytes());
|
||||
assertEquals(3, addressSettingsInfo.getPageCacheMaxSize());
|
||||
assertEquals(3, addressSettingsInfo.getMaxDeliveryAttempts());
|
||||
assertEquals(70000, addressSettingsInfo.getRedeliveryDelay());
|
||||
assertEquals(1.5, addressSettingsInfo.getRedeliveryMultiplier(), 0);
|
||||
assertEquals(100000, addressSettingsInfo.getMaxRedeliveryDelay());
|
||||
assertEquals("deadLettersGoHere", addressSettingsInfo.getDeadLetterAddress());
|
||||
assertEquals("", addressSettingsInfo.getExpiryAddress());
|
||||
assertTrue(addressSettingsInfo.isLastValueQueue());
|
||||
assertEquals(10004L, addressSettingsInfo.getRedistributionDelay());
|
||||
assertTrue(addressSettingsInfo.isSendToDLAOnNoRoute());
|
||||
assertEquals(200L, addressSettingsInfo.getSlowConsumerThreshold());
|
||||
assertEquals(300L, addressSettingsInfo.getSlowConsumerCheckPeriod());
|
||||
assertEquals("retire", addressSettingsInfo.getSlowConsumerPolicy());
|
||||
assertTrue(addressSettingsInfo.isAutoCreateJmsQueues());
|
||||
assertTrue(addressSettingsInfo.isAutoCreateJmsTopics());
|
||||
assertFalse(addressSettingsInfo.isAutoDeleteJmsQueues());
|
||||
assertFalse(addressSettingsInfo.isAutoDeleteJmsTopics());
|
||||
}
|
||||
|
||||
}
|
|
@ -188,6 +188,14 @@
|
|||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-codec-mqtt</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-json_1.0_spec</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.johnzon</groupId>
|
||||
<artifactId>johnzon-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -93,6 +93,8 @@
|
|||
<include>org.fusesource.hawtbuf:hawtbuf</include>
|
||||
<include>org.jgroups:jgroups</include>
|
||||
<include>io.netty:netty-codec-mqtt</include>
|
||||
<include>org.apache.geronimo.specs:geronimo-json_1.0_spec</include>
|
||||
<include>org.apache.johnzon:johnzon-core</include>
|
||||
</includes>
|
||||
<!--excludes>
|
||||
<exclude>org.apache.activemq:artemis-website</exclude>
|
||||
|
|
|
@ -51,6 +51,9 @@
|
|||
<bundle>mvn:org.jboss.logging/jboss-logging/${jboss.logging.version}</bundle>
|
||||
<bundle>mvn:org.jgroups/jgroups/${jgroups.version}</bundle>
|
||||
|
||||
<bundle>mvn:org.apache.geronimo.specs/geronimo-json_1.0_spec/${json-p.spec.version}</bundle>
|
||||
<bundle>mvn:org.apache.johnzon/johnzon-core/${johnzon.version}</bundle>
|
||||
|
||||
<bundle>mvn:org.apache.activemq/artemis-native/${pom.version}</bundle>
|
||||
<bundle>mvn:org.apache.activemq/artemis-server-osgi/${pom.version}</bundle>
|
||||
</feature>
|
||||
|
|
|
@ -69,7 +69,6 @@
|
|||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.api.jms.management;
|
||||
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
|
||||
public class JMSConnectionInfo {
|
||||
|
||||
|
@ -34,14 +36,16 @@ public class JMSConnectionInfo {
|
|||
// Static --------------------------------------------------------
|
||||
|
||||
public static JMSConnectionInfo[] from(final String jsonString) throws Exception {
|
||||
JSONArray array = new JSONArray(jsonString);
|
||||
JMSConnectionInfo[] infos = new JMSConnectionInfo[array.length()];
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
JSONObject obj = array.getJSONObject(i);
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
JMSConnectionInfo[] infos = new JMSConnectionInfo[array.size()];
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JsonObject obj = array.getJsonObject(i);
|
||||
String cid = obj.isNull("clientID") ? null : obj.getString("clientID");
|
||||
String uname = obj.isNull("principal") ? null : obj.getString("principal");
|
||||
|
||||
JMSConnectionInfo info = new JMSConnectionInfo(obj.getString("connectionID"), obj.getString("clientAddress"), obj.getLong("creationTime"), cid, uname);
|
||||
JMSConnectionInfo info = new JMSConnectionInfo(obj.getString("connectionID"), obj.getString("clientAddress"),
|
||||
obj.getJsonNumber("creationTime").longValue(),
|
||||
cid, uname);
|
||||
infos[i] = info;
|
||||
}
|
||||
return infos;
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.api.jms.management;
|
||||
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
|
||||
/**
|
||||
* Helper class to create Java Objects from the
|
||||
|
@ -48,11 +50,14 @@ public class JMSConsumerInfo {
|
|||
* by {@link TopicControl#listAllSubscriptionsAsJSON()} and related methods.
|
||||
*/
|
||||
public static JMSConsumerInfo[] from(final String jsonString) throws Exception {
|
||||
JSONArray array = new JSONArray(jsonString);
|
||||
JMSConsumerInfo[] infos = new JMSConsumerInfo[array.length()];
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
JSONObject sub = array.getJSONObject(i);
|
||||
JMSConsumerInfo info = new JMSConsumerInfo(sub.getString("consumerID"), sub.getString("connectionID"), sub.getString("destinationName"), sub.getString("destinationType"), sub.getBoolean("browseOnly"), sub.getLong("creationTime"), sub.getBoolean("durable"), sub.optString("filter", null));
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
JMSConsumerInfo[] infos = new JMSConsumerInfo[array.size()];
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JsonObject sub = array.getJsonObject(i);
|
||||
JMSConsumerInfo info = new JMSConsumerInfo(sub.getString("consumerID"), sub.getString("connectionID"),
|
||||
sub.getString("destinationName"), sub.getString("destinationType"), sub.getBoolean("browseOnly"),
|
||||
sub.getJsonNumber("creationTime").longValue(),
|
||||
sub.getBoolean("durable"), sub.getString("filter", null));
|
||||
infos[i] = info;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,10 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.api.jms.management;
|
||||
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONException;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
|
||||
public class JMSSessionInfo {
|
||||
|
||||
|
@ -31,13 +32,14 @@ public class JMSSessionInfo {
|
|||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
public static JMSSessionInfo[] from(final String jsonString) throws JSONException {
|
||||
JSONArray array = new JSONArray(jsonString);
|
||||
JMSSessionInfo[] infos = new JMSSessionInfo[array.length()];
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
JSONObject obj = array.getJSONObject(i);
|
||||
public static JMSSessionInfo[] from(final String jsonString) {
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
JMSSessionInfo[] infos = new JMSSessionInfo[array.size()];
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JsonObject obj = array.getJsonObject(i);
|
||||
|
||||
JMSSessionInfo info = new JMSSessionInfo(obj.getString("sessionID"), obj.getLong("creationTime"));
|
||||
JMSSessionInfo info = new JMSSessionInfo(obj.getString("sessionID"),
|
||||
obj.getJsonNumber("creationTime").longValue());
|
||||
infos[i] = info;
|
||||
}
|
||||
return infos;
|
||||
|
|
|
@ -16,8 +16,11 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.api.jms.management;
|
||||
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
|
||||
/**
|
||||
* Helper class to create Java Objects from the
|
||||
|
@ -46,11 +49,13 @@ public class SubscriptionInfo {
|
|||
* by {@link TopicControl#listAllSubscriptionsAsJSON()} and related methods.
|
||||
*/
|
||||
public static SubscriptionInfo[] from(final String jsonString) throws Exception {
|
||||
JSONArray array = new JSONArray(jsonString);
|
||||
SubscriptionInfo[] infos = new SubscriptionInfo[array.length()];
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
JSONObject sub = array.getJSONObject(i);
|
||||
SubscriptionInfo info = new SubscriptionInfo(sub.getString("queueName"), sub.optString("clientID", null), sub.optString("name", null), sub.getBoolean("durable"), sub.optString("selector", null), sub.getInt("messageCount"), sub.getInt("deliveringCount"));
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
SubscriptionInfo[] infos = new SubscriptionInfo[array.size()];
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JsonObject sub = array.getJsonObject(i);
|
||||
SubscriptionInfo info = new SubscriptionInfo(sub.getString("queueName"), sub.getString("clientID", null),
|
||||
sub.getString("name", null), sub.getBoolean("durable"), sub.getString("selector", null),
|
||||
sub.getInt("messageCount"), sub.getInt("deliveringCount"));
|
||||
infos[i] = info;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,14 @@
|
|||
<artifactId>geronimo-jta_1.1_spec</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-json_1.0_spec</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.johnzon</groupId>
|
||||
<artifactId>johnzon-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
package org.apache.activemq.artemis.jms.management.impl;
|
||||
|
||||
import javax.jms.InvalidSelectorException;
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.management.MBeanInfo;
|
||||
import javax.management.StandardMBean;
|
||||
import javax.management.openmbean.CompositeData;
|
||||
|
@ -33,6 +35,7 @@ import org.apache.activemq.artemis.api.core.ActiveMQInvalidFilterExpressionExcep
|
|||
import org.apache.activemq.artemis.api.core.FilterConstants;
|
||||
import org.apache.activemq.artemis.api.core.Message;
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.api.core.management.MessageCounterInfo;
|
||||
import org.apache.activemq.artemis.api.core.management.Operation;
|
||||
import org.apache.activemq.artemis.api.core.management.QueueControl;
|
||||
|
@ -47,8 +50,6 @@ import org.apache.activemq.artemis.jms.server.JMSServerManager;
|
|||
import org.apache.activemq.artemis.utils.Base64;
|
||||
import org.apache.activemq.artemis.utils.SelectorTranslator;
|
||||
import org.apache.activemq.artemis.utils.UUIDGenerator;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
|
||||
public class JMSQueueControlImpl extends StandardMBean implements JMSQueueControl {
|
||||
|
||||
|
@ -74,11 +75,11 @@ public class JMSQueueControlImpl extends StandardMBean implements JMSQueueContro
|
|||
}
|
||||
|
||||
static String toJSON(final Map<String, Object>[] messages) {
|
||||
JSONArray array = new JSONArray();
|
||||
JsonArrayBuilder array = Json.createArrayBuilder();
|
||||
for (Map<String, Object> message : messages) {
|
||||
array.put(new JSONObject(message));
|
||||
array.add(JsonUtil.toJsonObject(message));
|
||||
}
|
||||
return array.toString();
|
||||
return array.build().toString();
|
||||
}
|
||||
|
||||
// Constructors --------------------------------------------------
|
||||
|
|
|
@ -17,6 +17,11 @@
|
|||
package org.apache.activemq.artemis.jms.management.impl;
|
||||
|
||||
import javax.jms.JMSRuntimeException;
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
import javax.management.ListenerNotFoundException;
|
||||
import javax.management.MBeanAttributeInfo;
|
||||
import javax.management.MBeanNotificationInfo;
|
||||
|
@ -61,8 +66,6 @@ import org.apache.activemq.artemis.jms.server.config.impl.ConnectionFactoryConfi
|
|||
import org.apache.activemq.artemis.jms.server.management.JMSNotificationType;
|
||||
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
|
||||
import org.apache.activemq.artemis.utils.TypedProperties;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
|
||||
public class JMSServerControlImpl extends AbstractControl implements JMSServerControl, NotificationEmitter, org.apache.activemq.artemis.core.server.management.NotificationListener {
|
||||
|
||||
|
@ -599,7 +602,7 @@ public class JMSServerControlImpl extends AbstractControl implements JMSServerCo
|
|||
clearIO();
|
||||
|
||||
try {
|
||||
JSONArray array = new JSONArray();
|
||||
JsonArrayBuilder array = Json.createArrayBuilder();
|
||||
|
||||
Set<RemotingConnection> connections = server.getActiveMQServer().getRemotingService().getConnections();
|
||||
|
||||
|
@ -617,14 +620,15 @@ public class JMSServerControlImpl extends AbstractControl implements JMSServerCo
|
|||
for (RemotingConnection connection : connections) {
|
||||
ServerSession session = jmsSessions.get(connection.getID());
|
||||
if (session != null) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("connectionID", connection.getID().toString());
|
||||
obj.put("clientAddress", connection.getRemoteAddress());
|
||||
obj.put("creationTime", connection.getCreationTime());
|
||||
// Notice: this will be null when the user haven't set the client-id
|
||||
obj.put("clientID", session.getMetaData(ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY));
|
||||
obj.put("principal", session.getUsername());
|
||||
array.put(obj);
|
||||
JsonObject obj = Json.createObjectBuilder()
|
||||
.add("connectionID", connection.getID().toString())
|
||||
.add("clientAddress", connection.getRemoteAddress())
|
||||
.add("creationTime", connection.getCreationTime())
|
||||
// Notice: this will be null when the user haven't set the client-id
|
||||
.add("clientID", session.getMetaData(ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY))
|
||||
.add("principal", session.getUsername())
|
||||
.build();
|
||||
array.add(obj);
|
||||
}
|
||||
}
|
||||
return array.toString();
|
||||
|
@ -641,24 +645,17 @@ public class JMSServerControlImpl extends AbstractControl implements JMSServerCo
|
|||
clearIO();
|
||||
|
||||
try {
|
||||
JSONArray array = new JSONArray();
|
||||
JsonArrayBuilder array = Json.createArrayBuilder();
|
||||
|
||||
Set<RemotingConnection> connections = server.getActiveMQServer().getRemotingService().getConnections();
|
||||
for (RemotingConnection connection : connections) {
|
||||
if (connectionID.equals(connection.getID().toString())) {
|
||||
List<ServerSession> sessions = server.getActiveMQServer().getSessions(connectionID);
|
||||
for (ServerSession session : sessions) {
|
||||
Set<ServerConsumer> consumers = session.getServerConsumers();
|
||||
for (ServerConsumer consumer : consumers) {
|
||||
JSONObject obj = toJSONObject(consumer);
|
||||
if (obj != null) {
|
||||
array.put(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
JsonArray jsonSessions = toJsonArray(sessions);
|
||||
array.add(jsonSessions);
|
||||
}
|
||||
}
|
||||
return array.toString();
|
||||
return array.build().toString();
|
||||
}
|
||||
finally {
|
||||
blockOnIO();
|
||||
|
@ -672,19 +669,8 @@ public class JMSServerControlImpl extends AbstractControl implements JMSServerCo
|
|||
clearIO();
|
||||
|
||||
try {
|
||||
JSONArray array = new JSONArray();
|
||||
|
||||
Set<ServerSession> sessions = server.getActiveMQServer().getSessions();
|
||||
for (ServerSession session : sessions) {
|
||||
Set<ServerConsumer> consumers = session.getServerConsumers();
|
||||
for (ServerConsumer consumer : consumers) {
|
||||
JSONObject obj = toJSONObject(consumer);
|
||||
if (obj != null) {
|
||||
array.put(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
return array.toString();
|
||||
JsonArray jsonArray = toJsonArray(server.getActiveMQServer().getSessions());
|
||||
return jsonArray.toString();
|
||||
}
|
||||
finally {
|
||||
blockOnIO();
|
||||
|
@ -810,14 +796,14 @@ public class JMSServerControlImpl extends AbstractControl implements JMSServerCo
|
|||
|
||||
clearIO();
|
||||
|
||||
JSONArray array = new JSONArray();
|
||||
JsonArrayBuilder array = Json.createArrayBuilder();
|
||||
try {
|
||||
List<ServerSession> sessions = server.getActiveMQServer().getSessions(connectionID);
|
||||
for (ServerSession sess : sessions) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("sessionID", sess.getName());
|
||||
obj.put("creationTime", sess.getCreationTime());
|
||||
array.put(obj);
|
||||
JsonObjectBuilder obj = Json.createObjectBuilder()
|
||||
.add("sessionID", sess.getName())
|
||||
.add("creationTime", sess.getCreationTime());
|
||||
array.add(obj);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
@ -832,7 +818,7 @@ public class JMSServerControlImpl extends AbstractControl implements JMSServerCo
|
|||
|
||||
clearIO();
|
||||
try {
|
||||
JSONArray brokers = new JSONArray();
|
||||
JsonArrayBuilder brokers = Json.createArrayBuilder();
|
||||
ClusterManager clusterManager = server.getActiveMQServer().getClusterManager();
|
||||
if (clusterManager != null) {
|
||||
Set<ClusterConnection> clusterConnections = clusterManager.getClusterConnections();
|
||||
|
@ -841,17 +827,17 @@ public class JMSServerControlImpl extends AbstractControl implements JMSServerCo
|
|||
Collection<TopologyMemberImpl> members = topology.getMembers();
|
||||
for (TopologyMemberImpl member : members) {
|
||||
|
||||
JSONObject obj = new JSONObject();
|
||||
JsonObjectBuilder obj = Json.createObjectBuilder();
|
||||
TransportConfiguration live = member.getLive();
|
||||
if (live != null) {
|
||||
obj.put("nodeID", member.getNodeId());
|
||||
obj.put("live", live.getParams().get("host") + ":" + live.getParams().get("port"));
|
||||
obj.add("nodeID", member.getNodeId())
|
||||
.add("live", live.getParams().get("host") + ":" + live.getParams().get("port"));
|
||||
TransportConfiguration backup = member.getBackup();
|
||||
if (backup != null) {
|
||||
obj.put("backup", backup.getParams().get("host") + ":" + backup.getParams().get("port"));
|
||||
obj.add("backup", backup.getParams().get("host") + ":" + backup.getParams().get("port"));
|
||||
}
|
||||
}
|
||||
brokers.put(obj);
|
||||
brokers.add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -867,39 +853,41 @@ public class JMSServerControlImpl extends AbstractControl implements JMSServerCo
|
|||
return server.getActiveMQServer().destroyConnectionWithSessionMetadata(ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY, clientID);
|
||||
}
|
||||
|
||||
private JSONObject toJSONObject(ServerConsumer consumer) throws Exception {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("consumerID", consumer.getID());
|
||||
obj.put("connectionID", consumer.getConnectionID());
|
||||
obj.put("sessionID", consumer.getSessionID());
|
||||
obj.put("queueName", consumer.getQueue().getName().toString());
|
||||
obj.put("browseOnly", consumer.isBrowseOnly());
|
||||
obj.put("creationTime", consumer.getCreationTime());
|
||||
// JMS consumer with message filter use the queue's filter
|
||||
Filter queueFilter = consumer.getQueue().getFilter();
|
||||
if (queueFilter != null) {
|
||||
obj.put("filter", queueFilter.getFilterString().toString());
|
||||
}
|
||||
private JsonObject toJSONObject(ServerConsumer consumer) {
|
||||
String[] destinationInfo = determineJMSDestination(consumer.getQueue().getAddress().toString());
|
||||
if (destinationInfo == null) {
|
||||
return null;
|
||||
}
|
||||
obj.put("destinationName", destinationInfo[0]);
|
||||
obj.put("destinationType", destinationInfo[1]);
|
||||
JsonObjectBuilder obj = Json.createObjectBuilder()
|
||||
.add("consumerID", consumer.getID())
|
||||
.add("connectionID", consumer.getConnectionID().toString())
|
||||
.add("sessionID", consumer.getSessionID())
|
||||
.add("queueName", consumer.getQueue().getName().toString())
|
||||
.add("browseOnly", consumer.isBrowseOnly())
|
||||
.add("creationTime", consumer.getCreationTime())
|
||||
.add("destinationName", destinationInfo[0])
|
||||
.add("destinationType", destinationInfo[1]);
|
||||
// JMS consumer with message filter use the queue's filter
|
||||
Filter queueFilter = consumer.getQueue().getFilter();
|
||||
if (queueFilter != null) {
|
||||
obj.add("filter", queueFilter.getFilterString().toString());
|
||||
}
|
||||
|
||||
|
||||
if (destinationInfo[1].equals("topic")) {
|
||||
try {
|
||||
ActiveMQDestination.decomposeQueueNameForDurableSubscription(consumer.getQueue().getName().toString());
|
||||
obj.put("durable", true);
|
||||
obj.add("durable", true);
|
||||
}
|
||||
catch (IllegalArgumentException | JMSRuntimeException e) {
|
||||
obj.put("durable", false);
|
||||
obj.add("durable", false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
obj.put("durable", false);
|
||||
obj.add("durable", false);
|
||||
}
|
||||
|
||||
return obj;
|
||||
return obj.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -912,4 +900,19 @@ public class JMSServerControlImpl extends AbstractControl implements JMSServerCo
|
|||
this.broadcaster.sendNotification(new Notification(type.toString(), this, notifSeq.incrementAndGet(), prop.getSimpleStringProperty(JMSNotificationType.MESSAGE).toString()));
|
||||
}
|
||||
|
||||
private JsonArray toJsonArray(Collection<ServerSession> sessions) {
|
||||
JsonArrayBuilder array = Json.createArrayBuilder();
|
||||
|
||||
for (ServerSession session : sessions) {
|
||||
Set<ServerConsumer> consumers = session.getServerConsumers();
|
||||
for (ServerConsumer consumer : consumers) {
|
||||
JsonObject obj = toJSONObject(consumer);
|
||||
if (obj != null) {
|
||||
array.add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
return array.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonObject;
|
||||
import javax.management.MBeanInfo;
|
||||
import javax.management.StandardMBean;
|
||||
|
||||
|
@ -37,8 +40,8 @@ import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
|
|||
import org.apache.activemq.artemis.jms.client.ActiveMQMessage;
|
||||
import org.apache.activemq.artemis.jms.server.JMSServerManager;
|
||||
import org.apache.activemq.artemis.utils.SelectorTranslator;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
|
||||
import static org.apache.activemq.artemis.api.core.JsonUtil.nullSafe;
|
||||
|
||||
public class JMSTopicControlImpl extends StandardMBean implements TopicControl {
|
||||
|
||||
|
@ -289,7 +292,7 @@ public class JMSTopicControlImpl extends StandardMBean implements TopicControl {
|
|||
private String listSubscribersInfosAsJSON(final DurabilityType durability) throws Exception {
|
||||
try {
|
||||
List<QueueControl> queues = getQueues(durability);
|
||||
JSONArray array = new JSONArray();
|
||||
JsonArrayBuilder array = Json.createArrayBuilder();
|
||||
|
||||
for (QueueControl queue : queues) {
|
||||
String clientID = null;
|
||||
|
@ -310,20 +313,21 @@ public class JMSTopicControlImpl extends StandardMBean implements TopicControl {
|
|||
|
||||
String filter = queue.getFilter() != null ? queue.getFilter() : null;
|
||||
|
||||
JSONObject info = new JSONObject();
|
||||
JsonObject info = Json.createObjectBuilder()
|
||||
.add("queueName", queue.getName())
|
||||
.add("clientID", nullSafe(clientID))
|
||||
.add("selector", nullSafe(filter))
|
||||
.add("name", nullSafe(subName))
|
||||
.add("durable", queue.isDurable())
|
||||
.add("messageCount", queue.getMessageCount())
|
||||
.add("deliveringCount", queue.getDeliveringCount())
|
||||
.add("consumers", queue.listConsumersAsJSON())
|
||||
.build();
|
||||
|
||||
info.put("queueName", queue.getName());
|
||||
info.put("clientID", clientID);
|
||||
info.put("selector", filter);
|
||||
info.put("name", subName);
|
||||
info.put("durable", queue.isDurable());
|
||||
info.put("messageCount", queue.getMessageCount());
|
||||
info.put("deliveringCount", queue.getDeliveringCount());
|
||||
info.put("consumers", new JSONArray(queue.listConsumersAsJSON()));
|
||||
array.put(info);
|
||||
array.add(info);
|
||||
}
|
||||
|
||||
return array.toString();
|
||||
return array.build().toString();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.jms.server.impl;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonObject;
|
||||
import javax.naming.NamingException;
|
||||
import javax.transaction.xa.Xid;
|
||||
import java.net.InetAddress;
|
||||
|
@ -87,8 +91,6 @@ import org.apache.activemq.artemis.spi.core.naming.BindingRegistry;
|
|||
import org.apache.activemq.artemis.utils.SelectorTranslator;
|
||||
import org.apache.activemq.artemis.utils.TimeAndCounterIDGenerator;
|
||||
import org.apache.activemq.artemis.utils.TypedProperties;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
|
||||
/**
|
||||
* A Deployer used to create and add to Bindings queues, topics and connection
|
||||
|
@ -1343,7 +1345,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback
|
|||
}
|
||||
});
|
||||
|
||||
JSONArray txDetailListJson = new JSONArray();
|
||||
JsonArrayBuilder txDetailListJson = Json.createArrayBuilder();
|
||||
for (Map.Entry<Xid, Long> entry : xidsSortedByCreationTime) {
|
||||
Xid xid = entry.getKey();
|
||||
Transaction tx = resourceManager.getTransaction(xid);
|
||||
|
@ -1351,7 +1353,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback
|
|||
continue;
|
||||
}
|
||||
TransactionDetail detail = new JMSTransactionDetail(xid, tx, entry.getValue());
|
||||
txDetailListJson.put(detail.toJSON());
|
||||
txDetailListJson.add(detail.toJSON());
|
||||
}
|
||||
return txDetailListJson.toString();
|
||||
}
|
||||
|
@ -1383,7 +1385,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback
|
|||
continue;
|
||||
}
|
||||
TransactionDetail detail = new JMSTransactionDetail(xid, tx, entry.getValue());
|
||||
JSONObject txJson = detail.toJSON();
|
||||
JsonObject txJson = detail.toJSON();
|
||||
|
||||
html.append("<table border=\"1\">");
|
||||
html.append("<tr><th>creation_time</th>");
|
||||
|
@ -1401,14 +1403,13 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback
|
|||
html.append("<tr><td colspan=\"6\">");
|
||||
html.append("<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">");
|
||||
|
||||
JSONArray msgs = txJson.getJSONArray(TransactionDetail.KEY_TX_RELATED_MESSAGES);
|
||||
for (int i = 0; i < msgs.length(); i++) {
|
||||
JSONObject msgJson = msgs.getJSONObject(i);
|
||||
JSONObject props = msgJson.getJSONObject(TransactionDetail.KEY_MSG_PROPERTIES);
|
||||
JsonArray msgs = txJson.getJsonArray(TransactionDetail.KEY_TX_RELATED_MESSAGES);
|
||||
for (int i = 0; i < msgs.size(); i++) {
|
||||
JsonObject msgJson = msgs.getJsonObject(i);
|
||||
JsonObject props = msgJson.getJsonObject(TransactionDetail.KEY_MSG_PROPERTIES);
|
||||
StringBuilder propstr = new StringBuilder();
|
||||
Iterator<String> propkeys = props.keys();
|
||||
while (propkeys.hasNext()) {
|
||||
String key = propkeys.next();
|
||||
|
||||
for (String key : props.keySet()) {
|
||||
propstr.append(key);
|
||||
propstr.append("=");
|
||||
propstr.append(props.get(key));
|
||||
|
|
|
@ -19,8 +19,13 @@ package org.apache.activemq.artemis.api.core.management;
|
|||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.core.messagecounter.MessageCounter;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonObject;
|
||||
|
||||
import static org.apache.activemq.artemis.api.core.JsonUtil.nullSafe;
|
||||
|
||||
/**
|
||||
* Helper class to create Java Objects from the
|
||||
|
@ -55,27 +60,33 @@ public final class MessageCounterInfo {
|
|||
*/
|
||||
public static String toJSon(final MessageCounter counter) throws Exception {
|
||||
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
|
||||
|
||||
JSONObject json = new JSONObject(counter);
|
||||
String lastAddTimestamp = dateFormat.format(new Date(counter.getLastAddedMessageTime()));
|
||||
json.put("lastAddTimestamp", lastAddTimestamp);
|
||||
String updateTimestamp = dateFormat.format(new Date(counter.getLastUpdate()));
|
||||
json.put("updateTimestamp", updateTimestamp);
|
||||
|
||||
return json.toString();
|
||||
return Json.createObjectBuilder()
|
||||
.add("destinationName", nullSafe(counter.getDestinationName()))
|
||||
.add("destinationSubscription", nullSafe(counter.getDestinationSubscription()))
|
||||
.add("destinationDurable", counter.isDestinationDurable())
|
||||
.add("count", counter.getCount())
|
||||
.add("countDelta", counter.getCountDelta())
|
||||
.add("messageCount", counter.getMessageCount())
|
||||
.add("messageCountDelta", counter.getMessageCountDelta())
|
||||
.add("lastAddTimestamp", lastAddTimestamp)
|
||||
.add("updateTimestamp", updateTimestamp)
|
||||
.build()
|
||||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of RoleInfo corresponding to the JSON serialization returned
|
||||
* Returns a MessageCounterInfo corresponding to the JSON serialization returned
|
||||
* by {@link QueueControl#listMessageCounter()}.
|
||||
*/
|
||||
public static MessageCounterInfo fromJSON(final String jsonString) throws Exception {
|
||||
JSONObject data = new JSONObject(jsonString);
|
||||
JsonObject data = JsonUtil.readJsonObject(jsonString);
|
||||
String name = data.getString("destinationName");
|
||||
String subscription = data.getString("destinationSubscription");
|
||||
String subscription = data.getString("destinationSubscription", null);
|
||||
boolean durable = data.getBoolean("destinationDurable");
|
||||
long count = data.getLong("count");
|
||||
long countDelta = data.getLong("countDelta");
|
||||
long count = data.getJsonNumber("count").longValue();
|
||||
long countDelta = data.getJsonNumber("countDelta").longValue();
|
||||
int depth = data.getInt("messageCount");
|
||||
int depthDelta = data.getInt("messageCountDelta");
|
||||
String lastAddTimestamp = data.getString("lastAddTimestamp");
|
||||
|
|
|
@ -22,14 +22,17 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
import javax.management.ListenerNotFoundException;
|
||||
import javax.management.MBeanAttributeInfo;
|
||||
import javax.management.MBeanNotificationInfo;
|
||||
|
@ -88,8 +91,6 @@ import org.apache.activemq.artemis.core.transaction.impl.XidImpl;
|
|||
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
|
||||
import org.apache.activemq.artemis.utils.SecurityFormatter;
|
||||
import org.apache.activemq.artemis.utils.TypedProperties;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
|
||||
public class ActiveMQServerControlImpl extends AbstractControl implements ActiveMQServerControl, NotificationEmitter, org.apache.activemq.artemis.core.server.management.NotificationListener {
|
||||
// Constants -----------------------------------------------------
|
||||
|
@ -974,7 +975,7 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
}
|
||||
});
|
||||
|
||||
JSONArray txDetailListJson = new JSONArray();
|
||||
JsonArrayBuilder txDetailListJson = Json.createArrayBuilder();
|
||||
for (Map.Entry<Xid, Long> entry : xidsSortedByCreationTime) {
|
||||
Xid xid = entry.getKey();
|
||||
|
||||
|
@ -986,9 +987,9 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
|
||||
TransactionDetail detail = new CoreTransactionDetail(xid, tx, entry.getValue());
|
||||
|
||||
txDetailListJson.put(detail.toJSON());
|
||||
txDetailListJson.add(detail.toJSON());
|
||||
}
|
||||
return txDetailListJson.toString();
|
||||
return txDetailListJson.build().toString();
|
||||
}
|
||||
finally {
|
||||
blockOnIO();
|
||||
|
@ -1029,7 +1030,7 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
|
||||
TransactionDetail detail = new CoreTransactionDetail(xid, tx, entry.getValue());
|
||||
|
||||
JSONObject txJson = detail.toJSON();
|
||||
JsonObject txJson = detail.toJSON();
|
||||
|
||||
html.append("<table border=\"1\">");
|
||||
html.append("<tr><th>creation_time</th>");
|
||||
|
@ -1047,14 +1048,13 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
html.append("<tr><td colspan=\"6\">");
|
||||
html.append("<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">");
|
||||
|
||||
JSONArray msgs = txJson.getJSONArray(TransactionDetail.KEY_TX_RELATED_MESSAGES);
|
||||
for (int i = 0; i < msgs.length(); i++) {
|
||||
JSONObject msgJson = msgs.getJSONObject(i);
|
||||
JSONObject props = msgJson.getJSONObject(TransactionDetail.KEY_MSG_PROPERTIES);
|
||||
JsonArray msgs = txJson.getJsonArray(TransactionDetail.KEY_TX_RELATED_MESSAGES);
|
||||
for (int i = 0; i < msgs.size(); i++) {
|
||||
JsonObject msgJson = msgs.getJsonObject(i);
|
||||
JsonObject props = msgJson.getJsonObject(TransactionDetail.KEY_MSG_PROPERTIES);
|
||||
StringBuilder propstr = new StringBuilder();
|
||||
Iterator<String> propkeys = props.keys();
|
||||
while (propkeys.hasNext()) {
|
||||
String key = propkeys.next();
|
||||
Set<String> keys = props.keySet();
|
||||
for (String key : keys) {
|
||||
propstr.append(key);
|
||||
propstr.append("=");
|
||||
propstr.append(props.get(key));
|
||||
|
@ -1350,13 +1350,13 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
*/
|
||||
@Override
|
||||
public String listProducersInfoAsJSON() throws Exception {
|
||||
JSONArray producers = new JSONArray();
|
||||
JsonArrayBuilder producers = Json.createArrayBuilder();
|
||||
|
||||
for (ServerSession session : server.getSessions()) {
|
||||
session.describeProducersInfo(producers);
|
||||
}
|
||||
|
||||
return producers.toString();
|
||||
return producers.build().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1393,13 +1393,13 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
|
||||
clearIO();
|
||||
try {
|
||||
JSONArray array = new JSONArray();
|
||||
JsonArrayBuilder array = Json.createArrayBuilder();
|
||||
|
||||
for (TransportConfiguration config : configuration.getConnectorConfigurations().values()) {
|
||||
array.put(new JSONObject(config));
|
||||
array.add(config.toJson());
|
||||
}
|
||||
|
||||
return array.toString();
|
||||
return array.build().toString();
|
||||
}
|
||||
finally {
|
||||
blockOnIO();
|
||||
|
@ -1488,13 +1488,13 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
|
||||
clearIO();
|
||||
try {
|
||||
JSONArray json = new JSONArray();
|
||||
JsonArrayBuilder json = Json.createArrayBuilder();
|
||||
Set<Role> roles = server.getSecurityRepository().getMatch(addressMatch);
|
||||
|
||||
for (Role role : roles) {
|
||||
json.put(new JSONObject(role));
|
||||
json.add(role.toJson());
|
||||
}
|
||||
return json.toString();
|
||||
return json.build().toString();
|
||||
}
|
||||
finally {
|
||||
blockOnIO();
|
||||
|
@ -1506,37 +1506,36 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
checkStarted();
|
||||
|
||||
AddressSettings addressSettings = server.getAddressSettingsRepository().getMatch(address);
|
||||
Map<String, Object> settings = new HashMap<>();
|
||||
String policy = addressSettings.getAddressFullMessagePolicy() == AddressFullMessagePolicy.PAGE ? "PAGE" : addressSettings.getAddressFullMessagePolicy() == AddressFullMessagePolicy.BLOCK ? "BLOCK" : addressSettings.getAddressFullMessagePolicy() == AddressFullMessagePolicy.DROP ? "DROP" : "FAIL";
|
||||
String consumerPolicy = addressSettings.getSlowConsumerPolicy() == SlowConsumerPolicy.NOTIFY ? "NOTIFY" : "KILL";
|
||||
JsonObjectBuilder settings = Json.createObjectBuilder();
|
||||
if (addressSettings.getDeadLetterAddress() != null) {
|
||||
settings.put("DLA", addressSettings.getDeadLetterAddress());
|
||||
settings.add("DLA", addressSettings.getDeadLetterAddress().toString());
|
||||
}
|
||||
if (addressSettings.getExpiryAddress() != null) {
|
||||
settings.put("expiryAddress", addressSettings.getExpiryAddress());
|
||||
settings.add("expiryAddress", addressSettings.getExpiryAddress().toString());
|
||||
}
|
||||
settings.put("expiryDelay", addressSettings.getExpiryDelay());
|
||||
settings.put("maxDeliveryAttempts", addressSettings.getMaxDeliveryAttempts());
|
||||
settings.put("pageCacheMaxSize", addressSettings.getPageCacheMaxSize());
|
||||
settings.put("maxSizeBytes", addressSettings.getMaxSizeBytes());
|
||||
settings.put("pageSizeBytes", addressSettings.getPageSizeBytes());
|
||||
settings.put("redeliveryDelay", addressSettings.getRedeliveryDelay());
|
||||
settings.put("redeliveryMultiplier", addressSettings.getRedeliveryMultiplier());
|
||||
settings.put("maxRedeliveryDelay", addressSettings.getMaxRedeliveryDelay());
|
||||
settings.put("redistributionDelay", addressSettings.getRedistributionDelay());
|
||||
settings.put("lastValueQueue", addressSettings.isLastValueQueue());
|
||||
settings.put("sendToDLAOnNoRoute", addressSettings.isSendToDLAOnNoRoute());
|
||||
String policy = addressSettings.getAddressFullMessagePolicy() == AddressFullMessagePolicy.PAGE ? "PAGE" : addressSettings.getAddressFullMessagePolicy() == AddressFullMessagePolicy.BLOCK ? "BLOCK" : addressSettings.getAddressFullMessagePolicy() == AddressFullMessagePolicy.DROP ? "DROP" : "FAIL";
|
||||
settings.put("addressFullMessagePolicy", policy);
|
||||
settings.put("slowConsumerThreshold", addressSettings.getSlowConsumerThreshold());
|
||||
settings.put("slowConsumerCheckPeriod", addressSettings.getSlowConsumerCheckPeriod());
|
||||
policy = addressSettings.getSlowConsumerPolicy() == SlowConsumerPolicy.NOTIFY ? "NOTIFY" : "KILL";
|
||||
settings.put("slowConsumerPolicy", policy);
|
||||
settings.put("autoCreateJmsQueues", addressSettings.isAutoCreateJmsQueues());
|
||||
settings.put("autoDeleteJmsQueues", addressSettings.isAutoDeleteJmsQueues());
|
||||
settings.put("autoCreateJmsTopics", addressSettings.isAutoCreateJmsTopics());
|
||||
settings.put("autoDeleteJmsTopics", addressSettings.isAutoDeleteJmsTopics());
|
||||
|
||||
JSONObject jsonObject = new JSONObject(settings);
|
||||
return jsonObject.toString();
|
||||
return settings
|
||||
.add("expiryDelay", addressSettings.getExpiryDelay())
|
||||
.add("maxDeliveryAttempts", addressSettings.getMaxDeliveryAttempts())
|
||||
.add("pageCacheMaxSize", addressSettings.getPageCacheMaxSize())
|
||||
.add("maxSizeBytes", addressSettings.getMaxSizeBytes())
|
||||
.add("pageSizeBytes", addressSettings.getPageSizeBytes())
|
||||
.add("redeliveryDelay", addressSettings.getRedeliveryDelay())
|
||||
.add("redeliveryMultiplier", addressSettings.getRedeliveryMultiplier())
|
||||
.add("maxRedeliveryDelay", addressSettings.getMaxRedeliveryDelay())
|
||||
.add("redistributionDelay", addressSettings.getRedistributionDelay())
|
||||
.add("lastValueQueue", addressSettings.isLastValueQueue())
|
||||
.add("sendToDLAOnNoRoute", addressSettings.isSendToDLAOnNoRoute())
|
||||
.add("addressFullMessagePolicy", policy)
|
||||
.add("slowConsumerThreshold", addressSettings.getSlowConsumerThreshold())
|
||||
.add("slowConsumerCheckPeriod", addressSettings.getSlowConsumerCheckPeriod())
|
||||
.add("slowConsumerPolicy", consumerPolicy)
|
||||
.add("autoCreateJmsQueues", addressSettings.isAutoCreateJmsQueues())
|
||||
.add("autoDeleteJmsQueues", addressSettings.isAutoDeleteJmsQueues())
|
||||
.add("autoCreateJmsTopics", addressSettings.isAutoCreateJmsTopics())
|
||||
.add("autoDeleteJmsTopics", addressSettings.isAutoDeleteJmsTopics())
|
||||
.build().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.core.management.impl;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.management.MBeanAttributeInfo;
|
||||
import javax.management.MBeanOperationInfo;
|
||||
import java.util.ArrayList;
|
||||
|
@ -34,8 +36,6 @@ import org.apache.activemq.artemis.core.postoffice.QueueBinding;
|
|||
import org.apache.activemq.artemis.core.security.CheckType;
|
||||
import org.apache.activemq.artemis.core.security.Role;
|
||||
import org.apache.activemq.artemis.core.settings.HierarchicalRepository;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
|
||||
public class AddressControlImpl extends AbstractControl implements AddressControl {
|
||||
|
||||
|
@ -140,11 +140,11 @@ public class AddressControlImpl extends AbstractControl implements AddressContro
|
|||
public String getRolesAsJSON() throws Exception {
|
||||
clearIO();
|
||||
try {
|
||||
JSONArray json = new JSONArray();
|
||||
JsonArrayBuilder json = Json.createArrayBuilder();
|
||||
Set<Role> roles = securityRepository.getMatch(address.toString());
|
||||
|
||||
for (Role role : roles) {
|
||||
json.put(new JSONObject(role));
|
||||
json.add(role.toJson());
|
||||
}
|
||||
return json.toString();
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ import javax.management.MBeanOperationInfo;
|
|||
import org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration;
|
||||
import org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory;
|
||||
import org.apache.activemq.artemis.api.core.management.BroadcastGroupControl;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.core.persistence.StorageManager;
|
||||
import org.apache.activemq.artemis.core.server.cluster.BroadcastGroup;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
|
||||
public class BroadcastGroupControlImpl extends AbstractControl implements BroadcastGroupControl {
|
||||
|
||||
|
@ -94,12 +94,7 @@ public class BroadcastGroupControlImpl extends AbstractControl implements Broadc
|
|||
public String getConnectorPairsAsJSON() throws Exception {
|
||||
clearIO();
|
||||
try {
|
||||
JSONArray array = new JSONArray();
|
||||
|
||||
for (String connector : configuration.getConnectorInfos()) {
|
||||
array.put(connector);
|
||||
}
|
||||
return array.toString();
|
||||
return JsonUtil.toJsonArray(configuration.getConnectorInfos()).toString();
|
||||
}
|
||||
finally {
|
||||
blockOnIO();
|
||||
|
|
|
@ -22,10 +22,10 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.management.ClusterConnectionControl;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration;
|
||||
import org.apache.activemq.artemis.core.persistence.StorageManager;
|
||||
import org.apache.activemq.artemis.core.server.cluster.ClusterConnection;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
|
||||
public class ClusterConnectionControlImpl extends AbstractControl implements ClusterConnectionControl {
|
||||
|
||||
|
@ -143,18 +143,7 @@ public class ClusterConnectionControlImpl extends AbstractControl implements Clu
|
|||
public String getStaticConnectorsAsJSON() throws Exception {
|
||||
clearIO();
|
||||
try {
|
||||
List<String> connectors = configuration.getStaticConnectors();
|
||||
|
||||
if (connectors == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONArray array = new JSONArray();
|
||||
|
||||
for (String connector : connectors) {
|
||||
array.put(connector);
|
||||
}
|
||||
return array.toString();
|
||||
return JsonUtil.toJsonArray(configuration.getStaticConnectors()).toString();
|
||||
}
|
||||
finally {
|
||||
blockOnIO();
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.core.management.impl;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
import javax.management.MBeanAttributeInfo;
|
||||
import javax.management.MBeanOperationInfo;
|
||||
import javax.management.openmbean.CompositeData;
|
||||
|
@ -27,6 +31,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.ActiveMQException;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.api.core.Message;
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.api.core.management.MessageCounterInfo;
|
||||
|
@ -55,9 +60,6 @@ import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
|
|||
import org.apache.activemq.artemis.utils.Base64;
|
||||
import org.apache.activemq.artemis.utils.LinkedListIterator;
|
||||
import org.apache.activemq.artemis.utils.UUID;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONException;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
|
||||
public class QueueControlImpl extends AbstractControl implements QueueControl {
|
||||
|
||||
|
@ -81,33 +83,28 @@ public class QueueControlImpl extends AbstractControl implements QueueControl {
|
|||
// Static --------------------------------------------------------
|
||||
|
||||
private static String toJSON(final Map<String, Object>[] messages) {
|
||||
JSONArray array = toJSONMsgArray(messages);
|
||||
JsonArray array = toJSONMsgArray(messages);
|
||||
return array.toString();
|
||||
}
|
||||
|
||||
private static JSONArray toJSONMsgArray(final Map<String, Object>[] messages) {
|
||||
JSONArray array = new JSONArray();
|
||||
private static JsonArray toJSONMsgArray(final Map<String, Object>[] messages) {
|
||||
JsonArrayBuilder array = Json.createArrayBuilder();
|
||||
for (Map<String, Object> message : messages) {
|
||||
array.put(new JSONObject(message));
|
||||
array.add(JsonUtil.toJsonObject(message));
|
||||
}
|
||||
return array;
|
||||
return array.build();
|
||||
}
|
||||
|
||||
private static String toJSON(final Map<String, Map<String, Object>[]> messages) {
|
||||
try {
|
||||
JSONArray arrayReturn = new JSONArray();
|
||||
for (Map.Entry<String, Map<String, Object>[]> entry : messages.entrySet()) {
|
||||
JSONObject objectItem = new JSONObject();
|
||||
objectItem.put("consumerName", entry.getKey());
|
||||
objectItem.put("elements", toJSONMsgArray(entry.getValue()));
|
||||
arrayReturn.put(objectItem);
|
||||
}
|
||||
JsonArrayBuilder arrayReturn = Json.createArrayBuilder();
|
||||
for (Map.Entry<String, Map<String, Object>[]> entry : messages.entrySet()) {
|
||||
JsonObjectBuilder objectItem = Json.createObjectBuilder();
|
||||
objectItem.add("consumerName", entry.getKey());
|
||||
objectItem.add("elements", toJSONMsgArray(entry.getValue()));
|
||||
arrayReturn.add(objectItem);
|
||||
}
|
||||
|
||||
return arrayReturn.toString();
|
||||
}
|
||||
catch (JSONException e) {
|
||||
return "Invalid conversion " + e.toString();
|
||||
}
|
||||
return arrayReturn.build().toString();
|
||||
}
|
||||
|
||||
// Constructors --------------------------------------------------
|
||||
|
@ -950,26 +947,26 @@ public class QueueControlImpl extends AbstractControl implements QueueControl {
|
|||
try {
|
||||
Collection<Consumer> consumers = queue.getConsumers();
|
||||
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
JsonArrayBuilder jsonArray = Json.createArrayBuilder();
|
||||
|
||||
for (Consumer consumer : consumers) {
|
||||
|
||||
if (consumer instanceof ServerConsumer) {
|
||||
ServerConsumer serverConsumer = (ServerConsumer) consumer;
|
||||
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("consumerID", serverConsumer.getID());
|
||||
obj.put("connectionID", serverConsumer.getConnectionID().toString());
|
||||
obj.put("sessionID", serverConsumer.getSessionID());
|
||||
obj.put("browseOnly", serverConsumer.isBrowseOnly());
|
||||
obj.put("creationTime", serverConsumer.getCreationTime());
|
||||
JsonObjectBuilder obj = Json.createObjectBuilder()
|
||||
.add("consumerID", serverConsumer.getID())
|
||||
.add("connectionID", serverConsumer.getConnectionID().toString())
|
||||
.add("sessionID", serverConsumer.getSessionID())
|
||||
.add("browseOnly", serverConsumer.isBrowseOnly())
|
||||
.add("creationTime", serverConsumer.getCreationTime());
|
||||
|
||||
jsonArray.put(obj);
|
||||
jsonArray.add(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return jsonArray.toString();
|
||||
return jsonArray.build().toString();
|
||||
}
|
||||
finally {
|
||||
blockOnIO();
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.core.server;
|
||||
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.transaction.xa.Xid;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -27,7 +28,6 @@ import org.apache.activemq.artemis.core.postoffice.RoutingStatus;
|
|||
import org.apache.activemq.artemis.core.security.SecurityAuth;
|
||||
import org.apache.activemq.artemis.core.transaction.Transaction;
|
||||
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
|
||||
public interface ServerSession extends SecurityAuth {
|
||||
|
||||
|
@ -166,7 +166,7 @@ public interface ServerSession extends SecurityAuth {
|
|||
* @param objs
|
||||
* @throws Exception
|
||||
*/
|
||||
void describeProducersInfo(JSONArray objs) throws Exception;
|
||||
void describeProducersInfo(JsonArrayBuilder objs) throws Exception;
|
||||
|
||||
String getLastSentMessageID(String address);
|
||||
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.core.server.impl;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
import javax.transaction.xa.XAException;
|
||||
import javax.transaction.xa.Xid;
|
||||
import java.util.ArrayList;
|
||||
|
@ -83,10 +86,10 @@ import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
|
|||
import org.apache.activemq.artemis.spi.core.protocol.SessionCallback;
|
||||
import org.apache.activemq.artemis.utils.TypedProperties;
|
||||
import org.apache.activemq.artemis.utils.UUID;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.apache.activemq.artemis.api.core.JsonUtil.nullSafe;
|
||||
|
||||
/**
|
||||
* Server side Session implementation
|
||||
*/
|
||||
|
@ -1402,17 +1405,21 @@ public class ServerSessionImpl implements ServerSession, FailureListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void describeProducersInfo(JSONArray array) throws Exception {
|
||||
public void describeProducersInfo(JsonArrayBuilder array) throws Exception {
|
||||
Map<SimpleString, Pair<UUID, AtomicLong>> targetCopy = cloneTargetAddresses();
|
||||
|
||||
for (Map.Entry<SimpleString, Pair<UUID, AtomicLong>> entry : targetCopy.entrySet()) {
|
||||
JSONObject producerInfo = new JSONObject();
|
||||
producerInfo.put("connectionID", this.getConnectionID().toString());
|
||||
producerInfo.put("sessionID", this.getName());
|
||||
producerInfo.put("destination", entry.getKey().toString());
|
||||
producerInfo.put("lastUUIDSent", entry.getValue().getA());
|
||||
producerInfo.put("msgSent", entry.getValue().getB().longValue());
|
||||
array.put(producerInfo);
|
||||
String uuid = null;
|
||||
if (entry.getValue().getA() != null) {
|
||||
uuid = entry.getValue().getA().toString();
|
||||
}
|
||||
JsonObjectBuilder producerInfo = Json.createObjectBuilder()
|
||||
.add("connectionID", this.getConnectionID().toString())
|
||||
.add("sessionID", this.getName())
|
||||
.add("destination", entry.getKey().toString())
|
||||
.add("lastUUIDSent", nullSafe(uuid))
|
||||
.add("msgSent", entry.getValue().getB().longValue());
|
||||
array.add(producerInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,13 +21,16 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
import javax.transaction.xa.Xid;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.core.server.MessageReference;
|
||||
import org.apache.activemq.artemis.core.server.ServerMessage;
|
||||
import org.apache.activemq.artemis.core.transaction.impl.XidImpl;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
|
||||
public abstract class TransactionDetail {
|
||||
|
||||
|
@ -61,27 +64,24 @@ public abstract class TransactionDetail {
|
|||
this.creationTime = creation;
|
||||
}
|
||||
|
||||
public JSONObject toJSON() throws Exception {
|
||||
public JsonObject toJSON() throws Exception {
|
||||
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
|
||||
JSONObject detailJson = new JSONObject();
|
||||
JsonObjectBuilder detailJson = Json.createObjectBuilder()
|
||||
.add(KEY_CREATION_TIME, dateFormat.format(new Date(this.creationTime)))
|
||||
.add(KEY_XID_AS_BASE64, XidImpl.toBase64String(this.xid))
|
||||
.add(KEY_XID_FORMAT_ID, this.xid.getFormatId())
|
||||
.add(KEY_XID_GLOBAL_TXID, new String(this.xid.getGlobalTransactionId()))
|
||||
.add(KEY_XID_BRANCH_QUAL, new String(this.xid.getBranchQualifier()));
|
||||
|
||||
detailJson.put(KEY_CREATION_TIME, dateFormat.format(new Date(this.creationTime)));
|
||||
detailJson.put(KEY_XID_AS_BASE64, XidImpl.toBase64String(this.xid));
|
||||
detailJson.put(KEY_XID_FORMAT_ID, this.xid.getFormatId());
|
||||
detailJson.put(KEY_XID_GLOBAL_TXID, new String(this.xid.getGlobalTransactionId()));
|
||||
detailJson.put(KEY_XID_BRANCH_QUAL, new String(this.xid.getBranchQualifier()));
|
||||
|
||||
JSONArray msgsJson = new JSONArray();
|
||||
JsonArrayBuilder msgsJson = Json.createArrayBuilder();
|
||||
|
||||
List<TransactionOperation> txops = null;
|
||||
|
||||
if (this.transaction != null) {
|
||||
txops = this.transaction.getAllOperations();
|
||||
}
|
||||
|
||||
detailJson.put(KEY_TX_RELATED_MESSAGES, msgsJson);
|
||||
if (txops == null) {
|
||||
return detailJson;
|
||||
return detailJson.build();
|
||||
}
|
||||
|
||||
for (TransactionOperation op : txops) {
|
||||
|
@ -100,18 +100,19 @@ public abstract class TransactionDetail {
|
|||
}
|
||||
|
||||
for (MessageReference ref : msgs) {
|
||||
JSONObject msgJson = new JSONObject();
|
||||
msgsJson.put(msgJson);
|
||||
JsonObjectBuilder msgJson = Json.createObjectBuilder();
|
||||
|
||||
msgJson.put(KEY_MSG_OP_TYPE, opType);
|
||||
msgJson.add(KEY_MSG_OP_TYPE, opType);
|
||||
|
||||
ServerMessage msg = ref.getMessage().copy();
|
||||
|
||||
msgJson.put(KEY_MSG_TYPE, decodeMessageType(msg));
|
||||
msgJson.put(KEY_MSG_PROPERTIES, decodeMessageProperties(msg));
|
||||
msgJson.add(KEY_MSG_TYPE, decodeMessageType(msg));
|
||||
JsonUtil.addToObject(KEY_MSG_PROPERTIES, decodeMessageProperties(msg), msgJson);
|
||||
msgsJson.add(msgJson);
|
||||
}
|
||||
}
|
||||
return detailJson;
|
||||
detailJson.add(KEY_TX_RELATED_MESSAGES, msgsJson);
|
||||
return detailJson.build();
|
||||
}
|
||||
|
||||
public abstract String decodeMessageType(ServerMessage msg);
|
||||
|
|
17
pom.xml
17
pom.xml
|
@ -84,6 +84,8 @@
|
|||
<resteasy.version>3.0.17.Final</resteasy.version>
|
||||
<slf4j.version>1.7.12</slf4j.version>
|
||||
<qpid.jms.version>0.9.0</qpid.jms.version>
|
||||
<johnzon.version>0.9.4</johnzon.version>
|
||||
<json-p.spec.version>1.0-alpha-1</json-p.spec.version>
|
||||
|
||||
<activemq.version.versionName>${project.version}</activemq.version.versionName>
|
||||
<activemq.version.majorVersion>1</activemq.version.majorVersion>
|
||||
|
@ -91,9 +93,7 @@
|
|||
<activemq.version.microVersion>0</activemq.version.microVersion>
|
||||
<activemq.version.incrementingVersion>127,126,125,124,123,122</activemq.version.incrementingVersion>
|
||||
<activemq.version.versionTag>${project.version}</activemq.version.versionTag>
|
||||
<ActiveMQ-Version>
|
||||
${project.version}(${activemq.version.incrementingVersion})
|
||||
</ActiveMQ-Version>
|
||||
<ActiveMQ-Version>${project.version}(${activemq.version.incrementingVersion})</ActiveMQ-Version>
|
||||
|
||||
<skipUnitTests>true</skipUnitTests>
|
||||
<skipJmsTests>true</skipJmsTests>
|
||||
|
@ -436,6 +436,17 @@
|
|||
<version>${slf4j.version}</version>
|
||||
<!-- License: MIT -->
|
||||
</dependency>
|
||||
<!-- json -->
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-json_1.0_spec</artifactId>
|
||||
<version>${json-p.spec.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.johnzon</groupId>
|
||||
<artifactId>johnzon-core</artifactId>
|
||||
<version>${johnzon.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--needed for the rest support-->
|
||||
<dependency>
|
||||
|
|
|
@ -72,6 +72,16 @@
|
|||
<artifactId>artemis-jms-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-json_1.0_spec</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.johnzon</groupId>
|
||||
<artifactId>johnzon-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>artemis-jms-server</artifactId>
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.activemq.artemis.api.core.client.ClientSession;
|
|||
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
|
||||
import org.apache.activemq.artemis.api.core.client.SendAcknowledgementHandler;
|
||||
import org.apache.activemq.artemis.api.core.client.ServerLocator;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.core.config.Configuration;
|
||||
import org.apache.activemq.artemis.core.config.ConnectorServiceConfiguration;
|
||||
import org.apache.activemq.artemis.core.config.CoreQueueConfiguration;
|
||||
|
@ -31,9 +32,6 @@ import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
|||
import org.apache.activemq.artemis.integration.aerogear.AeroGearConnectorServiceFactory;
|
||||
import org.apache.activemq.artemis.integration.aerogear.AeroGearConstants;
|
||||
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONException;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -42,6 +40,8 @@ import org.mortbay.jetty.Server;
|
|||
import org.mortbay.jetty.handler.AbstractHandler;
|
||||
import org.mortbay.jetty.nio.SelectChannelConnector;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -118,7 +118,7 @@ public class AeroGearBasicServerTest extends ActiveMQTestBase {
|
|||
|
||||
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||
assertNotNull(aeroGearHandler.jsonObject);
|
||||
JSONObject body = (JSONObject) aeroGearHandler.jsonObject.get("message");
|
||||
JsonObject body = aeroGearHandler.jsonObject.getJsonObject("message");
|
||||
assertNotNull(body);
|
||||
String prop1 = body.getString("AEROGEAR_PROP1");
|
||||
assertNotNull(prop1);
|
||||
|
@ -132,25 +132,24 @@ public class AeroGearBasicServerTest extends ActiveMQTestBase {
|
|||
String sound = body.getString("sound");
|
||||
assertNotNull(sound);
|
||||
assertEquals(sound, "sound1");
|
||||
String badge = body.getString("badge");
|
||||
int badge = body.getInt("badge");
|
||||
assertNotNull(badge);
|
||||
assertEquals(badge, "99");
|
||||
JSONArray jsonArray = (JSONArray) aeroGearHandler.jsonObject.get("variants");
|
||||
assertEquals(badge, 99);
|
||||
JsonArray jsonArray = aeroGearHandler.jsonObject.getJsonArray("variants");
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(jsonArray.getString(0), "variant1");
|
||||
assertEquals(jsonArray.getString(1), "variant2");
|
||||
jsonArray = (JSONArray) aeroGearHandler.jsonObject.get("alias");
|
||||
jsonArray = aeroGearHandler.jsonObject.getJsonArray("alias");
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(jsonArray.getString(0), "me");
|
||||
assertEquals(jsonArray.getString(1), "him");
|
||||
assertEquals(jsonArray.getString(2), "them");
|
||||
jsonArray = (JSONArray) aeroGearHandler.jsonObject.get("deviceType");
|
||||
jsonArray = aeroGearHandler.jsonObject.getJsonArray("deviceType");
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(jsonArray.getString(0), "android");
|
||||
assertEquals(jsonArray.getString(1), "ipad");
|
||||
Integer ttl = (Integer) aeroGearHandler.jsonObject.get("ttl");
|
||||
assertNotNull(ttl);
|
||||
assertEquals(ttl.intValue(), 3600);
|
||||
int ttl = aeroGearHandler.jsonObject.getInt("ttl");
|
||||
assertEquals(ttl, 3600);
|
||||
latch = new CountDownLatch(1);
|
||||
aeroGearHandler.resetLatch(latch);
|
||||
|
||||
|
@ -167,7 +166,7 @@ public class AeroGearBasicServerTest extends ActiveMQTestBase {
|
|||
producer.send(m);
|
||||
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||
assertNotNull(aeroGearHandler.jsonObject);
|
||||
body = (JSONObject) aeroGearHandler.jsonObject.get("message");
|
||||
body = aeroGearHandler.jsonObject.getJsonObject("message");
|
||||
assertNotNull(body);
|
||||
alert = body.getString("alert");
|
||||
assertNotNull(alert);
|
||||
|
@ -175,24 +174,22 @@ public class AeroGearBasicServerTest extends ActiveMQTestBase {
|
|||
sound = body.getString("sound");
|
||||
assertNotNull(sound);
|
||||
assertEquals(sound, "s1");
|
||||
badge = body.getString("badge");
|
||||
assertNotNull(badge);
|
||||
assertEquals(badge, "111");
|
||||
jsonArray = (JSONArray) aeroGearHandler.jsonObject.get("variants");
|
||||
badge = body.getInt("badge");
|
||||
assertEquals(badge, 111);
|
||||
jsonArray = aeroGearHandler.jsonObject.getJsonArray("variants");
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(jsonArray.getString(0), "v1");
|
||||
assertEquals(jsonArray.getString(1), "v2");
|
||||
jsonArray = (JSONArray) aeroGearHandler.jsonObject.get("alias");
|
||||
jsonArray = aeroGearHandler.jsonObject.getJsonArray("alias");
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(jsonArray.getString(0), "alias1");
|
||||
assertEquals(jsonArray.getString(1), "alias2");
|
||||
jsonArray = (JSONArray) aeroGearHandler.jsonObject.get("deviceType");
|
||||
jsonArray = aeroGearHandler.jsonObject.getJsonArray("deviceType");
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(jsonArray.getString(0), "dev1");
|
||||
assertEquals(jsonArray.getString(1), "dev2");
|
||||
ttl = (Integer) aeroGearHandler.jsonObject.get("ttl");
|
||||
assertNotNull(ttl);
|
||||
assertEquals(ttl.intValue(), 10000);
|
||||
ttl = aeroGearHandler.jsonObject.getInt("ttl");
|
||||
assertEquals(ttl, 10000);
|
||||
session.start();
|
||||
ClientMessage message = session.createConsumer("testQueue").receiveImmediate();
|
||||
assertNull(message);
|
||||
|
@ -200,7 +197,7 @@ public class AeroGearBasicServerTest extends ActiveMQTestBase {
|
|||
|
||||
class AeroGearHandler extends AbstractHandler {
|
||||
|
||||
JSONObject jsonObject;
|
||||
JsonObject jsonObject;
|
||||
private CountDownLatch latch;
|
||||
|
||||
AeroGearHandler(CountDownLatch latch) {
|
||||
|
@ -219,12 +216,7 @@ public class AeroGearBasicServerTest extends ActiveMQTestBase {
|
|||
byte[] bytes = new byte[httpServletRequest.getContentLength()];
|
||||
httpServletRequest.getInputStream().read(bytes);
|
||||
String json = new String(bytes);
|
||||
try {
|
||||
jsonObject = new JSONObject(json);
|
||||
}
|
||||
catch (JSONException e) {
|
||||
jsonObject = null;
|
||||
}
|
||||
jsonObject = JsonUtil.readJsonObject(json);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.apache.activemq.artemis.api.core.client.ClientProducer;
|
|||
import org.apache.activemq.artemis.api.core.client.ClientSession;
|
||||
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
|
||||
import org.apache.activemq.artemis.api.core.client.ServerLocator;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
|
||||
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
|
||||
import org.apache.activemq.artemis.api.jms.JMSFactoryType;
|
||||
|
@ -68,10 +69,10 @@ import org.apache.activemq.artemis.tests.integration.management.ManagementTestBa
|
|||
import org.apache.activemq.artemis.tests.unit.util.InVMNamingContext;
|
||||
import org.apache.activemq.artemis.utils.RandomUtil;
|
||||
import org.apache.activemq.artemis.utils.UUIDGenerator;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import javax.json.JsonArray;
|
||||
|
||||
/**
|
||||
* A QueueControlTest
|
||||
|
@ -111,9 +112,9 @@ public class JMSQueueControlTest extends ManagementTestBase {
|
|||
|
||||
Assert.assertEquals(1, queueControl.getConsumerCount());
|
||||
|
||||
JSONArray jsonArray = new JSONArray(queueControl.listConsumersAsJSON());
|
||||
JsonArray jsonArray = JsonUtil.readJsonArray(queueControl.listConsumersAsJSON());
|
||||
|
||||
assertEquals(1, jsonArray.length());
|
||||
assertEquals(1, jsonArray.size());
|
||||
|
||||
JMSUtil.sendMessages(queue, 2);
|
||||
|
||||
|
@ -433,17 +434,17 @@ public class JMSQueueControlTest extends ManagementTestBase {
|
|||
|
||||
String jsonString = queueControl.listMessagesAsJSON(null);
|
||||
Assert.assertNotNull(jsonString);
|
||||
JSONArray array = new JSONArray(jsonString);
|
||||
Assert.assertEquals(2, array.length());
|
||||
Assert.assertEquals(ids[0], array.getJSONObject(0).get("JMSMessageID"));
|
||||
Assert.assertEquals(ids[1], array.getJSONObject(1).get("JMSMessageID"));
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(2, array.size());
|
||||
Assert.assertEquals(ids[0], array.getJsonObject(0).getString("JMSMessageID"));
|
||||
Assert.assertEquals(ids[1], array.getJsonObject(1).getString("JMSMessageID"));
|
||||
|
||||
JMSUtil.consumeMessages(2, queue);
|
||||
|
||||
jsonString = queueControl.listMessagesAsJSON(null);
|
||||
Assert.assertNotNull(jsonString);
|
||||
array = new JSONArray(jsonString);
|
||||
Assert.assertEquals(0, array.length());
|
||||
array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(0, array.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.apache.activemq.artemis.api.core.SimpleString;
|
|||
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
||||
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
|
||||
import org.apache.activemq.artemis.api.core.management.AddressControl;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
|
||||
import org.apache.activemq.artemis.api.core.management.ResourceNames;
|
||||
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
|
||||
|
@ -48,7 +49,6 @@ import org.apache.activemq.artemis.tests.integration.management.ManagementTestBa
|
|||
import org.apache.activemq.artemis.tests.unit.util.InVMNamingContext;
|
||||
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
|
||||
import org.apache.activemq.artemis.utils.RandomUtil;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -66,6 +66,7 @@ import javax.jms.Topic;
|
|||
import javax.jms.XAConnection;
|
||||
import javax.jms.XAConnectionFactory;
|
||||
import javax.jms.XASession;
|
||||
import javax.json.JsonArray;
|
||||
import javax.naming.NamingException;
|
||||
import javax.transaction.xa.XAResource;
|
||||
import javax.transaction.xa.Xid;
|
||||
|
@ -627,15 +628,15 @@ public class JMSServerControlTest extends ManagementTestBase {
|
|||
// create a consumer will create a Core queue bound to the topic address
|
||||
MessageConsumer cons = session.createConsumer(topic);
|
||||
|
||||
JSONArray jsonArray = new JSONArray(control.listAllConsumersAsJSON());
|
||||
JsonArray jsonArray = JsonUtil.readJsonArray(control.listAllConsumersAsJSON());
|
||||
|
||||
Assert.assertEquals(1 + getNumberOfConsumers(), jsonArray.length());
|
||||
Assert.assertEquals(1 + getNumberOfConsumers(), jsonArray.size());
|
||||
|
||||
cons.close();
|
||||
|
||||
jsonArray = new JSONArray(control.listAllConsumersAsJSON());
|
||||
jsonArray = JsonUtil.readJsonArray(control.listAllConsumersAsJSON());
|
||||
|
||||
Assert.assertEquals(getNumberOfConsumers(), jsonArray.length());
|
||||
Assert.assertEquals(getNumberOfConsumers(), jsonArray.size());
|
||||
|
||||
String topicAddress = ActiveMQDestination.createTopicAddressFromName(topicName).toString();
|
||||
AddressControl addressControl = (AddressControl) server.getManagementService().getResource(ResourceNames.CORE_ADDRESS + topicAddress);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.activemq.artemis.tests.integration.jms.server.management;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
|
||||
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
|
||||
import org.apache.activemq.artemis.api.jms.management.JMSServerControl;
|
||||
|
@ -37,7 +38,6 @@ import org.apache.activemq.artemis.tests.integration.management.ManagementContro
|
|||
import org.apache.activemq.artemis.tests.integration.management.ManagementTestBase;
|
||||
import org.apache.activemq.artemis.tests.unit.util.InVMNamingContext;
|
||||
import org.apache.activemq.artemis.utils.RandomUtil;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -51,6 +51,7 @@ import javax.jms.MessageProducer;
|
|||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
import javax.jms.TopicSubscriber;
|
||||
import javax.json.JsonArray;
|
||||
import javax.management.Notification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -159,9 +160,9 @@ public class TopicControlTest extends ManagementTestBase {
|
|||
|
||||
String json = topicControl.listAllSubscriptionsAsJSON();
|
||||
System.out.println("Json: " + json);
|
||||
JSONArray jsonArray = new JSONArray(json);
|
||||
JsonArray jsonArray = JsonUtil.readJsonArray(json);
|
||||
|
||||
Assert.assertEquals(3, jsonArray.length());
|
||||
Assert.assertEquals(3, jsonArray.size());
|
||||
|
||||
connection_1.close();
|
||||
connection_2.close();
|
||||
|
@ -221,17 +222,17 @@ public class TopicControlTest extends ManagementTestBase {
|
|||
SubscriptionInfo[] infos = SubscriptionInfo.from(jsonString);
|
||||
Assert.assertEquals(2, infos.length);
|
||||
|
||||
Assert.assertTrue(infos[0].getClientID().length() == 0);
|
||||
Assert.assertNull(infos[0].getClientID());
|
||||
Assert.assertTrue(infos[0].getName().equals(subscriptionName));
|
||||
|
||||
Assert.assertTrue(infos[1].getClientID().length() == 0);
|
||||
Assert.assertNull(infos[1].getClientID());
|
||||
Assert.assertTrue(infos[1].getName().equals(subscriptionName + "2"));
|
||||
|
||||
jsonString = topicControl.listNonDurableSubscriptionsAsJSON();
|
||||
infos = SubscriptionInfo.from(jsonString);
|
||||
Assert.assertEquals(1, infos.length);
|
||||
Assert.assertEquals(null, infos[0].getClientID());
|
||||
Assert.assertEquals(null, infos[0].getName());
|
||||
Assert.assertNull(infos[0].getClientID());
|
||||
Assert.assertNull(infos[0].getName());
|
||||
|
||||
jsonString = topicControl.listAllSubscriptionsAsJSON();
|
||||
infos = SubscriptionInfo.from(jsonString);
|
||||
|
@ -442,10 +443,10 @@ public class TopicControlTest extends ManagementTestBase {
|
|||
TopicControl topicControl = createManagementControl();
|
||||
String jsonString = topicControl.listMessagesForSubscriptionAsJSON(ActiveMQDestination.createQueueNameForDurableSubscription(true, clientID, subscriptionName));
|
||||
Assert.assertNotNull(jsonString);
|
||||
JSONArray array = new JSONArray(jsonString);
|
||||
Assert.assertEquals(3, array.length());
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(3, array.size());
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Assert.assertEquals(ids[i], array.getJSONObject(i).get("JMSMessageID"));
|
||||
Assert.assertEquals(ids[i], array.getJsonObject(i).getString("JMSMessageID"));
|
||||
}
|
||||
|
||||
connection.close();
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.tests.integration.management;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
import javax.transaction.xa.XAResource;
|
||||
import javax.transaction.xa.Xid;
|
||||
import java.util.HashMap;
|
||||
|
@ -33,6 +35,7 @@ import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl;
|
|||
import org.apache.activemq.artemis.api.core.management.AddressSettingsInfo;
|
||||
import org.apache.activemq.artemis.api.core.management.BridgeControl;
|
||||
import org.apache.activemq.artemis.api.core.management.DivertControl;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
|
||||
import org.apache.activemq.artemis.api.core.management.QueueControl;
|
||||
import org.apache.activemq.artemis.api.core.management.RoleInfo;
|
||||
|
@ -47,8 +50,6 @@ import org.apache.activemq.artemis.core.transaction.impl.XidImpl;
|
|||
import org.apache.activemq.artemis.jlibaio.LibaioContext;
|
||||
import org.apache.activemq.artemis.utils.RandomUtil;
|
||||
import org.apache.activemq.artemis.utils.UUIDGenerator;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -154,12 +155,12 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
|
|||
|
||||
String jsonString = serverControl.getConnectorsAsJSON();
|
||||
Assert.assertNotNull(jsonString);
|
||||
JSONArray array = new JSONArray(jsonString);
|
||||
Assert.assertEquals(1, array.length());
|
||||
JSONObject data = array.getJSONObject(0);
|
||||
Assert.assertEquals(connectorConfig.getName(), data.optString("name"));
|
||||
Assert.assertEquals(connectorConfig.getFactoryClassName(), data.optString("factoryClassName"));
|
||||
Assert.assertEquals(connectorConfig.getParams().size(), data.getJSONObject("params").length());
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(1, array.size());
|
||||
JsonObject data = array.getJsonObject(0);
|
||||
Assert.assertEquals(connectorConfig.getName(), data.getString("name"));
|
||||
Assert.assertEquals(connectorConfig.getFactoryClassName(), data.getString("factoryClassName"));
|
||||
Assert.assertEquals(connectorConfig.getParams().size(), data.getJsonObject("params").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -755,10 +756,10 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
|
|||
|
||||
ActiveMQServerControl serverControl = createManagementControl();
|
||||
|
||||
JSONArray jsonArray = new JSONArray(serverControl.listProducersInfoAsJSON());
|
||||
JsonArray jsonArray = JsonUtil.readJsonArray(serverControl.listProducersInfoAsJSON());
|
||||
|
||||
assertEquals(1, jsonArray.length());
|
||||
assertEquals(4, ((JSONObject) jsonArray.get(0)).getInt("msgSent"));
|
||||
assertEquals(1, jsonArray.size());
|
||||
assertEquals(4, ((JsonObject) jsonArray.get(0)).getInt("msgSent"));
|
||||
|
||||
clientSession.close();
|
||||
locator.close();
|
||||
|
|
|
@ -20,15 +20,16 @@ import org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration;
|
|||
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
||||
import org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory;
|
||||
import org.apache.activemq.artemis.api.core.management.BroadcastGroupControl;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.core.config.Configuration;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServers;
|
||||
import org.apache.activemq.artemis.utils.RandomUtil;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -54,8 +55,8 @@ public class BroadcastGroupControlTest extends ManagementTestBase {
|
|||
Assert.assertEquals(broadcastGroupConfig.getConnectorInfos().get(0), connectorPairData);
|
||||
String jsonString = broadcastGroupControl.getConnectorPairsAsJSON();
|
||||
Assert.assertNotNull(jsonString);
|
||||
JSONArray array = new JSONArray(jsonString);
|
||||
Assert.assertEquals(1, array.length());
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(1, array.size());
|
||||
Assert.assertEquals(broadcastGroupConfig.getConnectorInfos().get(0), array.getString(0));
|
||||
|
||||
Assert.assertTrue(broadcastGroupControl.isStarted());
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.tests.integration.management;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType;
|
||||
import org.junit.Before;
|
||||
import org.junit.After;
|
||||
|
@ -26,6 +27,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.MBeanServerFactory;
|
||||
|
||||
|
@ -48,7 +50,6 @@ import org.apache.activemq.artemis.core.server.ActiveMQServers;
|
|||
import org.apache.activemq.artemis.core.server.management.Notification;
|
||||
import org.apache.activemq.artemis.tests.integration.SimpleNotificationService;
|
||||
import org.apache.activemq.artemis.utils.RandomUtil;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
|
||||
public class ClusterConnectionControlTest extends ManagementTestBase {
|
||||
|
||||
|
@ -91,8 +92,8 @@ public class ClusterConnectionControlTest extends ManagementTestBase {
|
|||
|
||||
String jsonString = clusterConnectionControl.getStaticConnectorsAsJSON();
|
||||
Assert.assertNotNull(jsonString);
|
||||
JSONArray array = new JSONArray(jsonString);
|
||||
Assert.assertEquals(1, array.length());
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(1, array.size());
|
||||
Assert.assertEquals(clusterConnectionConfig1.getStaticConnectors().get(0), array.getString(0));
|
||||
|
||||
Assert.assertNull(clusterConnectionControl.getDiscoveryGroupName());
|
||||
|
|
|
@ -227,87 +227,6 @@ public class ManagementHelperTest extends Assert {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromCommaSeparatedKeyValues() throws Exception {
|
||||
String str = "key1=1, key2=false, key3=2.0, key4=whatever";
|
||||
|
||||
Map<String, Object> map = ManagementHelper.fromCommaSeparatedKeyValues(str);
|
||||
Assert.assertEquals(4, map.size());
|
||||
Assert.assertTrue(map.containsKey("key1"));
|
||||
Assert.assertEquals(1L, map.get("key1"));
|
||||
|
||||
Assert.assertTrue(map.containsKey("key2"));
|
||||
Assert.assertEquals(false, map.get("key2"));
|
||||
|
||||
Assert.assertTrue(map.containsKey("key3"));
|
||||
Assert.assertEquals(2.0, map.get("key3"));
|
||||
|
||||
Assert.assertTrue(map.containsKey("key4"));
|
||||
Assert.assertEquals("whatever", map.get("key4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromCommaSeparatedArrayOfCommaSeparatedKeyValuesForSingleItem() throws Exception {
|
||||
// if there is a single item, no need to enclose it in { }
|
||||
String str = "k11=1, k12=false, k13=2.0, k14=whatever ";
|
||||
|
||||
Object[] objects = ManagementHelper.fromCommaSeparatedArrayOfCommaSeparatedKeyValues(str);
|
||||
Assert.assertEquals(1, objects.length);
|
||||
|
||||
Assert.assertTrue(objects[0] instanceof Map<?, ?>);
|
||||
Map<String, Object> map = (Map<String, Object>) objects[0];
|
||||
Assert.assertEquals(4, map.size());
|
||||
Assert.assertTrue(map.containsKey("k11"));
|
||||
Assert.assertEquals(1L, map.get("k11"));
|
||||
|
||||
Assert.assertTrue(map.containsKey("k12"));
|
||||
Assert.assertEquals(false, map.get("k12"));
|
||||
|
||||
Assert.assertTrue(map.containsKey("k13"));
|
||||
Assert.assertEquals(2.0, map.get("k13"));
|
||||
|
||||
Assert.assertTrue(map.containsKey("k14"));
|
||||
Assert.assertEquals("whatever", map.get("k14"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromCommaSeparatedArrayOfCommaSeparatedKeyValues() throws Exception {
|
||||
String str = "{ k11=1, k12=false, k13=2.0, k14=whatever },{ k21=2, k22=true, k23=23.0, k24=foo }";
|
||||
|
||||
Object[] objects = ManagementHelper.fromCommaSeparatedArrayOfCommaSeparatedKeyValues(str);
|
||||
Assert.assertEquals(2, objects.length);
|
||||
|
||||
Assert.assertTrue(objects[0] instanceof Map<?, ?>);
|
||||
Map<String, Object> map = (Map<String, Object>) objects[0];
|
||||
Assert.assertEquals(4, map.size());
|
||||
Assert.assertTrue(map.containsKey("k11"));
|
||||
Assert.assertEquals(1L, map.get("k11"));
|
||||
|
||||
Assert.assertTrue(map.containsKey("k12"));
|
||||
Assert.assertEquals(false, map.get("k12"));
|
||||
|
||||
Assert.assertTrue(map.containsKey("k13"));
|
||||
Assert.assertEquals(2.0, map.get("k13"));
|
||||
|
||||
Assert.assertTrue(map.containsKey("k14"));
|
||||
Assert.assertEquals("whatever", map.get("k14"));
|
||||
|
||||
Assert.assertTrue(objects[1] instanceof Map<?, ?>);
|
||||
map = (Map<String, Object>) objects[1];
|
||||
Assert.assertEquals(4, map.size());
|
||||
Assert.assertTrue(map.containsKey("k21"));
|
||||
Assert.assertEquals(2L, map.get("k21"));
|
||||
|
||||
Assert.assertTrue(map.containsKey("k22"));
|
||||
Assert.assertEquals(true, map.get("k22"));
|
||||
|
||||
Assert.assertTrue(map.containsKey("k23"));
|
||||
Assert.assertEquals(23.0, map.get("k23"));
|
||||
|
||||
Assert.assertTrue(map.containsKey("k24"));
|
||||
Assert.assertEquals("foo", map.get("k24"));
|
||||
}
|
||||
|
||||
// Package protected ---------------------------------------------
|
||||
|
||||
// Protected -----------------------------------------------------
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.activemq.artemis.tests.integration.management;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.api.core.client.ClientConsumer;
|
||||
import org.apache.activemq.artemis.api.core.client.ClientMessage;
|
||||
|
@ -31,11 +32,11 @@ import org.apache.activemq.artemis.core.server.ActiveMQServers;
|
|||
import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy;
|
||||
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
|
||||
import org.apache.activemq.artemis.utils.RandomUtil;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
|
@ -77,9 +78,9 @@ public class ManagementWithPagingServerTest extends ManagementTestBase {
|
|||
|
||||
String result = queueControl.listMessagesAsJSON(null);
|
||||
|
||||
JSONArray array = new JSONArray(result);
|
||||
JsonArray array = JsonUtil.readJsonArray(result);
|
||||
|
||||
assertEquals(num, array.length());
|
||||
assertEquals(num, array.size());
|
||||
|
||||
//kick off receiver
|
||||
receiver.start();
|
||||
|
@ -88,9 +89,9 @@ public class ManagementWithPagingServerTest extends ManagementTestBase {
|
|||
|
||||
result = queueControl.listMessagesAsJSON(null);
|
||||
|
||||
array = new JSONArray(result);
|
||||
array = JsonUtil.readJsonArray(result);
|
||||
|
||||
assertEquals(0, array.length());
|
||||
assertEquals(0, array.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -129,9 +130,9 @@ public class ManagementWithPagingServerTest extends ManagementTestBase {
|
|||
|
||||
String jsonString = queueControl.listMessagesAsJSON(filter);
|
||||
Assert.assertNotNull(jsonString);
|
||||
JSONArray array = new JSONArray(jsonString);
|
||||
Assert.assertEquals(num / 2, array.length());
|
||||
Assert.assertEquals(matchingValue, array.getJSONObject(0).get("key"));
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(num / 2, array.size());
|
||||
Assert.assertEquals(matchingValue, array.getJsonObject(0).getJsonNumber("key").longValue());
|
||||
|
||||
long n = queueControl.countMessages(filter);
|
||||
assertEquals(num / 2, n);
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.tests.integration.management;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
import javax.management.Notification;
|
||||
import javax.management.openmbean.CompositeData;
|
||||
import java.util.HashMap;
|
||||
|
@ -25,6 +27,7 @@ import java.util.concurrent.CountDownLatch;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.ActiveMQException;
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.api.core.Message;
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.api.core.client.ClientConsumer;
|
||||
|
@ -49,8 +52,6 @@ import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
|
|||
import org.apache.activemq.artemis.tests.integration.jms.server.management.JMSUtil;
|
||||
import org.apache.activemq.artemis.utils.Base64;
|
||||
import org.apache.activemq.artemis.utils.RandomUtil;
|
||||
import org.apache.activemq.artemis.utils.json.JSONArray;
|
||||
import org.apache.activemq.artemis.utils.json.JSONObject;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -219,16 +220,16 @@ public class QueueControlTest extends ManagementTestBase {
|
|||
|
||||
System.out.println("Consumers: " + queueControl.listConsumersAsJSON());
|
||||
|
||||
JSONArray obj = new JSONArray(queueControl.listConsumersAsJSON());
|
||||
JsonArray obj = JsonUtil.readJsonArray(queueControl.listConsumersAsJSON());
|
||||
|
||||
assertEquals(1, obj.length());
|
||||
assertEquals(1, obj.size());
|
||||
|
||||
consumer.close();
|
||||
Assert.assertEquals(0, queueControl.getConsumerCount());
|
||||
|
||||
obj = new JSONArray(queueControl.listConsumersAsJSON());
|
||||
obj = JsonUtil.readJsonArray(queueControl.listConsumersAsJSON());
|
||||
|
||||
assertEquals(0, obj.length());
|
||||
assertEquals(0, obj.size());
|
||||
|
||||
session.deleteQueue(queue);
|
||||
}
|
||||
|
@ -562,16 +563,16 @@ public class QueueControlTest extends ManagementTestBase {
|
|||
|
||||
String jsonString = queueControl.listScheduledMessagesAsJSON();
|
||||
Assert.assertNotNull(jsonString);
|
||||
JSONArray array = new JSONArray(jsonString);
|
||||
Assert.assertEquals(1, array.length());
|
||||
Assert.assertEquals(intValue, array.getJSONObject(0).get("key"));
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(1, array.size());
|
||||
Assert.assertEquals(intValue, array.getJsonObject(0).getJsonNumber("key").intValue());
|
||||
|
||||
Thread.sleep(delay + 500);
|
||||
|
||||
jsonString = queueControl.listScheduledMessagesAsJSON();
|
||||
Assert.assertNotNull(jsonString);
|
||||
array = new JSONArray(jsonString);
|
||||
Assert.assertEquals(0, array.length());
|
||||
array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(0, array.size());
|
||||
|
||||
consumeMessages(2, session, queue);
|
||||
|
||||
|
@ -620,16 +621,16 @@ public class QueueControlTest extends ManagementTestBase {
|
|||
|
||||
String jsonString = queueControl.listMessagesAsJSON(null);
|
||||
Assert.assertNotNull(jsonString);
|
||||
JSONArray array = new JSONArray(jsonString);
|
||||
Assert.assertEquals(1, array.length());
|
||||
Assert.assertEquals(intValue, array.getJSONObject(0).get("key"));
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(1, array.size());
|
||||
Assert.assertEquals(intValue, array.getJsonObject(0).getInt("key"));
|
||||
|
||||
consumeMessages(1, session, queue);
|
||||
|
||||
jsonString = queueControl.listMessagesAsJSON(null);
|
||||
Assert.assertNotNull(jsonString);
|
||||
array = new JSONArray(jsonString);
|
||||
Assert.assertEquals(0, array.length());
|
||||
array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(0, array.size());
|
||||
|
||||
session.deleteQueue(queue);
|
||||
}
|
||||
|
@ -736,16 +737,16 @@ public class QueueControlTest extends ManagementTestBase {
|
|||
|
||||
String jsonString = queueControl.listMessagesAsJSON(filter);
|
||||
Assert.assertNotNull(jsonString);
|
||||
JSONArray array = new JSONArray(jsonString);
|
||||
Assert.assertEquals(1, array.length());
|
||||
Assert.assertEquals(matchingValue, array.getJSONObject(0).get("key"));
|
||||
JsonArray array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(1, array.size());
|
||||
Assert.assertEquals(matchingValue, array.getJsonObject(0).getJsonNumber("key").longValue());
|
||||
|
||||
consumeMessages(2, session, queue);
|
||||
|
||||
jsonString = queueControl.listMessagesAsJSON(filter);
|
||||
Assert.assertNotNull(jsonString);
|
||||
array = new JSONArray(jsonString);
|
||||
Assert.assertEquals(0, array.length());
|
||||
array = JsonUtil.readJsonArray(jsonString);
|
||||
Assert.assertEquals(0, array.size());
|
||||
|
||||
session.deleteQueue(queue);
|
||||
}
|
||||
|
@ -2099,8 +2100,8 @@ public class QueueControlTest extends ManagementTestBase {
|
|||
}
|
||||
|
||||
protected long getFirstMessageId(final QueueControl queueControl) throws Exception {
|
||||
JSONArray array = new JSONArray(queueControl.getFirstMessageAsJSON());
|
||||
JSONObject object = (JSONObject)array.get(0);
|
||||
return object.getLong("messageID");
|
||||
JsonArray array = JsonUtil.readJsonArray(queueControl.getFirstMessageAsJSON());
|
||||
JsonObject object = (JsonObject) array.get(0);
|
||||
return object.getJsonNumber("messageID").longValue();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue