You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2016/07/26 01:46:37 UTC
[4/5] activemq-artemis git commit: ARTEMIS-565 Replace json.org with
javax.json
ARTEMIS-565 Replace json.org with javax.json
Javax.json is a newer JSR, but has an ASF compliant version, is pretty close to the original JSON.org API and will support a standard annotation based JSON-B solution at some point soon.
Updated integration tests and removed JSON.org from license.
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/d0ecf0f3
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/d0ecf0f3
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/d0ecf0f3
Branch: refs/heads/master
Commit: d0ecf0f3a51ec82dd33b596ea948aa2994716b1b
Parents: e664780
Author: John D. Ament <jo...@apache.org>
Authored: Sun Jul 17 19:05:19 2016 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Mon Jul 25 21:44:57 2016 -0400
----------------------------------------------------------------------
LICENSE | 28 -
.../artemis/utils/StringEscapeUtils.java | 108 ++
artemis-core-client/pom.xml | 8 +
.../activemq/artemis/api/core/JsonUtil.java | 306 ++++
.../api/core/TransportConfiguration.java | 12 +
.../core/management/AddressSettingsInfo.java | 22 +-
.../api/core/management/DayCounterInfo.java | 46 +-
.../api/core/management/ManagementHelper.java | 209 +--
.../artemis/api/core/management/RoleInfo.java | 19 +-
.../activemq/artemis/core/security/Role.java | 16 +
.../activemq/artemis/utils/json/JSONArray.java | 931 -----------
.../artemis/utils/json/JSONException.java | 56 -
.../activemq/artemis/utils/json/JSONObject.java | 1540 ------------------
.../activemq/artemis/utils/json/JSONString.java | 43 -
.../artemis/utils/json/JSONTokener.java | 414 -----
.../management/AddressSettingsInfoTest.java | 77 +
artemis-distribution/pom.xml | 8 +
artemis-distribution/src/main/assembly/dep.xml | 2 +
.../src/main/resources/features.xml | 3 +
artemis-jms-client/pom.xml | 1 -
.../api/jms/management/JMSConnectionInfo.java | 18 +-
.../api/jms/management/JMSConsumerInfo.java | 19 +-
.../api/jms/management/JMSSessionInfo.java | 20 +-
.../api/jms/management/SubscriptionInfo.java | 19 +-
artemis-jms-server/pom.xml | 8 +
.../management/impl/JMSQueueControlImpl.java | 11 +-
.../management/impl/JMSServerControlImpl.java | 133 +-
.../management/impl/JMSTopicControlImpl.java | 34 +-
.../jms/server/impl/JMSServerManagerImpl.java | 25 +-
.../api/core/management/MessageCounterInfo.java | 35 +-
.../impl/ActiveMQServerControlImpl.java | 101 +-
.../management/impl/AddressControlImpl.java | 8 +-
.../impl/BroadcastGroupControlImpl.java | 9 +-
.../impl/ClusterConnectionControlImpl.java | 15 +-
.../core/management/impl/QueueControlImpl.java | 57 +-
.../artemis/core/server/ServerSession.java | 4 +-
.../core/server/impl/ServerSessionImpl.java | 27 +-
.../core/transaction/TransactionDetail.java | 41 +-
pom.xml | 17 +-
tests/integration-tests/pom.xml | 10 +
.../aerogear/AeroGearBasicServerTest.java | 50 +-
.../server/management/JMSQueueControlTest.java | 19 +-
.../server/management/JMSServerControlTest.java | 11 +-
.../jms/server/management/TopicControlTest.java | 21 +-
.../management/ActiveMQServerControlTest.java | 23 +-
.../management/BroadcastGroupControlTest.java | 7 +-
.../ClusterConnectionControlTest.java | 7 +-
.../management/ManagementHelperTest.java | 81 -
.../ManagementWithPagingServerTest.java | 17 +-
.../management/QueueControlTest.java | 49 +-
50 files changed, 1039 insertions(+), 3706 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d0ecf0f3/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
index 695ea18..f5d288d 100644
--- a/LICENSE
+++ b/LICENSE
@@ -202,34 +202,6 @@
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 =
===============================================================
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d0ecf0f3/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/StringEscapeUtils.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/StringEscapeUtils.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/StringEscapeUtils.java
new file mode 100644
index 0000000..ecff4da
--- /dev/null
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/StringEscapeUtils.java
@@ -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();
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d0ecf0f3/artemis-core-client/pom.xml
----------------------------------------------------------------------
diff --git a/artemis-core-client/pom.xml b/artemis-core-client/pom.xml
index 57bbe85..4ec1563 100644
--- a/artemis-core-client/pom.xml
+++ b/artemis-core-client/pom.xml
@@ -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>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d0ecf0f3/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
new file mode 100644
index 0000000..dbfec9a
--- /dev/null
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
@@ -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;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d0ecf0f3/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/TransportConfiguration.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/TransportConfiguration.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/TransportConfiguration.java
index a3e1d7c..3b9d927 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/TransportConfiguration.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/TransportConfiguration.java
@@ -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
*
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d0ecf0f3/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressSettingsInfo.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressSettingsInfo.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressSettingsInfo.java
index d4f5232..062ba46 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressSettingsInfo.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressSettingsInfo.java
@@ -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 --------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d0ecf0f3/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/DayCounterInfo.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/DayCounterInfo.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/DayCounterInfo.java
index 422772f..b6b4e8e 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/DayCounterInfo.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/DayCounterInfo.java
@@ -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);
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d0ecf0f3/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ManagementHelper.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ManagementHelper.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ManagementHelper.java
index 98fafc4..61a9306 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ManagementHelper.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ManagementHelper.java
@@ -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() {
}
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d0ecf0f3/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/RoleInfo.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/RoleInfo.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/RoleInfo.java
index d8c78ea..01be093 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/RoleInfo.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/RoleInfo.java
@@ -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;
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d0ecf0f3/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/security/Role.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/security/Role.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/security/Role.java
index 732da6d..baa872a 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/security/Role.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/security/Role.java
@@ -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
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d0ecf0f3/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/json/JSONArray.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/json/JSONArray.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/json/JSONArray.java
deleted file mode 100644
index 0b8fd0c..0000000
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/json/JSONArray.java
+++ /dev/null
@@ -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);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d0ecf0f3/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/json/JSONException.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/json/JSONException.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/json/JSONException.java
deleted file mode 100644
index abb79b0..0000000
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/json/JSONException.java
+++ /dev/null
@@ -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;
- }
-}