From bfc10dcf8bcb1663519fb74907623a5f6b1d0710 Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Wed, 10 Nov 2021 16:31:19 -0500 Subject: [PATCH] ARTEMIS-3546 Jakarta javax.json incompability on jakarta all client Domenico Bruscino provided the JSON Wrapper used here. Thanks Domenico! --- artemis-cli/pom.xml | 23 +- .../artemis/cli/commands/queue/StatQueue.java | 4 +- .../artemis/cli/commands/user/ListUser.java | 7 +- .../apache/activemq/cli/test/ArtemisTest.java | 4 +- artemis-commons/pom.xml | 63 ++++- .../artemis/api/core/QueueConfiguration.java | 8 +- .../activemq/artemis/json/JsonArray.java | 159 ++++++++++++ .../artemis/json/JsonArrayBuilder.java | 142 +++++++++++ .../activemq/artemis/json/JsonNumber.java | 63 +++++ .../activemq/artemis/json/JsonObject.java | 105 ++++++++ .../artemis/json/JsonObjectBuilder.java | 155 ++++++++++++ .../activemq/artemis/json/JsonString.java | 32 +++ .../activemq/artemis/json/JsonValue.java | 74 ++++++ .../json/impl/JsonArrayBuilderImpl.java | 125 ++++++++++ .../artemis/json/impl/JsonArrayImpl.java | 234 ++++++++++++++++++ .../artemis/json/impl/JsonNumberImpl.java | 87 +++++++ .../json/impl/JsonObjectBuilderImpl.java | 155 ++++++++++++ .../artemis/json/impl/JsonObjectImpl.java | 217 ++++++++++++++++ .../artemis/json/impl/JsonStringImpl.java | 44 ++++ .../artemis/json/impl/JsonValueImpl.java | 116 +++++++++ .../activemq/artemis/utils/JsonLoader.java | 46 ++-- artemis-core-client-osgi/pom.xml | 2 +- artemis-core-client/pom.xml | 25 +- .../activemq/artemis/api/core/JsonUtil.java | 16 +- .../api/core/TransportConfiguration.java | 2 +- .../core/management/AddressSettingsInfo.java | 2 +- .../api/core/management/DayCounterInfo.java | 8 +- .../api/core/management/ManagementHelper.java | 2 +- .../core/management/MessageCounterInfo.java | 2 +- .../artemis/api/core/management/NodeInfo.java | 4 +- .../artemis/api/core/management/RoleInfo.java | 4 +- .../core/config/TransformerConfiguration.java | 6 +- .../activemq/artemis/core/security/Role.java | 2 +- .../artemis/api/core/JsonUtilTest.java | 8 +- artemis-distribution/pom.xml | 8 - .../src/main/assembly/dep.xml | 2 - .../src/main/resources/features.xml | 3 - artemis-jakarta-client-all/pom.xml | 5 - artemis-jakarta-server/pom.xml | 6 - artemis-jms-client-all/pom.xml | 4 - artemis-jms-client-osgi/pom.xml | 2 +- artemis-jms-server/pom.xml | 4 - .../artemis/maven/ArtemisClientPlugin.java | 27 +- artemis-server-osgi/pom.xml | 2 +- artemis-server/pom.xml | 19 +- .../core/config/BridgeConfiguration.java | 21 +- .../impl/ActiveMQServerControlImpl.java | 8 +- .../management/impl/AddressControlImpl.java | 2 +- .../impl/BrokerBalancerControlImpl.java | 2 +- .../management/impl/QueueControlImpl.java | 6 +- .../impl/view/ActiveMQAbstractView.java | 6 +- .../management/impl/view/AddressView.java | 2 +- .../management/impl/view/ConnectionView.java | 2 +- .../management/impl/view/ConsumerView.java | 2 +- .../management/impl/view/ProducerView.java | 2 +- .../core/management/impl/view/QueueView.java | 2 +- .../management/impl/view/SessionView.java | 2 +- .../core/messagecounter/MessageCounter.java | 7 +- .../artemis/core/server/ServerSession.java | 2 +- .../artemis/core/server/impl/AddressInfo.java | 14 +- .../core/server/impl/ServerSessionImpl.java | 9 +- .../core/transaction/TransactionDetail.java | 6 +- .../core/config/BridgeConfigurationTest.java | 9 +- examples/features/standard/pom.xml | 1 + .../features/standard/queue-jakarta/pom.xml | 15 ++ .../artemis/jms/example/QueueExample.java | 25 +- .../src/main/resources/jndi.properties | 20 -- pom.xml | 39 +-- tests/compatibility-tests/pom.xml | 25 +- .../ActiveMQServerControlMultiThreadTest.java | 4 +- tests/integration-tests/pom.xml | 26 +- .../integration/amqp/JMXManagementTest.java | 4 +- .../integration/karaf/ArtemisFeatureTest.java | 10 +- .../management/ActiveMQServerControlTest.java | 4 +- .../management/AddressControlTest.java | 4 +- .../management/BroadcastGroupControlTest.java | 2 +- .../management/BrokerBalancerControlTest.java | 4 +- .../ClusterConnectionControlTest.java | 2 +- ...roupsChannelBroadcastGroupControlTest.java | 2 +- .../JGroupsFileBroadcastGroupControlTest.java | 2 +- .../ManagementWithPagingServerTest.java | 10 +- .../management/QueueControlTest.java | 4 +- tests/joram-tests/pom.xml | 14 ++ tests/smoke-tests/pom.xml | 15 ++ .../smoke/jmx2/JmxServerControlTest.java | 4 +- .../ReplicatedMultipleFailbackTest.java | 35 ++- .../artemis/tests/smoke/utils/Jmx.java | 35 ++- 87 files changed, 2113 insertions(+), 325 deletions(-) create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonArray.java create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonArrayBuilder.java create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonNumber.java create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonObject.java create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonObjectBuilder.java create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonString.java create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonValue.java create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonArrayBuilderImpl.java create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonArrayImpl.java create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonNumberImpl.java create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonObjectBuilderImpl.java create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonObjectImpl.java create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonStringImpl.java create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonValueImpl.java delete mode 100644 examples/features/standard/queue-jakarta/src/main/resources/jndi.properties diff --git a/artemis-cli/pom.xml b/artemis-cli/pom.xml index 155791aea3..4a4369dbfd 100644 --- a/artemis-cli/pom.xml +++ b/artemis-cli/pom.xml @@ -77,14 +77,6 @@ jakarta.inject jakarta.inject-api - - jakarta.jms - jakarta.jms-api - - - jakarta.json - jakarta.json-api - org.apache.qpid @@ -162,6 +154,21 @@ test test-jar + + + + org.apache.johnzon + johnzon-core + test + + + jakarta.json + jakarta.json-api + test + diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/StatQueue.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/StatQueue.java index a949ead868..5791d0ab6b 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/StatQueue.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/queue/StatQueue.java @@ -24,8 +24,8 @@ import org.apache.activemq.artemis.api.core.management.ManagementHelper; import org.apache.activemq.artemis.cli.commands.AbstractAction; import org.apache.activemq.artemis.cli.commands.ActionContext; -import javax.json.JsonArray; -import javax.json.JsonObject; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonObject; import java.util.Arrays; import java.util.HashMap; import java.util.Map; diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/user/ListUser.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/user/ListUser.java index 11a51f79fa..0704f2949d 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/user/ListUser.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/user/ListUser.java @@ -16,8 +16,8 @@ */ package org.apache.activemq.artemis.cli.commands.user; -import javax.json.JsonArray; -import javax.json.JsonObject; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonObject; import io.airlift.airline.Command; import org.apache.activemq.artemis.api.core.JsonUtil; @@ -72,7 +72,8 @@ public class ListUser extends UserAction { // process the JSON results from the broker JsonArray array = JsonUtil.readJsonArray(result[0]); - for (JsonObject object : array.getValuesAs(JsonObject.class)) { + for (int arrayIndex = 0; arrayIndex < array.size(); arrayIndex++) { + JsonObject object = array.getJsonObject(arrayIndex); logMessage.append("\"").append(object.getString("username")).append("\"").append("("); JsonArray roles = object.getJsonArray("roles"); for (int i = 0; i < roles.size(); i++) { diff --git a/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java b/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java index f16cb2a0a6..f453cb6a1f 100644 --- a/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java +++ b/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java @@ -24,8 +24,8 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import javax.json.JsonArray; -import javax.json.JsonObject; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonObject; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; diff --git a/artemis-commons/pom.xml b/artemis-commons/pom.xml index d244029b34..8f013d0ea9 100644 --- a/artemis-commons/pom.xml +++ b/artemis-commons/pom.xml @@ -32,6 +32,25 @@ + + + + org.apache.johnzon + johnzon-core + compile + true + + + jakarta.json + jakarta.json-api + compile + true + + + + org.jboss.logging jboss-logging-processor @@ -53,6 +72,7 @@ com.google.errorprone error_prone_core + provided org.wildfly.common @@ -80,10 +100,6 @@ commons-beanutils commons-beanutils - - jakarta.json - jakarta.json-api - junit junit @@ -111,6 +127,45 @@ + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + true + + + *:* + + META-INF/**/* + + + + + + javax.json + org.apache.activemq.artemis.commons.shaded.json + + + org.apache.johnzon + org.apache.activemq.artemis.commons.shaded.johnzon + + + + + org.apache.johnzon:johnzon-core + jakarta.json:jakarta.json-api + + + + + + diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/QueueConfiguration.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/QueueConfiguration.java index b0a2ae6407..ef4396d36a 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/QueueConfiguration.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/QueueConfiguration.java @@ -17,10 +17,10 @@ package org.apache.activemq.artemis.api.core; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import javax.json.JsonString; -import javax.json.JsonValue; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonString; +import org.apache.activemq.artemis.json.JsonValue; import java.io.Serializable; import java.io.StringReader; import java.util.Map; diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonArray.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonArray.java new file mode 100644 index 0000000000..88833dec64 --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonArray.java @@ -0,0 +1,159 @@ +/* + * 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.json; + +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * A JsonArray e.g. + *
+ * [1,5,8]
+ * 
+ * or + *
+ *  [
+ *   {"name":"karl", "age": 38},
+ *   {"name":"sue", "age": 42},
+ *  ]
+ * 
+ * + * + */ +public interface JsonArray extends JsonValue, List { + + /** + * @return the JsonObject at the given position + * @throws IndexOutOfBoundsException if the index is out of range + * @throws ClassCastException if the value at the specified position is not + * assignable to the JsonObject + */ + JsonObject getJsonObject(int index); + + /** + * @return the JsonArray at the given position + * @throws IndexOutOfBoundsException if the index is out of range + * @throws ClassCastException if the value at the specified position is not + * assignable to the JsonArray + */ + JsonArray getJsonArray(int index); + + /** + * @return the JsonNumber at the given position + * @throws IndexOutOfBoundsException if the index is out of range + * @throws ClassCastException if the value at the specified position is not + * assignable to the JsonNumber + */ + JsonNumber getJsonNumber(int index); + + /** + * @return the JsonString at the given position + * @throws IndexOutOfBoundsException if the index is out of range + * @throws ClassCastException if the value at the specified position is not + * assignable to the JsonString + */ + JsonString getJsonString(int index); + + /** + * @return the respective JsonValue at the given position + * @throws IndexOutOfBoundsException if the index is out of range + * @throws ClassCastException if the value at the specified position is not + * assignable to the given slazz + */ + List getValuesAs(Class clazz); + + /** + * Returns a list for the array. The value and the type of the elements + * in the list is specified by the {@code func} argument. + *

This method can be used to obtain a list of the unwrapped types, such as + *

{@code
+    *     List strings = ary1.getValuesAs(JsonString::getString);
+    *     List ints = ary2.getValuesAs(JsonNumber::intValue);
+    * } 
+ * It can also be used to obtain a list of simple projections, such as + *
 {@code
+    *     Lsit stringsizes = arr.getValueAs((JsonString v) -> v.getString().length();
+    * } 
+ * @param The element type (must be a subtype of JsonValue) of this JsonArray. + * @param The element type of the returned List + * @param func The function that maps the elements of this JsonArray to the target elements. + * @return A List of the specified values and type. + * @throws ClassCastException if the {@code JsonArray} contains a value of wrong type + */ + default List getValuesAs(Function func) { + Stream stream = (Stream) stream(); + return stream.map(func).collect(Collectors.toList()); + } + + /** + * @return the native String at the given position + * @throws IndexOutOfBoundsException if the index is out of range + * @throws ClassCastException if the value at the specified position is not + * assignable to a String + */ + String getString(int index); + + /** + * @return the native String at the given position or the defaultValue if null + * @throws IndexOutOfBoundsException if the index is out of range + * @throws ClassCastException if the value at the specified position is not + * assignable to a String + */ + String getString(int index, String defaultValue); + + /** + * @return the native int value at the given position + * @throws IndexOutOfBoundsException if the index is out of range + * @throws ClassCastException if the value at the specified position is not + * assignable to an int + * @throws NullPointerException if an object with the given name doesn't exist + */ + int getInt(int index); + + /** + * @return the native int value at the given position or the defaultValue if null + * @throws IndexOutOfBoundsException if the index is out of range + * @throws ClassCastException if the value at the specified position is not + * assignable to an int + */ + int getInt(int index, int defaultValue); + + /** + * @return the native boolean value at the given position + * @throws IndexOutOfBoundsException if the index is out of range + * @throws ClassCastException if the value at the specified position is not + * assignable to a boolean + * @throws NullPointerException if an object with the given name doesn't exist + */ + boolean getBoolean(int index); + + /** + * @return the native boolean value at the given position or the defaultValue if null + * @throws IndexOutOfBoundsException if the index is out of range + * @throws ClassCastException if the value at the specified position is not + * assignable to a boolean + */ + boolean getBoolean(int index, boolean defaultValue); + + /** + * @return whether the value at the given position is {@link JsonValue#NULL}. + * @throws IndexOutOfBoundsException if the index is out of range + */ + boolean isNull(int index); +} diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonArrayBuilder.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonArrayBuilder.java new file mode 100644 index 0000000000..17a8d98f23 --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonArrayBuilder.java @@ -0,0 +1,142 @@ +/* + * 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.json; + +import java.math.BigDecimal; +import java.math.BigInteger; + +public interface JsonArrayBuilder { + JsonArrayBuilder add(JsonValue value); + + JsonArrayBuilder add(String value); + + JsonArrayBuilder add(BigDecimal value); + + JsonArrayBuilder add(BigInteger value); + + JsonArrayBuilder add(int value); + + JsonArrayBuilder add(long value); + + JsonArrayBuilder add(double value); + + JsonArrayBuilder add(boolean value); + + JsonArrayBuilder addNull(); + + JsonArrayBuilder add(JsonObjectBuilder builder); + + JsonArrayBuilder add(JsonArrayBuilder builder); + + JsonArray build(); + + default JsonArrayBuilder addAll(JsonArrayBuilder builder) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder add(int index, JsonValue value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder add(int index, String value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder add(int index, BigDecimal value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder add(int index, BigInteger value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder add(int index, int value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder add(int index, long value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder add(int index, double value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder add(int index, boolean value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder addNull(int index) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder add(int index, JsonObjectBuilder builder) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder add(int index, JsonArrayBuilder builder) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder set(int index, JsonValue value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder set(int index, String value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder set(int index, BigDecimal value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder set(int index, BigInteger value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder set(int index, int value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder set(int index, long value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder set(int index, double value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder set(int index, boolean value) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder setNull(int index) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder set(int index, JsonObjectBuilder builder) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder set(int index, JsonArrayBuilder builder) { + throw new UnsupportedOperationException(); + } + + default JsonArrayBuilder remove(int index) { + throw new UnsupportedOperationException(); + } +} \ No newline at end of file diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonNumber.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonNumber.java new file mode 100644 index 0000000000..5713b3257f --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonNumber.java @@ -0,0 +1,63 @@ +/* + * 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.json; + +import java.math.BigDecimal; +import java.math.BigInteger; + +/** + * JsonValue which represents a number. + * + * The decimal point is defined as dot '.'. + * + * @see RFC-4627 JSON Specification + */ +public interface JsonNumber extends JsonValue { + boolean isIntegral(); + + int intValue(); + + int intValueExact(); + + long longValue(); + + long longValueExact(); + + BigInteger bigIntegerValue(); + + BigInteger bigIntegerValueExact(); + + double doubleValue(); + + BigDecimal bigDecimalValue(); + + /** + * @since 1.1 + */ + default Number numberValue() { + throw new UnsupportedOperationException(); + } + + @Override + String toString(); + + @Override + boolean equals(Object obj); + + @Override + int hashCode(); +} \ No newline at end of file diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonObject.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonObject.java new file mode 100644 index 0000000000..b044edd20b --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonObject.java @@ -0,0 +1,105 @@ +/* + * 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.json; + +import java.util.Map; + +/** + * A JsonObject, e.g. + *
+ * {
+ *     "name":"karl",
+ *     "age":38,
+ *     "address": {
+ *         "street":"dummystreet"
+ *         "housenumber":12
+ *     }
+ * }
+ * 
+ * + * A JsonObject is always also a Map which uses the attribute names as key mapping + * to their JsonValues. + */ +public interface JsonObject extends JsonValue, Map { + + /** + * @return the JsonArray with the given name or {@code null} if there is no attribute with that name + * @throws ClassCastException if the JsonValue cannot be correctly cast + */ + JsonArray getJsonArray(String name); + + /** + * @return the JsonObject with the given name or {@code null} if there is no attribute with that name + * @throws ClassCastException if the JsonValue cannot be correctly cast + */ + JsonObject getJsonObject(String name); + + /** + * @return the JsonNumber with the given name or {@code null} if there is no attribute with that name + * @throws ClassCastException if the JsonValue cannot be correctly cast + */ + JsonNumber getJsonNumber(String name); + + /** + * @return the JsonString with the given name or {@code null} if there is no attribute with that name + * @throws ClassCastException if the JsonValue cannot be correctly cast + */ + JsonString getJsonString(String name); + + /** + * @return the native string with the given name or {@code null} if there is no attribute with that name + * @throws ClassCastException if the JsonValue cannot be correctly cast + */ + String getString(String name); + + /** + * @return the native string with the given name or the default value if there is no attribute with that name + * @throws ClassCastException if the JsonValue cannot be correctly cast + */ + String getString(String name, String defaultValue); + + /** + * @return the int with the given name or {@code null} if there is no attribute with that name + * @throws ClassCastException if the JsonValue cannot be correctly cast + * @throws NullPointerException if an object with the given name doesn't exist + */ + int getInt(String name); + + /** + * @return the int with the given name or the default value if there is no attribute with that name + * @throws ClassCastException if the JsonValue cannot be correctly cast + */ + int getInt(String name, int defaultValue); + + /** + * @return the boolean with the given name or {@code null} if there is no attribute with that name + * @throws ClassCastException if the JsonValue cannot be correctly cast + * @throws NullPointerException if an object with the given name doesn't exist + */ + boolean getBoolean(String name); + + /** + * @return the boolean with the given name or the default value if there is no attribute with that name + * @throws ClassCastException if the JsonValue cannot be correctly cast + */ + boolean getBoolean(String name, boolean defaultValue); + + /** + * @return whether the attribute with the given name is {@link JsonValue#NULL} + */ + boolean isNull(String name); +} \ No newline at end of file diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonObjectBuilder.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonObjectBuilder.java new file mode 100644 index 0000000000..fa08e0c95c --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonObjectBuilder.java @@ -0,0 +1,155 @@ +/* + * 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.json; + +import java.math.BigDecimal; +import java.math.BigInteger; + +/** + * A JsonObjectBuilder can be used to build {@link JsonObject JsonObjects}. + * Instances are not thread safe. + * + * Calling any of those methods with either the {@code name} or {@code value} param as {@code null} + * will result in a {@code NullPointerException} + */ +public interface JsonObjectBuilder { + /** + * Add the given JsonValue value to the JsonObject to be created. + * If a value with that name already exists it will be replaced by the new value. + * @param name the JSON attribute name + * @param value the JsonValue to add + * @return the current JsonObjectBuilder + */ + JsonObjectBuilder add(String name, JsonValue value); + + /** + * Add the given String value to the JsonObject to be created. + * If a value with that name already exists it will be replaced by the new value. + * @param name the JSON attribute name + * @param value the String value to add + * @return the current JsonObjectBuilder + */ + JsonObjectBuilder add(String name, String value); + JsonObjectBuilder add(String name, String value, JsonValue defaultValue); + + /** + * Add the given BigInteger value to the JsonObject to be created. + * If a value with that name already exists it will be replaced by the new value. + * @param name the JSON attribute name + * @param value the BigInteger value to add + * @return the current JsonObjectBuilder + */ + JsonObjectBuilder add(String name, BigInteger value); + JsonObjectBuilder add(String name, BigInteger value, JsonValue defaultValue); + + /** + * Add the given BigDecimal value to the JsonObject to be created. + * If a value with that name already exists it will be replaced by the new value. + * @param name the JSON attribute name + * @param value the BigDecimal value to add + * @return the current JsonObjectBuilder + */ + JsonObjectBuilder add(String name, BigDecimal value); + JsonObjectBuilder add(String name, BigDecimal value, JsonValue defaultValue); + + /** + * Add the given int value to the JsonObject to be created. + * If a value with that name already exists it will be replaced by the new value. + * @param name the JSON attribute name + * @param value to add + * @return the current JsonObjectBuilder + */ + JsonObjectBuilder add(String name, int value); + + /** + * Add the given long value to the JsonObject to be created. + * If a value with that name already exists it will be replaced by the new value. + * @param name the JSON attribute name + * @param value to add + * @return the current JsonObjectBuilder + */ + JsonObjectBuilder add(String name, long value); + + /** + * Add the given double value to the JsonObject to be created. + * If a value with that name already exists it will be replaced by the new value. + * @param name the JSON attribute name + * @param value to add + * @return the current JsonObjectBuilder + */ + JsonObjectBuilder add(String name, double value); + + /** + * Add the given boolean value to the JsonObject to be created. + * If a value with that name already exists it will be replaced by the new value. + * @param name the JSON attribute name + * @param value to add + * @return the current JsonObjectBuilder + */ + JsonObjectBuilder add(String name, boolean value); + + /** + * Add a {@link JsonValue#NULL} value to the JsonObject to be created. + * If a value with that name already exists it will be replaced by the null value. + * @param name the JSON attribute name + * @return the current JsonObjectBuilder + */ + JsonObjectBuilder addNull(String name); + + /** + * Use the given {@link JsonObjectBuilder} to create a {@link JsonObject} which will be + * added to the JsonObject to be created by this builder. + * If a value with that name already exists it will be replaced by the new value. + * @param name the JSON attribute name + * @param builder for creating the JsonObject to add + * @return the current JsonObjectBuilder + */ + JsonObjectBuilder add(String name, JsonObjectBuilder builder); + + /** + * Use the given {@link JsonArrayBuilder} to create a {@link JsonArray} which will be + * added to the JsonObject to be created by this builder. + * If a value with that name already exists it will be replaced by the new value. + * @param name the JSON attribute name + * @param builder for creating the JsonArray to add + * @return the current JsonObjectBuilder + */ + JsonObjectBuilder add(String name, JsonArrayBuilder builder); + + /** + * @return a {@link JsonObject} based on the added values. + */ + JsonObject build(); + + /** + * Add all of the attributes of the given {@link JsonObjectBuilder} to the current one + * + * @since 1.1 + */ + default JsonObjectBuilder addAll(JsonObjectBuilder builder) { + throw new UnsupportedOperationException(); + } + + /** + * Remove the attribute with the given name from the builder. + * + * @since 1.1 + */ + default JsonObjectBuilder remove(String name) { + throw new UnsupportedOperationException(); + } +} \ No newline at end of file diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonString.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonString.java new file mode 100644 index 0000000000..24dfd3e692 --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonString.java @@ -0,0 +1,32 @@ +/* + * 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.json; + +/** + * JsonValue which represents a string. + */ +public interface JsonString extends JsonValue { + String getString(); + + CharSequence getChars(); + + @Override + boolean equals(Object obj); + + @Override + int hashCode(); +} \ No newline at end of file diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonValue.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonValue.java new file mode 100644 index 0000000000..a0e54488e3 --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/JsonValue.java @@ -0,0 +1,74 @@ +/* + * 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.json; + +import org.apache.activemq.artemis.json.impl.JsonArrayImpl; +import org.apache.activemq.artemis.json.impl.JsonObjectImpl; +import org.apache.activemq.artemis.json.impl.JsonValueImpl; + +/** + * A single value in a JSON expression. + */ +public interface JsonValue { + + /** + * The empty JSON object. + */ + JsonObject EMPTY_JSON_OBJECT = new JsonObjectImpl(javax.json.JsonValue.EMPTY_JSON_OBJECT); + + /** + * The empty JSON array. + */ + JsonArray EMPTY_JSON_ARRAY = new JsonArrayImpl(javax.json.JsonValue.EMPTY_JSON_ARRAY); + + + /** + * A constant JsonValue for null values + */ + JsonValue NULL = new JsonValueImpl(javax.json.JsonValue.NULL); + + /** + * A constant JsonValue for TRUE + */ + JsonValue TRUE = new JsonValueImpl(javax.json.JsonValue.TRUE); + + /** + * A constant JsonValue for FALSE + */ + JsonValue FALSE = new JsonValueImpl(javax.json.JsonValue.FALSE); + + ValueType getValueType(); + + @Override + String toString(); + + enum ValueType { + ARRAY, + OBJECT, STRING, NUMBER, + TRUE, FALSE, + NULL + } + + default JsonObject asJsonObject() { + return JsonObject.class.cast(this); + } + + default JsonArray asJsonArray() { + return JsonArray.class.cast(this); + } + +} \ No newline at end of file diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonArrayBuilderImpl.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonArrayBuilderImpl.java new file mode 100644 index 0000000000..89653c0f62 --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonArrayBuilderImpl.java @@ -0,0 +1,125 @@ +/** + * 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.json.impl; + +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonValue; + +import java.math.BigDecimal; +import java.math.BigInteger; + +public class JsonArrayBuilderImpl implements JsonArrayBuilder { + + private final javax.json.JsonArrayBuilder rawArrayBuilder; + + public javax.json.JsonArrayBuilder getRawArrayBuilder() { + return rawArrayBuilder; + } + + public JsonArrayBuilderImpl(javax.json.JsonArrayBuilder rawArrayBuilder) { + this.rawArrayBuilder = rawArrayBuilder; + } + + @Override + public JsonArrayBuilder add(JsonValue value) { + if (!(value instanceof JsonValueImpl)) { + throw new UnsupportedOperationException(); + } + rawArrayBuilder.add(((JsonValueImpl)value).getRawValue()); + return this; + } + + @Override + public JsonArrayBuilder add(String value) { + rawArrayBuilder.add(value); + return this; + } + + @Override + public JsonArrayBuilder add(BigDecimal value) { + rawArrayBuilder.add(value); + return this; + } + + @Override + public JsonArrayBuilder add(BigInteger value) { + rawArrayBuilder.add(value); + return this; + } + + @Override + public JsonArrayBuilder add(int value) { + rawArrayBuilder.add(value); + return this; + } + + @Override + public JsonArrayBuilder add(long value) { + rawArrayBuilder.add(value); + return this; + } + + @Override + public JsonArrayBuilder add(double value) { + rawArrayBuilder.add(value); + return this; + } + + @Override + public JsonArrayBuilder add(boolean value) { + rawArrayBuilder.add(value); + return this; + } + + @Override + public JsonArrayBuilder addNull() { + rawArrayBuilder.addNull(); + return this; + } + + @Override + public JsonArrayBuilder add(JsonObjectBuilder builder) { + if (!(builder instanceof JsonObjectBuilderImpl)) { + throw new UnsupportedOperationException(); + } + rawArrayBuilder.add(((JsonObjectBuilderImpl)builder).getRawObjectBuilder()); + return this; + } + + @Override + public JsonArrayBuilder add(JsonArrayBuilder builder) { + if (!(builder instanceof JsonArrayBuilderImpl)) { + throw new UnsupportedOperationException(); + } + rawArrayBuilder.add(((JsonArrayBuilderImpl)builder).getRawArrayBuilder()); + return this; + } + + @Override + public JsonArrayBuilder remove(int index) { + rawArrayBuilder.remove(index); + return this; + } + + @Override + public JsonArray build() { + return new JsonArrayImpl(rawArrayBuilder.build()); + } +} diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonArrayImpl.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonArrayImpl.java new file mode 100644 index 0000000000..7f972faefa --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonArrayImpl.java @@ -0,0 +1,234 @@ +/** + * 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.json.impl; + +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonNumber; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonString; +import org.apache.activemq.artemis.json.JsonValue; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +public class JsonArrayImpl extends JsonValueImpl implements JsonArray { + + private final javax.json.JsonArray rawArray; + + public javax.json.JsonArray getRawArray() { + return rawArray; + } + + public JsonArrayImpl(javax.json.JsonArray rawArray) { + super(rawArray); + this.rawArray = rawArray; + } + + @Override + public JsonObject getJsonObject(int index) { + return (JsonObject)this.wrap(rawArray.getJsonObject(index)); + } + + @Override + public JsonArray getJsonArray(int index) { + return (JsonArray)this.wrap(rawArray.getJsonArray(index)); + } + + @Override + public JsonNumber getJsonNumber(int index) { + return (JsonNumber)this.wrap(rawArray.getJsonNumber(index)); + } + + @Override + public JsonString getJsonString(int index) { + return (JsonString)this.wrap(rawArray.getJsonString(index)); + } + + @Override + public List getValuesAs(Class clazz) { + throw new UnsupportedOperationException(); + } + + @Override + public String getString(int index) { + return rawArray.getString(index); + } + + @Override + public String getString(int index, String defaultValue) { + return rawArray.getString(index, defaultValue); + } + + @Override + public int getInt(int index) { + return rawArray.getInt(index); + } + + @Override + public int getInt(int index, int defaultValue) { + return rawArray.getInt(index, defaultValue); + } + + @Override + public boolean getBoolean(int index) { + return rawArray.getBoolean(index); + } + + @Override + public boolean getBoolean(int index, boolean defaultValue) { + return rawArray.getBoolean(index, defaultValue); + } + + @Override + public boolean isNull(int index) { + return rawArray.isNull(index); + } + + @Override + public int size() { + return rawArray.size(); + } + + @Override + public boolean isEmpty() { + return rawArray.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof JsonValueImpl) { + return rawArray.contains(((JsonValueImpl)o).getRawValue()); + } else { + return rawArray.contains(o); + } + } + + @Override + public Iterator iterator() { + return new Iterator() { + private Iterator rawIterator = rawArray.iterator(); + + @Override + public boolean hasNext() { + return rawIterator.hasNext(); + } + + @Override + public JsonValue next() { + return wrap(rawIterator.next()); + } + }; + } + + @Override + public Object[] toArray() { + throw new UnsupportedOperationException(); + } + + @Override + public T[] toArray(T[] a) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean add(JsonValue jsonValue) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(int index, Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + rawArray.clear(); + } + + @Override + public JsonValue get(int index) { + return wrap(rawArray.get(index)); + } + + @Override + public JsonValue set(int index, JsonValue element) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(int index, JsonValue element) { + throw new UnsupportedOperationException(); + } + + @Override + public JsonValue remove(int index) { + throw new UnsupportedOperationException(); + } + + @Override + public int indexOf(Object o) { + throw new UnsupportedOperationException(); + } + + @Override + public int lastIndexOf(Object o) { + throw new UnsupportedOperationException(); + } + + @Override + public ListIterator listIterator() { + throw new UnsupportedOperationException(); + } + + @Override + public ListIterator listIterator(int index) { + throw new UnsupportedOperationException(); + } + + @Override + public List subList(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } +} diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonNumberImpl.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonNumberImpl.java new file mode 100644 index 0000000000..6d8149dd4f --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonNumberImpl.java @@ -0,0 +1,87 @@ +/** + * 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.json.impl; + +import org.apache.activemq.artemis.json.JsonNumber; + +import java.math.BigDecimal; +import java.math.BigInteger; + +public class JsonNumberImpl extends JsonValueImpl implements JsonNumber { + + private final javax.json.JsonNumber rawNumber; + + public javax.json.JsonNumber getRawNumber() { + return rawNumber; + } + + public JsonNumberImpl(javax.json.JsonNumber rawNumber) { + super(rawNumber); + this.rawNumber = rawNumber; + } + + @Override + public boolean isIntegral() { + return rawNumber.isIntegral(); + } + + @Override + public int intValue() { + return rawNumber.intValue(); + } + + @Override + public int intValueExact() { + return rawNumber.intValueExact(); + } + + @Override + public long longValue() { + return rawNumber.longValue(); + } + + @Override + public long longValueExact() { + return rawNumber.longValueExact(); + } + + @Override + public BigInteger bigIntegerValue() { + return rawNumber.bigIntegerValue(); + } + + @Override + public BigInteger bigIntegerValueExact() { + return rawNumber.bigIntegerValueExact(); + } + + @Override + public double doubleValue() { + return rawNumber.doubleValue(); + } + + @Override + public BigDecimal bigDecimalValue() { + return rawNumber.bigDecimalValue(); + } + + @Override + public Number numberValue() { + return rawNumber.numberValue(); + } +} diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonObjectBuilderImpl.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonObjectBuilderImpl.java new file mode 100644 index 0000000000..e427219a90 --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonObjectBuilderImpl.java @@ -0,0 +1,155 @@ +/** + * 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.json.impl; + +import org.apache.activemq.artemis.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonValue; + +import java.math.BigDecimal; +import java.math.BigInteger; + +public class JsonObjectBuilderImpl implements JsonObjectBuilder { + + private final javax.json.JsonObjectBuilder rawObjectBuilder; + + public javax.json.JsonObjectBuilder getRawObjectBuilder() { + return rawObjectBuilder; + } + + public JsonObjectBuilderImpl(javax.json.JsonObjectBuilder rawObjectBuilder) { + this.rawObjectBuilder = rawObjectBuilder; + } + + @Override + public JsonObjectBuilder add(String name, JsonValue value) { + if (!(value instanceof JsonValueImpl)) { + throw new UnsupportedOperationException(); + } + rawObjectBuilder.add(name, ((JsonValueImpl)value).getRawValue()); + return this; + } + + @Override + public JsonObjectBuilder add(String name, String value) { + rawObjectBuilder.add(name, value); + return this; + } + + @Override + public JsonObjectBuilder add(String name, String value, JsonValue defaultValue) { + if (value != null) { + rawObjectBuilder.add(name, value); + } else { + add(name, defaultValue); + } + return this; + } + + @Override + public JsonObjectBuilder add(String name, BigInteger value) { + rawObjectBuilder.add(name, value); + return this; + } + + @Override + public JsonObjectBuilder add(String name, BigInteger value, JsonValue defaultValue) { + if (value != null) { + rawObjectBuilder.add(name, value); + } else { + add(name, defaultValue); + } + return this; + } + + @Override + public JsonObjectBuilder add(String name, BigDecimal value) { + rawObjectBuilder.add(name, value); + return this; + } + + @Override + public JsonObjectBuilder add(String name, BigDecimal value, JsonValue defaultValue) { + if (value != null) { + rawObjectBuilder.add(name, value); + } else { + add(name, defaultValue); + } + return this; + } + + @Override + public JsonObjectBuilder add(String name, int value) { + rawObjectBuilder.add(name, value); + return this; + } + + @Override + public JsonObjectBuilder add(String name, long value) { + rawObjectBuilder.add(name, value); + return this; + } + + @Override + public JsonObjectBuilder add(String name, double value) { + rawObjectBuilder.add(name, value); + return this; + } + + @Override + public JsonObjectBuilder add(String name, boolean value) { + rawObjectBuilder.add(name, value); + return this; + } + + @Override + public JsonObjectBuilder addNull(String name) { + rawObjectBuilder.addNull(name); + return this; + } + + @Override + public JsonObjectBuilder add(String name, JsonObjectBuilder builder) { + if (!(builder instanceof JsonObjectBuilderImpl)) { + throw new UnsupportedOperationException(); + } + rawObjectBuilder.add(name, ((JsonObjectBuilderImpl)builder).getRawObjectBuilder()); + return this; + } + + @Override + public JsonObjectBuilder add(String name, JsonArrayBuilder builder) { + if (!(builder instanceof JsonArrayBuilderImpl)) { + throw new UnsupportedOperationException(); + } + rawObjectBuilder.add(name, ((JsonArrayBuilderImpl)builder).getRawArrayBuilder()); + return this; + } + + @Override + public JsonObjectBuilder remove(String name) { + rawObjectBuilder.remove(name); + return this; + } + + @Override + public JsonObject build() { + return new JsonObjectImpl(rawObjectBuilder.build()); + } +} diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonObjectImpl.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonObjectImpl.java new file mode 100644 index 0000000000..39fb6ad33c --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonObjectImpl.java @@ -0,0 +1,217 @@ +/** + * 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.json.impl; + +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonNumber; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonString; +import org.apache.activemq.artemis.json.JsonValue; + +import java.util.AbstractCollection; +import java.util.AbstractMap; +import java.util.AbstractSet; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +public class JsonObjectImpl extends JsonValueImpl implements JsonObject { + + private final javax.json.JsonObject rawObject; + + public javax.json.JsonObject getRawObject() { + return rawObject; + } + + public JsonObjectImpl(javax.json.JsonObject rawObject) { + super(rawObject); + this.rawObject = rawObject; + } + + @Override + public JsonArray getJsonArray(String name) { + return (JsonArray)wrap(rawObject.getJsonArray(name)); + } + + @Override + public JsonObject getJsonObject(String name) { + return (JsonObject)wrap(rawObject.getJsonObject(name)); + } + + @Override + public JsonNumber getJsonNumber(String name) { + return (JsonNumber)wrap(rawObject.getJsonNumber(name)); + } + + @Override + public JsonString getJsonString(String name) { + return (JsonString)wrap(rawObject.getJsonString(name)); + } + + @Override + public String getString(String name) { + return rawObject.getString(name); + } + + @Override + public String getString(String name, String defaultValue) { + return rawObject.getString(name, defaultValue); + } + + @Override + public int getInt(String name) { + return rawObject.getInt(name); + } + + @Override + public int getInt(String name, int defaultValue) { + return rawObject.getInt(name, defaultValue); + } + + @Override + public boolean getBoolean(String name) { + return rawObject.getBoolean(name); + } + + @Override + public boolean getBoolean(String name, boolean defaultValue) { + return rawObject.getBoolean(name, defaultValue); + } + + @Override + public boolean isNull(String name) { + return rawObject.isNull(name); + } + + @Override + public int size() { + return rawObject.size(); + } + + + @Override + public boolean isEmpty() { + return rawObject.isEmpty(); + } + + + @Override + public boolean containsKey(Object key) { + return rawObject.containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return rawObject.containsValue(value); + } + + @Override + public JsonValue get(Object key) { + return wrap(rawObject.get(key)); + } + + @Override + public JsonValue put(String key, JsonValue value) { + if (!(value instanceof JsonValueImpl)) { + throw new UnsupportedOperationException(); + } + + javax.json.JsonValue rawValue = rawObject.put(key, ((JsonValueImpl)value).getRawValue()); + + return rawValue != null ? wrap(rawValue) : null; + } + + @Override + public JsonValue remove(Object key) { + javax.json.JsonValue rawValue = rawObject.remove(key); + + return rawValue != null ? wrap(rawValue) : null; + } + + @Override + public void putAll(Map m) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + rawObject.clear(); + } + + @Override + public Set keySet() { + return rawObject.keySet(); + } + + @Override + public Collection values() { + return new AbstractCollection() { + @Override + public Iterator iterator() { + return new Iterator() { + private Iterator rawIterator = rawObject.values().iterator(); + + @Override + public boolean hasNext() { + return rawIterator.hasNext(); + } + + @Override + public JsonValue next() { + return wrap(rawIterator.next()); + } + }; + } + + @Override + public int size() { + return rawObject.size(); + } + }; + } + + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public Iterator> iterator() { + return new Iterator>() { + private Iterator> rawIterator = rawObject.entrySet().iterator(); + + @Override + public boolean hasNext() { + return rawIterator.hasNext(); + } + + @Override + public Map.Entry next() { + Map.Entry rawEntry = rawIterator.next(); + + return rawEntry != null ? new AbstractMap.SimpleEntry<>(rawEntry.getKey(), wrap(rawEntry.getValue())) : null; + } + }; + } + + @Override + public int size() { + return rawObject.size(); + } + }; + } +} diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonStringImpl.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonStringImpl.java new file mode 100644 index 0000000000..588b8fd4e7 --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonStringImpl.java @@ -0,0 +1,44 @@ +/** + * 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.json.impl; + +import org.apache.activemq.artemis.json.JsonString; + +public class JsonStringImpl extends JsonValueImpl implements JsonString { + + private final javax.json.JsonString rawString; + + public javax.json.JsonString getRawString() { + return rawString; + } + + public JsonStringImpl(javax.json.JsonString rawString) { + super(rawString); + this.rawString = rawString; + } + + @Override + public String getString() { + return rawString.getString(); + } + + @Override + public CharSequence getChars() { + return rawString.getChars(); + } +} diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonValueImpl.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonValueImpl.java new file mode 100644 index 0000000000..3e94b4d45c --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonValueImpl.java @@ -0,0 +1,116 @@ +/** + * 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.json.impl; + +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonValue; + +import java.util.HashMap; +import java.util.Map; + +public class JsonValueImpl implements JsonValue { + + private Map cache = new HashMap<>(); + + public JsonValue wrap(javax.json.JsonValue rawValue) { + if (rawValue == null) { + return null; + } + + JsonValue cacheValue = cache.get(rawValue); + + if (cacheValue != null) { + return cacheValue; + } else if (rawValue == javax.json.JsonValue.EMPTY_JSON_OBJECT) { + return JsonValue.EMPTY_JSON_OBJECT; + } else if (rawValue == javax.json.JsonValue.EMPTY_JSON_ARRAY) { + return JsonValue.EMPTY_JSON_ARRAY; + } else if (rawValue == javax.json.JsonValue.TRUE) { + return JsonValue.TRUE; + } else if (rawValue == javax.json.JsonValue.FALSE) { + return JsonValue.FALSE; + } else if (rawValue == javax.json.JsonValue.NULL) { + return JsonValue.NULL; + } else if (rawValue.getValueType() == javax.json.JsonValue.ValueType.ARRAY) { + cacheValue = new JsonArrayImpl((javax.json.JsonArray) rawValue); + } else if (rawValue.getValueType() == javax.json.JsonValue.ValueType.OBJECT) { + cacheValue = new JsonObjectImpl((javax.json.JsonObject) rawValue); + } else if (rawValue.getValueType() == javax.json.JsonValue.ValueType.STRING) { + cacheValue = new JsonStringImpl((javax.json.JsonString) rawValue); + } else if (rawValue.getValueType() == javax.json.JsonValue.ValueType.NUMBER) { + cacheValue = new JsonNumberImpl((javax.json.JsonNumber) rawValue); + } else if (rawValue.getValueType() == javax.json.JsonValue.ValueType.TRUE) { + cacheValue = new JsonValueImpl(rawValue); + } else if (rawValue.getValueType() == javax.json.JsonValue.ValueType.FALSE) { + cacheValue = new JsonValueImpl(rawValue); + } else if (rawValue.getValueType() == javax.json.JsonValue.ValueType.NULL) { + cacheValue = new JsonValueImpl(rawValue); + } else { + throw new IllegalStateException("Unexpected value: " + rawValue.getValueType()); + } + + cache.put(rawValue, cacheValue); + + return cacheValue; + } + + private final javax.json.JsonValue rawValue; + + public javax.json.JsonValue getRawValue() { + return rawValue; + } + + public JsonValueImpl(javax.json.JsonValue rawValue) { + this.rawValue = rawValue; + } + + + @Override + public JsonValue.ValueType getValueType() { + return ValueType.valueOf(rawValue.getValueType().name()); + } + + @Override + public JsonObject asJsonObject() { + return JsonValue.super.asJsonObject(); + } + + @Override + public JsonArray asJsonArray() { + return JsonValue.super.asJsonArray(); + } + + @Override + public String toString() { + return rawValue.toString(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof JsonValueImpl) { + return rawValue.equals(((JsonValueImpl)obj).getRawValue()); + } + return super.equals(obj); + } + + @Override + public int hashCode() { + return rawValue.hashCode(); + } +} diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/JsonLoader.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/JsonLoader.java index 0e9df69f72..789e530d99 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/JsonLoader.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/JsonLoader.java @@ -17,15 +17,18 @@ package org.apache.activemq.artemis.utils; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.impl.JsonArrayBuilderImpl; +import org.apache.activemq.artemis.json.impl.JsonArrayImpl; +import org.apache.activemq.artemis.json.impl.JsonObjectBuilderImpl; +import org.apache.activemq.artemis.json.impl.JsonObjectImpl; + import javax.json.JsonReader; import javax.json.spi.JsonProvider; import java.io.Reader; -import java.security.AccessController; -import java.security.PrivilegedAction; /** * This is to make sure we use the proper classLoader to load JSon libraries. @@ -33,46 +36,25 @@ import java.security.PrivilegedAction; */ public class JsonLoader { - private static final JsonProvider provider; - - static { - provider = loadProvider(); - } - - private static JsonProvider loadProvider() { - return AccessController.doPrivileged(new PrivilegedAction() { - @Override - public JsonProvider run() { - ClassLoader originalLoader = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(JsonLoader.class.getClassLoader()); - return JsonProvider.provider(); - } finally { - Thread.currentThread().setContextClassLoader(originalLoader); - } - } - }); - - } + private static final JsonProvider provider = new org.apache.johnzon.core.JsonProviderImpl(); public static JsonObject readObject(Reader reader) { try (JsonReader jsonReader = provider.createReader(reader)) { - return jsonReader.readObject(); + return new JsonObjectImpl(jsonReader.readObject()); } } public static JsonArray readArray(Reader reader) { try (JsonReader jsonReader = provider.createReader(reader)) { - return jsonReader.readArray(); + return new JsonArrayImpl(jsonReader.readArray()); } } public static JsonArrayBuilder createArrayBuilder() { - return provider.createArrayBuilder(); + return new JsonArrayBuilderImpl(provider.createArrayBuilder()); } public static JsonObjectBuilder createObjectBuilder() { - return provider.createObjectBuilder(); + return new JsonObjectBuilderImpl(provider.createObjectBuilder()); } - } diff --git a/artemis-core-client-osgi/pom.xml b/artemis-core-client-osgi/pom.xml index b84ba94f7b..1fcfd777a4 100644 --- a/artemis-core-client-osgi/pom.xml +++ b/artemis-core-client-osgi/pom.xml @@ -98,8 +98,8 @@ *;scope=compile|runtime;groupId=org.apache.activemq + org.glassfish.json*;resolution:=optional, io.netty.buffer;io.netty.*;version="[4.1,5)", - org.apache.johnzon.core, * <_exportcontents>org.apache.activemq.artemis.*;-noimport:=true diff --git a/artemis-core-client/pom.xml b/artemis-core-client/pom.xml index a4832e9b71..8743eda027 100644 --- a/artemis-core-client/pom.xml +++ b/artemis-core-client/pom.xml @@ -86,14 +86,6 @@ ${hamcrest.version} test - - jakarta.json - jakarta.json-api - - - org.apache.johnzon - johnzon-core - io.netty netty-transport-native-epoll @@ -136,6 +128,21 @@ io.netty netty-common + + + + org.apache.johnzon + johnzon-core + test + + + jakarta.json + jakarta.json-api + test + @@ -152,7 +159,7 @@ 512m false true - org.apache.activemq.artemis.core:org.apache.activemq.artemis.utils + org.apache.activemq.artemis.core:org.apache.activemq.artemis.utils,org.apache.activemq.artemis.commons 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 index b1535bb3e6..052a09b0bc 100644 --- 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 @@ -16,13 +16,13 @@ */ package org.apache.activemq.artemis.api.core; -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 org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonNumber; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonString; +import org.apache.activemq.artemis.json.JsonValue; import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeDataSupport; import java.io.ByteArrayInputStream; @@ -264,7 +264,7 @@ public final class JsonUtil { public static Map readJsonProperties(String jsonString) { Map properties = new HashMap<>(); if (jsonString != null) { - JsonUtil.readJsonObject(jsonString).forEach((k, v) -> properties.put(k, v.toString())); + JsonUtil.readJsonObject(jsonString).entrySet().forEach(e -> properties.put(e.getKey(), e.getValue().toString())); } return properties; } 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 15a3b522be..2d9f415010 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 @@ -16,7 +16,7 @@ */ package org.apache.activemq.artemis.api.core; -import javax.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObject; import java.io.Serializable; import java.util.HashMap; import java.util.Map; 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 ebe030b3be..f96d28c746 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,7 @@ */ package org.apache.activemq.artemis.api.core.management; -import javax.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObject; import org.apache.activemq.artemis.api.core.JsonUtil; 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 3955a8b633..36885ea836 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,10 +16,10 @@ */ package org.apache.activemq.artemis.api.core.management; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObjectBuilder; import org.apache.activemq.artemis.api.core.JsonUtil; import org.apache.activemq.artemis.utils.JsonLoader; 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 462a7b74fb..678df28625 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,7 +16,7 @@ */ package org.apache.activemq.artemis.api.core.management; -import javax.json.JsonArray; +import org.apache.activemq.artemis.json.JsonArray; import org.apache.activemq.artemis.api.core.ICoreMessage; import org.apache.activemq.artemis.api.core.JsonUtil; diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/MessageCounterInfo.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/MessageCounterInfo.java index 528238771a..e5c3cc964e 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/MessageCounterInfo.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/MessageCounterInfo.java @@ -16,7 +16,7 @@ */ package org.apache.activemq.artemis.api.core.management; -import javax.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObject; import org.apache.activemq.artemis.api.core.JsonUtil; diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/NodeInfo.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/NodeInfo.java index 1f60e0c143..9c00cae02c 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/NodeInfo.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/NodeInfo.java @@ -17,8 +17,8 @@ package org.apache.activemq.artemis.api.core.management; -import javax.json.JsonArray; -import javax.json.JsonObject; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonObject; import org.apache.activemq.artemis.api.core.JsonUtil; 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 bbf12aa188..808fb65ab7 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,8 @@ */ package org.apache.activemq.artemis.api.core.management; -import javax.json.JsonArray; -import javax.json.JsonObject; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonObject; import org.apache.activemq.artemis.api.core.JsonUtil; diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/TransformerConfiguration.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/TransformerConfiguration.java index e05bba9909..cc9622c44b 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/TransformerConfiguration.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/TransformerConfiguration.java @@ -18,9 +18,9 @@ package org.apache.activemq.artemis.core.config; import org.apache.activemq.artemis.utils.JsonLoader; -import javax.json.JsonObject; -import javax.json.JsonString; -import javax.json.JsonValue; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonString; +import org.apache.activemq.artemis.json.JsonValue; import java.io.Serializable; import java.io.StringReader; import java.util.HashMap; 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 7757b3ba24..fcaa97450c 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,7 +16,7 @@ */ package org.apache.activemq.artemis.core.security; -import javax.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObject; import java.io.Serializable; import org.apache.activemq.artemis.utils.JsonLoader; diff --git a/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/JsonUtilTest.java b/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/JsonUtilTest.java index ab87cf2304..40ea35a20a 100644 --- a/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/JsonUtilTest.java +++ b/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/JsonUtilTest.java @@ -17,10 +17,10 @@ package org.apache.activemq.artemis.api.core; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObjectBuilder; import org.apache.activemq.artemis.utils.JsonLoader; import org.junit.Assert; diff --git a/artemis-distribution/pom.xml b/artemis-distribution/pom.xml index 1ff3270ce5..08dc65dfe5 100644 --- a/artemis-distribution/pom.xml +++ b/artemis-distribution/pom.xml @@ -304,14 +304,6 @@ netty-transport-native-kqueue ${netty-transport-native-kqueue-classifier} - - jakarta.json - jakarta.json-api - - - org.apache.johnzon - johnzon-core - jakarta.security.auth.message jakarta.security.auth.message-api diff --git a/artemis-distribution/src/main/assembly/dep.xml b/artemis-distribution/src/main/assembly/dep.xml index dc982e6772..342a0cfcd3 100644 --- a/artemis-distribution/src/main/assembly/dep.xml +++ b/artemis-distribution/src/main/assembly/dep.xml @@ -107,8 +107,6 @@ org.apache.commons:commons-lang3 org.fusesource.hawtbuf:hawtbuf org.jgroups:jgroups - jakarta.json:jakarta.json-api - org.apache.johnzon:johnzon-core jakarta.xml.bind:jakarta.xml.bind-api com.sun.xml.bind:jaxb-impl jakarta.activation:jakarta.activation-api diff --git a/artemis-features/src/main/resources/features.xml b/artemis-features/src/main/resources/features.xml index 5de867530f..d5894b1fc3 100644 --- a/artemis-features/src/main/resources/features.xml +++ b/artemis-features/src/main/resources/features.xml @@ -53,9 +53,6 @@ mvn:org.jboss.logging/jboss-logging/${jboss.logging.version} mvn:org.jgroups/jgroups/${jgroups.version} - - mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.json-api-1.1/${servicemix.json-1.1.spec.version} - mvn:org.apache.johnzon/johnzon-core/${johnzon.version} diff --git a/artemis-jakarta-client-all/pom.xml b/artemis-jakarta-client-all/pom.xml index e15d22fa12..4611104aa6 100644 --- a/artemis-jakarta-client-all/pom.xml +++ b/artemis-jakarta-client-all/pom.xml @@ -30,7 +30,6 @@ ${project.basedir}/.. 3.0.0 - 2.0.1 @@ -110,10 +109,6 @@ com.google org.apache.activemq.artemis.shaded.com.google - - org.apache.johnzon - org.apache.activemq.artemis.shaded.org.apache.johnzon - org.apache.commons org.apache.activemq.artemis.shaded.org.apache.commons diff --git a/artemis-jakarta-server/pom.xml b/artemis-jakarta-server/pom.xml index 38b685c1d6..35c12cf95d 100644 --- a/artemis-jakarta-server/pom.xml +++ b/artemis-jakarta-server/pom.xml @@ -32,7 +32,6 @@ 3.0.0 2.0.0 2.0.0 - 2.0.1 @@ -96,11 +95,6 @@ jakarta.transaction-api ${jakarta.transaction-api.version} - - jakarta.json - jakarta.json-api - ${jakarta.json-api.version} - diff --git a/artemis-jms-client-all/pom.xml b/artemis-jms-client-all/pom.xml index 166e66eb75..40299dbb8c 100644 --- a/artemis-jms-client-all/pom.xml +++ b/artemis-jms-client-all/pom.xml @@ -108,10 +108,6 @@ com.google org.apache.activemq.artemis.shaded.com.google - - org.apache.johnzon - org.apache.activemq.artemis.shaded.org.apache.johnzon - org.apache.commons org.apache.activemq.artemis.shaded.org.apache.commons diff --git a/artemis-jms-client-osgi/pom.xml b/artemis-jms-client-osgi/pom.xml index 9b653fc652..e95708fb3e 100644 --- a/artemis-jms-client-osgi/pom.xml +++ b/artemis-jms-client-osgi/pom.xml @@ -107,8 +107,8 @@ *;scope=compile|runtime;groupId=org.apache.activemq + org.glassfish.json*;resolution:=optional, io.netty.buffer;io.netty.*;version="[4.1,5)", - org.apache.johnzon.core, * <_exportcontents>org.apache.activemq.artemis.*;-noimport:=true diff --git a/artemis-jms-server/pom.xml b/artemis-jms-server/pom.xml index 029a69fb78..5d2db1431d 100644 --- a/artemis-jms-server/pom.xml +++ b/artemis-jms-server/pom.xml @@ -90,10 +90,6 @@ jakarta.transaction jakarta.transaction-api - - jakarta.json - jakarta.json-api - diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisClientPlugin.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisClientPlugin.java index 533fc6ba59..97b5fbc8d7 100644 --- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisClientPlugin.java +++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisClientPlugin.java @@ -16,7 +16,10 @@ */ package org.apache.activemq.artemis.maven; +import java.io.File; import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; import java.util.Properties; import org.apache.maven.plugin.MojoExecutionException; @@ -37,6 +40,10 @@ public class ArtemisClientPlugin extends ArtemisAbstractPlugin { @Parameter String[] args; + + @Parameter + String classPath; + @Parameter(defaultValue = "${noClient}") boolean ignore; @@ -50,13 +57,31 @@ public class ArtemisClientPlugin extends ArtemisAbstractPlugin { return ignore; } + + protected ClassLoader defineClassLoader(String classPath) throws Exception { + String[] classPathArray = classPath.split(File.pathSeparator); + URL[] elements = new URL[classPathArray.length]; + for (int i = 0; i < classPathArray.length; i++) { + elements[i] = new File(classPathArray[i]).toPath().toUri().toURL(); + } + return new URLClassLoader(elements); + } + + @Override protected void doExecute() throws MojoExecutionException, MojoFailureException { try { if (systemProperties != null && !systemProperties.isEmpty()) { System.getProperties().putAll(systemProperties); } - Class aClass = Class.forName(clientClass); + + Class aClass; + if (classPath != null) { + ClassLoader loader = defineClassLoader(classPath); + aClass = loader.loadClass(clientClass); + } else { + aClass = Class.forName(clientClass); + } Method method = aClass.getDeclaredMethod("main", new Class[]{String[].class}); method.invoke(null, new Object[]{args}); } catch (Exception e) { diff --git a/artemis-server-osgi/pom.xml b/artemis-server-osgi/pom.xml index 7fb37ce346..c80cb471c8 100644 --- a/artemis-server-osgi/pom.xml +++ b/artemis-server-osgi/pom.xml @@ -146,9 +146,9 @@ *;scope=compile|runtime;groupId=org.apache.activemq + org.glassfish.json*;resolution:=optional, org.postgresql*;resolution:=optional, io.netty.buffer;io.netty.*;version="[4.1,5)", - org.apache.johnzon.core, * <_exportcontents>org.apache.activemq.artemis.*;-noimport:=true diff --git a/artemis-server/pom.xml b/artemis-server/pom.xml index 1cfedd42c9..15918854d0 100644 --- a/artemis-server/pom.xml +++ b/artemis-server/pom.xml @@ -156,10 +156,6 @@ commons-io commons-io - - jakarta.json - jakarta.json-api - junit junit @@ -219,6 +215,21 @@ ${hamcrest.version} test + + + + org.apache.johnzon + johnzon-core + test + + + jakarta.json + jakarta.json-api + test + diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/BridgeConfiguration.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/BridgeConfiguration.java index aaafebd418..da8709c700 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/BridgeConfiguration.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/BridgeConfiguration.java @@ -16,16 +16,17 @@ */ package org.apache.activemq.artemis.core.config; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import javax.json.JsonString; -import javax.json.JsonValue; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonString; +import org.apache.activemq.artemis.json.JsonValue; import java.io.Serializable; import java.io.StringReader; +import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; import org.apache.activemq.artemis.api.core.client.ActiveMQClient; @@ -172,9 +173,11 @@ public final class BridgeConfiguration implements Serializable { setFilterString(value); } else if (key.equals(STATIC_CONNECTORS)) { // convert JSON array to string list - List stringList = JsonLoader.readArray(new StringReader(value)).stream() - .map(v -> ((JsonString) v).getString()) - .collect(Collectors.toList()); + List stringList = new ArrayList<>(); + JsonArray staticConnectors = JsonLoader.readArray(new StringReader(value)); + for (int i = 0; i < staticConnectors.size(); i++) { + stringList.add(staticConnectors.getString(i)); + } setStaticConnectors(stringList); } else if (key.equals(DISCOVERY_GROUP_NAME)) { setDiscoveryGroupName(value); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java index 70f8a2d49e..2e0520fa6a 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java @@ -16,10 +16,10 @@ */ package org.apache.activemq.artemis.core.management.impl; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObjectBuilder; import javax.management.ListenerNotFoundException; import javax.management.MBeanAttributeInfo; import javax.management.MBeanNotificationInfo; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java index b2f520979e..ac45a3059b 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java @@ -16,7 +16,7 @@ */ package org.apache.activemq.artemis.core.management.impl; -import javax.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonArrayBuilder; import javax.management.MBeanAttributeInfo; import javax.management.MBeanOperationInfo; import java.text.SimpleDateFormat; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/BrokerBalancerControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/BrokerBalancerControlImpl.java index 72963bb0c4..298c95639a 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/BrokerBalancerControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/BrokerBalancerControlImpl.java @@ -24,7 +24,7 @@ import org.apache.activemq.artemis.core.server.balancing.BrokerBalancer; import org.apache.activemq.artemis.core.server.balancing.targets.Target; import org.apache.activemq.artemis.utils.JsonLoader; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonObjectBuilder; import javax.management.MBeanAttributeInfo; import javax.management.MBeanOperationInfo; import javax.management.NotCompliantMBeanException; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java index fe19ff76f0..4b4550da17 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java @@ -16,9 +16,9 @@ */ package org.apache.activemq.artemis.core.management.impl; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonObjectBuilder; import javax.management.MBeanAttributeInfo; import javax.management.MBeanOperationInfo; import javax.management.openmbean.CompositeData; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ActiveMQAbstractView.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ActiveMQAbstractView.java index 265fb4215e..9522a28654 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ActiveMQAbstractView.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ActiveMQAbstractView.java @@ -16,9 +16,9 @@ */ package org.apache.activemq.artemis.core.management.impl.view; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObjectBuilder; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/AddressView.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/AddressView.java index 2594f206bf..0964de5457 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/AddressView.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/AddressView.java @@ -16,7 +16,7 @@ */ package org.apache.activemq.artemis.core.management.impl.view; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonObjectBuilder; import org.apache.activemq.artemis.core.management.impl.view.predicate.AddressFilterPredicate; import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.impl.AddressInfo; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java index 18b8d3058f..6f38df3922 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java @@ -16,7 +16,7 @@ */ package org.apache.activemq.artemis.core.management.impl.view; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonObjectBuilder; import java.util.Date; import java.util.List; import java.util.Set; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConsumerView.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConsumerView.java index 17919cada0..0c8c50c06f 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConsumerView.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConsumerView.java @@ -16,7 +16,7 @@ */ package org.apache.activemq.artemis.core.management.impl.view; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonObjectBuilder; import java.util.Date; import org.apache.activemq.artemis.api.core.client.ClientSession; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ProducerView.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ProducerView.java index fb4a6d6ddf..30f2b680a7 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ProducerView.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ProducerView.java @@ -16,7 +16,7 @@ */ package org.apache.activemq.artemis.core.management.impl.view; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonObjectBuilder; import org.apache.activemq.artemis.api.core.client.ClientSession; import org.apache.activemq.artemis.core.management.impl.view.predicate.ProducerFilterPredicate; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/QueueView.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/QueueView.java index e38831a60b..cf5f303b55 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/QueueView.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/QueueView.java @@ -16,7 +16,7 @@ */ package org.apache.activemq.artemis.core.management.impl.view; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonObjectBuilder; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.management.QueueControl; import org.apache.activemq.artemis.core.management.impl.view.predicate.QueueFilterPredicate; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/SessionView.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/SessionView.java index f1ece695c4..279e24f13f 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/SessionView.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/SessionView.java @@ -16,7 +16,7 @@ */ package org.apache.activemq.artemis.core.management.impl.view; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonObjectBuilder; import java.util.Date; import org.apache.activemq.artemis.core.management.impl.view.predicate.SessionFilterPredicate; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/MessageCounter.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/MessageCounter.java index 8e0b6f4b85..24399618ae 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/MessageCounter.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/MessageCounter.java @@ -24,10 +24,9 @@ import java.util.GregorianCalendar; import java.util.List; import org.apache.activemq.artemis.core.server.Queue; +import org.apache.activemq.artemis.json.JsonValue; import org.apache.activemq.artemis.utils.JsonLoader; -import static org.apache.activemq.artemis.api.core.JsonUtil.nullSafe; - /** * This class stores message count informations for a given queue * @@ -336,8 +335,8 @@ public class MessageCounter { String updateTimestamp = dateFormat.format(new Date(this.getLastUpdate())); return JsonLoader .createObjectBuilder() - .add("destinationName", nullSafe(this.getDestinationName())) - .add("destinationSubscription", nullSafe(this.getDestinationSubscription())) + .add("destinationName", this.getDestinationName(), JsonValue.NULL) + .add("destinationSubscription", this.getDestinationSubscription(), JsonValue.NULL) .add("destinationDurable", this.isDestinationDurable()) .add("count", this.getCount()) .add("countDelta", this.getCountDelta()) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServerSession.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServerSession.java index 9be941200f..eff638f1e0 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServerSession.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServerSession.java @@ -16,7 +16,7 @@ */ package org.apache.activemq.artemis.core.server; -import javax.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonArrayBuilder; import javax.transaction.xa.Xid; import java.util.EnumSet; import java.util.List; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java index 0da2946592..1c3cd0c267 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java @@ -16,13 +16,13 @@ */ package org.apache.activemq.artemis.core.server.impl; -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 org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonNumber; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonString; +import org.apache.activemq.artemis.json.JsonValue; import java.io.StringReader; import java.util.EnumSet; import java.util.Map; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java index e80f91cc60..e36e54a861 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java @@ -16,8 +16,8 @@ */ package org.apache.activemq.artemis.core.server.impl; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonObjectBuilder; import java.security.cert.X509Certificate; import javax.transaction.xa.XAException; import javax.transaction.xa.Xid; @@ -91,6 +91,7 @@ import org.apache.activemq.artemis.core.transaction.Transaction.State; import org.apache.activemq.artemis.core.transaction.TransactionOperationAbstract; import org.apache.activemq.artemis.core.transaction.TransactionPropertyIndexes; import org.apache.activemq.artemis.core.transaction.impl.TransactionImpl; +import org.apache.activemq.artemis.json.JsonValue; import org.apache.activemq.artemis.logs.AuditLogger; import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection; import org.apache.activemq.artemis.spi.core.protocol.SessionCallback; @@ -102,8 +103,6 @@ import org.apache.activemq.artemis.utils.collections.MaxSizeMap; import org.apache.activemq.artemis.utils.collections.TypedProperties; import org.jboss.logging.Logger; -import static org.apache.activemq.artemis.api.core.JsonUtil.nullSafe; - /** * Server side Session implementation */ @@ -1964,7 +1963,7 @@ public class ServerSessionImpl implements ServerSession, FailureListener { if (entry.getValue().getA() != null) { uuid = entry.getValue().getA().toString(); } - JsonObjectBuilder producerInfo = JsonLoader.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()); + JsonObjectBuilder producerInfo = JsonLoader.createObjectBuilder().add("connectionID", this.getConnectionID().toString()).add("sessionID", this.getName()).add("destination", entry.getKey().toString()).add("lastUUIDSent", uuid, JsonValue.NULL).add("msgSent", entry.getValue().getB().longValue()); array.add(producerInfo); } } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/TransactionDetail.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/TransactionDetail.java index 800aec3a88..255b0414b1 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/TransactionDetail.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/TransactionDetail.java @@ -16,9 +16,9 @@ */ package org.apache.activemq.artemis.core.transaction; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonArrayBuilder; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObjectBuilder; import javax.transaction.xa.Xid; import java.text.DateFormat; import java.util.Date; diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/BridgeConfigurationTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/BridgeConfigurationTest.java index 85ed6b9378..65f9b9930d 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/BridgeConfigurationTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/BridgeConfigurationTest.java @@ -21,10 +21,9 @@ import org.apache.activemq.artemis.utils.JsonLoader; import org.junit.Assert; import org.junit.Test; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import javax.json.JsonValue; -import javax.json.spi.JsonProvider; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonObjectBuilder; +import org.apache.activemq.artemis.json.JsonValue; import java.io.StringReader; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -162,7 +161,7 @@ public class BridgeConfigurationTest { objectBuilder.add(BridgeConfiguration.FORWARDING_ADDRESS, "forwarding-address"); objectBuilder.add(BridgeConfiguration.FILTER_STRING, "filter-string"); objectBuilder.add(BridgeConfiguration.STATIC_CONNECTORS, - JsonProvider.provider().createArrayBuilder() + JsonLoader.createArrayBuilder() .add("connector1") .add("connector2")); objectBuilder.add(BridgeConfiguration.DISCOVERY_GROUP_NAME, "dg"); diff --git a/examples/features/standard/pom.xml b/examples/features/standard/pom.xml index f29decdac1..37b95abffc 100644 --- a/examples/features/standard/pom.xml +++ b/examples/features/standard/pom.xml @@ -160,6 +160,7 @@ under the License. pre-acknowledge producer-rate-limit queue + queue-jakarta queue-requestor queue-selector reattach-node diff --git a/examples/features/standard/queue-jakarta/pom.xml b/examples/features/standard/queue-jakarta/pom.xml index 9de424350a..a9ba4159c1 100644 --- a/examples/features/standard/queue-jakarta/pom.xml +++ b/examples/features/standard/queue-jakarta/pom.xml @@ -49,6 +49,20 @@ under the License. org.apache.activemq artemis-maven-plugin + + snapshot-check + compile + + dependency-scan + + + + org.apache.activemq:artemis-jakarta-client-all:${project.version} + org.apache.activemq.examples.broker:queue-jakarta:${project.version} + + ARTEMIS-JAKARTA + + create @@ -79,6 +93,7 @@ under the License. org.apache.activemq.artemis.jms.example.QueueExample + ${ARTEMIS-JAKARTA} diff --git a/examples/features/standard/queue-jakarta/src/main/java/org/apache/activemq/artemis/jms/example/QueueExample.java b/examples/features/standard/queue-jakarta/src/main/java/org/apache/activemq/artemis/jms/example/QueueExample.java index d85c5ede8d..9ffed0832c 100644 --- a/examples/features/standard/queue-jakarta/src/main/java/org/apache/activemq/artemis/jms/example/QueueExample.java +++ b/examples/features/standard/queue-jakarta/src/main/java/org/apache/activemq/artemis/jms/example/QueueExample.java @@ -23,7 +23,7 @@ import jakarta.jms.MessageProducer; import jakarta.jms.Queue; import jakarta.jms.Session; import jakarta.jms.TextMessage; -import javax.naming.InitialContext; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * A simple JMS Queue example that creates a producer and consumer on a queue and sends then receives a message. @@ -31,39 +31,28 @@ import javax.naming.InitialContext; public class QueueExample { public static void main(final String[] args) throws Exception { + Connection connection = null; - InitialContext initialContext = null; try { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); - // Step 2. Perform a lookup on the queue - Queue queue = (Queue) initialContext.lookup("queue/exampleQueue"); + ConnectionFactory cf = new ActiveMQConnectionFactory(); - // Step 3. Perform a lookup on the Connection Factory - ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory"); - - // Step 4.Create a JMS Connection connection = cf.createConnection(); - // Step 5. Create a JMS Session Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 6. Create a JMS Message Producer + Queue queue = session.createQueue("exampleQueue"); + MessageProducer producer = session.createProducer(queue); - // Step 7. Create a Text Message TextMessage message = session.createTextMessage("This is a text message"); System.out.println("Sent message: " + message.getText()); - // Step 8. Send the Message producer.send(message); - // Step 9. Create a JMS Message Consumer MessageConsumer messageConsumer = session.createConsumer(queue); - // Step 10. Start the Connection connection.start(); // Step 11. Receive the message @@ -71,10 +60,6 @@ public class QueueExample { System.out.println("Received message: " + messageReceived.getText()); } finally { - // Step 12. Be sure to close our JMS resources! - if (initialContext != null) { - initialContext.close(); - } if (connection != null) { connection.close(); } diff --git a/examples/features/standard/queue-jakarta/src/main/resources/jndi.properties b/examples/features/standard/queue-jakarta/src/main/resources/jndi.properties deleted file mode 100644 index 93537c415a..0000000000 --- a/examples/features/standard/queue-jakarta/src/main/resources/jndi.properties +++ /dev/null @@ -1,20 +0,0 @@ -# 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. - -java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory -connectionFactory.ConnectionFactory=tcp://localhost:61616 -queue.queue/exampleQueue=exampleQueue diff --git a/pom.xml b/pom.xml index bfc05e86a6..fa6438a4d4 100644 --- a/pom.xml +++ b/pom.xml @@ -105,6 +105,7 @@ 2.9.0 3.0.0-M3 5.1.2 + 3.2.4 3.1.1 1.39.0 8.43 @@ -480,12 +481,6 @@ ${jakarta.transaction-api.version} - - jakarta.json - jakarta.json-api - ${jakarta.json-api.version} - - jakarta.ejb jakarta.ejb-api @@ -689,13 +684,6 @@ ${slf4j.version} - - - org.apache.johnzon - johnzon-core - ${johnzon.version} - - org.jboss.resteasy @@ -930,6 +918,29 @@ zookeeper-jute ${zookeeper.version} + + + + + + org.apache.johnzon + johnzon-core + ${johnzon.version} + test + + + jakarta.json + jakarta.json-api + ${jakarta.json-api.version} + test + + @@ -1441,7 +1452,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.0 + ${maven.shade.plugin.version} org.eclipse.jetty diff --git a/tests/compatibility-tests/pom.xml b/tests/compatibility-tests/pom.xml index c98fd106f2..611656e816 100644 --- a/tests/compatibility-tests/pom.xml +++ b/tests/compatibility-tests/pom.xml @@ -208,11 +208,6 @@ org.fusesource.mqtt-client mqtt-client - - jakarta.json - jakarta.json-api - test - jakarta.resource jakarta.resource-api @@ -229,11 +224,6 @@ jakarta.management.j2ee jakarta.management.j2ee-api - - org.apache.johnzon - johnzon-core - test - io.netty netty-buffer @@ -300,6 +290,21 @@ jboss-marshalling-river 2.0.9.Final + + + + org.apache.johnzon + johnzon-core + test + + + jakarta.json + jakarta.json-api + test + diff --git a/tests/extra-tests/src/test/java/org/apache/activemq/artemis/tests/extras/byteman/ActiveMQServerControlMultiThreadTest.java b/tests/extra-tests/src/test/java/org/apache/activemq/artemis/tests/extras/byteman/ActiveMQServerControlMultiThreadTest.java index 081ab88b0f..1767630b2c 100644 --- a/tests/extra-tests/src/test/java/org/apache/activemq/artemis/tests/extras/byteman/ActiveMQServerControlMultiThreadTest.java +++ b/tests/extra-tests/src/test/java/org/apache/activemq/artemis/tests/extras/byteman/ActiveMQServerControlMultiThreadTest.java @@ -17,8 +17,8 @@ package org.apache.activemq.artemis.tests.extras.byteman; -import javax.json.JsonArray; -import javax.json.JsonObject; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonObject; import java.util.HashMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; diff --git a/tests/integration-tests/pom.xml b/tests/integration-tests/pom.xml index 03f13c04cf..1f373742d7 100644 --- a/tests/integration-tests/pom.xml +++ b/tests/integration-tests/pom.xml @@ -213,11 +213,6 @@ org.eclipse.paho org.eclipse.paho.client.mqttv3 - - jakarta.json - jakarta.json-api - test - jakarta.resource jakarta.resource-api @@ -234,11 +229,6 @@ jakarta.management.j2ee jakarta.management.j2ee-api - - org.apache.johnzon - johnzon-core - test - io.netty netty-buffer @@ -463,6 +453,22 @@ + + + + org.apache.johnzon + johnzon-core + test + + + jakarta.json + jakarta.json-api + test + + diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMXManagementTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMXManagementTest.java index f32153a4c2..42b94c5ae6 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMXManagementTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMXManagementTest.java @@ -40,8 +40,8 @@ import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; -import javax.json.JsonArray; -import javax.json.JsonObject; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonObject; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.util.Map; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/karaf/ArtemisFeatureTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/karaf/ArtemisFeatureTest.java index dfffee1cbc..e67a82888e 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/karaf/ArtemisFeatureTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/karaf/ArtemisFeatureTest.java @@ -26,9 +26,7 @@ import javax.jms.QueueBrowser; import javax.jms.QueueRequestor; import javax.jms.QueueSession; import javax.jms.TextMessage; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonString; +import org.apache.activemq.artemis.json.JsonArray; import javax.security.auth.Subject; import java.io.ByteArrayOutputStream; import java.io.File; @@ -38,13 +36,13 @@ import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Arrays; import java.util.Enumeration; -import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; +import org.apache.activemq.artemis.utils.JsonLoader; import org.apache.karaf.jaas.boot.principal.RolePrincipal; import org.apache.karaf.jaas.boot.principal.UserPrincipal; import org.apache.karaf.shell.api.console.Session; @@ -183,8 +181,8 @@ public class ArtemisFeatureTest extends Assert { m.setText("[\"ANYCAST\"]"); Message reply = requestor.request(m); String json = ((TextMessage) reply).getText(); - JsonArray array = Json.createReader(new StringReader(json)).readArray(); - List queues = (List) array.get(0); + JsonArray array = JsonLoader.readArray(new StringReader(json)); + JsonArray queues = array.getJsonArray(0); assertNotNull(queues); assertFalse(queues.isEmpty()); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java index c4e3c269f6..8cda6ccf36 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java @@ -22,8 +22,8 @@ import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; -import javax.json.JsonArray; -import javax.json.JsonObject; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonObject; import javax.transaction.xa.XAResource; import javax.transaction.xa.Xid; import java.nio.ByteBuffer; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java index 55c0f4dc60..73b39e15a8 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java @@ -22,8 +22,8 @@ import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; -import javax.json.JsonArray; -import javax.json.JsonString; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonString; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.EnumSet; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/BroadcastGroupControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/BroadcastGroupControlTest.java index bf447c740d..93a141eab3 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/BroadcastGroupControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/BroadcastGroupControlTest.java @@ -16,7 +16,7 @@ */ package org.apache.activemq.artemis.tests.integration.management; -import javax.json.JsonArray; +import org.apache.activemq.artemis.json.JsonArray; import java.util.ArrayList; import java.util.List; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/BrokerBalancerControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/BrokerBalancerControlTest.java index 08716ca0c5..005de61a05 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/BrokerBalancerControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/BrokerBalancerControlTest.java @@ -28,8 +28,8 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import javax.json.JsonObject; -import javax.json.JsonValue; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonValue; import javax.management.MBeanServer; import javax.management.MBeanServerFactory; import javax.management.openmbean.CompositeData; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ClusterConnectionControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ClusterConnectionControlTest.java index 092bce2b83..70d725b196 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ClusterConnectionControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ClusterConnectionControlTest.java @@ -16,7 +16,7 @@ */ package org.apache.activemq.artemis.tests.integration.management; -import javax.json.JsonArray; +import org.apache.activemq.artemis.json.JsonArray; import javax.management.MBeanServer; import javax.management.MBeanServerFactory; import java.util.ArrayList; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/JGroupsChannelBroadcastGroupControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/JGroupsChannelBroadcastGroupControlTest.java index bef5b7cdd5..13878bd145 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/JGroupsChannelBroadcastGroupControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/JGroupsChannelBroadcastGroupControlTest.java @@ -35,7 +35,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import javax.json.JsonArray; +import org.apache.activemq.artemis.json.JsonArray; import java.util.ArrayList; import java.util.List; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/JGroupsFileBroadcastGroupControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/JGroupsFileBroadcastGroupControlTest.java index ca8646e053..4710bc09bc 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/JGroupsFileBroadcastGroupControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/JGroupsFileBroadcastGroupControlTest.java @@ -29,7 +29,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import javax.json.JsonArray; +import org.apache.activemq.artemis.json.JsonArray; import java.util.ArrayList; import java.util.List; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementWithPagingServerTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementWithPagingServerTest.java index 3b79b13604..47164caee6 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementWithPagingServerTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementWithPagingServerTest.java @@ -16,9 +16,10 @@ */ package org.apache.activemq.artemis.tests.integration.management; -import javax.json.JsonArray; -import javax.json.JsonObject; -import javax.json.JsonValue; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonNumber; +import org.apache.activemq.artemis.json.JsonObject; +import org.apache.activemq.artemis.json.JsonValue; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; @@ -40,7 +41,6 @@ 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.johnzon.core.JsonLongImpl; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -88,7 +88,7 @@ public class ManagementWithPagingServerTest extends ManagementTestBase { List longs = new ArrayList<>(); for (JsonValue jsonValue : array) { JsonValue val = ((JsonObject) jsonValue).get("messageID"); - Long l = ((JsonLongImpl) val).longValue(); + Long l = ((JsonNumber) val).longValue(); longs.add(l); } assertEquals(num, array.size()); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlTest.java index 4b2a58f8db..7d4804c89d 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlTest.java @@ -22,8 +22,8 @@ import javax.jms.DeliveryMode; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; -import javax.json.JsonArray; -import javax.json.JsonObject; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonObject; import javax.management.Notification; import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeDataSupport; diff --git a/tests/joram-tests/pom.xml b/tests/joram-tests/pom.xml index e29af9af41..3b4386fc62 100644 --- a/tests/joram-tests/pom.xml +++ b/tests/joram-tests/pom.xml @@ -107,6 +107,20 @@ error_prone_core + + + org.apache.johnzon + johnzon-core + test + + + jakarta.json + jakarta.json-api + test + diff --git a/tests/smoke-tests/pom.xml b/tests/smoke-tests/pom.xml index 7de98a7b44..6552742ca0 100644 --- a/tests/smoke-tests/pom.xml +++ b/tests/smoke-tests/pom.xml @@ -202,6 +202,21 @@ zookeeper-jute test + + + + org.apache.johnzon + johnzon-core + test + + + jakarta.json + jakarta.json-api + test + diff --git a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jmx2/JmxServerControlTest.java b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jmx2/JmxServerControlTest.java index a7802e7ea5..ad16adb53b 100644 --- a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jmx2/JmxServerControlTest.java +++ b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jmx2/JmxServerControlTest.java @@ -19,8 +19,8 @@ package org.apache.activemq.artemis.tests.smoke.jmx2; import javax.jms.MessageConsumer; import javax.jms.Session; -import javax.json.JsonArray; -import javax.json.JsonObject; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonObject; import javax.management.MBeanServerConnection; import javax.management.MBeanServerInvocationHandler; import javax.management.remote.JMXConnector; diff --git a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jmxmultiplefailback/ReplicatedMultipleFailbackTest.java b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jmxmultiplefailback/ReplicatedMultipleFailbackTest.java index 95a2346b33..7bfe660f87 100644 --- a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jmxmultiplefailback/ReplicatedMultipleFailbackTest.java +++ b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/jmxmultiplefailback/ReplicatedMultipleFailbackTest.java @@ -17,10 +17,8 @@ package org.apache.activemq.artemis.tests.smoke.jmxmultiplefailback; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonObject; -import javax.json.JsonReader; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonObject; import javax.management.MBeanServerInvocationHandler; import javax.management.ObjectName; import javax.management.remote.JMXConnector; @@ -44,6 +42,7 @@ import org.apache.activemq.artemis.api.core.Pair; import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl; import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder; import org.apache.activemq.artemis.tests.smoke.common.SmokeTestBase; +import org.apache.activemq.artemis.utils.JsonLoader; import org.apache.activemq.artemis.utils.Wait; import org.jboss.logging.Logger; import org.junit.Assert; @@ -92,23 +91,21 @@ public class ReplicatedMultipleFailbackTest extends SmokeTestBase { if (networkTopologyJson == null || networkTopologyJson.isEmpty()) { return Collections.emptyMap(); } - try (JsonReader jsonReader = Json.createReader(new StringReader(networkTopologyJson))) { - final JsonArray nodeIDs = jsonReader.readArray(); - final int nodeCount = nodeIDs.size(); - Map> networkTopology = new HashMap<>(nodeCount); - for (int i = 0; i < nodeCount; i++) { - final JsonObject nodePair = nodeIDs.getJsonObject(i); - try { - final String nodeID = nodePair.getString("nodeID"); - final String live = nodePair.getString("live"); - final String backup = nodePair.getString("backup", null); - networkTopology.put(nodeID, new Pair<>(live, backup)); - } catch (Exception e) { - LOGGER.warnf(e, "Error on %s", nodePair); - } + final JsonArray nodeIDs = JsonLoader.readArray(new StringReader(networkTopologyJson)); + final int nodeCount = nodeIDs.size(); + Map> networkTopology = new HashMap<>(nodeCount); + for (int i = 0; i < nodeCount; i++) { + final JsonObject nodePair = nodeIDs.getJsonObject(i); + try { + final String nodeID = nodePair.getString("nodeID"); + final String live = nodePair.getString("live"); + final String backup = nodePair.getString("backup", null); + networkTopology.put(nodeID, new Pair<>(live, backup)); + } catch (Exception e) { + LOGGER.warnf(e, "Error on %s", nodePair); } - return networkTopology; } + return networkTopology; } private static long countMembers(Map> networkTopology) { diff --git a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/utils/Jmx.java b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/utils/Jmx.java index 5c5f044382..b36b029e5a 100644 --- a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/utils/Jmx.java +++ b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/utils/Jmx.java @@ -16,10 +16,8 @@ */ package org.apache.activemq.artemis.tests.smoke.utils; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonObject; -import javax.json.JsonReader; +import org.apache.activemq.artemis.json.JsonArray; +import org.apache.activemq.artemis.json.JsonObject; import javax.management.MBeanServerInvocationHandler; import javax.management.ObjectName; import javax.management.remote.JMXConnector; @@ -38,6 +36,7 @@ import java.util.stream.Stream; import org.apache.activemq.artemis.api.core.Pair; import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl; import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder; +import org.apache.activemq.artemis.utils.JsonLoader; import org.jboss.logging.Logger; public class Jmx { @@ -96,23 +95,21 @@ public class Jmx { if (networkTopologyJson == null || networkTopologyJson.isEmpty()) { return Collections.emptyMap(); } - try (JsonReader jsonReader = Json.createReader(new StringReader(networkTopologyJson))) { - final JsonArray nodeIDs = jsonReader.readArray(); - final int nodeCount = nodeIDs.size(); - Map> networkTopology = new HashMap<>(nodeCount); - for (int i = 0; i < nodeCount; i++) { - final JsonObject nodePair = nodeIDs.getJsonObject(i); - try { - final String nodeID = nodePair.getString("nodeID"); - final String live = nodePair.getString("live"); - final String backup = nodePair.getString("backup", null); - networkTopology.put(nodeID, new Pair<>(live, backup)); - } catch (Exception e) { - LOGGER.warnf(e, "Error on %s", nodePair); - } + final JsonArray nodeIDs = JsonLoader.readArray(new StringReader(networkTopologyJson)); + final int nodeCount = nodeIDs.size(); + Map> networkTopology = new HashMap<>(nodeCount); + for (int i = 0; i < nodeCount; i++) { + final JsonObject nodePair = nodeIDs.getJsonObject(i); + try { + final String nodeID = nodePair.getString("nodeID"); + final String live = nodePair.getString("live"); + final String backup = nodePair.getString("backup", null); + networkTopology.put(nodeID, new Pair<>(live, backup)); + } catch (Exception e) { + LOGGER.warnf(e, "Error on %s", nodePair); } - return networkTopology; } + return networkTopology; } private static long countMembers(Map> networkTopology) {