ARTEMIS-3546 Jakarta javax.json incompability on jakarta all client

Domenico Bruscino provided the JSON Wrapper used here. Thanks Domenico!
This commit is contained in:
Clebert Suconic 2021-11-10 16:31:19 -05:00
parent 8d50aa916c
commit bfc10dcf8b
87 changed files with 2113 additions and 325 deletions

View File

@ -77,14 +77,6 @@
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.jms</groupId>
<artifactId>jakarta.jms-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
</dependency>
<!-- artemis producer and consumer can use amqp as the protocol -->
<dependency>
<groupId>org.apache.qpid</groupId>
@ -162,6 +154,21 @@
<scope>test</scope>
<type>test-jar</type>
</dependency>
<!-- The johnzon-core and json-api contents are repackaged in -commons,
However maven can still need them during tests, which run against
the original -commons classes when built+run in the same reactor,
and not the jar containing the shaded bits. -->
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -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;

View File

@ -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++) {

View File

@ -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;

View File

@ -32,6 +32,25 @@
</properties>
<dependencies>
<!-- Johnzon and JSON is meant to be referenced only here on this package (commons)
and we should not leak any dependencies to JSON or Johnzon in any of our packages.
Any other references would be meant for tests. -->
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<scope>compile</scope>
<optional>true</optional>
<!-- License: EPL 2.0 -->
</dependency>
<!-- ^^ these dependencies are shaded on this JAR -->
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
@ -53,6 +72,7 @@
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wildfly.common</groupId>
@ -80,10 +100,6 @@
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@ -111,6 +127,45 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/**/*</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>javax.json</pattern>
<shadedPattern>org.apache.activemq.artemis.commons.shaded.json</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.johnzon</pattern>
<shadedPattern>org.apache.activemq.artemis.commons.shaded.johnzon</shadedPattern>
</relocation>
</relocations>
<artifactSet>
<includes>
<include>org.apache.johnzon:johnzon-core</include>
<include>jakarta.json:jakarta.json-api</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@ -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;

View File

@ -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.
* <pre>
* [1,5,8]
* </pre>
* or
* <pre>
* [
* {"name":"karl", "age": 38},
* {"name":"sue", "age": 42},
* ]
* </pre>
*
*
*/
public interface JsonArray extends JsonValue, List<JsonValue> {
/**
* @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
*/
<T extends JsonValue> List<T> getValuesAs(Class<T> 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.
* <p>This method can be used to obtain a list of the unwrapped types, such as
* <pre>{@code
* List<String> strings = ary1.getValuesAs(JsonString::getString);
* List<Integer> ints = ary2.getValuesAs(JsonNumber::intValue);
* } </pre>
* It can also be used to obtain a list of simple projections, such as
* <pre> {@code
* Lsit<Integer> stringsizes = arr.getValueAs((JsonString v) -> v.getString().length();
* } </pre>
* @param <K> The element type (must be a subtype of JsonValue) of this JsonArray.
* @param <T> 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 <T, K extends JsonValue> List<T> getValuesAs(Function<K, T> func) {
Stream<K> stream = (Stream<K>) 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);
}

View File

@ -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();
}
}

View File

@ -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 <a href="https://tools.ietf.org/html/rfc4627">RFC-4627 JSON Specification</a>
*/
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();
}

View File

@ -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.
* <pre>
* {
* "name":"karl",
* "age":38,
* "address": {
* "street":"dummystreet"
* "housenumber":12
* }
* }
* </pre>
*
* A JsonObject is always also a Map which uses the attribute names as key mapping
* to their JsonValues.
*/
public interface JsonObject extends JsonValue, Map<String, JsonValue> {
/**
* @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);
}

View File

@ -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();
}
}

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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());
}
}

View File

@ -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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 <T extends JsonValue> List<T> getValuesAs(Class<T> 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<JsonValue> iterator() {
return new Iterator<JsonValue>() {
private Iterator<javax.json.JsonValue> 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> 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<? extends JsonValue> c) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(int index, Collection<? extends JsonValue> 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<JsonValue> listIterator() {
throw new UnsupportedOperationException();
}
@Override
public ListIterator<JsonValue> listIterator(int index) {
throw new UnsupportedOperationException();
}
@Override
public List<JsonValue> subList(int fromIndex, int toIndex) {
throw new UnsupportedOperationException();
}
}

View File

@ -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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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();
}
}

View File

@ -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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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());
}
}

View File

@ -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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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<? extends String, ? extends JsonValue> m) {
throw new UnsupportedOperationException();
}
@Override
public void clear() {
rawObject.clear();
}
@Override
public Set<String> keySet() {
return rawObject.keySet();
}
@Override
public Collection<JsonValue> values() {
return new AbstractCollection<JsonValue>() {
@Override
public Iterator<JsonValue> iterator() {
return new Iterator<JsonValue>() {
private Iterator<javax.json.JsonValue> 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<Map.Entry<String, JsonValue>> entrySet() {
return new AbstractSet<Map.Entry<String, JsonValue>>() {
@Override
public Iterator<Map.Entry<String, JsonValue>> iterator() {
return new Iterator<Map.Entry<String, JsonValue>>() {
private Iterator<Map.Entry<String, javax.json.JsonValue>> rawIterator = rawObject.entrySet().iterator();
@Override
public boolean hasNext() {
return rawIterator.hasNext();
}
@Override
public Map.Entry<String, JsonValue> next() {
Map.Entry<String, javax.json.JsonValue> rawEntry = rawIterator.next();
return rawEntry != null ? new AbstractMap.SimpleEntry<>(rawEntry.getKey(), wrap(rawEntry.getValue())) : null;
}
};
}
@Override
public int size() {
return rawObject.size();
}
};
}
}

View File

@ -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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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();
}
}

View File

@ -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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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<javax.json.JsonValue, JsonValue> 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();
}
}

View File

@ -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<JsonProvider>() {
@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());
}
}

View File

@ -98,8 +98,8 @@
<instructions>
<Embed-Dependency>*;scope=compile|runtime;groupId=org.apache.activemq</Embed-Dependency>
<Import-Package>
org.glassfish.json*;resolution:=optional,
io.netty.buffer;io.netty.*;version="[4.1,5)",
org.apache.johnzon.core,
*
</Import-Package>
<_exportcontents>org.apache.activemq.artemis.*;-noimport:=true</_exportcontents>

View File

@ -86,14 +86,6 @@
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
@ -136,6 +128,21 @@
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
</dependency>
<!-- The johnzon-core and json-api contents are repackaged in -commons,
However maven can still need them during tests, which run against
the original -commons classes when built+run in the same reactor,
and not the jar containing the shaded bits. -->
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
@ -152,7 +159,7 @@
<maxmemory>512m</maxmemory>
<quiet>false</quiet>
<aggregate>true</aggregate>
<excludePackageNames>org.apache.activemq.artemis.core:org.apache.activemq.artemis.utils
<excludePackageNames>org.apache.activemq.artemis.core:org.apache.activemq.artemis.utils,org.apache.activemq.artemis.commons
</excludePackageNames>
</configuration>
<executions>

View File

@ -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<String, String> readJsonProperties(String jsonString) {
Map<String, String> properties = new HashMap<>();
if (jsonString != null) {
JsonUtil.readJsonObject(jsonString).forEach((k, v) -> properties.put(k, v.toString()));
JsonUtil.readJsonObject(jsonString).entrySet().forEach(e -> properties.put(e.getKey(), e.getValue().toString()));
}
return properties;
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -304,14 +304,6 @@
<artifactId>netty-transport-native-kqueue</artifactId>
<classifier>${netty-transport-native-kqueue-classifier}</classifier>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
</dependency>
<dependency>
<groupId>jakarta.security.auth.message</groupId>
<artifactId>jakarta.security.auth.message-api</artifactId>

View File

@ -107,8 +107,6 @@
<include>org.apache.commons:commons-lang3</include>
<include>org.fusesource.hawtbuf:hawtbuf</include>
<include>org.jgroups:jgroups</include>
<include>jakarta.json:jakarta.json-api</include>
<include>org.apache.johnzon:johnzon-core</include>
<include>jakarta.xml.bind:jakarta.xml.bind-api</include>
<include>com.sun.xml.bind:jaxb-impl</include>
<include>jakarta.activation:jakarta.activation-api</include>

View File

@ -53,9 +53,6 @@
<bundle dependency="true">mvn:org.jboss.logging/jboss-logging/${jboss.logging.version}</bundle>
<bundle dependency="true">mvn:org.jgroups/jgroups/${jgroups.version}</bundle>
<bundle dependency="true">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.json-api-1.1/${servicemix.json-1.1.spec.version}</bundle>
<bundle>mvn:org.apache.johnzon/johnzon-core/${johnzon.version}</bundle>
</feature>
<feature name="artemis-core" version="${pom.version}" description="ActiveMQ Artemis broker libraries">

View File

@ -30,7 +30,6 @@
<properties>
<activemq.basedir>${project.basedir}/..</activemq.basedir>
<jakarta.jms-api.version>3.0.0</jakarta.jms-api.version>
<jakarta.json-api.version>2.0.1</jakarta.json-api.version>
</properties>
<dependencies>
@ -110,10 +109,6 @@
<pattern>com.google</pattern>
<shadedPattern>org.apache.activemq.artemis.shaded.com.google</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.johnzon</pattern>
<shadedPattern>org.apache.activemq.artemis.shaded.org.apache.johnzon</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons</pattern>
<shadedPattern>org.apache.activemq.artemis.shaded.org.apache.commons</shadedPattern>

View File

@ -32,7 +32,6 @@
<jakarta.jms-api.version>3.0.0</jakarta.jms-api.version>
<jakarta.transaction-api.version>2.0.0</jakarta.transaction-api.version>
<jakarta.resource-api.version>2.0.0</jakarta.resource-api.version>
<jakarta.json-api.version>2.0.1</jakarta.json-api.version>
</properties>
<dependencies>
@ -96,11 +95,6 @@
<artifactId>jakarta.transaction-api</artifactId>
<version>${jakarta.transaction-api.version}</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>${jakarta.json-api.version}</version>
</dependency>
</dependencies>
<build>

View File

@ -108,10 +108,6 @@
<pattern>com.google</pattern>
<shadedPattern>org.apache.activemq.artemis.shaded.com.google</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.johnzon</pattern>
<shadedPattern>org.apache.activemq.artemis.shaded.org.apache.johnzon</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons</pattern>
<shadedPattern>org.apache.activemq.artemis.shaded.org.apache.commons</shadedPattern>

View File

@ -107,8 +107,8 @@
<instructions>
<Embed-Dependency>*;scope=compile|runtime;groupId=org.apache.activemq</Embed-Dependency>
<Import-Package>
org.glassfish.json*;resolution:=optional,
io.netty.buffer;io.netty.*;version="[4.1,5)",
org.apache.johnzon.core,
*
</Import-Package>
<_exportcontents>org.apache.activemq.artemis.*;-noimport:=true</_exportcontents>

View File

@ -90,10 +90,6 @@
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
</dependency>
</dependencies>
<profiles>

View File

@ -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) {

View File

@ -146,9 +146,9 @@
<instructions>
<Embed-Dependency>*;scope=compile|runtime;groupId=org.apache.activemq</Embed-Dependency>
<Import-Package>
org.glassfish.json*;resolution:=optional,
org.postgresql*;resolution:=optional,
io.netty.buffer;io.netty.*;version="[4.1,5)",
org.apache.johnzon.core,
*
</Import-Package>
<_exportcontents>org.apache.activemq.artemis.*;-noimport:=true</_exportcontents>

View File

@ -156,10 +156,6 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@ -219,6 +215,21 @@
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<!-- The johnzon-core and json-api contents are repackaged in -commons,
However maven can still need them during tests, which run against
the original -commons classes when built+run in the same reactor,
and not the jar containing the shaded bits. -->
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>

View File

@ -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<String> stringList = JsonLoader.readArray(new StringReader(value)).stream()
.map(v -> ((JsonString) v).getString())
.collect(Collectors.toList());
List<String> 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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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())

View File

@ -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;

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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");

View File

@ -160,6 +160,7 @@ under the License.
<module>pre-acknowledge</module>
<module>producer-rate-limit</module>
<module>queue</module>
<module>queue-jakarta</module>
<module>queue-requestor</module>
<module>queue-selector</module>
<module>reattach-node</module>

View File

@ -49,6 +49,20 @@ under the License.
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>snapshot-check</id>
<phase>compile</phase>
<goals>
<goal>dependency-scan</goal>
</goals>
<configuration>
<libList>
<arg>org.apache.activemq:artemis-jakarta-client-all:${project.version}</arg>
<arg>org.apache.activemq.examples.broker:queue-jakarta:${project.version}</arg>
</libList>
<variableName>ARTEMIS-JAKARTA</variableName>
</configuration>
</execution>
<execution>
<id>create</id>
<goals>
@ -79,6 +93,7 @@ under the License.
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.QueueExample</clientClass>
<classPath>${ARTEMIS-JAKARTA}</classPath>
</configuration>
</execution>
<execution>

View File

@ -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();
}

View File

@ -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

39
pom.xml
View File

@ -105,6 +105,7 @@
<errorprone.version>2.9.0</errorprone.version>
<maven.enforcer.plugin.version>3.0.0-M3</maven.enforcer.plugin.version>
<maven.bundle.plugin.version>5.1.2</maven.bundle.plugin.version>
<maven.shade.plugin.version>3.2.4</maven.shade.plugin.version>
<maven.checkstyle.plugin.version>3.1.1</maven.checkstyle.plugin.version>
<sevntu.checks.version>1.39.0</sevntu.checks.version>
<checkstyle.version>8.43</checkstyle.version>
@ -480,12 +481,6 @@
<version>${jakarta.transaction-api.version}</version>
<!-- License: EPL 2.0 -->
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>${jakarta.json-api.version}</version>
<!-- License: EPL 2.0 -->
</dependency>
<dependency>
<groupId>jakarta.ejb</groupId>
<artifactId>jakarta.ejb-api</artifactId>
@ -689,13 +684,6 @@
<version>${slf4j.version}</version>
<!-- License: MIT -->
</dependency>
<!-- json -->
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<version>${johnzon.version}</version>
</dependency>
<!--needed for the rest support-->
<dependency>
<groupId>org.jboss.resteasy</groupId>
@ -930,6 +918,29 @@
<artifactId>zookeeper-jute</artifactId>
<version>${zookeeper.version}</version>
</dependency>
<!-- johnzon and jakarta.json are shaded on artemis-commons.
However during internal builds and test phase original bits may be used,
and this library would still be needed for test phase.
I am declaring scope as test by default to avoid any accidental use.
The only place where we are allowed to use this library is within artemis-commons.
anything other than that need to be carefully thought.
-->
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<version>${johnzon.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>${jakarta.json-api.version}</version>
<scope>test</scope>
<!-- License: EPL 2.0 -->
</dependency>
</dependencies>
</dependencyManagement>
@ -1441,7 +1452,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<version>${maven.shade.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>

View File

@ -208,11 +208,6 @@
<groupId>org.fusesource.mqtt-client</groupId>
<artifactId>mqtt-client</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.resource</groupId>
<artifactId>jakarta.resource-api</artifactId>
@ -229,11 +224,6 @@
<groupId>jakarta.management.j2ee</groupId>
<artifactId>jakarta.management.j2ee-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
@ -300,6 +290,21 @@
<artifactId>jboss-marshalling-river</artifactId>
<version>2.0.9.Final</version>
</dependency>
<!-- The johnzon-core and json-api contents are repackaged in -commons,
However maven can still need them during tests, which run against
the original -commons classes when built+run in the same reactor,
and not the jar containing the shaded bits. -->
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -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;

View File

@ -213,11 +213,6 @@
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.resource</groupId>
<artifactId>jakarta.resource-api</artifactId>
@ -234,11 +229,6 @@
<groupId>jakarta.management.j2ee</groupId>
<artifactId>jakarta.management.j2ee-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
@ -463,6 +453,22 @@
</exclusion>
</exclusions>
</dependency>
<!-- The johnzon-core and json-api contents are repackaged in -commons,
However maven can still need them during tests, which run against
the original -commons classes when built+run in the same reactor,
and not the jar containing the shaded bits. -->
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -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;

View File

@ -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<JsonString> queues = (List<JsonString>) array.get(0);
JsonArray array = JsonLoader.readArray(new StringReader(json));
JsonArray queues = array.getJsonArray(0);
assertNotNull(queues);
assertFalse(queues.isEmpty());

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<Long> 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());

View File

@ -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;

View File

@ -107,6 +107,20 @@
<artifactId>error_prone_core</artifactId>
</dependency>
<!-- The johnzon-core and json-api contents are repackaged in -commons,
However maven can still need them during tests, which run against
the original -commons classes when built+run in the same reactor,
and not the jar containing the shaded bits. -->
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -202,6 +202,21 @@
<artifactId>zookeeper-jute</artifactId>
<scope>test</scope>
</dependency>
<!-- The johnzon-core and json-api contents are repackaged in -commons,
However maven can still need them during tests, which run against
the original -commons classes when built+run in the same reactor,
and not the jar containing the shaded bits. -->
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -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;

View File

@ -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<String, Pair<String, String>> 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<String, Pair<String, String>> 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<String, Pair<String, String>> networkTopology) {

View File

@ -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<String, Pair<String, String>> 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<String, Pair<String, String>> 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<String, Pair<String, String>> networkTopology) {