You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2022/09/09 14:03:36 UTC
[activemq-artemis] branch new-logging updated: JIRA-TBD Removing artemis-rest as a module
This is an automated email from the ASF dual-hosted git repository.
clebertsuconic pushed a commit to branch new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/new-logging by this push:
new c17e80ae13 JIRA-TBD Removing artemis-rest as a module
c17e80ae13 is described below
commit c17e80ae1308b4147882b210a08de53d7087ada2
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Fri Sep 9 10:02:26 2022 -0400
JIRA-TBD Removing artemis-rest as a module
As we recently switched artemis to 3.0, artemis-rest should be removed
---
artemis-rest/pom.xml | 184 ---
.../org/apache/activemq/artemis/rest/ActiveMQ.java | 174 ---
.../activemq/artemis/rest/ActiveMQRestLogger.java | 69 -
.../activemq/artemis/rest/HttpHeaderProperty.java | 53 -
.../java/org/apache/activemq/artemis/rest/Jms.java | 174 ---
.../artemis/rest/MessageServiceConfiguration.java | 168 ---
.../artemis/rest/MessageServiceManager.java | 216 ---
.../activemq/artemis/rest/UnknownMediaType.java | 26 -
.../activemq/artemis/rest/UnmarshalException.java | 30 -
.../integration/ActiveMQBootstrapListener.java | 47 -
.../rest/integration/EmbeddedRestActiveMQ.java | 75 -
.../rest/integration/EmbeddedRestActiveMQJMS.java | 42 -
.../RestMessagingBootstrapListener.java | 86 --
.../integration/ServletContextBindingRegistry.java | 50 -
.../rest/queue/AcknowledgedQueueConsumer.java | 242 ---
.../artemis/rest/queue/Acknowledgement.java | 61 -
.../artemis/rest/queue/ConsumedHttpMessage.java | 45 -
.../artemis/rest/queue/ConsumedMessage.java | 68 -
.../artemis/rest/queue/ConsumedObjectMessage.java | 62 -
.../artemis/rest/queue/ConsumersResource.java | 273 ----
.../artemis/rest/queue/DestinationResource.java | 48 -
.../rest/queue/DestinationServiceManager.java | 170 ---
.../artemis/rest/queue/DestinationSettings.java | 56 -
.../activemq/artemis/rest/queue/PostMessage.java | 269 ----
.../artemis/rest/queue/PostMessageDupsOk.java | 91 --
.../artemis/rest/queue/PostMessageNoDups.java | 43 -
.../activemq/artemis/rest/queue/QueueConsumer.java | 269 ----
.../artemis/rest/queue/QueueDeployment.java | 39 -
.../rest/queue/QueueDestinationsResource.java | 175 ---
.../activemq/artemis/rest/queue/QueueResource.java | 179 ---
.../artemis/rest/queue/QueueServiceManager.java | 116 --
.../rest/queue/push/ActiveMQPushStrategy.java | 77 -
.../artemis/rest/queue/push/FilePushStore.java | 115 --
.../artemis/rest/queue/push/PushConsumer.java | 140 --
.../queue/push/PushConsumerMessageHandler.java | 74 -
.../rest/queue/push/PushConsumerResource.java | 154 --
.../artemis/rest/queue/push/PushStore.java | 34 -
.../artemis/rest/queue/push/PushStrategy.java | 42 -
.../artemis/rest/queue/push/UriStrategy.java | 224 ---
.../rest/queue/push/UriTemplateStrategy.java | 29 -
.../rest/queue/push/xml/Authentication.java | 47 -
.../rest/queue/push/xml/AuthenticationType.java | 26 -
.../artemis/rest/queue/push/xml/BasicAuth.java | 53 -
.../artemis/rest/queue/push/xml/DigestAuth.java | 25 -
.../rest/queue/push/xml/PushRegistration.java | 184 ---
.../artemis/rest/queue/push/xml/XmlHttpHeader.java | 59 -
.../artemis/rest/queue/push/xml/XmlLink.java | 91 --
.../topic/AcknowledgedSubscriptionResource.java | 71 -
.../artemis/rest/topic/FileTopicPushStore.java | 42 -
.../artemis/rest/topic/PushSubscription.java | 63 -
.../rest/topic/PushSubscriptionsResource.java | 216 ---
.../artemis/rest/topic/PushTopicRegistration.java | 43 -
.../activemq/artemis/rest/topic/Subscription.java | 32 -
.../artemis/rest/topic/SubscriptionResource.java | 71 -
.../artemis/rest/topic/SubscriptionsResource.java | 427 ------
.../artemis/rest/topic/TopicDeployment.java | 40 -
.../rest/topic/TopicDestinationsResource.java | 170 ---
.../artemis/rest/topic/TopicPushStore.java | 26 -
.../activemq/artemis/rest/topic/TopicResource.java | 183 ---
.../artemis/rest/topic/TopicServiceManager.java | 110 --
.../activemq/artemis/rest/util/Constants.java | 23 -
.../rest/util/CustomHeaderLinkStrategy.java | 39 -
.../artemis/rest/util/HttpMessageHelper.java | 131 --
.../artemis/rest/util/LinkHeaderLinkStrategy.java | 55 -
.../activemq/artemis/rest/util/LinkStrategy.java | 24 -
.../activemq/artemis/rest/util/TimeoutTask.java | 164 --
.../src/main/resources/schema/artemis-rest.xsd | 119 --
.../integration/EmbeddedRestActiveMQJMSTest.java | 199 ---
.../artemis/rest/test/AutoAckQueueTest.java | 88 --
.../artemis/rest/test/AutoAckTopicTest.java | 217 ---
.../artemis/rest/test/ClientAckQueueTest.java | 376 -----
.../artemis/rest/test/ClientAckTopicTest.java | 319 ----
.../artemis/rest/test/CreateDestinationTest.java | 180 ---
.../activemq/artemis/rest/test/DupQueueTest.java | 154 --
.../activemq/artemis/rest/test/Embedded.java | 94 --
.../activemq/artemis/rest/test/EmbeddedTest.java | 157 --
.../artemis/rest/test/EmbeddedTestServer.java | 95 --
.../artemis/rest/test/FindDestinationTest.java | 135 --
.../apache/activemq/artemis/rest/test/JMSTest.java | 275 ----
.../artemis/rest/test/MessagePropertiesTest.java | 104 --
.../artemis/rest/test/MessageTestBase.java | 79 -
.../rest/test/PersistentPushQueueConsumerTest.java | 204 ---
.../rest/test/PersistentPushTopicConsumerTest.java | 240 ---
.../artemis/rest/test/PushQueueConsumerTest.java | 336 -----
.../artemis/rest/test/PushTopicConsumerTest.java | 363 -----
.../activemq/artemis/rest/test/RawAckTest.java | 158 --
.../artemis/rest/test/RepostingQueueTest.java | 563 -------
.../artemis/rest/test/RepostingTopicTest.java | 691 ---------
.../artemis/rest/test/RoundtripTimeTest.java | 72 -
.../activemq/artemis/rest/test/SelectorTest.java | 304 ----
.../activemq/artemis/rest/test/SessionTest.java | 309 ----
.../activemq/artemis/rest/test/TransformTest.java | 248 ---
.../apache/activemq/artemis/rest/test/Util.java | 49 -
.../apache/activemq/artemis/rest/test/XmlTest.java | 48 -
.../artemis/rest/topic/RepostingTopicTest.java | 692 ---------
artemis-rest/src/test/resources/activemq-rest.xml | 19 -
artemis-rest/src/test/resources/broker.xml | 49 -
docs/user-manual/en/SUMMARY.md | 1 -
docs/user-manual/en/rest.md | 1585 --------------------
examples/features/standard/pom.xml | 2 -
examples/features/standard/rest/dup-send/pom.xml | 161 --
examples/features/standard/rest/dup-send/readme.md | 41 -
.../rest/dup-send/src/main/java/Order.java | 69 -
.../rest/dup-send/src/main/java/PostOrder.java | 69 -
.../dup-send/src/main/java/PostOrderWithId.java | 45 -
.../rest/dup-send/src/main/java/ReceiveOrder.java | 49 -
.../dup-send/src/main/resources/activemq-rest.xml | 23 -
.../rest/dup-send/src/main/resources/broker.xml | 36 -
.../rest/dup-send/src/main/webapp/WEB-INF/web.xml | 55 -
.../features/standard/rest/javascript-chat/pom.xml | 175 ---
.../standard/rest/javascript-chat/readme.md | 15 -
.../javascript-chat/src/main/resources/broker.xml | 34 -
.../src/main/webapp/WEB-INF/web.xml | 51 -
.../javascript-chat/src/main/webapp/index.html | 188 ---
.../resteasy/messaging/test/AutoAckTopicTest.java | 88 --
.../features/standard/rest/jms-to-rest/pom.xml | 161 --
.../standard/rest/jms-to-rest/postOrder.py | 45 -
.../features/standard/rest/jms-to-rest/readme.md | 49 -
.../standard/rest/jms-to-rest/receiveOrder.py | 69 -
.../rest/jms-to-rest/src/main/java/JmsReceive.java | 52 -
.../rest/jms-to-rest/src/main/java/JmsSend.java | 44 -
.../rest/jms-to-rest/src/main/java/Order.java | 69 -
.../jms-to-rest/src/main/java/RestReceive.java | 50 -
.../rest/jms-to-rest/src/main/java/RestSend.java | 40 -
.../rest/jms-to-rest/src/main/resources/broker.xml | 37 -
.../jms-to-rest/src/main/webapp/WEB-INF/web.xml | 51 -
examples/features/standard/rest/pom.xml | 45 -
examples/features/standard/rest/push/pom.xml | 161 --
examples/features/standard/rest/push/readme.md | 32 -
.../standard/rest/push/src/main/java/Order.java | 69 -
.../rest/push/src/main/java/PostOrder.java | 44 -
.../standard/rest/push/src/main/java/PushReg.java | 44 -
.../rest/push/src/main/java/ReceiveShipping.java | 51 -
.../rest/push/src/main/resources/broker.xml | 42 -
.../rest/push/src/main/webapp/WEB-INF/web.xml | 51 -
pom.xml | 3 -
tests/integration-tests/pom.xml | 9 -
.../artemis/tests/integration/rest/Order.java | 80 -
.../integration/rest/RestDeserializationTest.java | 198 ---
.../tests/integration/rest/RestTestBase.java | 99 --
.../rest/util/QueueRestMessageContext.java | 75 -
.../tests/integration/rest/util/ResponseUtil.java | 35 -
.../integration/rest/util/RestAMQConnection.java | 104 --
.../integration/rest/util/RestMessageContext.java | 259 ----
.../rest/util/TopicRestMessageContext.java | 83 -
.../test/resources/rest/bwlist-rest-test-asm.xml | 37 -
.../src/test/resources/rest/rest-test-asm.xml | 37 -
.../rest/rest-test-bwlist/webapp/WEB-INF/web.xml | 56 -
.../rest/rest-test/webapp/WEB-INF/web.xml | 58 -
149 files changed, 18866 deletions(-)
diff --git a/artemis-rest/pom.xml b/artemis-rest/pom.xml
deleted file mode 100644
index 26ab9ef4a2..0000000000
--- a/artemis-rest/pom.xml
+++ /dev/null
@@ -1,184 +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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-pom</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- </parent>
-
- <groupId>org.apache.activemq.rest</groupId>
- <artifactId>artemis-rest</artifactId>
- <packaging>jar</packaging>
- <name>ActiveMQ Artemis REST Interface Implementation</name>
-
- <properties>
- <activemq.basedir>${project.basedir}/..</activemq.basedir>
- </properties>
-
- <dependencies>
- <!-- logging -->
- <dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-log-processor</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- <scope>runtime</scope> <!-- TODO: decide whether to only supply via assembly or here -->
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>tomcat-servlet-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-server</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxrs</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.jboss.spec.javax.ws.rs</groupId>
- <artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxb-provider</artifactId>
- <exclusions>
- <exclusion>
- <groupId>com.sun.xml.bind</groupId>
- <artifactId>jaxb-impl</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.sun.xml.stream</groupId>
- <artifactId>sjsxp</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jackson2-provider</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>tjws</artifactId>
- <scope>provided</scope>
- <exclusions>
- <exclusion>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-server</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-jms-server</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-jms-client</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-core-client</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-commons</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>jakarta.jms</groupId>
- <artifactId>jakarta.jms-api</artifactId>
- </dependency>
- <dependency>
- <groupId>jakarta.ws.rs</groupId>
- <artifactId>jakarta.ws.rs-api</artifactId>
- <version>${jakarta.ws.rs-api.version}</version>
- </dependency>
- <dependency>
- <groupId>jakarta.xml.bind</groupId>
- <artifactId>jakarta.xml.bind-api</artifactId>
- <version>${jakarta.xml.bind-api.version}</version>
- </dependency>
- <dependency>
- <groupId>org.glassfish.jaxb</groupId>
- <artifactId>jaxb-runtime</artifactId>
- <version>2.3.2</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpcore</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- </dependency>
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-unit-test-support</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <argLine>${activemq-surefire-argline}</argLine>
- <skipTests>${skipRestTests}</skipTests>
- <!--includes>
- <include>**/PushQueueConsumerTest.java</include>
- </includes-->
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/ActiveMQ.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/ActiveMQ.java
deleted file mode 100644
index 45dd3188b7..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/ActiveMQ.java
+++ /dev/null
@@ -1,174 +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.
- */
-package org.apache.activemq.artemis.rest;
-
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.ext.MessageBodyReader;
-import javax.ws.rs.ext.Providers;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.lang.reflect.Type;
-
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.rest.util.HttpMessageHelper;
-import org.jboss.resteasy.core.Headers;
-import org.jboss.resteasy.spi.ResteasyProviderFactory;
-import org.jboss.resteasy.util.GenericType;
-
-public class ActiveMQ {
-
- /**
- * Sets the message body to a serialized
- * byte array of the object. HTTP consumers will have to provide an Accept header to marshal the object
- *
- * @param message
- * @param object
- */
- public static void setEntity(ClientMessage message, Serializable object) {
- setEntity(message, object, null);
- }
-
- /**
- * Sets a message property to be the Content-Type passed in. Sets the message body to a serialized
- * byte array of the object.
- *
- * @param message
- * @param object
- * @param contentType HTTP Content-Type header
- */
- public static void setEntity(ClientMessage message, Serializable object, String contentType) {
- if (contentType != null)
- message.putStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType);
- byte[] data;
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
-
- ObjectOutputStream oos = new ObjectOutputStream(baos);
-
- oos.writeObject(object);
-
- oos.flush();
-
- data = baos.toByteArray();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- message.getBodyBuffer().writeInt(data.length);
- message.getBodyBuffer().writeBytes(data);
-
- }
-
- public static void setHttpHeader(ClientMessage message, String name, String value) {
- message.putStringProperty(HttpHeaderProperty.toPropertyName(name), value);
- }
-
- /**
- * Get an HTTP header value from a JMS Message
- *
- * @param message
- * @param name
- * @return the HTTP header String
- */
- public static String getHttpHeader(ClientMessage message, String name) {
- return message.getStringProperty(HttpHeaderProperty.toPropertyName(name));
- }
-
- /**
- * Extract an object using a built-in RESTEasy JAX-RS MessageBodyReader
- *
- * @param message
- * @param type
- * @return
- */
- public static <T> T getEntity(ClientMessage message, Class<T> type) {
- return getEntity(message, type, null, ResteasyProviderFactory.getInstance());
- }
-
- /**
- * Extract an object using a built-in RESTEasy JAX-RS MessageBodyReader
- *
- * @param message
- * @param type
- * @param factory
- * @return
- */
- public static <T> T getEntity(ClientMessage message, Class<T> type, ResteasyProviderFactory factory) {
- return getEntity(message, type, null, factory);
- }
-
- /**
- * Extract an object using a built-in RESTEasy JAX-RS MessageBodyReader
- *
- * @param message
- * @param type
- * @param factory
- * @return
- * @throws UnknownMediaType
- * @throws UnmarshalException
- */
- public static <T> T getEntity(ClientMessage message,
- GenericType<T> type,
- ResteasyProviderFactory factory) throws UnknownMediaType, UnmarshalException {
- return getEntity(message, type.getType(), type.getGenericType(), factory);
- }
-
- public static <T> T getEntity(ClientMessage msg, Class<T> type, Type genericType, ResteasyProviderFactory factory) {
- int size = msg.getBodySize();
- if (size <= 0)
- return null;
-
- byte[] body = new byte[size];
- msg.getBodyBuffer().readBytes(body);
-
- String contentType = msg.getStringProperty(HttpHeaderProperty.CONTENT_TYPE);
- if (contentType == null) {
- throw new UnknownMediaType("Message did not have a Content-Type header cannot extract entity");
- }
- MediaType ct = MediaType.valueOf(contentType);
- MessageBodyReader<T> reader = factory.getMessageBodyReader(type, genericType, null, ct);
- if (reader == null) {
- throw new UnmarshalException("Unable to find a JAX-RS reader for type " + type.getName() + " and media type " + contentType);
- }
-
- Providers current = ResteasyProviderFactory.getContextData(Providers.class);
- ResteasyProviderFactory.pushContext(Providers.class, factory);
- try {
- return reader.readFrom(type, genericType, null, ct, new Headers<String>(), new ByteArrayInputStream(body));
- } catch (IOException e) {
- throw new RuntimeException(e);
- } finally {
- ResteasyProviderFactory.popContextData(Providers.class);
- if (current != null)
- ResteasyProviderFactory.pushContext(Providers.class, current);
- }
- }
-
- /**
- * Was this ActiveMQ Artemis message generated from a REST call?
- *
- * @param msg
- * @return
- */
- public static boolean isHttpMessage(ClientMessage msg) {
- Boolean aBoolean = msg.getBooleanProperty(HttpMessageHelper.POSTED_AS_HTTP_MESSAGE);
- return aBoolean != null && aBoolean.booleanValue() == true;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/ActiveMQRestLogger.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/ActiveMQRestLogger.java
deleted file mode 100644
index dfc0a83cdd..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/ActiveMQRestLogger.java
+++ /dev/null
@@ -1,69 +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.
- */
-package org.apache.activemq.artemis.rest;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.logs.BundleFactory;
-import org.apache.activemq.artemis.rest.queue.push.xml.XmlLink;
-import org.apache.activemq.artemis.logprocessor.annotation.LogBundle;
-import org.apache.activemq.artemis.logprocessor.annotation.LogMessage;
-
-/**
- * Logger Code 19
- * so an INFO message would be 191000 to 191999
- */
-@LogBundle(projectCode = "AMQ")
-public interface ActiveMQRestLogger {
-
- ActiveMQRestLogger LOGGER = BundleFactory.newBundle(ActiveMQRestLogger.class, ActiveMQRestLogger.class.getPackage().getName());
-
- @LogMessage(id = 181000, value = "Loading REST push store from: {}", level = LogMessage.Level.INFO)
- void loadingRestStore(String path);
-
- @LogMessage(id = 181001, value = "adding REST push registration: {}", level = LogMessage.Level.INFO)
- void addingPushRegistration(String id);
-
- @LogMessage(id = 181002, value = "Push consumer started for: {}", level = LogMessage.Level.INFO)
- void startingPushConsumer(XmlLink link);
-
- @LogMessage(id = 182000, value = "shutdown REST consumer because of timeout for: {}", level = LogMessage.Level.WARN)
- void shutdownRestConsumer(String id);
-
- @LogMessage(id = 182001, value = "shutdown REST subscription because of timeout for: {}", level = LogMessage.Level.WARN)
- void shutdownRestSubscription(String id);
-
- @LogMessage(id = 182002, value = "Failed to push message to {}", level = LogMessage.Level.WARN)
- void failedToPushMessageToUri(String uri, Exception e);
-
- @LogMessage(id = 182003, value = "Failed to build Message from object", level = LogMessage.Level.WARN)
- void failedToBuildMessageFromObject(Exception e);
-
- @LogMessage(id = 182004, value = "REST configuration parameter '{}' is deprecated. Use '{}' instead.", level = LogMessage.Level.WARN)
- void deprecatedConfiguration(String oldConfigParameter, String newConfigParameter);
-
- @LogMessage(id = 184000, value = "Failed to load push store {}, it is probably corrupted", level = LogMessage.Level.ERROR)
- void errorLoadingStore(String name, Exception e);
-
- @LogMessage(id = 184001, value = "Error updating store", level = LogMessage.Level.ERROR)
- void errorUpdatingStore(Exception e);
-
- @LogMessage(id = 184002, value = "Failed to push message to {} disabling push registration...", level = LogMessage.Level.ERROR)
- void errorPushingMessage(XmlLink link);
-
- @LogMessage(id = 184003, value = "Error deleting Subscriber queue", level = LogMessage.Level.ERROR)
- void errorDeletingSubscriberQueue(ActiveMQException e);
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/HttpHeaderProperty.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/HttpHeaderProperty.java
deleted file mode 100644
index 7a0b74dc74..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/HttpHeaderProperty.java
+++ /dev/null
@@ -1,53 +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.
- */
-package org.apache.activemq.artemis.rest;
-
-public class HttpHeaderProperty {
-
- public static final String CONTENT_TYPE = "http_content$type";
- public static final String MESSAGE_PROPERTY_DISCRIMINATOR = "message.property.";
-
- /**
- * Either strips the prefix "message.property." and returns the rest of the name or (if not starting with aforementioned prefix)
- * converts an HTTP header name to a selector compatible property name. '-' character is converted to
- * '$'. The return property name will also be all lower case with an "http_" prepended. For example
- * "Content-Type" would be converted to "http_content$type";
- *
- * @param httpHeader
- * @return
- */
- public static String toPropertyName(String httpHeader) {
- if (httpHeader.startsWith( MESSAGE_PROPERTY_DISCRIMINATOR )) {
- return httpHeader.replaceAll( MESSAGE_PROPERTY_DISCRIMINATOR, "" );
- } else {
- httpHeader = httpHeader.replace( '-', '$' );
- return "http_" + httpHeader.toLowerCase();
- }
- }
-
- /**
- * Converts a JMS property name to an HTTP header name.
- *
- * @param name
- * @return null if property name isn't an HTTP header name.
- */
- public static String fromPropertyName(String name) {
- if (!name.startsWith("http_"))
- return null;
- return name.substring("http_".length()).replace('$', '-');
- }
-}
\ No newline at end of file
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/Jms.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/Jms.java
deleted file mode 100644
index e5aed5854d..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/Jms.java
+++ /dev/null
@@ -1,174 +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.
- */
-package org.apache.activemq.artemis.rest;
-
-import javax.jms.BytesMessage;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.ObjectMessage;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.ext.MessageBodyReader;
-import javax.ws.rs.ext.Providers;
-import java.io.ByteArrayInputStream;
-import java.lang.reflect.Type;
-
-import org.apache.activemq.artemis.rest.util.HttpMessageHelper;
-import org.jboss.resteasy.core.Headers;
-import org.jboss.resteasy.spi.ResteasyProviderFactory;
-import org.jboss.resteasy.util.GenericType;
-
-public class Jms {
-
- /**
- * Set a JMS Message property to the value of an HTTP header
- *
- * @param message
- * @param name
- * @param value
- */
- public static void setHttpHeader(Message message, String name, String value) {
- try {
- message.setStringProperty(HttpHeaderProperty.toPropertyName(name), value);
- } catch (JMSException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Get an HTTP header value from a JMS Message
- *
- * @param message
- * @param name
- * @return the header or {@code null} if not present
- */
- public static String getHttpHeader(Message message, String name) {
- try {
- return message.getStringProperty(HttpHeaderProperty.toPropertyName(name));
- } catch (JMSException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Extract an object using a built-in RESTEasy JAX-RS MessageBodyReader
- *
- * @param message
- * @param type
- * @param <T>
- * @return
- */
- public static <T> T getEntity(Message message, Class<T> type) {
- return getEntity(message, type, null, ResteasyProviderFactory.getInstance());
- }
-
- /**
- * Extract an object using a built-in RESTEasy JAX-RS MessageBodyReader
- *
- * @param message
- * @param type
- * @param factory
- * @param <T>
- * @return
- */
- public static <T> T getEntity(Message message, Class<T> type, ResteasyProviderFactory factory) {
- return getEntity(message, type, null, factory);
- }
-
- /**
- * Extract an object using a built-in RESTEasy JAX-RS MessageBodyReader
- *
- * @param message
- * @param type
- * @param factory
- * @param <T>
- * @return
- * @throws UnknownMediaType
- * @throws UnmarshalException
- */
- public static <T> T getEntity(Message message,
- GenericType<T> type,
- ResteasyProviderFactory factory) throws UnknownMediaType {
- return getEntity(message, type.getType(), type.getGenericType(), factory);
- }
-
- public static boolean isHttpMessage(Message message) {
- try {
- return message.getBooleanProperty(HttpMessageHelper.POSTED_AS_HTTP_MESSAGE);
- } catch (JMSException e) {
- return false;
- }
- }
-
- /**
- * Extract an object using a built-in RESTEasy JAX-RS MessageBodyReader
- *
- * @param message
- * @param type
- * @param genericType
- * @param factory
- * @param <T>
- * @return
- * @throws UnknownMediaType
- * @throws UnmarshalException
- */
- public static <T> T getEntity(Message message,
- Class<T> type,
- Type genericType,
- ResteasyProviderFactory factory) throws UnknownMediaType {
- if (!isHttpMessage(message)) {
- try {
- return (T) ((ObjectMessage) message).getObject();
- } catch (JMSException e) {
- throw new RuntimeException(e);
- }
- }
- BytesMessage bytesMessage = (BytesMessage) message;
-
- try {
- long size = bytesMessage.getBodyLength();
- if (size <= 0) {
- return null;
- }
-
- byte[] body = new byte[(int) size];
- bytesMessage.readBytes(body);
-
- String contentType = message.getStringProperty(HttpHeaderProperty.CONTENT_TYPE);
- if (contentType == null) {
- throw new UnknownMediaType("Message did not have a Content-Type header cannot extract entity");
- }
- MediaType ct = MediaType.valueOf(contentType);
- MessageBodyReader<T> reader = factory.getMessageBodyReader(type, genericType, null, ct);
- if (reader == null) {
- throw new UnmarshalException("Unable to find a JAX-RS reader for type " + type.getName() + " and media type " + contentType);
- }
-
- Providers current = ResteasyProviderFactory.getContextData(Providers.class);
- ResteasyProviderFactory.pushContext(Providers.class, factory);
- try {
- return reader.readFrom(type, genericType, null, ct, new Headers<String>(), new ByteArrayInputStream(body));
- } finally {
- ResteasyProviderFactory.popContextData(Providers.class);
- if (current != null)
- ResteasyProviderFactory.pushContext(Providers.class, current);
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/MessageServiceConfiguration.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/MessageServiceConfiguration.java
deleted file mode 100644
index 4c9dd0690e..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/MessageServiceConfiguration.java
+++ /dev/null
@@ -1,168 +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.
- */
-package org.apache.activemq.artemis.rest;
-
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-@XmlRootElement(name = "rest-messaging")
-public class MessageServiceConfiguration {
-
- private int producerSessionPoolSize = 10;
- private long producerTimeToLive = -1;
- private int timeoutTaskInterval = 1;
- private int consumerSessionTimeoutSeconds = 300;
- @Deprecated
- private int consumerWindowSize = -1;
- private boolean defaultDurableSend = false;
- private boolean dupsOk = true;
- private String topicPushStoreDirectory = "topic-push-store";
- private String queuePushStoreDirectory = "queue-push-store";
- @Deprecated
- private String inVmId = "0";
- private String url = "vm://0";
- private boolean useLinkHeaders = false;
-
- private String deserializationWhiteList;
- private String deserializationBlackList;
-
- @XmlElement(name = "server-in-vm-id")
- public String getInVmId() {
- return inVmId;
- }
-
- public void setInVmId(String inVmId) {
- ActiveMQRestLogger.LOGGER.deprecatedConfiguration("server-in-vm-id", "url");
- this.inVmId = inVmId;
- }
-
- @XmlElement(name = "use-link-headers")
- public boolean isUseLinkHeaders() {
- return useLinkHeaders;
- }
-
- public void setUseLinkHeaders(boolean useLinkHeaders) {
- this.useLinkHeaders = useLinkHeaders;
- }
-
- @XmlElement(name = "default-durable-send")
- public boolean isDefaultDurableSend() {
- return defaultDurableSend;
- }
-
- public void setDefaultDurableSend(boolean defaultDurableSend) {
- this.defaultDurableSend = defaultDurableSend;
- }
-
- @XmlElement(name = "dups-ok")
- public boolean isDupsOk() {
- return dupsOk;
- }
-
- public void setDupsOk(boolean dupsOk) {
- this.dupsOk = dupsOk;
- }
-
- @XmlElement(name = "topic-push-store-dir")
- public String getTopicPushStoreDirectory() {
- return topicPushStoreDirectory;
- }
-
- public void setTopicPushStoreDirectory(String topicPushStoreDirectory) {
- this.topicPushStoreDirectory = topicPushStoreDirectory;
- }
-
- @XmlElement(name = "queue-push-store-dir")
- public String getQueuePushStoreDirectory() {
- return queuePushStoreDirectory;
- }
-
- public void setQueuePushStoreDirectory(String queuePushStoreDirectory) {
- this.queuePushStoreDirectory = queuePushStoreDirectory;
- }
-
- @XmlElement(name = "producer-time-to-live")
- public long getProducerTimeToLive() {
- return producerTimeToLive;
- }
-
- public void setProducerTimeToLive(long producerTimeToLive) {
- this.producerTimeToLive = producerTimeToLive;
- }
-
- @XmlElement(name = "producer-session-pool-size")
- public int getProducerSessionPoolSize() {
- return producerSessionPoolSize;
- }
-
- public void setProducerSessionPoolSize(int producerSessionPoolSize) {
- this.producerSessionPoolSize = producerSessionPoolSize;
- }
-
- @XmlElement(name = "session-timeout-task-interval")
- public int getTimeoutTaskInterval() {
- return timeoutTaskInterval;
- }
-
- public void setTimeoutTaskInterval(int timeoutTaskInterval) {
- this.timeoutTaskInterval = timeoutTaskInterval;
- }
-
- @XmlElement(name = "consumer-session-timeout-seconds")
- public int getConsumerSessionTimeoutSeconds() {
- return consumerSessionTimeoutSeconds;
- }
-
- public void setConsumerSessionTimeoutSeconds(int consumerSessionTimeoutSeconds) {
- this.consumerSessionTimeoutSeconds = consumerSessionTimeoutSeconds;
- }
-
- @XmlElement(name = "consumer-window-size")
- public int getConsumerWindowSize() {
- return consumerWindowSize;
- }
-
- public void setConsumerWindowSize(int consumerWindowSize) {
- ActiveMQRestLogger.LOGGER.deprecatedConfiguration("consumer-window-size", "url");
- this.consumerWindowSize = consumerWindowSize;
- }
-
- @XmlElement(name = "url")
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public String getDeserializationWhiteList() {
- return deserializationWhiteList;
- }
-
- public void setDeserializationWhiteList(String deserializationWhiteList) {
- this.deserializationWhiteList = deserializationWhiteList;
- }
-
- public String getDeserializationBlackList() {
- return deserializationBlackList;
- }
-
- public void setDeserializationBlackList(String deserializationBlackList) {
- this.deserializationBlackList = deserializationBlackList;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/MessageServiceManager.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/MessageServiceManager.java
deleted file mode 100644
index 5ad79a21c2..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/MessageServiceManager.java
+++ /dev/null
@@ -1,216 +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.
- */
-package org.apache.activemq.artemis.rest;
-
-import javax.xml.bind.JAXBContext;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.StringReader;
-import java.net.URL;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.api.core.client.ServerLocator;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.queue.DestinationSettings;
-import org.apache.activemq.artemis.rest.queue.QueueServiceManager;
-import org.apache.activemq.artemis.rest.topic.TopicServiceManager;
-import org.apache.activemq.artemis.rest.util.CustomHeaderLinkStrategy;
-import org.apache.activemq.artemis.rest.util.LinkHeaderLinkStrategy;
-import org.apache.activemq.artemis.rest.util.LinkStrategy;
-import org.apache.activemq.artemis.rest.util.TimeoutTask;
-import org.apache.activemq.artemis.spi.core.naming.BindingRegistry;
-import org.apache.activemq.artemis.utils.ActiveMQThreadFactory;
-import org.apache.activemq.artemis.utils.XMLUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class MessageServiceManager {
-
- private static final Logger logger = LoggerFactory.getLogger(MessageServiceManager.class);
-
- private ExecutorService threadPool;
- private QueueServiceManager queueManager;
- private TopicServiceManager topicManager;
- private TimeoutTask timeoutTask;
- private int timeoutTaskInterval = 1;
- protected MessageServiceConfiguration configuration = new MessageServiceConfiguration();
- private boolean configSet = false;
- private String configResourcePath;
- protected BindingRegistry registry;
-
- private ClientSessionFactory consumerSessionFactory;
-
- public MessageServiceManager(ConnectionFactoryOptions jmsOptions) {
- queueManager = new QueueServiceManager(jmsOptions);
- topicManager = new TopicServiceManager(jmsOptions);
- }
-
- public BindingRegistry getRegistry() {
- return registry;
- }
-
- public void setRegistry(BindingRegistry registry) {
- this.registry = registry;
- }
-
- public int getTimeoutTaskInterval() {
- return timeoutTaskInterval;
- }
-
- public void setTimeoutTaskInterval(int timeoutTaskInterval) {
- this.timeoutTaskInterval = timeoutTaskInterval;
- if (timeoutTask != null) {
- timeoutTask.setInterval(timeoutTaskInterval);
- }
- }
-
- public ExecutorService getThreadPool() {
- return threadPool;
- }
-
- public void setThreadPool(ExecutorService threadPool) {
- this.threadPool = threadPool;
- }
-
- public QueueServiceManager getQueueManager() {
- return queueManager;
- }
-
- public TopicServiceManager getTopicManager() {
- return topicManager;
- }
-
- public MessageServiceConfiguration getConfiguration() {
- return configuration;
- }
-
- public String getConfigResourcePath() {
- return configResourcePath;
- }
-
- public void setConfigResourcePath(String configResourcePath) {
- this.configResourcePath = configResourcePath;
- }
-
- public void setConfiguration(MessageServiceConfiguration configuration) {
- this.configuration = configuration;
- this.configSet = true;
- }
-
- public void start() throws Exception {
- if (configuration == null || !configSet) {
- if (configResourcePath == null) {
- configuration = new MessageServiceConfiguration();
- } else {
- URL url = getClass().getClassLoader().getResource(configResourcePath);
-
- if (isOutsideOfClassloader(url)) {
- url = new URL(configResourcePath);
- }
- JAXBContext jaxb = JAXBContext.newInstance(MessageServiceConfiguration.class);
- try (Reader reader = new InputStreamReader(url.openStream())) {
- String xml = XMLUtil.readerToString(reader);
- xml = XMLUtil.replaceSystemPropsInString(xml);
- configuration = (MessageServiceConfiguration) jaxb.createUnmarshaller().unmarshal(new StringReader(xml));
- }
- }
- }
- if (threadPool == null)
- threadPool = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory(getClass().getName()));
- timeoutTaskInterval = configuration.getTimeoutTaskInterval();
- timeoutTask = new TimeoutTask(timeoutTaskInterval);
- threadPool.execute(timeoutTask);
-
- DestinationSettings defaultSettings = new DestinationSettings();
- defaultSettings.setConsumerSessionTimeoutSeconds(configuration.getConsumerSessionTimeoutSeconds());
- defaultSettings.setDuplicatesAllowed(configuration.isDupsOk());
- defaultSettings.setDurableSend(configuration.isDefaultDurableSend());
-
- ServerLocator consumerLocator = ActiveMQClient.createServerLocator(configuration.getUrl());
-
- if (configuration.getConsumerWindowSize() != -1) {
- consumerLocator.setConsumerWindowSize(configuration.getConsumerWindowSize());
- }
-
- logger.debug("Created ServerLocator: " + consumerLocator);
-
- consumerSessionFactory = consumerLocator.createSessionFactory();
- logger.debug("Created ClientSessionFactory: " + consumerSessionFactory);
-
- ServerLocator defaultLocator = ActiveMQClient.createServerLocator(configuration.getUrl());
-
- ClientSessionFactory sessionFactory = defaultLocator.createSessionFactory();
-
- LinkStrategy linkStrategy;
- if (configuration.isUseLinkHeaders()) {
- linkStrategy = new LinkHeaderLinkStrategy();
- } else {
- linkStrategy = new CustomHeaderLinkStrategy();
- }
-
- queueManager.setServerLocator(defaultLocator);
- queueManager.setSessionFactory(sessionFactory);
- queueManager.setTimeoutTask(timeoutTask);
- queueManager.setConsumerServerLocator(consumerLocator);
- queueManager.setConsumerSessionFactory(consumerSessionFactory);
- queueManager.setDefaultSettings(defaultSettings);
- queueManager.setPushStoreFile(configuration.getQueuePushStoreDirectory());
- queueManager.setProducerPoolSize(configuration.getProducerSessionPoolSize());
- queueManager.setProducerTimeToLive(configuration.getProducerTimeToLive());
- queueManager.setLinkStrategy(linkStrategy);
- queueManager.setRegistry(registry);
-
- topicManager.setServerLocator(defaultLocator);
- topicManager.setSessionFactory(sessionFactory);
- topicManager.setTimeoutTask(timeoutTask);
- topicManager.setConsumerServerLocator(consumerLocator);
- topicManager.setConsumerSessionFactory(consumerSessionFactory);
- topicManager.setDefaultSettings(defaultSettings);
- topicManager.setPushStoreFile(configuration.getTopicPushStoreDirectory());
- topicManager.setProducerPoolSize(configuration.getProducerSessionPoolSize());
- queueManager.setProducerTimeToLive(configuration.getProducerTimeToLive());
- topicManager.setLinkStrategy(linkStrategy);
- topicManager.setRegistry(registry);
-
- queueManager.start();
- topicManager.start();
- }
-
- private boolean isOutsideOfClassloader(URL url) {
- return url == null;
- }
-
- public void stop() {
- if (queueManager != null)
- queueManager.stop();
- queueManager = null;
- if (topicManager != null)
- topicManager.stop();
- topicManager = null;
- this.timeoutTask.stop();
- threadPool.shutdown();
- try {
- threadPool.awaitTermination(5000, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- }
- this.consumerSessionFactory.close();
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/UnknownMediaType.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/UnknownMediaType.java
deleted file mode 100644
index cc4d35656b..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/UnknownMediaType.java
+++ /dev/null
@@ -1,26 +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.
- */
-package org.apache.activemq.artemis.rest;
-
-public class UnknownMediaType extends RuntimeException {
-
- private static final long serialVersionUID = -1445038845165315001L;
-
- public UnknownMediaType(String s) {
- super(s);
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/UnmarshalException.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/UnmarshalException.java
deleted file mode 100644
index abc3f0e68c..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/UnmarshalException.java
+++ /dev/null
@@ -1,30 +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.
- */
-package org.apache.activemq.artemis.rest;
-
-public class UnmarshalException extends RuntimeException {
-
- private static final long serialVersionUID = 3932027442263719425L;
-
- public UnmarshalException(String s) {
- super(s);
- }
-
- public UnmarshalException(String s, Throwable throwable) {
- super(s, throwable);
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/ActiveMQBootstrapListener.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/ActiveMQBootstrapListener.java
deleted file mode 100644
index 035cfeea20..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/ActiveMQBootstrapListener.java
+++ /dev/null
@@ -1,47 +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.
- */
-package org.apache.activemq.artemis.rest.integration;
-
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-
-import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ;
-
-public class ActiveMQBootstrapListener implements ServletContextListener {
-
- private EmbeddedActiveMQ activeMQ;
-
- @Override
- public void contextInitialized(ServletContextEvent contextEvent) {
- activeMQ = new EmbeddedActiveMQ();
- try {
- activeMQ.start();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public void contextDestroyed(ServletContextEvent servletContextEvent) {
- try {
- if (activeMQ != null)
- activeMQ.stop();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/EmbeddedRestActiveMQ.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/EmbeddedRestActiveMQ.java
deleted file mode 100644
index 7a24caa4c9..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/EmbeddedRestActiveMQ.java
+++ /dev/null
@@ -1,75 +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.
- */
-package org.apache.activemq.artemis.rest.integration;
-
-import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.MessageServiceManager;
-import org.jboss.resteasy.plugins.server.tjws.TJWSEmbeddedJaxrsServer;
-import org.jboss.resteasy.test.TestPortProvider;
-
-public class EmbeddedRestActiveMQ {
-
- private TJWSEmbeddedJaxrsServer tjws = new TJWSEmbeddedJaxrsServer();
- private EmbeddedActiveMQ embeddedActiveMQ;
- private MessageServiceManager manager = new MessageServiceManager(null);
-
- public EmbeddedRestActiveMQ(ConnectionFactoryOptions jmsOptions) {
- int port = TestPortProvider.getPort();
- tjws.setPort(port);
- tjws.setRootResourcePath("");
- tjws.setSecurityDomain(null);
- manager = new MessageServiceManager(jmsOptions);
- initEmbeddedActiveMQ();
- }
-
- protected void initEmbeddedActiveMQ() {
- embeddedActiveMQ = new EmbeddedActiveMQ();
- }
-
- public MessageServiceManager getManager() {
- return manager;
- }
-
- public void start() throws Exception {
- embeddedActiveMQ.start();
- tjws.start();
- manager.start();
- tjws.getDeployment().getRegistry().addSingletonResource(manager.getQueueManager().getDestination());
- tjws.getDeployment().getRegistry().addSingletonResource(manager.getTopicManager().getDestination());
- }
-
- public void stop() throws Exception {
- try {
- tjws.stop();
- } catch (Exception e) {
- }
- try {
- manager.stop();
- } catch (Exception e) {
- }
- embeddedActiveMQ.stop();
- }
-
- public EmbeddedActiveMQ getEmbeddedActiveMQ() {
- return embeddedActiveMQ;
- }
-
- public void setEmbeddedActiveMQ(EmbeddedActiveMQ embeddedActiveMQ) {
- this.embeddedActiveMQ = embeddedActiveMQ;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/EmbeddedRestActiveMQJMS.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/EmbeddedRestActiveMQJMS.java
deleted file mode 100644
index 8be6903c8b..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/EmbeddedRestActiveMQJMS.java
+++ /dev/null
@@ -1,42 +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.
- */
-package org.apache.activemq.artemis.rest.integration;
-
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS;
-import org.apache.activemq.artemis.spi.core.naming.BindingRegistry;
-
-@Deprecated
-public class EmbeddedRestActiveMQJMS extends EmbeddedRestActiveMQ {
-
- public EmbeddedRestActiveMQJMS(ConnectionFactoryOptions jmsOptions) {
- super(jmsOptions);
- }
-
- @Override
- protected void initEmbeddedActiveMQ() {
- super.setEmbeddedActiveMQ(new EmbeddedJMS());
- }
-
- public BindingRegistry getRegistry() {
- return ((EmbeddedJMS) getEmbeddedActiveMQ()).getRegistry();
- }
-
- public EmbeddedJMS getEmbeddedJMS() {
- return (EmbeddedJMS) getEmbeddedActiveMQ();
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/RestMessagingBootstrapListener.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/RestMessagingBootstrapListener.java
deleted file mode 100644
index d8db6656b9..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/RestMessagingBootstrapListener.java
+++ /dev/null
@@ -1,86 +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.
- */
-package org.apache.activemq.artemis.rest.integration;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.MessageServiceManager;
-import org.apache.activemq.artemis.utils.ObjectInputStreamWithClassLoader;
-import org.jboss.resteasy.spi.Registry;
-import org.jboss.resteasy.spi.ResteasyDeployment;
-
-public class RestMessagingBootstrapListener implements ServletContextListener, ConnectionFactoryOptions {
-
- MessageServiceManager manager;
- private String deserializationBlackList;
- private String deserializationWhiteList;
-
- @Override
- public void contextInitialized(ServletContextEvent contextEvent) {
- ServletContext context = contextEvent.getServletContext();
- ResteasyDeployment resteasyDeployment = (ResteasyDeployment) context.getAttribute(ResteasyDeployment.class.getName());
- if (resteasyDeployment == null) {
- throw new RuntimeException("You must install RESTEasy as a Bootstrap Listener and it must be listed before this class");
- }
- Registry registry = resteasyDeployment.getRegistry();
- String configfile = context.getInitParameter("rest.messaging.config.file");
- deserializationBlackList = context.getInitParameter(ObjectInputStreamWithClassLoader.BLACKLIST_PROPERTY);
- deserializationWhiteList = context.getInitParameter(ObjectInputStreamWithClassLoader.WHITELIST_PROPERTY);
- manager = new MessageServiceManager(this);
-
- if (configfile != null) {
- manager.setConfigResourcePath(configfile);
- }
- try {
- manager.start();
- registry.addSingletonResource(manager.getQueueManager().getDestination());
- registry.addSingletonResource(manager.getTopicManager().getDestination());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public void contextDestroyed(ServletContextEvent servletContextEvent) {
- if (manager != null) {
- manager.stop();
- }
- }
-
- @Override
- public String getDeserializationBlackList() {
- return deserializationBlackList;
- }
-
- @Override
- public void setDeserializationBlackList(String blackList) {
- deserializationBlackList = blackList;
- }
-
- @Override
- public String getDeserializationWhiteList() {
- return deserializationWhiteList;
- }
-
- @Override
- public void setDeserializationWhiteList(String whiteList) {
- deserializationWhiteList = whiteList;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/ServletContextBindingRegistry.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/ServletContextBindingRegistry.java
deleted file mode 100644
index 22b4690fde..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/integration/ServletContextBindingRegistry.java
+++ /dev/null
@@ -1,50 +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.
- */
-package org.apache.activemq.artemis.rest.integration;
-
-import javax.servlet.ServletContext;
-
-import org.apache.activemq.artemis.spi.core.naming.BindingRegistry;
-
-public class ServletContextBindingRegistry implements BindingRegistry {
-
- private ServletContext servletContext;
-
- public ServletContextBindingRegistry(ServletContext servletContext) {
- this.servletContext = servletContext;
- }
-
- @Override
- public Object lookup(String name) {
- return servletContext.getAttribute(name);
- }
-
- @Override
- public boolean bind(String name, Object obj) {
- servletContext.setAttribute(name, obj);
- return true;
- }
-
- @Override
- public void unbind(String name) {
- servletContext.removeAttribute(name);
- }
-
- @Override
- public void close() {
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/AcknowledgedQueueConsumer.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/AcknowledgedQueueConsumer.java
deleted file mode 100644
index 76de4d9412..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/AcknowledgedQueueConsumer.java
+++ /dev/null
@@ -1,242 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
-import java.net.URI;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.api.core.client.ClientConsumer;
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.rest.util.Constants;
-import org.apache.activemq.artemis.rest.util.LinkStrategy;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class AcknowledgedQueueConsumer extends QueueConsumer {
-
- private static final Logger logger = LoggerFactory.getLogger( AcknowledgedQueueConsumer.class );
-
- protected long counter;
- protected String startup = Long.toString(System.currentTimeMillis());
- protected volatile Acknowledgement ack;
-
- public AcknowledgedQueueConsumer(ClientSessionFactory factory,
- String destination,
- String id,
- DestinationServiceManager serviceManager,
- String selector) throws ActiveMQException {
- super(factory, destination, id, serviceManager, selector);
- autoAck = false;
- }
-
- public synchronized Acknowledgement getAck() {
- return ack;
- }
-
- @Override
- @Path("acknowledge-next{index}")
- @POST
- public synchronized Response poll(@HeaderParam(Constants.WAIT_HEADER) @DefaultValue("0") long wait,
- @PathParam("index") long index,
- @Context UriInfo info) {
- logger.debug("Handling POST request for \"" + info.getPath() + "\"");
-
- if (closed) {
- UriBuilder builder = info.getBaseUriBuilder();
- String path = info.getMatchedURIs().get(1);
- builder.path(path).path("acknowledge-next");
- String uri = builder.build().toString();
-
- // redirect to another acknowledge-next
-
- return Response.status(307).location(URI.create(uri)).build();
- }
- return checkIndexAndPoll(wait, info, info.getMatchedURIs().get(1), index);
- }
-
- @Override
- public synchronized void shutdown() {
- super.shutdown();
- if (ack != null) {
- ack = null;
- }
- }
-
- @Path("acknowledgement/{ackToken}")
- @POST
- public synchronized Response acknowledge(@PathParam("ackToken") String ackToken,
- @FormParam("acknowledge") boolean doAcknowledge,
- @Context UriInfo uriInfo) {
- logger.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");
-
- ping(0);
- String basePath = uriInfo.getMatchedURIs().get(1);
- if (closed) {
- Response.ResponseBuilder builder = Response.status(Response.Status.PRECONDITION_FAILED).entity("Could not acknowledge message, it was probably requeued from a timeout").type("text/plain");
- setAcknowledgeLinks(uriInfo, basePath, builder, "-1");
- return builder.build();
- }
-
- if (ack == null || !ack.getAckToken().equals(ackToken)) {
- Response.ResponseBuilder builder = Response.status(Response.Status.PRECONDITION_FAILED).entity("Could not acknowledge message, it was probably requeued from a timeout or you have an old link").type("text/plain");
- setAcknowledgeLinks(uriInfo, basePath, builder, "-1");
- return builder.build();
- }
-
- // clear indexes as we know the client got the message and won't send a duplicate ack-next
- previousIndex = -2;
- lastConsumed = null;
-
- if (ack.wasSet() && doAcknowledge != ack.isAcknowledged()) {
- StringBuilder msg = new StringBuilder("Could not ");
- if (doAcknowledge == false)
- msg.append("un");
- msg.append("acknowledge message because it has already been ");
- if (doAcknowledge == true)
- msg.append("un");
- msg.append("acknowledged");
-
- Response.ResponseBuilder builder = Response.status(Response.Status.PRECONDITION_FAILED).entity(msg.toString()).type("text/plain");
- setAcknowledgeLinks(uriInfo, basePath, builder, "-1");
- return builder.build();
- }
-
- if (ack.wasSet() && doAcknowledge == ack.isAcknowledged()) {
- Response.ResponseBuilder builder = Response.noContent();
- setAcknowledgeLinks(uriInfo, basePath, builder, "-1");
- return builder.build();
- }
-
- if (doAcknowledge) {
- try {
- ack.acknowledge();
- //System.out.println("Acknowledge message: " + ack.getMessage());
- ack.getMessage().acknowledge();
- } catch (ActiveMQException e) {
- throw new RuntimeException(e);
- }
- } else {
- ack.unacknowledge();
- unacknowledge();
- }
- Response.ResponseBuilder builder = Response.noContent();
- setAcknowledgeLinks(uriInfo, basePath, builder, "-1");
- return builder.build();
- }
-
- @Override
- protected ClientMessage receive(long timeoutSecs) throws Exception {
- ClientMessage msg = super.receive(timeoutSecs);
- return msg;
- }
-
- @Override
- protected ClientMessage receiveFromConsumer(long timeoutSecs) throws Exception {
- ClientMessage message = super.receiveFromConsumer(timeoutSecs);
- if (message != null) {
- ack = new Acknowledgement((counter++) + startup, message);
- //System.out.println("---> Setting ack: " + ack.getAckToken());
- }
- return message;
- }
-
- protected String getAckToken() {
- return ack.getAckToken();
- }
-
- protected void unacknowledge() {
- // we close current session so that message is redelivered
- // for temporary queues/topics, create a new session before closing old so we don't lose the temporary topic/queue
-
- ClientConsumer old = consumer;
- ClientSession oldSession = session;
-
- try {
- createSession();
- } catch (Exception e) {
- shutdown();
- throw new RuntimeException(e);
-
- } finally {
- try {
- old.close();
- } catch (ActiveMQException e) {
- }
- try {
- oldSession.close();
- } catch (ActiveMQException e) {
- }
- }
- }
-
- protected void setAcknowledgeLinks(UriInfo uriInfo,
- String basePath,
- Response.ResponseBuilder builder,
- String index) {
- setAcknowledgeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, basePath, index);
- setSessionLink(builder, uriInfo, basePath);
- }
-
- @Override
- protected void setMessageResponseLinks(UriInfo info,
- String basePath,
- Response.ResponseBuilder builder,
- String index) {
- setAcknowledgementLink(builder, info, basePath);
- setSessionLink(builder, info, basePath);
- }
-
- @Override
- protected void setPollTimeoutLinks(UriInfo info, String basePath, Response.ResponseBuilder builder, String index) {
- setAcknowledgeNextLink(serviceManager.getLinkStrategy(), builder, info, basePath, index);
- setSessionLink(builder, info, basePath);
- }
-
- public void setAcknowledgementLink(Response.ResponseBuilder response, UriInfo info, String basePath) {
- UriBuilder builder = info.getBaseUriBuilder();
- builder.path(basePath).path("acknowledgement").path(getAckToken());
- String uri = builder.build().toString();
- serviceManager.getLinkStrategy().setLinkHeader(response, "acknowledgement", "acknowledgement", uri, MediaType.APPLICATION_FORM_URLENCODED);
- }
-
- public static void setAcknowledgeNextLink(LinkStrategy linkStrategy,
- Response.ResponseBuilder response,
- UriInfo info,
- String basePath,
- String index) {
- if (index == null)
- throw new IllegalArgumentException("index cannot be null");
- UriBuilder builder = info.getBaseUriBuilder();
- builder.path(basePath).path("acknowledge-next" + index);
- String uri = builder.build().toString();
- linkStrategy.setLinkHeader(response, "acknowledge-next", "acknowledge-next", uri, MediaType.APPLICATION_FORM_URLENCODED);
- }
-
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/Acknowledgement.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/Acknowledgement.java
deleted file mode 100644
index 5f38c8fec0..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/Acknowledgement.java
+++ /dev/null
@@ -1,61 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-
-public class Acknowledgement {
-
- private final String ackToken;
- private final ClientMessage message;
- private boolean wasSet;
- private boolean acknowledged;
-
- public Acknowledgement(String ackToken, ClientMessage message) {
- this.ackToken = ackToken;
- this.message = message;
- }
-
- public String getAckToken() {
- return ackToken;
- }
-
- public ClientMessage getMessage() {
- return message;
- }
-
- public boolean wasSet() {
- return wasSet;
- }
-
- public void acknowledge() {
- if (wasSet)
- throw new RuntimeException("Ack state is immutable");
- wasSet = true;
- acknowledged = true;
- }
-
- public void unacknowledge() {
- if (wasSet)
- throw new RuntimeException("Ack state is immutable");
- wasSet = true;
- }
-
- public boolean isAcknowledged() {
- return acknowledged;
- }
-}
\ No newline at end of file
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumedHttpMessage.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumedHttpMessage.java
deleted file mode 100644
index ce8b24b223..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumedHttpMessage.java
+++ /dev/null
@@ -1,45 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-import javax.ws.rs.core.Response;
-
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-
-public class ConsumedHttpMessage extends ConsumedMessage {
-
- private byte[] data;
-
- public ConsumedHttpMessage(ClientMessage message) {
- super(message);
- }
-
- @Override
- public void build(Response.ResponseBuilder builder) {
- buildHeaders(builder);
- if (data == null) {
- int size = message.getBodySize();
- if (size > 0) {
- data = new byte[size];
- message.getBodyBuffer().readBytes(data);
- } else {
- data = new byte[0];
- }
- }
- builder.entity(data);
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumedMessage.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumedMessage.java
deleted file mode 100644
index 529d77c278..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumedMessage.java
+++ /dev/null
@@ -1,68 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-import javax.ws.rs.core.Response;
-
-import org.apache.activemq.artemis.api.core.Message;
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.HttpHeaderProperty;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class ConsumedMessage {
-
- private static final Logger logger = LoggerFactory.getLogger(ConsumedMessage.class);
-
- public static final String POSTED_AS_HTTP_MESSAGE = "postedAsHttpMessage";
- protected ClientMessage message;
-
- public ConsumedMessage(ClientMessage message) {
- this.message = message;
- }
-
- public long getMessageID() {
- return message.getMessageID();
- }
-
- public abstract void build(Response.ResponseBuilder builder);
-
- protected void buildHeaders(Response.ResponseBuilder builder) {
- for (SimpleString key : message.getPropertyNames()) {
- String k = key.toString();
- String headerName = HttpHeaderProperty.fromPropertyName(k);
- if (headerName == null) {
- continue;
- }
- builder.header(headerName, message.getStringProperty(k));
- logger.debug("Adding " + headerName + "=" + message.getStringProperty(k));
- }
- }
-
- public static ConsumedMessage createConsumedMessage(ClientMessage message, ConnectionFactoryOptions options) {
- Boolean aBoolean = message.getBooleanProperty(POSTED_AS_HTTP_MESSAGE);
- if (aBoolean != null && aBoolean.booleanValue()) {
- return new ConsumedHttpMessage(message);
- } else if (message.getType() == Message.OBJECT_TYPE) {
- return new ConsumedObjectMessage(message, options);
- } else {
- throw new IllegalArgumentException("ClientMessage must be an HTTP message or an Object message: " + message + " type: " + message.getType());
- }
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumedObjectMessage.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumedObjectMessage.java
deleted file mode 100644
index 9481feb31e..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumedObjectMessage.java
+++ /dev/null
@@ -1,62 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-import javax.ws.rs.core.Response;
-import java.io.ByteArrayInputStream;
-
-import org.apache.activemq.artemis.api.core.Message;
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.utils.ObjectInputStreamWithClassLoader;
-
-public class ConsumedObjectMessage extends ConsumedMessage {
-
- protected Object readObject;
- private ConnectionFactoryOptions options;
-
- public ConsumedObjectMessage(ClientMessage message, ConnectionFactoryOptions options) {
- super(message);
- if (message.getType() != Message.OBJECT_TYPE)
- throw new IllegalArgumentException("Client message must be an OBJECT_TYPE");
- this.options = options;
- }
-
- @Override
- public void build(Response.ResponseBuilder builder) {
- buildHeaders(builder);
- if (readObject == null) {
- int size = message.getBodyBuffer().readInt();
- if (size > 0) {
- byte[] body = new byte[size];
- message.getBodyBuffer().readBytes(body);
- ByteArrayInputStream bais = new ByteArrayInputStream(body);
- try (ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(bais)) {
- if (options != null) {
- ois.setWhiteList(options.getDeserializationWhiteList());
- ois.setBlackList(options.getDeserializationBlackList());
- }
- readObject = ois.readObject();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- }
- builder.entity(readObject);
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumersResource.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumersResource.java
deleted file mode 100644
index 228df5eb79..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumersResource.java
+++ /dev/null
@@ -1,273 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-import javax.ws.rs.DELETE;
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.GET;
-import javax.ws.rs.HEAD;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.rest.ActiveMQRestLogger;
-import org.apache.activemq.artemis.rest.util.TimeoutTask;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ConsumersResource implements TimeoutTask.Callback {
-
- private static final Logger logger = LoggerFactory.getLogger( ConsumersResource.class );
-
- protected ConcurrentMap<String, QueueConsumer> queueConsumers = new ConcurrentHashMap<>();
- protected ClientSessionFactory sessionFactory;
- protected String destination;
- protected final String startup = Long.toString(System.currentTimeMillis());
- protected AtomicLong sessionCounter = new AtomicLong(1);
- protected int consumerTimeoutSeconds;
- protected DestinationServiceManager serviceManager;
-
- protected static final int ACKNOWLEDGED = 0x01;
- protected static final int SELECTOR_SET = 0x02;
-
- public DestinationServiceManager getServiceManager() {
- return serviceManager;
- }
-
- public void setServiceManager(DestinationServiceManager serviceManager) {
- this.serviceManager = serviceManager;
- }
-
- public ClientSessionFactory getSessionFactory() {
- return sessionFactory;
- }
-
- public void setSessionFactory(ClientSessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- }
-
- public String getDestination() {
- return destination;
- }
-
- public void setDestination(String destination) {
- this.destination = destination;
- }
-
- public int getConsumerTimeoutSeconds() {
- return consumerTimeoutSeconds;
- }
-
- public void setConsumerTimeoutSeconds(int consumerTimeoutSeconds) {
- this.consumerTimeoutSeconds = consumerTimeoutSeconds;
- }
-
- @Override
- public boolean testTimeout(String target, boolean autoShutdown) {
- QueueConsumer consumer = queueConsumers.get(target);
- if (consumer == null)
- return false;
- if (System.currentTimeMillis() - consumer.getLastPingTime() > consumerTimeoutSeconds * 1000) {
- ActiveMQRestLogger.LOGGER.shutdownRestConsumer(consumer.getId());
- if (autoShutdown) {
- shutdown(consumer);
- }
- return true;
- } else {
- return false;
- }
- }
-
- @Override
- public void shutdown(String target) {
- QueueConsumer consumer = queueConsumers.get(target);
- if (consumer == null)
- return;
- shutdown(consumer);
- }
-
- private void shutdown(QueueConsumer consumer) {
- synchronized (consumer) {
- consumer.shutdown();
- queueConsumers.remove(consumer.getId());
- }
- }
-
- public void stop() {
- for (QueueConsumer consumer : queueConsumers.values()) {
- consumer.shutdown();
- }
- }
-
- @POST
- public Response createSubscription(@FormParam("autoAck") @DefaultValue("true") boolean autoAck,
- @FormParam("selector") String selector,
- @Context UriInfo uriInfo) {
- logger.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");
-
- try {
- QueueConsumer consumer = null;
- int attributes = 0;
- if (selector != null) {
- attributes = attributes | SELECTOR_SET;
- }
-
- if (autoAck) {
- consumer = createConsumer(selector);
- } else {
- attributes |= ACKNOWLEDGED;
- consumer = createAcknowledgedConsumer(selector);
- }
-
- String attributesSegment = "attributes-" + attributes;
- UriBuilder location = uriInfo.getAbsolutePathBuilder();
- location.path(attributesSegment);
- location.path(consumer.getId());
- Response.ResponseBuilder builder = Response.created(location.build());
-
- if (autoAck) {
- QueueConsumer.setConsumeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(0) + "/" + attributesSegment + "/" + consumer.getId(), "-1");
- } else {
- AcknowledgedQueueConsumer.setAcknowledgeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(0) + "/" + attributesSegment + "/" + consumer.getId(), "-1");
-
- }
- return builder.build();
-
- } catch (ActiveMQException e) {
- throw new RuntimeException(e);
- } finally {
- }
- }
-
- protected void addConsumer(QueueConsumer consumer) {
- queueConsumers.put(consumer.getId(), consumer);
- serviceManager.getTimeoutTask().add(this, consumer.getId());
- }
-
- public QueueConsumer createConsumer(String selector) throws ActiveMQException {
- String genId = sessionCounter.getAndIncrement() + "-queue-" + destination + "-" + startup;
- QueueConsumer consumer = new QueueConsumer(sessionFactory, destination, genId, serviceManager, selector);
- addConsumer(consumer);
- return consumer;
- }
-
- public QueueConsumer createAcknowledgedConsumer(String selector) throws ActiveMQException {
- String genId = sessionCounter.getAndIncrement() + "-queue-" + destination + "-" + startup;
- QueueConsumer consumer = new AcknowledgedQueueConsumer(sessionFactory, destination, genId, serviceManager, selector);
- addConsumer(consumer);
- return consumer;
- }
-
- @Path("attributes-{attributes}/{consumer-id}")
- @GET
- public Response getConsumer(@PathParam("attributes") int attributes,
- @PathParam("consumer-id") String consumerId,
- @Context UriInfo uriInfo) throws Exception {
- logger.debug("Handling GET request for \"" + uriInfo.getPath() + "\"");
-
- return headConsumer(attributes, consumerId, uriInfo);
- }
-
- @Path("attributes-{attributes}/{consumer-id}")
- @HEAD
- public Response headConsumer(@PathParam("attributes") int attributes,
- @PathParam("consumer-id") String consumerId,
- @Context UriInfo uriInfo) throws Exception {
- logger.debug("Handling HEAD request for \"" + uriInfo.getPath() + "\"");
-
- QueueConsumer consumer = findConsumer(attributes, consumerId, uriInfo);
- Response.ResponseBuilder builder = Response.noContent();
- // we synchronize just in case a failed request is still processing
- synchronized (consumer) {
- if ((attributes & ACKNOWLEDGED) > 0) {
- AcknowledgedQueueConsumer ackedConsumer = (AcknowledgedQueueConsumer) consumer;
- Acknowledgement ack = ackedConsumer.getAck();
- if (ack == null || ack.wasSet()) {
- AcknowledgedQueueConsumer.setAcknowledgeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/attributes-" + attributes + "/" + consumer.getId(), Long.toString(consumer.getConsumeIndex()));
- } else {
- ackedConsumer.setAcknowledgementLink(builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/attributes-" + attributes + "/" + consumer.getId());
- }
-
- } else {
- QueueConsumer.setConsumeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/attributes-" + attributes + "/" + consumer.getId(), Long.toString(consumer.getConsumeIndex()));
- }
- }
- return builder.build();
- }
-
- @Path("attributes-{attributes}/{consumer-id}")
- public QueueConsumer findConsumer(@PathParam("attributes") int attributes,
- @PathParam("consumer-id") String consumerId,
- @Context UriInfo uriInfo) throws Exception {
- QueueConsumer consumer = queueConsumers.get(consumerId);
- if (consumer == null) {
- if ((attributes & SELECTOR_SET) > 0) {
-
- Response.ResponseBuilder builder = Response.status(Response.Status.GONE).entity("Cannot reconnect to selector-based consumer. You must recreate the consumer session.").type("text/plain");
- UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
- uriBuilder.path(uriInfo.getMatchedURIs().get(1));
- serviceManager.getLinkStrategy().setLinkHeader(builder, "pull-consumers", "pull-consumers", uriBuilder.build().toString(), null);
- throw new WebApplicationException(builder.build());
-
- }
- if ((attributes & ACKNOWLEDGED) > 0) {
- QueueConsumer tmp = new AcknowledgedQueueConsumer(sessionFactory, destination, consumerId, serviceManager, null);
- consumer = addReconnectedConsumerToMap(consumerId, tmp);
-
- } else {
- QueueConsumer tmp = new QueueConsumer(sessionFactory, destination, consumerId, serviceManager, null);
- consumer = addReconnectedConsumerToMap(consumerId, tmp);
- }
- }
- return consumer;
- }
-
- private QueueConsumer addReconnectedConsumerToMap(String consumerId, QueueConsumer tmp) {
- QueueConsumer consumer;
- consumer = queueConsumers.putIfAbsent(consumerId, tmp);
- if (consumer != null) {
- tmp.shutdown();
- } else {
- consumer = tmp;
- serviceManager.getTimeoutTask().add(this, consumer.getId());
- }
- return consumer;
- }
-
- @Path("attributes-{attributes}/{consumer-id}")
- @DELETE
- public void closeSession(@PathParam("consumer-id") String consumerId, @Context UriInfo uriInfo) {
- logger.debug("Handling DELETE request for \"" + uriInfo.getPath() + "\"");
-
- QueueConsumer consumer = queueConsumers.remove(consumerId);
- if (consumer == null) {
- throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity("Failed to match a consumer to URL" + consumerId).type("text/plain").build());
- }
- consumer.shutdown();
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/DestinationResource.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/DestinationResource.java
deleted file mode 100644
index e28ad897e5..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/DestinationResource.java
+++ /dev/null
@@ -1,48 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-public class DestinationResource {
-
- protected String destination;
- protected PostMessage sender;
- protected DestinationServiceManager serviceManager;
-
- public DestinationServiceManager getServiceManager() {
- return serviceManager;
- }
-
- public void setServiceManager(DestinationServiceManager serviceManager) {
- this.serviceManager = serviceManager;
- }
-
- public PostMessage getSender() {
- return sender;
- }
-
- public void setSender(PostMessage sender) {
- this.sender = sender;
- }
-
- public String getDestination() {
- return destination;
- }
-
- public void setDestination(String destination) {
- this.destination = destination;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/DestinationServiceManager.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/DestinationServiceManager.java
deleted file mode 100644
index 9b0eb1a9a9..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/DestinationServiceManager.java
+++ /dev/null
@@ -1,170 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-import org.apache.activemq.artemis.api.core.TransportConfiguration;
-import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.api.core.client.ServerLocator;
-import org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.util.LinkStrategy;
-import org.apache.activemq.artemis.rest.util.TimeoutTask;
-import org.apache.activemq.artemis.spi.core.naming.BindingRegistry;
-
-public abstract class DestinationServiceManager {
-
- protected ServerLocator locator;
- protected ClientSessionFactory sessionFactory;
- protected ServerLocator consumerServerLocator;
- protected ClientSessionFactory consumerSessionFactory;
- protected boolean started;
- protected String pushStoreFile;
- protected DestinationSettings defaultSettings = DestinationSettings.defaultSettings;
- protected TimeoutTask timeoutTask;
- protected int producerPoolSize;
- protected long producerTimeToLive;
- protected LinkStrategy linkStrategy;
- protected BindingRegistry registry;
-
- protected ConnectionFactoryOptions jmsOptions;
-
- public DestinationServiceManager(ConnectionFactoryOptions jmsOptions) {
- this.jmsOptions = jmsOptions;
- }
-
- public BindingRegistry getRegistry() {
- return registry;
- }
-
- public void setRegistry(BindingRegistry registry) {
- this.registry = registry;
- }
-
- public LinkStrategy getLinkStrategy() {
- return linkStrategy;
- }
-
- public void setLinkStrategy(LinkStrategy linkStrategy) {
- this.linkStrategy = linkStrategy;
- }
-
- public long getProducerTimeToLive() {
- return producerTimeToLive;
- }
-
- public void setProducerTimeToLive(long producerTimeToLive) {
- this.producerTimeToLive = producerTimeToLive;
- }
-
- public int getProducerPoolSize() {
- return producerPoolSize;
- }
-
- public void setProducerPoolSize(int producerPoolSize) {
- this.producerPoolSize = producerPoolSize;
- }
-
- public ClientSessionFactory getConsumerSessionFactory() {
- return consumerSessionFactory;
- }
-
- public void setConsumerSessionFactory(ClientSessionFactory consumerSessionFactory) {
- this.consumerSessionFactory = consumerSessionFactory;
- }
-
- /**
- * @return the consumerServerLocator
- */
- public ServerLocator getConsumerServerLocator() {
- return consumerServerLocator;
- }
-
- /**
- * @param consumerServerLocator the consumerServerLocator to set
- */
- public void setConsumerServerLocator(ServerLocator consumerServerLocator) {
- this.consumerServerLocator = consumerServerLocator;
- }
-
- public TimeoutTask getTimeoutTask() {
- return timeoutTask;
- }
-
- public void setTimeoutTask(TimeoutTask timeoutTask) {
- this.timeoutTask = timeoutTask;
- }
-
- public DestinationSettings getDefaultSettings() {
- return defaultSettings;
- }
-
- public void setDefaultSettings(DestinationSettings defaultSettings) {
- this.defaultSettings = defaultSettings;
- }
-
- public ServerLocator getServerLocator() {
- return this.locator;
- }
-
- public void setServerLocator(ServerLocator locator) {
- this.locator = locator;
- }
-
- public ClientSessionFactory getSessionFactory() {
- return sessionFactory;
- }
-
- public void setSessionFactory(ClientSessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- }
-
- public String getPushStoreFile() {
- return pushStoreFile;
- }
-
- public void setPushStoreFile(String pushStoreFile) {
- this.pushStoreFile = pushStoreFile;
- }
-
- protected void initDefaults() {
- if (locator == null) {
- locator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(InVMConnectorFactory.class.getName()));
- }
- if (sessionFactory == null) {
- try {
- sessionFactory = locator.createSessionFactory();
- } catch (Exception e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- if (consumerSessionFactory == null)
- consumerSessionFactory = sessionFactory;
-
- if (timeoutTask == null)
- throw new RuntimeException("TimeoutTask is not set");
- }
-
- public abstract void start() throws Exception;
-
- public abstract void stop();
-
- public ConnectionFactoryOptions getJmsOptions() {
- return jmsOptions;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/DestinationSettings.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/DestinationSettings.java
deleted file mode 100644
index 35657eee85..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/DestinationSettings.java
+++ /dev/null
@@ -1,56 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-public class DestinationSettings {
-
- protected boolean duplicatesAllowed;
- private boolean durableSend;
- private int consumerSessionTimeoutSeconds = 1000;
-
- public boolean isDuplicatesAllowed() {
- return duplicatesAllowed;
- }
-
- public void setDuplicatesAllowed(boolean duplicatesAllowed) {
- this.duplicatesAllowed = duplicatesAllowed;
- }
-
- public int getConsumerSessionTimeoutSeconds() {
- return consumerSessionTimeoutSeconds;
- }
-
- public void setConsumerSessionTimeoutSeconds(int consumerSessionTimeoutSeconds) {
- this.consumerSessionTimeoutSeconds = consumerSessionTimeoutSeconds;
- }
-
- public boolean isDurableSend() {
- return durableSend;
- }
-
- public void setDurableSend(boolean durableSend) {
- this.durableSend = durableSend;
- }
-
- public static final DestinationSettings defaultSettings;
-
- static {
- defaultSettings = new DestinationSettings();
- defaultSettings.setDuplicatesAllowed(true);
- defaultSettings.setDurableSend(false);
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/PostMessage.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/PostMessage.java
deleted file mode 100644
index 194d709b00..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/PostMessage.java
+++ /dev/null
@@ -1,269 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
-import java.net.URI;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.api.core.Message;
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.api.core.client.ClientProducer;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.rest.util.HttpMessageHelper;
-import org.apache.activemq.artemis.utils.UUID;
-import org.apache.activemq.artemis.utils.UUIDGenerator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class PostMessage {
-
- private static final Logger logger = LoggerFactory.getLogger(PostMessage.class);
-
- protected ClientSessionFactory sessionFactory;
- protected String destination;
- protected boolean defaultDurable = false;
- protected DestinationServiceManager serviceManager;
- private AtomicLong counter = new AtomicLong(1);
- private final String startupTime = Long.toString(System.currentTimeMillis());
- protected long producerTimeToLive;
- protected ArrayBlockingQueue<Pooled> pool;
- protected int poolSize = 10;
-
- protected static class Pooled {
-
- public ClientSession session;
- public ClientProducer producer;
-
- private Pooled(ClientSession session, ClientProducer producer) {
- this.session = session;
- this.producer = producer;
- }
- }
-
- protected String generateDupId() {
- return startupTime + Long.toString(counter.incrementAndGet());
- }
-
- public void publish(HttpHeaders headers,
- byte[] body,
- String dup,
- boolean durable,
- Long ttl,
- Long expiration,
- Integer priority) throws Exception {
- Pooled pooled = getPooled();
- try {
- ClientProducer producer = pooled.producer;
- ClientMessage message = createActiveMQMessage(headers, body, durable, ttl, expiration, priority, pooled.session);
- message.putStringProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(), dup);
- producer.send(message);
- logger.debug("Sent message: " + message);
- pool.add(pooled);
- } catch (Exception ex) {
- try {
- pooled.session.close();
- } catch (ActiveMQException e) {
- }
- addPooled();
- throw ex;
- }
- }
-
- @PUT
- @Path("{id}")
- public Response putWithId(@PathParam("id") String dupId,
- @QueryParam("durable") Boolean durable,
- @QueryParam("ttl") Long ttl,
- @QueryParam("expiration") Long expiration,
- @QueryParam("priority") Integer priority,
- @Context HttpHeaders headers,
- @Context UriInfo uriInfo,
- byte[] body) {
- logger.debug("Handling PUT request for \"" + uriInfo.getRequestUri() + "\"");
-
- return internalPostWithId(dupId, durable, ttl, expiration, priority, headers, uriInfo, body);
- }
-
- @POST
- @Path("{id}")
- public Response postWithId(@PathParam("id") String dupId,
- @QueryParam("durable") Boolean durable,
- @QueryParam("ttl") Long ttl,
- @QueryParam("expiration") Long expiration,
- @QueryParam("priority") Integer priority,
- @Context HttpHeaders headers,
- @Context UriInfo uriInfo,
- byte[] body) {
- logger.debug("Handling POST request for \"" + uriInfo.getRequestUri() + "\"");
-
- return internalPostWithId(dupId, durable, ttl, expiration, priority, headers, uriInfo, body);
- }
-
- private Response internalPostWithId(String dupId,
- Boolean durable,
- Long ttl,
- Long expiration,
- Integer priority,
- HttpHeaders headers,
- UriInfo uriInfo,
- byte[] body) {
- String matched = uriInfo.getMatchedURIs().get(1);
- UriBuilder nextBuilder = uriInfo.getBaseUriBuilder();
- String nextId = generateDupId();
- nextBuilder.path(matched).path(nextId);
- URI next = nextBuilder.build();
-
- boolean isDurable = defaultDurable;
- if (durable != null) {
- isDurable = durable.booleanValue();
- }
- try {
- publish(headers, body, dupId, isDurable, ttl, expiration, priority);
- } catch (Exception e) {
- Response error = Response.serverError().entity("Problem posting message: " + e.getMessage()).type("text/plain").build();
- throw new WebApplicationException(e, error);
- }
- Response.ResponseBuilder builder = Response.status(201);
- serviceManager.getLinkStrategy().setLinkHeader(builder, "create-next", "create-next", next.toString(), "*/*");
- return builder.build();
- }
-
- public long getProducerTimeToLive() {
- return producerTimeToLive;
- }
-
- public void setProducerTimeToLive(long producerTimeToLive) {
- this.producerTimeToLive = producerTimeToLive;
- }
-
- public DestinationServiceManager getServiceManager() {
- return serviceManager;
- }
-
- public void setServiceManager(DestinationServiceManager serviceManager) {
- this.serviceManager = serviceManager;
- }
-
- public ClientSessionFactory getSessionFactory() {
- return sessionFactory;
- }
-
- public void setSessionFactory(ClientSessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- }
-
- public String getDestination() {
- return destination;
- }
-
- public void setDestination(String destination) {
- this.destination = destination;
- }
-
- public boolean isDefaultDurable() {
- return defaultDurable;
- }
-
- public void setDefaultDurable(boolean defaultDurable) {
- this.defaultDurable = defaultDurable;
- }
-
- public int getPoolSize() {
- return poolSize;
- }
-
- public void setPoolSize(int poolSize) {
- this.poolSize = poolSize;
- }
-
- public void init() throws Exception {
- pool = new ArrayBlockingQueue<>(poolSize);
- for (int i = 0; i < poolSize; i++) {
- addPooled();
- }
- }
-
- protected void addPooled() throws ActiveMQException {
- ClientSession session = sessionFactory.createSession();
- ClientProducer producer = session.createProducer(destination);
- session.start();
- pool.add(new Pooled(session, producer));
- }
-
- protected Pooled getPooled() throws InterruptedException {
- Pooled pooled = pool.poll(1, TimeUnit.SECONDS);
- if (pooled == null) {
- throw new WebApplicationException(Response.status(503).entity("Timed out waiting for available producer.").type("text/plain").build());
- }
- return pooled;
- }
-
- public void cleanup() {
- for (Pooled pooled : pool) {
- try {
- pooled.session.close();
- } catch (ActiveMQException e) {
- throw new RuntimeException(e);
- }
- }
- }
-
- protected ClientMessage createActiveMQMessage(HttpHeaders headers,
- byte[] body,
- boolean durable,
- Long ttl,
- Long expiration,
- Integer priority,
- ClientSession session) throws Exception {
- ClientMessage message = session.createMessage(Message.BYTES_TYPE, durable);
-
- // HORNETQ-962
- UUID uid = UUIDGenerator.getInstance().generateUUID();
- message.setUserID(uid);
-
- if (expiration != null) {
- message.setExpiration(expiration.longValue());
- } else if (ttl != null) {
- message.setExpiration(System.currentTimeMillis() + ttl.longValue());
- } else if (producerTimeToLive > 0) {
- message.setExpiration(System.currentTimeMillis() + producerTimeToLive);
- }
- if (priority != null) {
- byte p = priority.byteValue();
- if (p >= 0 && p <= 9) {
- message.setPriority(p);
- }
- }
- HttpMessageHelper.writeHttpMessage(headers, body, message);
- return message;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/PostMessageDupsOk.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/PostMessageDupsOk.java
deleted file mode 100644
index 64de6739ec..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/PostMessageDupsOk.java
+++ /dev/null
@@ -1,91 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-import javax.ws.rs.POST;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
-import java.net.URI;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.api.core.client.ClientProducer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Implements simple "create" link. Returns 201 with Location of created resource as per HTTP
- */
-public class PostMessageDupsOk extends PostMessage {
-
- private static final Logger logger = LoggerFactory.getLogger(PostMessageDupsOk.class);
-
- public void publish(HttpHeaders headers,
- byte[] body,
- boolean durable,
- Long ttl,
- Long expiration,
- Integer priority) throws Exception {
- Pooled pooled = getPooled();
- try {
- ClientProducer producer = pooled.producer;
- ClientMessage message = createActiveMQMessage(headers, body, durable, ttl, expiration, priority, pooled.session);
- producer.send(message);
- logger.debug("Sent message: " + message);
- pool.add(pooled);
- } catch (Exception ex) {
- try {
- pooled.session.close();
- } catch (ActiveMQException e) {
- }
- addPooled();
- throw ex;
- }
- }
-
- @POST
- public Response create(@Context HttpHeaders headers,
- @QueryParam("durable") Boolean durable,
- @QueryParam("ttl") Long ttl,
- @QueryParam("expiration") Long expiration,
- @QueryParam("priority") Integer priority,
- @Context UriInfo uriInfo,
- byte[] body) {
- logger.debug("Handling POST request for \"" + uriInfo.getRequestUri() + "\"");
-
- try {
- boolean isDurable = defaultDurable;
- if (durable != null) {
- isDurable = durable.booleanValue();
- }
- publish(headers, body, isDurable, ttl, expiration, priority);
- } catch (Exception e) {
- Response error = Response.serverError().entity("Problem posting message: " + e.getMessage()).type("text/plain").build();
- throw new WebApplicationException(e, error);
- }
- Response.ResponseBuilder builder = Response.status(201);
- UriBuilder nextBuilder = uriInfo.getAbsolutePathBuilder();
- URI next = nextBuilder.build();
- serviceManager.getLinkStrategy().setLinkHeader(builder, "create-next", "create-next", next.toString(), "*/*");
- return builder.build();
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/PostMessageNoDups.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/PostMessageNoDups.java
deleted file mode 100644
index 70aaff5da9..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/PostMessageNoDups.java
+++ /dev/null
@@ -1,43 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-import javax.ws.rs.POST;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * implements reliable "create", "create-next" pattern defined by REST-* Messaging specification
- */
-public class PostMessageNoDups extends PostMessage {
-
- private static final Logger logger = LoggerFactory.getLogger(PostMessageNoDups.class);
-
- @POST
- public Response redirectCreation(@Context UriInfo uriInfo) {
- logger.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");
-
- String id = generateDupId();
- Response.ResponseBuilder res = Response.status(Response.Status.TEMPORARY_REDIRECT.getStatusCode());
- res.location(uriInfo.getAbsolutePathBuilder().path(id).build());
- return res.build();
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueConsumer.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueConsumer.java
deleted file mode 100644
index a08010319d..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueConsumer.java
+++ /dev/null
@@ -1,269 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
-import java.net.URI;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.api.core.client.ClientConsumer;
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.util.Constants;
-import org.apache.activemq.artemis.rest.util.LinkStrategy;
-import org.apache.activemq.artemis.utils.SelectorTranslator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Auto-acknowledged consumer
- */
-public class QueueConsumer {
- private static final Logger logger = LoggerFactory.getLogger( QueueConsumer.class );
-
- protected ClientSessionFactory factory;
- protected ClientSession session;
- protected ClientConsumer consumer;
- protected String destination;
- protected boolean closed;
- protected String id;
- protected long lastPing = System.currentTimeMillis();
- protected DestinationServiceManager serviceManager;
- protected boolean autoAck = true;
- protected String selector;
-
- /**
- * token used to create consume-next links
- */
- protected long previousIndex = -1;
- protected ConsumedMessage lastConsumed;
-
- public long getConsumeIndex() {
- if (lastConsumed == null)
- return -1;
- return lastConsumed.getMessageID();
- }
-
- public DestinationServiceManager getServiceManager() {
- return serviceManager;
- }
-
- public void setServiceManager(DestinationServiceManager serviceManager) {
- this.serviceManager = serviceManager;
- }
-
- public long getLastPingTime() {
- return lastPing;
- }
-
- protected void ping(long offsetSecs) {
- lastPing = System.currentTimeMillis() + (offsetSecs * 1000);
- }
-
- public QueueConsumer(ClientSessionFactory factory,
- String destination,
- String id,
- DestinationServiceManager serviceManager,
- String selector) throws ActiveMQException {
- this.factory = factory;
- this.destination = destination;
- this.id = id;
- this.serviceManager = serviceManager;
- this.selector = selector;
-
- createSession();
- }
-
- public String getId() {
- return id;
- }
-
- public boolean isClosed() {
- return closed;
- }
-
- public synchronized void shutdown() {
- if (closed)
- return;
- closed = true;
- lastConsumed = null;
- previousIndex = -2;
- try {
- consumer.close();
- logger.debug("Closed consumer: " + consumer);
- } catch (Exception e) {
- }
-
- try {
- session.close();
- logger.debug("Closed session: " + session);
- } catch (Exception e) {
- }
- session = null;
- consumer = null;
- }
-
- @Path("consume-next{index}")
- @POST
- public synchronized Response poll(@HeaderParam(Constants.WAIT_HEADER) @DefaultValue("0") long wait,
- @PathParam("index") long index,
- @Context UriInfo info) {
- logger.debug("Handling POST request for \"" + info.getRequestUri() + "\"");
-
- if (closed) {
- UriBuilder builder = info.getBaseUriBuilder();
- builder.path(info.getMatchedURIs().get(1)).path("consume-next");
- String uri = builder.build().toString();
-
- // redirect to another consume-next
-
- return Response.status(307).location(URI.create(uri)).build();
- }
- return checkIndexAndPoll(wait, info, info.getMatchedURIs().get(1), index);
- }
-
- protected Response checkIndexAndPoll(long wait, UriInfo info, String basePath, long index) {
- ping(wait);
-
- if (lastConsumed == null && index > 0) {
- return Response.status(412).entity("You are using an old consume-next link and are out of sync with the JMS session on the server").type("text/plain").build();
- }
- if (lastConsumed != null) {
- if (index == previousIndex) {
- String token = Long.toString(lastConsumed.getMessageID());
- return getMessageResponse(lastConsumed, info, basePath, token).build();
- }
- if (index != lastConsumed.getMessageID()) {
- return Response.status(412).entity("You are using an old consume-next link and are out of sync with the JMS session on the server").type("text/plain").build();
- }
- }
-
- try {
- return pollWithIndex(wait, info, basePath, index);
- } finally {
- ping(0); // ping again as we don't want wait time included in timeout.
- }
- }
-
- protected Response pollWithIndex(long wait, UriInfo info, String basePath, long index) {
- try {
- ClientMessage message = receive(wait);
- if (message == null) {
- Response.ResponseBuilder builder = Response.status(503).entity("Timed out waiting for message receive.").type("text/plain");
- setPollTimeoutLinks(info, basePath, builder, Long.toString(index));
- return builder.build();
- }
- previousIndex = index;
- lastConsumed = ConsumedMessage.createConsumedMessage(message, this.getJmsOptions());
- String token = Long.toString(lastConsumed.getMessageID());
- Response response = getMessageResponse(lastConsumed, info, basePath, token).build();
- if (autoAck)
- message.acknowledge();
- return response;
- } catch (Exception e) {
- Response errorResponse = Response.serverError().entity(e.getMessage()).status(Response.Status.INTERNAL_SERVER_ERROR).build();
- return errorResponse;
- }
- }
-
- protected void createSession() throws ActiveMQException {
- session = factory.createSession(true, true, 0);
- logger.debug("Created session: " + session);
- if (selector == null) {
- consumer = session.createConsumer(destination);
- } else {
- consumer = session.createConsumer(destination, SelectorTranslator.convertToActiveMQFilterString(selector));
- }
- logger.debug("Created consumer: " + consumer);
- session.start();
- }
-
- protected ClientMessage receiveFromConsumer(long timeoutSecs) throws Exception {
- ClientMessage m = null;
- if (timeoutSecs <= 0) {
- m = consumer.receive(1);
- } else {
- m = consumer.receive(timeoutSecs * 1000);
- }
-
- logger.debug("Returning message " + m + " from consumer: " + consumer);
-
- return m;
- }
-
- protected ClientMessage receive(long timeoutSecs) throws Exception {
- return receiveFromConsumer(timeoutSecs);
- }
-
- protected void setPollTimeoutLinks(UriInfo info, String basePath, Response.ResponseBuilder builder, String index) {
- setSessionLink(builder, info, basePath);
- setConsumeNextLink(serviceManager.getLinkStrategy(), builder, info, basePath, index);
- }
-
- protected Response.ResponseBuilder getMessageResponse(ConsumedMessage msg,
- UriInfo info,
- String basePath,
- String index) {
- Response.ResponseBuilder responseBuilder = Response.ok();
- setMessageResponseLinks(info, basePath, responseBuilder, index);
- msg.build(responseBuilder);
- return responseBuilder;
- }
-
- protected void setMessageResponseLinks(UriInfo info,
- String basePath,
- Response.ResponseBuilder responseBuilder,
- String index) {
- setConsumeNextLink(serviceManager.getLinkStrategy(), responseBuilder, info, basePath, index);
- setSessionLink(responseBuilder, info, basePath);
- }
-
- public static void setConsumeNextLink(LinkStrategy linkStrategy,
- Response.ResponseBuilder response,
- UriInfo info,
- String basePath,
- String index) {
- if (index == null)
- throw new IllegalArgumentException("index cannot be null");
- UriBuilder builder = info.getBaseUriBuilder();
- builder.path(basePath).path("consume-next" + index);
- String uri = builder.build().toString();
- linkStrategy.setLinkHeader(response, "consume-next", "consume-next", uri, MediaType.APPLICATION_FORM_URLENCODED);
- }
-
- public void setSessionLink(Response.ResponseBuilder response, UriInfo info, String basePath) {
- UriBuilder builder = info.getBaseUriBuilder();
- builder.path(basePath);
- String uri = builder.build().toString();
- serviceManager.getLinkStrategy().setLinkHeader(response, "consumer", "consumer", uri, MediaType.APPLICATION_XML);
- }
-
- public ConnectionFactoryOptions getJmsOptions() {
- return serviceManager.getJmsOptions();
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueDeployment.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueDeployment.java
deleted file mode 100644
index d5105604b8..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueDeployment.java
+++ /dev/null
@@ -1,39 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-public class QueueDeployment extends DestinationSettings {
-
- private String name;
-
- public QueueDeployment() {
- }
-
- public QueueDeployment(String name, boolean duplicatesAllowed) {
- this.name = name;
- this.duplicatesAllowed = duplicatesAllowed;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
-}
\ No newline at end of file
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueDestinationsResource.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueDestinationsResource.java
deleted file mode 100644
index 189c4f31ef..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueDestinationsResource.java
+++ /dev/null
@@ -1,175 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import java.net.URI;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.api.core.QueueConfiguration;
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
-import org.apache.activemq.artemis.jms.client.ActiveMQQueue;
-import org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration;
-import org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration;
-import org.apache.activemq.artemis.rest.queue.push.PushConsumerResource;
-import org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration;
-import org.apache.activemq.artemis.rest.util.Constants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-
-@Path(Constants.PATH_FOR_QUEUES)
-public class QueueDestinationsResource {
-
- private static final Logger logger = LoggerFactory.getLogger(QueueDestinationsResource.class);
-
- private final Map<String, QueueResource> queues = new ConcurrentHashMap<>();
- private final QueueServiceManager manager;
-
- public QueueDestinationsResource(QueueServiceManager manager) {
- this.manager = manager;
- }
-
- @POST
- @Consumes("application/activemq.jms.queue+xml")
- public Response createJmsQueue(@Context UriInfo uriInfo, Document document) {
- logger.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");
-
- try {
- JMSQueueConfiguration queue = FileJMSConfiguration.parseQueueConfiguration(document.getDocumentElement());
- ActiveMQQueue activeMQQueue = ActiveMQDestination.createQueue(queue.getName());
- String queueName = activeMQQueue.getAddress();
- ClientSession session = manager.getSessionFactory().createSession(false, false, false);
- try {
-
- ClientSession.QueueQuery query = session.queueQuery(new SimpleString(queueName));
- if (!query.isExists()) {
- if (queue.getSelector() != null) {
- session.createQueue(new QueueConfiguration(queueName).setFilterString(queue.getSelector()).setDurable(queue.isDurable()));
- } else {
- session.createQueue(new QueueConfiguration(queueName).setDurable(queue.isDurable()));
- }
-
- } else {
- throw new WebApplicationException(Response.status(412).type("text/plain").entity("Queue already exists.").build());
- }
- } finally {
- try {
- session.close();
- } catch (Exception ignored) {
- }
- }
- URI uri = uriInfo.getRequestUriBuilder().path(queueName).build();
- return Response.created(uri).build();
- } catch (Exception e) {
- if (e instanceof WebApplicationException)
- throw (WebApplicationException) e;
- throw new WebApplicationException(e, Response.serverError().type("text/plain").entity("Failed to create queue.").build());
- }
- }
-
- public Map<String, QueueResource> getQueues() {
- return queues;
- }
-
- @Path("/{queue-name}")
- public synchronized QueueResource findQueue(@PathParam("queue-name") String name) throws Exception {
- QueueResource queue = queues.get(name);
- if (queue == null) {
- String queueName = name;
- ClientSession session = manager.getSessionFactory().createSession(false, false, false);
- try {
- ClientSession.QueueQuery query = session.queueQuery(new SimpleString(queueName));
- if (!query.isExists()) {
- throw new WebApplicationException(Response.status(404).type("text/plain").entity("Queue '" + name + "' does not exist").build());
- }
- DestinationSettings queueSettings = manager.getDefaultSettings();
- boolean defaultDurable = queueSettings.isDurableSend() || query.isDurable();
-
- queue = createQueueResource(queueName, defaultDurable, queueSettings.getConsumerSessionTimeoutSeconds(), queueSettings.isDuplicatesAllowed());
- } finally {
- try {
- session.close();
- } catch (ActiveMQException e) {
- }
- }
- }
- return queue;
- }
-
- public QueueResource createQueueResource(String queueName,
- boolean defaultDurable,
- int timeoutSeconds,
- boolean duplicates) throws Exception {
- QueueResource queueResource = new QueueResource();
- queueResource.setQueueDestinationsResource(this);
- queueResource.setDestination(queueName);
- queueResource.setServiceManager(manager);
-
- ConsumersResource consumers = new ConsumersResource();
- consumers.setConsumerTimeoutSeconds(timeoutSeconds);
- consumers.setDestination(queueName);
- consumers.setSessionFactory(manager.getConsumerSessionFactory());
- consumers.setServiceManager(manager);
- queueResource.setConsumers(consumers);
-
- PushConsumerResource push = new PushConsumerResource();
- push.setDestination(queueName);
- push.setSessionFactory(manager.getConsumerSessionFactory());
- push.setJmsOptions(manager.getJmsOptions());
- queueResource.setPushConsumers(push);
-
- PostMessage sender = null;
- if (duplicates) {
- sender = new PostMessageDupsOk();
- } else {
- sender = new PostMessageNoDups();
- }
- sender.setServiceManager(manager);
- sender.setDefaultDurable(defaultDurable);
- sender.setDestination(queueName);
- sender.setSessionFactory(manager.getSessionFactory());
- sender.setPoolSize(manager.getProducerPoolSize());
- sender.setProducerTimeToLive(manager.getProducerTimeToLive());
- sender.init();
- queueResource.setSender(sender);
-
- if (manager.getPushStore() != null) {
- push.setPushStore(manager.getPushStore());
- List<PushRegistration> regs = manager.getPushStore().getByDestination(queueName);
- for (PushRegistration reg : regs) {
- push.addRegistration(reg);
- }
- }
-
- queueResource.start();
- getQueues().put(queueName, queueResource);
- return queueResource;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueResource.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueResource.java
deleted file mode 100644
index ba1cca1f83..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueResource.java
+++ /dev/null
@@ -1,179 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HEAD;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
-
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.rest.queue.push.PushConsumerResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class QueueResource extends DestinationResource {
-
- private static final Logger logger = LoggerFactory.getLogger(QueueResource.class);
-
- protected ConsumersResource consumers;
- protected PushConsumerResource pushConsumers;
- private QueueDestinationsResource queueDestinationsResource;
-
- public void start() throws Exception {
- }
-
- public void stop() {
- consumers.stop();
- pushConsumers.stop();
- sender.cleanup();
- }
-
- @GET
- @Produces("application/xml")
- public Response get(@Context UriInfo uriInfo, @Context HttpServletRequest requestContext) {
- logger.debug("Handling GET request for \"" + destination + "\" from " + requestContext.getRemoteAddr() + ":" + requestContext.getRemotePort());
-
- StringBuilder msg = new StringBuilder();
- msg.append("<queue>").append("<name>").append(destination).append("</name>").append("<atom:link rel=\"create\" href=\"").append(createSenderLink(uriInfo)).append("\"/>").append("<atom:link rel=\"create-with-id\" href=\"").append(createSenderWithIdLink(uriInfo)).append("\"/>").append("<atom:link rel=\"pull-consumers\" href=\"").append(createConsumersLink(uriInfo)).append("\"/>").append("<atom:link rel=\"push-consumers\" href=\"").append(createPushConsumersLink(uriInfo)).append("\"/>")
-
- .append("</queue>");
-
- Response.ResponseBuilder builder = Response.ok(msg.toString());
- setSenderLink(builder, uriInfo);
- setSenderWithIdLink(builder, uriInfo);
- setConsumersLink(builder, uriInfo);
- setPushConsumersLink(builder, uriInfo);
- return builder.build();
- }
-
- @HEAD
- @Produces("application/xml")
- public Response head(@Context UriInfo uriInfo) {
- logger.debug("Handling HEAD request for \"" + uriInfo.getRequestUri() + "\"");
-
- Response.ResponseBuilder builder = Response.ok();
- setSenderLink(builder, uriInfo);
- setSenderWithIdLink(builder, uriInfo);
- setConsumersLink(builder, uriInfo);
- setPushConsumersLink(builder, uriInfo);
- return builder.build();
- }
-
- protected void setSenderLink(Response.ResponseBuilder response, UriInfo info) {
- String uri = createSenderLink(info);
- serviceManager.getLinkStrategy().setLinkHeader(response, "create", "create", uri, null);
- }
-
- protected String createSenderLink(UriInfo info) {
- UriBuilder builder = info.getRequestUriBuilder();
- builder.path("create");
- String uri = builder.build().toString();
- return uri;
- }
-
- protected void setSenderWithIdLink(Response.ResponseBuilder response, UriInfo info) {
- String uri = createSenderWithIdLink(info);
- serviceManager.getLinkStrategy().setLinkHeader(response, "create-with-id", "create-with-id", uri, null);
- }
-
- protected String createSenderWithIdLink(UriInfo info) {
- UriBuilder builder = info.getRequestUriBuilder();
- builder.path("create");
- String uri = builder.build().toString();
- uri += "/{id}";
- return uri;
- }
-
- protected void setConsumersLink(Response.ResponseBuilder response, UriInfo info) {
- String uri = createConsumersLink(info);
- serviceManager.getLinkStrategy().setLinkHeader(response, "pull-consumers", "pull-consumers", uri, null);
- }
-
- protected String createConsumersLink(UriInfo info) {
- UriBuilder builder = info.getRequestUriBuilder();
- builder.path("pull-consumers");
- String uri = builder.build().toString();
- return uri;
- }
-
- protected void setPushConsumersLink(Response.ResponseBuilder response, UriInfo info) {
- String uri = createPushConsumersLink(info);
- serviceManager.getLinkStrategy().setLinkHeader(response, "push-consumers", "push-consumers", uri, null);
- }
-
- protected String createPushConsumersLink(UriInfo info) {
- UriBuilder builder = info.getRequestUriBuilder();
- builder.path("push-consumers");
- String uri = builder.build().toString();
- return uri;
- }
-
- public void setConsumers(ConsumersResource consumers) {
- this.consumers = consumers;
- }
-
- @Path("create")
- public PostMessage post() throws Exception {
- return sender;
- }
-
- @Path("pull-consumers")
- public ConsumersResource getConsumers() {
- return consumers;
- }
-
- public void setPushConsumers(PushConsumerResource pushConsumers) {
- this.pushConsumers = pushConsumers;
- }
-
- @Path("push-consumers")
- public PushConsumerResource getPushConsumers() {
- return pushConsumers;
- }
-
- public void setQueueDestinationsResource(QueueDestinationsResource queueDestinationsResource) {
- this.queueDestinationsResource = queueDestinationsResource;
- }
-
- @DELETE
- public void deleteQueue(@Context UriInfo uriInfo) throws Exception {
- logger.debug("Handling DELETE request for \"" + uriInfo.getPath() + "\"");
-
- queueDestinationsResource.getQueues().remove(destination);
- stop();
-
- ClientSession session = serviceManager.getSessionFactory().createSession(false, false, false);
- try {
- SimpleString queueName = new SimpleString(destination);
- session.deleteQueue(queueName);
- } finally {
- try {
- session.close();
- } catch (Exception ignored) {
- }
- }
- }
-
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueServiceManager.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueServiceManager.java
deleted file mode 100644
index 2907daa3c5..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/QueueServiceManager.java
+++ /dev/null
@@ -1,116 +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.
- */
-package org.apache.activemq.artemis.rest.queue;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.activemq.artemis.api.core.QueueConfiguration;
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.api.core.RoutingType;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.queue.push.FilePushStore;
-import org.apache.activemq.artemis.rest.queue.push.PushStore;
-
-public class QueueServiceManager extends DestinationServiceManager {
-
- protected PushStore pushStore;
- protected List<QueueDeployment> queues = new ArrayList<>();
- protected QueueDestinationsResource destination;
-
- public QueueServiceManager(ConnectionFactoryOptions jmsOptions) {
- super(jmsOptions);
- }
-
- public List<QueueDeployment> getQueues() {
- return queues;
- }
-
- public void setQueues(List<QueueDeployment> queues) {
- this.queues = queues;
- }
-
- public PushStore getPushStore() {
- return pushStore;
- }
-
- public void setPushStore(PushStore pushStore) {
- this.pushStore = pushStore;
- }
-
- public QueueDestinationsResource getDestination() {
- return destination;
- }
-
- public void setDestination(QueueDestinationsResource destination) {
- this.destination = destination;
- }
-
- @Override
- public void start() throws Exception {
- initDefaults();
-
- destination = new QueueDestinationsResource(this);
-
- started = true;
-
- if (pushStoreFile != null && pushStore == null) {
- pushStore = new FilePushStore(pushStoreFile);
- }
-
- for (QueueDeployment queueDeployment : queues) {
- deploy(queueDeployment);
- }
- }
-
- public void deploy(QueueDeployment queueDeployment) throws Exception {
- if (!started) {
- throw new Exception("You must start() this class instance before deploying");
- }
- String queueName = queueDeployment.getName();
- try (ClientSession session = sessionFactory.createSession(false, false, false)) {
- ClientSession.AddressQuery query = session.addressQuery(SimpleString.toSimpleString(queueName));
- if (!query.isExists()) {
- session.createAddress(SimpleString.toSimpleString(queueName), RoutingType.ANYCAST, true);
- session.createQueue(new QueueConfiguration(queueName).setRoutingType(RoutingType.ANYCAST).setDurable(queueDeployment.isDurableSend()));
- } else {
- ClientSession.QueueQuery qquery = session.queueQuery(SimpleString.toSimpleString(queueName));
- if (!qquery.isExists()) {
- session.createQueue(new QueueConfiguration(queueName).setRoutingType(RoutingType.ANYCAST).setDurable(queueDeployment.isDurableSend()));
- }
- }
- }
-
- destination.createQueueResource(queueName, queueDeployment.isDurableSend(), queueDeployment.getConsumerSessionTimeoutSeconds(), queueDeployment.isDuplicatesAllowed());
-
- }
-
- @Override
- public void stop() {
- if (started == false)
- return;
- for (QueueResource queue : destination.getQueues().values()) {
- queue.stop();
- }
- try {
- timeoutTask.stop();
- sessionFactory.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/ActiveMQPushStrategy.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/ActiveMQPushStrategy.java
deleted file mode 100644
index b2a08682c0..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/ActiveMQPushStrategy.java
+++ /dev/null
@@ -1,77 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push;
-
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.rest.queue.push.xml.XmlHttpHeader;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.specimpl.ResteasyUriBuilder;
-import org.jboss.resteasy.spi.Link;
-
-/**
- * Forwarding to an ActiveMQ/REST-* endpoing
- */
-public class ActiveMQPushStrategy extends UriTemplateStrategy {
-
- protected boolean initialized = false;
-
- @Override
- public void start() throws Exception {
- // initialize();
- }
-
- protected void initialize() throws Exception {
- super.start();
- initialized = true;
- initAuthentication();
- ClientRequest request = executor.createRequest(registration.getTarget().getHref());
- for (XmlHttpHeader header : registration.getHeaders()) {
- request.header(header.getName(), header.getValue());
- }
- ClientResponse<?> res = request.head();
- if (res.getStatus() != 200) {
- throw new RuntimeException("Failed to query REST destination for init information. Status: " + res.getStatus());
- }
- String url = (String) res.getHeaders().getFirst("msg-create-with-id");
- if (url == null) {
- if (res.getLinkHeader() == null) {
- throw new RuntimeException("Could not find create-with-id URL");
- }
- Link link = res.getLinkHeader().getLinkByTitle("create-with-id");
- if (link == null) {
- throw new RuntimeException("Could not find create-with-id URL");
- }
- url = link.getHref();
- }
- targetUri = ResteasyUriBuilder.fromTemplate(url);
- }
-
- @Override
- public boolean push(ClientMessage message) {
- // we initialize lazily just in case target is in same VM
- if (!initialized) {
- try {
- initialize();
- initialized = true;
- } catch (Exception e) {
- throw new RuntimeException("Failed to initialize.", e);
- }
- }
- return super.push(message);
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/FilePushStore.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/FilePushStore.java
deleted file mode 100644
index 77ad60a1de..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/FilePushStore.java
+++ /dev/null
@@ -1,115 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.activemq.artemis.rest.ActiveMQRestLogger;
-import org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration;
-import org.apache.activemq.artemis.rest.topic.PushTopicRegistration;
-
-public class FilePushStore implements PushStore {
-
- protected Map<String, PushRegistration> map = new HashMap<>();
- protected File dir;
- protected JAXBContext ctx;
-
- public FilePushStore(String dirname) throws Exception {
- this.dir = new File(dirname);
- this.ctx = JAXBContext.newInstance(PushRegistration.class, PushTopicRegistration.class);
- if (this.dir.exists()) {
- ActiveMQRestLogger.LOGGER.loadingRestStore(dir.getAbsolutePath());
- for (File file : this.dir.listFiles()) {
- if (!file.isFile())
- continue;
- PushRegistration reg = null;
- try {
- reg = (PushRegistration) ctx.createUnmarshaller().unmarshal(file);
- reg.setLoadedFrom(file);
- ActiveMQRestLogger.LOGGER.addingPushRegistration(reg.getId());
- map.put(reg.getId(), reg);
- } catch (Exception e) {
- ActiveMQRestLogger.LOGGER.errorLoadingStore(file.getName(), e);
- }
- }
- }
- }
-
- public synchronized List<PushRegistration> getRegistrations() {
- List<PushRegistration> list = new ArrayList<>(map.values());
- return list;
- }
-
- @Override
- public synchronized List<PushRegistration> getByDestination(String destination) {
- List<PushRegistration> list = new ArrayList<>();
- for (PushRegistration reg : map.values()) {
- if (reg.getDestination().equals(destination)) {
- list.add(reg);
- }
- }
- return list;
- }
-
- @Override
- public synchronized void update(PushRegistration reg) throws Exception {
- if (reg.getLoadedFrom() == null)
- return;
- save(reg);
- }
-
- protected void save(PushRegistration reg) throws JAXBException {
- Marshaller marshaller = ctx.createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
- marshaller.marshal(reg, (File) reg.getLoadedFrom());
- }
-
- @Override
- public synchronized void add(PushRegistration reg) throws Exception {
- map.put(reg.getId(), reg);
- if (!this.dir.exists())
- this.dir.mkdirs();
- File fp = new File(dir, "reg-" + reg.getId() + ".xml");
- reg.setLoadedFrom(fp);
- //System.out.println("******* Saving: " + fp.getAbsolutePath());
- save(reg);
- }
-
- @Override
- public synchronized void remove(PushRegistration reg) throws Exception {
- map.remove(reg.getId());
- if (reg.getLoadedFrom() == null)
- return;
- File fp = (File) reg.getLoadedFrom();
- fp.delete();
- }
-
- @Override
- public synchronized void removeAll() throws Exception {
- ArrayList<PushRegistration> copy = new ArrayList<>(map.values());
- for (PushRegistration reg : copy)
- remove(reg);
- this.dir.delete();
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushConsumer.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushConsumer.java
deleted file mode 100644
index 9474ec8b13..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushConsumer.java
+++ /dev/null
@@ -1,140 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.api.core.client.ClientConsumer;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.ActiveMQRestLogger;
-import org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration;
-import org.apache.activemq.artemis.utils.SelectorTranslator;
-
-public class PushConsumer {
-
- protected PushRegistration registration;
- protected ClientSessionFactory factory;
- protected List<ClientSession> sessions;
- protected List<ClientConsumer> consumers;
- protected String destination;
- protected String id;
- protected PushStrategy strategy;
- protected PushStore store;
-
- private ConnectionFactoryOptions jmsOptions;
-
- public PushConsumer(ClientSessionFactory factory,
- String destination,
- String id,
- PushRegistration registration,
- PushStore store,
- ConnectionFactoryOptions jmsOptions) {
- this.factory = factory;
- this.destination = destination;
- this.id = id;
- this.registration = registration;
- this.store = store;
- this.jmsOptions = jmsOptions;
- }
-
- public PushStrategy getStrategy() {
- return strategy;
- }
-
- public PushRegistration getRegistration() {
- return registration;
- }
-
- public String getDestination() {
- return destination;
- }
-
- public void start() throws Exception {
- if (registration.getTarget().getClassName() != null) {
- Class clazz = Thread.currentThread().getContextClassLoader().loadClass(registration.getTarget().getClassName());
- strategy = (PushStrategy) clazz.newInstance();
- } else if (registration.getTarget().getRelationship() != null) {
- if (registration.getTarget().getRelationship().equals("destination")) {
- strategy = new ActiveMQPushStrategy();
- } else if (registration.getTarget().getRelationship().equals("template")) {
- strategy = new UriTemplateStrategy();
- }
- }
- if (strategy == null) {
- strategy = new UriStrategy();
- }
- strategy.setRegistration(registration);
- strategy.setJmsOptions(jmsOptions);
- strategy.start();
-
- sessions = new ArrayList<>();
- consumers = new ArrayList<>();
-
- for (int i = 0; i < registration.getSessionCount(); i++) {
- ClientSession session = factory.createSession(false, false, 0);
-
- ClientConsumer consumer;
-
- if (registration.getSelector() != null) {
- consumer = session.createConsumer(destination, SelectorTranslator.convertToActiveMQFilterString(registration.getSelector()));
- } else {
- consumer = session.createConsumer(destination);
- }
- consumer.setMessageHandler(new PushConsumerMessageHandler(this, session));
- session.start();
- ActiveMQRestLogger.LOGGER.startingPushConsumer(registration.getTarget());
-
- consumers.add(consumer);
- sessions.add(session);
- }
- }
-
- public void stop() {
- for (ClientSession session : sessions) {
- try {
- if (session != null) {
- session.close();
- }
- } catch (ActiveMQException e) {
-
- }
- }
-
- try {
- if (strategy != null) {
- strategy.stop();
- }
- } catch (Exception e) {
- }
- }
-
- public void disableFromFailure() {
- registration.setEnabled(false);
- try {
- if (registration.isDurable()) {
- store.update(registration);
- }
- } catch (Exception e) {
- ActiveMQRestLogger.LOGGER.errorUpdatingStore(e);
- }
- stop();
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushConsumerMessageHandler.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushConsumerMessageHandler.java
deleted file mode 100644
index 95636f5e65..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushConsumerMessageHandler.java
+++ /dev/null
@@ -1,74 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.api.core.client.MessageHandler;
-import org.apache.activemq.artemis.rest.ActiveMQRestLogger;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class PushConsumerMessageHandler implements MessageHandler {
-
- private static final Logger logger = LoggerFactory.getLogger(PushConsumerMessageHandler.class);
-
- private ClientSession session;
- private PushConsumer pushConsumer;
-
- PushConsumerMessageHandler(PushConsumer pushConsumer, ClientSession session) {
- this.pushConsumer = pushConsumer;
- this.session = session;
- }
-
- @Override
- public void onMessage(ClientMessage clientMessage) {
- logger.debug(this + ": receiving " + clientMessage);
-
- try {
- clientMessage.acknowledge();
- logger.debug(this + ": acknowledged " + clientMessage);
- } catch (ActiveMQException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
-
- logger.debug(this + ": pushing " + clientMessage + " via " + pushConsumer.getStrategy());
- boolean acknowledge = pushConsumer.getStrategy().push(clientMessage);
-
- if (acknowledge) {
- try {
- logger.debug("Acknowledging: " + clientMessage.getMessageID());
- session.commit();
- return;
- } catch (ActiveMQException e) {
- throw new RuntimeException(e);
- }
- } else {
- try {
- session.rollback();
- } catch (ActiveMQException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- if (pushConsumer.getRegistration().isDisableOnFailure()) {
- ActiveMQRestLogger.LOGGER.errorPushingMessage(pushConsumer.getRegistration().getTarget());
- pushConsumer.disableFromFailure();
- return;
- }
- }
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushConsumerResource.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushConsumerResource.java
deleted file mode 100644
index 4a3e78b434..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushConsumerResource.java
+++ /dev/null
@@ -1,154 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class PushConsumerResource {
-
- private static final Logger logger = LoggerFactory.getLogger(PushConsumerResource.class);
-
- protected Map<String, PushConsumer> consumers = new ConcurrentHashMap<>();
- protected ClientSessionFactory sessionFactory;
- protected String destination;
- protected final String startup = Long.toString(System.currentTimeMillis());
- protected final AtomicLong sessionCounter = new AtomicLong(1);
- protected PushStore pushStore;
-
- private ConnectionFactoryOptions jmsOptions;
-
- public void start() {
-
- }
-
- public void stop() {
- for (PushConsumer consumer : consumers.values()) {
- consumer.stop();
- }
- }
-
- public PushStore getPushStore() {
- return pushStore;
- }
-
- public void setPushStore(PushStore pushStore) {
- this.pushStore = pushStore;
- }
-
- public void addRegistration(PushRegistration reg) throws Exception {
- if (reg.isEnabled() == false)
- return;
- PushConsumer consumer = new PushConsumer(sessionFactory, destination, reg.getId(), reg, pushStore, jmsOptions);
- consumer.start();
- consumers.put(reg.getId(), consumer);
- }
-
- @POST
- @Consumes("application/xml")
- public Response create(@Context UriInfo uriInfo, PushRegistration registration) {
- logger.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");
-
- // todo put some logic here to check for duplicates
- String genId = sessionCounter.getAndIncrement() + "-" + startup;
- registration.setId(genId);
- registration.setDestination(destination);
- PushConsumer consumer = new PushConsumer(sessionFactory, destination, genId, registration, pushStore, jmsOptions);
- try {
- consumer.start();
- if (registration.isDurable() && pushStore != null) {
- pushStore.add(registration);
- }
- } catch (Exception e) {
- consumer.stop();
- throw new WebApplicationException(e, Response.serverError().entity("Failed to start consumer.").type("text/plain").build());
- }
-
- consumers.put(genId, consumer);
- UriBuilder location = uriInfo.getAbsolutePathBuilder();
- location.path(genId);
- return Response.created(location.build()).build();
- }
-
- @GET
- @Path("{consumer-id}")
- @Produces("application/xml")
- public PushRegistration getConsumer(@Context UriInfo uriInfo, @PathParam("consumer-id") String consumerId) {
- logger.debug("Handling GET request for \"" + uriInfo.getPath() + "\"");
-
- PushConsumer consumer = consumers.get(consumerId);
- if (consumer == null) {
- throw new WebApplicationException(Response.status(404).entity("Could not find consumer.").type("text/plain").build());
- }
- return consumer.getRegistration();
- }
-
- @DELETE
- @Path("{consumer-id}")
- public void deleteConsumer(@Context UriInfo uriInfo, @PathParam("consumer-id") String consumerId) {
- logger.debug("Handling DELETE request for \"" + uriInfo.getPath() + "\"");
-
- PushConsumer consumer = consumers.remove(consumerId);
- if (consumer == null) {
- throw new WebApplicationException(Response.status(404).entity("Could not find consumer.").type("text/plain").build());
- }
- consumer.stop();
- }
-
- public Map<String, PushConsumer> getConsumers() {
- return consumers;
- }
-
- public ClientSessionFactory getSessionFactory() {
- return sessionFactory;
- }
-
- public void setSessionFactory(ClientSessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- }
-
- public String getDestination() {
- return destination;
- }
-
- public void setDestination(String destination) {
- this.destination = destination;
- }
-
- public void setJmsOptions(ConnectionFactoryOptions jmsOptions) {
- this.jmsOptions = jmsOptions;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushStore.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushStore.java
deleted file mode 100644
index d3aae6d78f..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushStore.java
+++ /dev/null
@@ -1,34 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push;
-
-import java.util.List;
-
-import org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration;
-
-public interface PushStore {
-
- void add(PushRegistration reg) throws Exception;
-
- void remove(PushRegistration reg) throws Exception;
-
- List<PushRegistration> getByDestination(String destination);
-
- void update(PushRegistration reg) throws Exception;
-
- void removeAll() throws Exception;
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushStrategy.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushStrategy.java
deleted file mode 100644
index 6f291d36bc..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/PushStrategy.java
+++ /dev/null
@@ -1,42 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push;
-
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration;
-
-public interface PushStrategy {
-
- /**
- * Return false if unable to connect. Push consumer may be disabled if configured to do so when
- * unable to connect. Throw an exception if the message sent was unaccepted by the receiver.
- * ActiveMQ's retry and dead letter logic will take over from there.
- *
- * @param message
- * @return {@code false} if unable to connect
- */
- boolean push(ClientMessage message);
-
- void setRegistration(PushRegistration reg);
-
- void start() throws Exception;
-
- void stop() throws Exception;
-
- void setJmsOptions(ConnectionFactoryOptions jmsOptions);
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/UriStrategy.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/UriStrategy.java
deleted file mode 100644
index 9413b2144b..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/UriStrategy.java
+++ /dev/null
@@ -1,224 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push;
-
-import javax.ws.rs.core.UriBuilder;
-import java.io.IOException;
-
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.ActiveMQRestLogger;
-import org.apache.activemq.artemis.rest.queue.push.xml.BasicAuth;
-import org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration;
-import org.apache.activemq.artemis.rest.queue.push.xml.XmlHttpHeader;
-import org.apache.activemq.artemis.rest.util.HttpMessageHelper;
-import org.apache.http.HttpException;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpRequestInterceptor;
-import org.apache.http.auth.AuthScheme;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.AuthState;
-import org.apache.http.auth.Credentials;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.impl.auth.BasicScheme;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
-import org.apache.http.protocol.BasicHttpContext;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.protocol.HttpCoreContext;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor;
-import org.jboss.resteasy.specimpl.ResteasyUriBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class UriStrategy implements PushStrategy {
-
- private static final Logger logger = LoggerFactory.getLogger(UriStrategy.class);
-
- ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager();
- protected HttpClient client = new DefaultHttpClient(connManager);
- protected BasicHttpContext localContext;
- protected ApacheHttpClient4Executor executor = new ApacheHttpClient4Executor(client);
- protected PushRegistration registration;
- protected UriBuilder targetUri;
- protected String method;
- protected String contentType;
-
- protected ConnectionFactoryOptions jmsOptions;
-
- UriStrategy() {
- connManager.setDefaultMaxPerRoute(100);
- connManager.setMaxTotal(1000);
- }
-
- @Override
- public void setRegistration(PushRegistration reg) {
- this.registration = reg;
- }
-
- @Override
- public void start() throws Exception {
- initAuthentication();
- method = registration.getTarget().getMethod();
- if (method == null)
- method = "POST";
- contentType = registration.getTarget().getType();
- targetUri = ResteasyUriBuilder.fromTemplate(registration.getTarget().getHref());
- }
-
- protected void initAuthentication() {
- if (registration.getAuthenticationMechanism() != null) {
- if (registration.getAuthenticationMechanism().getType() instanceof BasicAuth) {
- BasicAuth basic = (BasicAuth) registration.getAuthenticationMechanism().getType();
- UsernamePasswordCredentials creds = new UsernamePasswordCredentials(basic.getUsername(), basic.getPassword());
- AuthScope authScope = new AuthScope(AuthScope.ANY);
- ((DefaultHttpClient) client).getCredentialsProvider().setCredentials(authScope, creds);
-
- localContext = new BasicHttpContext();
-
- // Generate BASIC scheme object and stick it to the local execution context
- BasicScheme basicAuth = new BasicScheme();
- localContext.setAttribute("preemptive-auth", basicAuth);
-
- // Add as the first request interceptor
- ((DefaultHttpClient) client).addRequestInterceptor(new PreemptiveAuth(), 0);
- executor.setHttpContext(localContext);
- }
- }
- }
-
- @Override
- public void stop() {
- connManager.shutdown();
- }
-
- @Override
- public void setJmsOptions(ConnectionFactoryOptions jmsOptions) {
- this.jmsOptions = jmsOptions;
- }
-
- @Override
- public boolean push(ClientMessage message) {
- logger.debug("Pushing " + message);
- String uri = createUri(message);
- for (int i = 0; i < registration.getMaxRetries(); i++) {
- long wait = registration.getRetryWaitMillis();
- System.out.println("Creating request from " + uri);
- ClientRequest request = executor.createRequest(uri);
- request.followRedirects(false);
- logger.debug("Created request " + request);
-
- for (XmlHttpHeader header : registration.getHeaders()) {
- logger.debug("Setting XmlHttpHeader: " + header.getName() + "=" + header.getValue());
- request.header(header.getName(), header.getValue());
- }
- HttpMessageHelper.buildMessage(message, request, contentType, jmsOptions);
- ClientResponse<?> res = null;
- try {
- logger.debug(method + " " + uri);
- res = request.httpMethod(method);
- int status = res.getStatus();
- logger.debug("Status of push: " + status);
- if (status == 503) {
- String retryAfter = res.getStringHeaders().getFirst("Retry-After");
- if (retryAfter != null) {
- wait = Long.parseLong(retryAfter) * 1000;
- }
- } else if (status == 307) {
- uri = res.getLocation().toString();
- wait = 0;
- } else if ((status >= 200 && status < 299) || status == 303 || status == 304) {
- logger.debug("Success");
- return true;
- } else if (status >= 400) {
- switch (status) {
- case 400: // these usually mean the message you are trying to send is crap, let dead letter logic take over
- case 411:
- case 412:
- case 413:
- case 414:
- case 415:
- case 416:
- throw new RuntimeException("Something is wrong with the message, status returned: " + status + " for push registration of URI: " + uri);
- case 401: // might as well consider these critical failures and abort. Immediately signal to disable push registration depending on config
- case 402:
- case 403:
- case 405:
- case 406:
- case 407:
- case 417:
- case 505:
- return false;
- case 404: // request timeout, gone, and not found treat as a retry
- case 408:
- case 409:
- case 410:
- break;
- default: // all 50x requests just retry (except 505)
- break;
- }
- }
- } catch (Exception e) {
- ActiveMQRestLogger.LOGGER.failedToPushMessageToUri(uri, e);
- return false;
- } finally {
- if (res != null)
- res.releaseConnection();
- }
- try {
- if (wait > 0)
- Thread.sleep(wait);
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted");
- }
- }
- return false;
- }
-
- protected String createUri(ClientMessage message) {
- String uri = targetUri.build().toString();
- return uri;
- }
-
- static class PreemptiveAuth implements HttpRequestInterceptor {
-
- @Override
- public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
- AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
-
- // If no auth scheme available yet, try to initialize it preemptively
- if (authState.getAuthScheme() == null) {
- AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
- CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
- HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
- if (authScheme != null) {
- Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
- if (creds == null) {
- throw new HttpException("No credentials for preemptive authentication");
- }
- authState.update(authScheme, creds);
- }
- }
- }
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/UriTemplateStrategy.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/UriTemplateStrategy.java
deleted file mode 100644
index f08d3fc0e4..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/UriTemplateStrategy.java
+++ /dev/null
@@ -1,29 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push;
-
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-
-public class UriTemplateStrategy extends UriStrategy {
-
- @Override
- protected String createUri(ClientMessage message) {
- String dupId = registration.getId() + "-" + message.getMessageID() + "-" + message.getTimestamp();
- String uri = targetUri.build(dupId).toString();
- return uri;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/Authentication.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/Authentication.java
deleted file mode 100644
index b599dc5adc..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/Authentication.java
+++ /dev/null
@@ -1,47 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push.xml;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElementRef;
-import javax.xml.bind.annotation.XmlRootElement;
-import java.io.Serializable;
-
-@XmlRootElement
-@XmlAccessorType(XmlAccessType.PROPERTY)
-public class Authentication implements Serializable {
-
- private static final long serialVersionUID = -6218446923598032634L;
- private AuthenticationType type;
-
- @XmlElementRef
- public AuthenticationType getType() {
- return type;
- }
-
- public void setType(AuthenticationType type) {
- this.type = type;
- }
-
- @Override
- public String toString() {
- return "Authentication{" +
- "type=" + type +
- '}';
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/AuthenticationType.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/AuthenticationType.java
deleted file mode 100644
index 380bd04042..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/AuthenticationType.java
+++ /dev/null
@@ -1,26 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push.xml;
-
-import javax.xml.bind.annotation.XmlSeeAlso;
-import java.io.Serializable;
-
-@XmlSeeAlso({BasicAuth.class, DigestAuth.class})
-public class AuthenticationType implements Serializable {
-
- private static final long serialVersionUID = -4856752055689300045L;
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/BasicAuth.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/BasicAuth.java
deleted file mode 100644
index 0392fbd39f..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/BasicAuth.java
+++ /dev/null
@@ -1,53 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push.xml;
-
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
-
-@XmlRootElement(name = "basic-auth")
-@XmlType(propOrder = {"username", "password"})
-public class BasicAuth extends AuthenticationType {
-
- private static final long serialVersionUID = 2052716241089832934L;
- private String username;
- private String password;
-
- public String getUsername() {
- return username;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- @Override
- public String toString() {
- return "BasicAuth{" +
- "username='" + username + '\'' +
- ", password='" + password + '\'' +
- '}';
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/DigestAuth.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/DigestAuth.java
deleted file mode 100644
index 7ead7e8092..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/DigestAuth.java
+++ /dev/null
@@ -1,25 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push.xml;
-
-import javax.xml.bind.annotation.XmlRootElement;
-
-@XmlRootElement(name = "digest")
-public class DigestAuth extends BasicAuth {
-
- private static final long serialVersionUID = 1857805131477468686L;
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/PushRegistration.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/PushRegistration.java
deleted file mode 100644
index b934f7bd78..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/PushRegistration.java
+++ /dev/null
@@ -1,184 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push.xml;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElementRef;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
-import javax.xml.bind.annotation.XmlType;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-@XmlRootElement(name = "push-registration")
-@XmlAccessorType(XmlAccessType.PROPERTY)
-@XmlType(propOrder = {"enabled", "destination", "durable", "selector", "target", "maxRetries", "retryWaitMillis", "disableOnFailure", "authenticationMechanism", "headers", "sessionCount"})
-public class PushRegistration implements Serializable {
-
- private static final long serialVersionUID = -2749818399978544262L;
- private String id;
- private boolean durable;
- private XmlLink target;
- private Authentication authenticationMechanism;
- private List<XmlHttpHeader> headers = new ArrayList<>();
- private String destination;
- private Object loadedFrom;
- private String selector;
- private long retryWaitMillis = 1000;
- private boolean disableOnFailure;
- private int maxRetries = 10;
- private boolean enabled = true;
- private int sessionCount = 1;
-
- @XmlElement
- public int getMaxRetries() {
- return maxRetries;
- }
-
- public void setMaxRetries(int maxRetries) {
- this.maxRetries = maxRetries;
- }
-
- @XmlElement
- public long getRetryWaitMillis() {
- return retryWaitMillis;
- }
-
- public void setRetryWaitMillis(long retryWaitMillis) {
- this.retryWaitMillis = retryWaitMillis;
- }
-
- @XmlElement
- public boolean isDisableOnFailure() {
- return disableOnFailure;
- }
-
- public void setDisableOnFailure(boolean disableOnFailure) {
- this.disableOnFailure = disableOnFailure;
- }
-
- @XmlElement
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- @XmlTransient
- public Object getLoadedFrom() {
- return loadedFrom;
- }
-
- public void setLoadedFrom(Object loadedFrom) {
- this.loadedFrom = loadedFrom;
- }
-
- @XmlAttribute
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- @XmlElement
- public String getDestination() {
- return destination;
- }
-
- public void setDestination(String destination) {
- this.destination = destination;
- }
-
- @XmlElement
- public boolean isDurable() {
- return durable;
- }
-
- public void setDurable(boolean durable) {
- this.durable = durable;
- }
-
- public String getSelector() {
- return selector;
- }
-
- public void setSelector(String selector) {
- this.selector = selector;
- }
-
- @XmlElementRef
- public XmlLink getTarget() {
- return target;
- }
-
- public void setTarget(XmlLink target) {
- this.target = target;
- }
-
- @XmlElementRef
- public Authentication getAuthenticationMechanism() {
- return authenticationMechanism;
- }
-
- public void setAuthenticationMechanism(Authentication authenticationMechanism) {
- this.authenticationMechanism = authenticationMechanism;
- }
-
- @XmlElementRef
- public List<XmlHttpHeader> getHeaders() {
- return headers;
- }
-
- public void setHeaders(List<XmlHttpHeader> headers) {
- this.headers = headers;
- }
-
- @XmlElement
- public int getSessionCount() {
- return sessionCount;
- }
-
- public void setSessionCount(int sessionCount) {
- this.sessionCount = sessionCount;
- }
-
- @Override
- public String toString() {
- return "PushRegistration{" +
- "id='" + id + '\'' +
- ", durable=" + durable +
- ", target=" + target +
- ", authenticationMechanism=" + authenticationMechanism +
- ", headers=" + headers +
- ", destination='" + destination + '\'' +
- ", selector='" + selector + '\'' +
- ", retryWaitMillis=" + retryWaitMillis +
- ", disableOnFailure=" + disableOnFailure +
- ", maxRetries=" + maxRetries +
- ", sessionCount=" + sessionCount +
- ", enabled=" + enabled +
- '}';
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/XmlHttpHeader.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/XmlHttpHeader.java
deleted file mode 100644
index 97df082fee..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/XmlHttpHeader.java
+++ /dev/null
@@ -1,59 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push.xml;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlValue;
-import java.io.Serializable;
-
-@XmlRootElement(name = "header")
-@XmlAccessorType(XmlAccessType.PROPERTY)
-public class XmlHttpHeader implements Serializable {
-
- private static final long serialVersionUID = -3900391946161818601L;
- private String name;
- private String value;
-
- @XmlAttribute
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @XmlValue
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- @Override
- public String toString() {
- return "XmlHttpHeader{" +
- "name='" + name + '\'' +
- ", value='" + value + '\'' +
- '}';
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/XmlLink.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/XmlLink.java
deleted file mode 100644
index 7d2317b1a7..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/push/xml/XmlLink.java
+++ /dev/null
@@ -1,91 +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.
- */
-package org.apache.activemq.artemis.rest.queue.push.xml;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlRootElement;
-import java.io.Serializable;
-
-@XmlRootElement(name = "link")
-@XmlAccessorType(XmlAccessType.PROPERTY)
-public class XmlLink implements Serializable {
-
- private static final long serialVersionUID = -6517264072911034419L;
- protected String method;
- protected String className;
- protected String rel;
- protected String type;
- protected String href;
-
- @XmlAttribute(name = "class")
- public String getClassName() {
- return className;
- }
-
- public void setClassName(String className) {
- this.className = className;
- }
-
- @XmlAttribute
- public String getMethod() {
- return method;
- }
-
- public void setMethod(String method) {
- this.method = method;
- }
-
- @XmlAttribute(name = "rel")
- public String getRelationship() {
- return rel;
- }
-
- public void setRelationship(String relationship) {
- rel = relationship;
- }
-
- @XmlAttribute
- public String getHref() {
- return href;
- }
-
- public void setHref(String href) {
- this.href = href;
- }
-
- @XmlAttribute
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- @Override
- public String toString() {
- return "XmlLink{" +
- "className='" + className + '\'' +
- ", rel='" + rel + '\'' +
- ", href='" + href + '\'' +
- ", type='" + type + '\'' +
- ", method='" + method + '\'' +
- '}';
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/AcknowledgedSubscriptionResource.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/AcknowledgedSubscriptionResource.java
deleted file mode 100644
index 44922f73fa..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/AcknowledgedSubscriptionResource.java
+++ /dev/null
@@ -1,71 +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.
- */
-package org.apache.activemq.artemis.rest.topic;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.rest.queue.AcknowledgedQueueConsumer;
-import org.apache.activemq.artemis.rest.queue.DestinationServiceManager;
-
-public class AcknowledgedSubscriptionResource extends AcknowledgedQueueConsumer implements Subscription {
-
- private boolean durable;
- private long timeout;
- private boolean deleteWhenIdle;
-
- public AcknowledgedSubscriptionResource(ClientSessionFactory factory,
- String destination,
- String id,
- DestinationServiceManager serviceManager,
- String selector,
- boolean durable,
- Long timeout) throws ActiveMQException {
- super(factory, destination, id, serviceManager, selector);
- this.timeout = timeout;
- this.durable = durable;
- }
-
- @Override
- public boolean isDurable() {
- return durable;
- }
-
- @Override
- public void setDurable(boolean durable) {
- this.durable = durable;
- }
-
- @Override
- public long getTimeout() {
- return timeout;
- }
-
- @Override
- public void setTimeout(long timeout) {
- this.timeout = timeout;
- }
-
- @Override
- public boolean isDeleteWhenIdle() {
- return deleteWhenIdle;
- }
-
- @Override
- public void setDeleteWhenIdle(boolean deleteWhenIdle) {
- this.deleteWhenIdle = deleteWhenIdle;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/FileTopicPushStore.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/FileTopicPushStore.java
deleted file mode 100644
index 53a3e69026..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/FileTopicPushStore.java
+++ /dev/null
@@ -1,42 +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.
- */
-package org.apache.activemq.artemis.rest.topic;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.activemq.artemis.rest.queue.push.FilePushStore;
-import org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration;
-
-class FileTopicPushStore extends FilePushStore implements TopicPushStore {
-
- FileTopicPushStore(String dirname) throws Exception {
- super(dirname);
- }
-
- @Override
- public synchronized List<PushTopicRegistration> getByTopic(String topic) {
- List<PushTopicRegistration> list = new ArrayList<>();
- for (PushRegistration reg : map.values()) {
- PushTopicRegistration topicReg = (PushTopicRegistration) reg;
- if (topicReg.getTopic().equals(topic)) {
- list.add(topicReg);
- }
- }
- return list;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/PushSubscription.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/PushSubscription.java
deleted file mode 100644
index 997e9772b2..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/PushSubscription.java
+++ /dev/null
@@ -1,63 +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.
- */
-package org.apache.activemq.artemis.rest.topic;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.ActiveMQRestLogger;
-import org.apache.activemq.artemis.rest.queue.push.PushConsumer;
-import org.apache.activemq.artemis.rest.queue.push.PushStore;
-import org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration;
-
-public class PushSubscription extends PushConsumer {
-
- public PushSubscription(ClientSessionFactory factory,
- String destination,
- String id,
- PushRegistration registration,
- PushStore store,
- ConnectionFactoryOptions jmsOptions) {
- super(factory, destination, id, registration, store, jmsOptions);
- }
-
- @Override
- public void disableFromFailure() {
- super.disableFromFailure();
- if (registration.isDurable())
- deleteSubscriberQueue();
- }
-
- protected void deleteSubscriberQueue() {
- String subscriptionName = registration.getDestination();
- ClientSession session = null;
- try {
- session = factory.createSession();
-
- session.deleteQueue(subscriptionName);
- } catch (ActiveMQException e) {
- ActiveMQRestLogger.LOGGER.errorDeletingSubscriberQueue(e);
- } finally {
- try {
- if (session != null)
- session.close();
- } catch (ActiveMQException e) {
- }
- }
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/PushSubscriptionsResource.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/PushSubscriptionsResource.java
deleted file mode 100644
index 8f4d506172..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/PushSubscriptionsResource.java
+++ /dev/null
@@ -1,216 +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.
- */
-package org.apache.activemq.artemis.rest.topic;
-
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.api.core.QueueConfiguration;
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.queue.push.PushConsumer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class PushSubscriptionsResource {
-
- private static final Logger logger = LoggerFactory.getLogger(PushSubscriptionsResource.class);
-
- protected Map<String, PushSubscription> consumers = new ConcurrentHashMap<>();
- protected ClientSessionFactory sessionFactory;
- protected String destination;
- protected final String startup = Long.toString(System.currentTimeMillis());
- protected final AtomicLong sessionCounter = new AtomicLong(1);
- protected TopicPushStore pushStore;
-
- private ConnectionFactoryOptions jmsOptions;
-
- public PushSubscriptionsResource(ConnectionFactoryOptions jmsOptions) {
- this.jmsOptions = jmsOptions;
- }
-
- public void stop() {
- for (PushConsumer consumer : consumers.values()) {
- consumer.stop();
- if (consumer.getRegistration().isDurable() == false) {
- deleteSubscriberQueue(consumer);
- }
- }
- }
-
- public TopicPushStore getPushStore() {
- return pushStore;
- }
-
- public void setPushStore(TopicPushStore pushStore) {
- this.pushStore = pushStore;
- }
-
- public ClientSession createSubscription(String subscriptionName, boolean durable) {
- ClientSession session = null;
- try {
- session = sessionFactory.createSession();
-
- session.createQueue(new QueueConfiguration(subscriptionName).setAddress(destination).setDurable(durable).setTemporary(!durable));
- return session;
- } catch (ActiveMQException e) {
- throw new RuntimeException(e);
- }
- }
-
- public void addRegistration(PushTopicRegistration reg) throws Exception {
- if (reg.isEnabled() == false)
- return;
- String destination = reg.getDestination();
- ClientSession session = sessionFactory.createSession(false, false, false);
- ClientSession.QueueQuery query = session.queueQuery(new SimpleString(destination));
- ClientSession createSession = null;
- if (!query.isExists()) {
- createSession = createSubscription(destination, reg.isDurable());
- }
- PushSubscription consumer = new PushSubscription(sessionFactory, reg.getDestination(), reg.getId(), reg, pushStore, jmsOptions);
- try {
- consumer.start();
- } catch (Exception e) {
- consumer.stop();
- throw new Exception("Failed starting push subscriber for " + destination + " of push subscriber: " + reg.getTarget(), e);
- } finally {
- closeSession(createSession);
- closeSession(session);
- }
-
- consumers.put(reg.getId(), consumer);
-
- }
-
- private void closeSession(ClientSession createSession) {
- if (createSession != null) {
- try {
- createSession.close();
- } catch (ActiveMQException e) {
- }
- }
- }
-
- @POST
- public Response create(@Context UriInfo uriInfo, PushTopicRegistration registration) {
- logger.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");
-
- //System.out.println("PushRegistration: " + registration);
- // todo put some logic here to check for duplicates
- String genId = sessionCounter.getAndIncrement() + "-topic-" + destination + "-" + startup;
- if (registration.getDestination() == null) {
- registration.setDestination(genId);
- }
- registration.setId(genId);
- registration.setTopic(destination);
- ClientSession createSession = createSubscription(genId, registration.isDurable());
- try {
- PushSubscription consumer = new PushSubscription(sessionFactory, genId, genId, registration, pushStore, jmsOptions);
- try {
- consumer.start();
- if (registration.isDurable() && pushStore != null) {
- pushStore.add(registration);
- }
- } catch (Exception e) {
- consumer.stop();
- throw new WebApplicationException(e, Response.serverError().entity("Failed to start consumer.").type("text/plain").build());
- }
-
- consumers.put(genId, consumer);
- UriBuilder location = uriInfo.getAbsolutePathBuilder();
- location.path(genId);
- return Response.created(location.build()).build();
- } finally {
- closeSession(createSession);
- }
- }
-
- @GET
- @Path("{consumer-id}")
- @Produces("application/xml")
- public PushTopicRegistration getConsumer(@Context UriInfo uriInfo, @PathParam("consumer-id") String consumerId) {
- logger.debug("Handling GET request for \"" + uriInfo.getPath() + "\"");
-
- PushConsumer consumer = consumers.get(consumerId);
- if (consumer == null) {
- throw new WebApplicationException(Response.status(404).entity("Could not find consumer.").type("text/plain").build());
- }
- return (PushTopicRegistration) consumer.getRegistration();
- }
-
- @DELETE
- @Path("{consumer-id}")
- public void deleteConsumer(@Context UriInfo uriInfo, @PathParam("consumer-id") String consumerId) {
- logger.debug("Handling DELETE request for \"" + uriInfo.getPath() + "\"");
-
- PushConsumer consumer = consumers.remove(consumerId);
- if (consumer == null) {
- throw new WebApplicationException(Response.status(404).entity("Could not find consumer.").type("text/plain").build());
- }
- consumer.stop();
- deleteSubscriberQueue(consumer);
- }
-
- public Map<String, PushSubscription> getConsumers() {
- return consumers;
- }
-
- public ClientSessionFactory getSessionFactory() {
- return sessionFactory;
- }
-
- public void setSessionFactory(ClientSessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- }
-
- public String getDestination() {
- return destination;
- }
-
- public void setDestination(String destination) {
- this.destination = destination;
- }
-
- private void deleteSubscriberQueue(PushConsumer consumer) {
- String subscriptionName = consumer.getDestination();
- ClientSession session = null;
- try {
- session = sessionFactory.createSession();
-
- session.deleteQueue(subscriptionName);
- } catch (ActiveMQException e) {
- } finally {
- closeSession(session);
- }
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/PushTopicRegistration.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/PushTopicRegistration.java
deleted file mode 100644
index 89d9a62a13..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/PushTopicRegistration.java
+++ /dev/null
@@ -1,43 +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.
- */
-package org.apache.activemq.artemis.rest.topic;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
-
-import org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration;
-
-@XmlRootElement(name = "push-topic-registration")
-@XmlAccessorType(XmlAccessType.PROPERTY)
-@XmlType(propOrder = {"topic"})
-public class PushTopicRegistration extends PushRegistration {
-
- private static final long serialVersionUID = -2526239344680405891L;
- private String topic;
-
- @XmlElement
- public String getTopic() {
- return topic;
- }
-
- public void setTopic(String topic) {
- this.topic = topic;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/Subscription.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/Subscription.java
deleted file mode 100644
index 1da22e5343..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/Subscription.java
+++ /dev/null
@@ -1,32 +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.
- */
-package org.apache.activemq.artemis.rest.topic;
-
-public interface Subscription {
-
- boolean isDurable();
-
- void setDurable(boolean isDurable);
-
- long getTimeout();
-
- void setTimeout(long timeout);
-
- boolean isDeleteWhenIdle();
-
- void setDeleteWhenIdle(boolean deleteWhenIdle);
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/SubscriptionResource.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/SubscriptionResource.java
deleted file mode 100644
index 7c8f72657e..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/SubscriptionResource.java
+++ /dev/null
@@ -1,71 +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.
- */
-package org.apache.activemq.artemis.rest.topic;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.rest.queue.DestinationServiceManager;
-import org.apache.activemq.artemis.rest.queue.QueueConsumer;
-
-public class SubscriptionResource extends QueueConsumer implements Subscription {
-
- protected boolean durable;
- protected long timeout;
- private boolean deleteWhenIdle;
-
- public SubscriptionResource(ClientSessionFactory factory,
- String destination,
- String id,
- DestinationServiceManager serviceManager,
- String selector,
- boolean durable,
- long timeout) throws ActiveMQException {
- super(factory, destination, id, serviceManager, selector);
- this.durable = durable;
- this.timeout = timeout;
- }
-
- @Override
- public boolean isDurable() {
- return durable;
- }
-
- @Override
- public void setDurable(boolean durable) {
- this.durable = durable;
- }
-
- @Override
- public long getTimeout() {
- return timeout;
- }
-
- @Override
- public void setTimeout(long timeout) {
- this.timeout = timeout;
- }
-
- @Override
- public boolean isDeleteWhenIdle() {
- return deleteWhenIdle;
- }
-
- @Override
- public void setDeleteWhenIdle(boolean deleteWhenIdle) {
- this.deleteWhenIdle = deleteWhenIdle;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/SubscriptionsResource.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/SubscriptionsResource.java
deleted file mode 100644
index 12ba19f09e..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/SubscriptionsResource.java
+++ /dev/null
@@ -1,427 +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.
- */
-package org.apache.activemq.artemis.rest.topic;
-
-import javax.ws.rs.DELETE;
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.GET;
-import javax.ws.rs.HEAD;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.api.core.QueueConfiguration;
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.rest.ActiveMQRestLogger;
-import org.apache.activemq.artemis.rest.queue.AcknowledgedQueueConsumer;
-import org.apache.activemq.artemis.rest.queue.Acknowledgement;
-import org.apache.activemq.artemis.rest.queue.DestinationServiceManager;
-import org.apache.activemq.artemis.rest.queue.QueueConsumer;
-import org.apache.activemq.artemis.rest.util.TimeoutTask;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SubscriptionsResource implements TimeoutTask.Callback {
-
- private static final Logger logger = LoggerFactory.getLogger(SubscriptionsResource.class);
-
- protected ConcurrentMap<String, QueueConsumer> queueConsumers = new ConcurrentHashMap<>();
- protected ClientSessionFactory sessionFactory;
- protected String destination;
- protected final String startup = Long.toString(System.currentTimeMillis());
- protected AtomicLong sessionCounter = new AtomicLong(1);
- protected int consumerTimeoutSeconds;
- protected DestinationServiceManager serviceManager;
-
- public DestinationServiceManager getServiceManager() {
- return serviceManager;
- }
-
- public void setServiceManager(DestinationServiceManager serviceManager) {
- this.serviceManager = serviceManager;
- }
-
- public int getConsumerTimeoutSeconds() {
- return consumerTimeoutSeconds;
- }
-
- public void setConsumerTimeoutSeconds(int consumerTimeoutSeconds) {
- this.consumerTimeoutSeconds = consumerTimeoutSeconds;
- }
-
- public ClientSessionFactory getSessionFactory() {
- return sessionFactory;
- }
-
- public void setSessionFactory(ClientSessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- }
-
- public String getDestination() {
- return destination;
- }
-
- public void setDestination(String destination) {
- this.destination = destination;
- }
-
- @Override
- public boolean testTimeout(String target, boolean autoShutdown) {
- QueueConsumer consumer = queueConsumers.get(target);
- Subscription subscription = (Subscription) consumer;
- if (consumer == null)
- return false;
- if (System.currentTimeMillis() - consumer.getLastPingTime() > subscription.getTimeout()) {
- ActiveMQRestLogger.LOGGER.shutdownRestSubscription(consumer.getId());
- if (autoShutdown) {
- shutdown(consumer);
- }
- return true;
- } else {
- return false;
- }
- }
-
- @Override
- public void shutdown(String target) {
- QueueConsumer consumer = queueConsumers.get(target);
- if (consumer == null)
- return;
- shutdown(consumer);
- }
-
- private void shutdown(QueueConsumer consumer) {
- synchronized (consumer) {
- consumer.shutdown();
- queueConsumers.remove(consumer.getId());
- Subscription subscription = (Subscription) consumer;
- if (subscription.isDeleteWhenIdle())
- deleteSubscriberQueue(consumer);
- }
- }
-
- public void stop() {
- for (QueueConsumer consumer : queueConsumers.values()) {
- consumer.shutdown();
- Subscription subscription = (Subscription) consumer;
- if (!subscription.isDurable()) {
- deleteSubscriberQueue(consumer);
- }
-
- }
- queueConsumers.clear();
- }
-
- protected String generateSubscriptionName() {
- return startup + "-" + sessionCounter.getAndIncrement() + "-" + destination;
- }
-
- @POST
- public Response createSubscription(@FormParam("durable") @DefaultValue("false") boolean durable,
- @FormParam("autoAck") @DefaultValue("true") boolean autoAck,
- @FormParam("name") String subscriptionName,
- @FormParam("selector") String selector,
- @FormParam("delete-when-idle") Boolean destroyWhenIdle,
- @FormParam("idle-timeout") Long timeout,
- @Context UriInfo uriInfo) {
- logger.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");
-
- if (timeout == null)
- timeout = Long.valueOf((long) consumerTimeoutSeconds * 1000);
- boolean deleteWhenIdle = !durable; // default is true if non-durable
- if (destroyWhenIdle != null)
- deleteWhenIdle = destroyWhenIdle.booleanValue();
-
- if (subscriptionName != null) {
- // see if this is a reconnect
- QueueConsumer consumer = queueConsumers.get(subscriptionName);
- if (consumer != null) {
- boolean acked = consumer instanceof AcknowledgedSubscriptionResource;
- acked = !acked;
- if (acked != autoAck) {
- throw new WebApplicationException(Response.status(412).entity("Consumer already exists and ack-modes don't match.").type("text/plain").build());
- }
- Subscription sub = (Subscription) consumer;
- if (sub.isDurable() != durable) {
- throw new WebApplicationException(Response.status(412).entity("Consumer already exists and durability doesn't match.").type("text/plain").build());
- }
- Response.ResponseBuilder builder = Response.noContent();
- String pathToPullSubscriptions = uriInfo.getMatchedURIs().get(0);
- if (autoAck) {
- headAutoAckSubscriptionResponse(uriInfo, consumer, builder, pathToPullSubscriptions);
- consumer.setSessionLink(builder, uriInfo, pathToPullSubscriptions + "/auto-ack/" + consumer.getId());
- } else {
- headAcknowledgedConsumerResponse(uriInfo, (AcknowledgedQueueConsumer) consumer, builder);
- consumer.setSessionLink(builder, uriInfo, pathToPullSubscriptions + "/acknowledged/" + consumer.getId());
- }
- return builder.build();
- }
- } else {
- subscriptionName = generateSubscriptionName();
- }
- ClientSession session = null;
- try {
- // if this is not a reconnect, create the subscription queue
- if (!subscriptionExists(subscriptionName)) {
- session = sessionFactory.createSession();
-
- session.createQueue(new QueueConfiguration(subscriptionName).setAddress(destination).setDurable(durable).setTemporary(!durable));
- }
- QueueConsumer consumer = createConsumer(durable, autoAck, subscriptionName, selector, timeout, deleteWhenIdle);
- queueConsumers.put(consumer.getId(), consumer);
- serviceManager.getTimeoutTask().add(this, consumer.getId());
-
- UriBuilder location = uriInfo.getAbsolutePathBuilder();
- if (autoAck)
- location.path("auto-ack");
- else
- location.path("acknowledged");
- location.path(consumer.getId());
- Response.ResponseBuilder builder = Response.created(location.build());
- if (autoAck) {
- QueueConsumer.setConsumeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(0) + "/auto-ack/" + consumer.getId(), "-1");
- } else {
- AcknowledgedQueueConsumer.setAcknowledgeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(0) + "/acknowledged/" + consumer.getId(), "-1");
-
- }
- return builder.build();
-
- } catch (ActiveMQException e) {
- throw new RuntimeException(e);
- } finally {
- if (session != null) {
- try {
- session.close();
- } catch (ActiveMQException e) {
- }
- }
- }
- }
-
- protected QueueConsumer createConsumer(boolean durable,
- boolean autoAck,
- String subscriptionName,
- String selector,
- long timeout,
- boolean deleteWhenIdle) throws ActiveMQException {
- QueueConsumer consumer;
- if (autoAck) {
- SubscriptionResource subscription = new SubscriptionResource(sessionFactory, subscriptionName, subscriptionName, serviceManager, selector, durable, timeout);
- subscription.setDurable(durable);
- subscription.setDeleteWhenIdle(deleteWhenIdle);
- consumer = subscription;
- } else {
- AcknowledgedSubscriptionResource subscription = new AcknowledgedSubscriptionResource(sessionFactory, subscriptionName, subscriptionName, serviceManager, selector, durable, timeout);
- subscription.setDurable(durable);
- subscription.setDeleteWhenIdle(deleteWhenIdle);
- consumer = subscription;
- }
- return consumer;
- }
-
- @Path("auto-ack/{consumer-id}")
- @GET
- public Response getAutoAckSubscription(@PathParam("consumer-id") String consumerId,
- @Context UriInfo uriInfo) throws Exception {
- logger.debug("Handling GET request for \"" + uriInfo.getPath() + "\"");
-
- return internalHeadAutoAckSubscription(uriInfo, consumerId);
- }
-
- @Path("auto-ack/{consumer-id}")
- @HEAD
- public Response headAutoAckSubscription(@PathParam("consumer-id") String consumerId,
- @Context UriInfo uriInfo) throws Exception {
- logger.debug("Handling HEAD request for \"" + uriInfo.getPath() + "\"");
-
- return internalHeadAutoAckSubscription(uriInfo, consumerId);
- }
-
- private Response internalHeadAutoAckSubscription(UriInfo uriInfo, String consumerId) {
- QueueConsumer consumer = findAutoAckSubscription(consumerId);
- Response.ResponseBuilder builder = Response.noContent();
- String pathToPullSubscriptions = uriInfo.getMatchedURIs().get(1);
- headAutoAckSubscriptionResponse(uriInfo, consumer, builder, pathToPullSubscriptions);
-
- return builder.build();
- }
-
- private void headAutoAckSubscriptionResponse(UriInfo uriInfo,
- QueueConsumer consumer,
- Response.ResponseBuilder builder,
- String pathToPullSubscriptions) {
- // we synchronize just in case a failed request is still processing
- synchronized (consumer) {
- QueueConsumer.setConsumeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, pathToPullSubscriptions + "/acknowledged/" + consumer.getId(), Long.toString(consumer.getConsumeIndex()));
- }
- }
-
- @Path("auto-ack/{subscription-id}")
- public QueueConsumer findAutoAckSubscription(@PathParam("subscription-id") String subscriptionId) {
- QueueConsumer consumer = queueConsumers.get(subscriptionId);
- if (consumer == null) {
- consumer = recreateTopicConsumer(subscriptionId, true);
- }
- return consumer;
- }
-
- @Path("acknowledged/{consumer-id}")
- @GET
- public Response getAcknowledgedConsumer(@PathParam("consumer-id") String consumerId,
- @Context UriInfo uriInfo) throws Exception {
- logger.debug("Handling GET request for \"" + uriInfo.getPath() + "\"");
-
- return internalHeadAcknowledgedConsumer(uriInfo, consumerId);
- }
-
- @Path("acknowledged/{consumer-id}")
- @HEAD
- public Response headAcknowledgedConsumer(@PathParam("consumer-id") String consumerId,
- @Context UriInfo uriInfo) throws Exception {
- logger.debug("Handling HEAD request for \"" + uriInfo.getPath() + "\"");
-
- return internalHeadAcknowledgedConsumer(uriInfo, consumerId);
- }
-
- private Response internalHeadAcknowledgedConsumer(UriInfo uriInfo, String consumerId) {
- AcknowledgedQueueConsumer consumer = (AcknowledgedQueueConsumer) findAcknoledgeSubscription(consumerId);
- Response.ResponseBuilder builder = Response.ok();
- headAcknowledgedConsumerResponse(uriInfo, consumer, builder);
-
- return builder.build();
- }
-
- private void headAcknowledgedConsumerResponse(UriInfo uriInfo,
- AcknowledgedQueueConsumer consumer,
- Response.ResponseBuilder builder) {
- // we synchronize just in case a failed request is still processing
- synchronized (consumer) {
- Acknowledgement ack = consumer.getAck();
- if (ack == null || ack.wasSet()) {
- AcknowledgedQueueConsumer.setAcknowledgeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/acknowledged/" + consumer.getId(), Long.toString(consumer.getConsumeIndex()));
- } else {
- consumer.setAcknowledgementLink(builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/acknowledged/" + consumer.getId());
- }
- }
- }
-
- @Path("acknowledged/{subscription-id}")
- public QueueConsumer findAcknoledgeSubscription(@PathParam("subscription-id") String subscriptionId) {
- QueueConsumer consumer = queueConsumers.get(subscriptionId);
- if (consumer == null) {
- consumer = recreateTopicConsumer(subscriptionId, false);
- }
- return consumer;
- }
-
- private boolean subscriptionExists(String subscriptionId) {
- ClientSession session = null;
- try {
- session = sessionFactory.createSession();
-
- ClientSession.QueueQuery query = session.queueQuery(new SimpleString(subscriptionId));
- return query.isExists();
- } catch (ActiveMQException e) {
- throw new RuntimeException(e);
- } finally {
- if (session != null) {
- try {
- session.close();
- } catch (ActiveMQException e) {
- }
- }
- }
- }
-
- private QueueConsumer recreateTopicConsumer(String subscriptionId, boolean autoAck) {
- QueueConsumer consumer;
- if (subscriptionExists(subscriptionId)) {
- QueueConsumer tmp = null;
- try {
- tmp = createConsumer(true, autoAck, subscriptionId, null, consumerTimeoutSeconds * 1000L, false);
- } catch (ActiveMQException e) {
- throw new RuntimeException(e);
- }
- consumer = queueConsumers.putIfAbsent(subscriptionId, tmp);
- if (consumer == null) {
- consumer = tmp;
- serviceManager.getTimeoutTask().add(this, subscriptionId);
- } else {
- tmp.shutdown();
- }
- } else {
- throw new WebApplicationException(Response.status(405).entity("Failed to find subscriber " + subscriptionId + " you will have to reconnect").type("text/plain").build());
- }
- return consumer;
- }
-
- @Path("acknowledged/{subscription-id}")
- @DELETE
- public void deleteAckSubscription(@Context UriInfo uriInfo, @PathParam("subscription-id") String consumerId) {
- logger.debug("Handling DELETE request for \"" + uriInfo.getPath() + "\"");
-
- internalDeleteSubscription(consumerId);
- }
-
- @Path("auto-ack/{subscription-id}")
- @DELETE
- public void deleteSubscription(@Context UriInfo uriInfo, @PathParam("subscription-id") String consumerId) {
- logger.debug("Handling DELETE request for \"" + uriInfo.getPath() + "\"");
-
- internalDeleteSubscription(consumerId);
- }
-
- private void internalDeleteSubscription(String consumerId) {
- QueueConsumer consumer = queueConsumers.remove(consumerId);
- if (consumer == null) {
- String msg = "Failed to match a subscription to URL " + consumerId;
- throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity(msg).type("text/plain").build());
- }
- consumer.shutdown();
- deleteSubscriberQueue(consumer);
- }
-
- private void deleteSubscriberQueue(QueueConsumer consumer) {
- String subscriptionName = consumer.getId();
- ClientSession session = null;
- try {
- session = sessionFactory.createSession();
-
- session.deleteQueue(subscriptionName);
- } catch (ActiveMQException e) {
- } finally {
- if (session != null) {
- try {
- session.close();
- } catch (ActiveMQException e) {
- }
- }
- }
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicDeployment.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicDeployment.java
deleted file mode 100644
index 938e45de8d..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicDeployment.java
+++ /dev/null
@@ -1,40 +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.
- */
-package org.apache.activemq.artemis.rest.topic;
-
-import org.apache.activemq.artemis.rest.queue.DestinationSettings;
-
-public class TopicDeployment extends DestinationSettings {
-
- private String name;
-
- public TopicDeployment() {
- }
-
- public TopicDeployment(String name, boolean duplicatesAllowed) {
- this.name = name;
- this.duplicatesAllowed = duplicatesAllowed;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-}
\ No newline at end of file
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicDestinationsResource.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicDestinationsResource.java
deleted file mode 100644
index b3f8bdda35..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicDestinationsResource.java
+++ /dev/null
@@ -1,170 +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.
- */
-package org.apache.activemq.artemis.rest.topic;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import java.net.URI;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.activemq.artemis.api.core.ActiveMQException;
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.api.core.RoutingType;
-import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
-import org.apache.activemq.artemis.jms.client.ActiveMQTopic;
-import org.apache.activemq.artemis.jms.server.config.TopicConfiguration;
-import org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration;
-import org.apache.activemq.artemis.rest.queue.DestinationSettings;
-import org.apache.activemq.artemis.rest.queue.PostMessage;
-import org.apache.activemq.artemis.rest.queue.PostMessageDupsOk;
-import org.apache.activemq.artemis.rest.queue.PostMessageNoDups;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-
-@Path("/topics")
-public class TopicDestinationsResource {
-
- private static final Logger logger = LoggerFactory.getLogger(TopicDestinationsResource.class);
-
- private final Map<String, TopicResource> topics = new ConcurrentHashMap<>();
- private final TopicServiceManager manager;
-
- public TopicDestinationsResource(TopicServiceManager manager) {
- this.manager = manager;
- }
-
- @POST
- @Consumes("application/activemq.jms.topic+xml")
- public Response createJmsTopic(@Context UriInfo uriInfo, Document document) {
- logger.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");
-
- try {
- TopicConfiguration topic = FileJMSConfiguration.parseTopicConfiguration(document.getDocumentElement());
- ActiveMQTopic activeMQTopic = ActiveMQDestination.createTopic(topic.getName());
- String topicName = activeMQTopic.getAddress();
- ClientSession session = manager.getSessionFactory().createSession(false, false, false);
- try {
-
- ClientSession.AddressQuery query = session.addressQuery(new SimpleString(topicName));
- if (!query.isExists()) {
- session.createAddress(SimpleString.toSimpleString(topicName), RoutingType.MULTICAST, true);
-
- } else {
- throw new WebApplicationException(Response.status(412).type("text/plain").entity("Queue already exists.").build());
- }
- } finally {
- try {
- session.close();
- } catch (Exception ignored) {
- }
- }
- URI uri = uriInfo.getRequestUriBuilder().path(topicName).build();
- return Response.created(uri).build();
- } catch (Exception e) {
- if (e instanceof WebApplicationException)
- throw (WebApplicationException) e;
- throw new WebApplicationException(e, Response.serverError().type("text/plain").entity("Failed to create queue.").build());
- }
- }
-
- @Path("/{topic-name}")
- public TopicResource findTopic(@PathParam("topic-name") String name) throws Exception {
- TopicResource topic = topics.get(name);
- if (topic == null) {
- ClientSession session = manager.getSessionFactory().createSession(false, false, false);
- try {
- ClientSession.AddressQuery query = session.addressQuery(new SimpleString(name));
- if (!query.isExists()) {
- System.err.println("Topic '" + name + "' does not exist");
- throw new WebApplicationException(Response.status(404).type("text/plain").entity("Topic '" + name + "' does not exist").build());
- }
- DestinationSettings queueSettings = manager.getDefaultSettings();
- boolean defaultDurable = queueSettings.isDurableSend();
-
- topic = createTopicResource(name, defaultDurable, queueSettings.getConsumerSessionTimeoutSeconds(), queueSettings.isDuplicatesAllowed());
- } finally {
- try {
- session.close();
- } catch (ActiveMQException e) {
- }
- }
- }
- return topic;
- }
-
- public Map<String, TopicResource> getTopics() {
- return topics;
- }
-
- public TopicResource createTopicResource(String topicName,
- boolean defaultDurable,
- int timeoutSeconds,
- boolean duplicates) throws Exception {
- TopicResource topicResource = new TopicResource();
- topicResource.setTopicDestinationsResource(this);
- topicResource.setDestination(topicName);
- topicResource.setServiceManager(manager);
- SubscriptionsResource subscriptionsResource = new SubscriptionsResource();
- topicResource.setSubscriptions(subscriptionsResource);
- subscriptionsResource.setConsumerTimeoutSeconds(timeoutSeconds);
- subscriptionsResource.setServiceManager(manager);
-
- subscriptionsResource.setDestination(topicName);
- subscriptionsResource.setSessionFactory(manager.getConsumerSessionFactory());
- PushSubscriptionsResource push = new PushSubscriptionsResource(manager.getJmsOptions());
- push.setDestination(topicName);
- push.setSessionFactory(manager.getConsumerSessionFactory());
- topicResource.setPushSubscriptions(push);
-
- PostMessage sender = null;
- if (duplicates) {
- sender = new PostMessageDupsOk();
- } else {
- sender = new PostMessageNoDups();
- }
- sender.setDefaultDurable(defaultDurable);
- sender.setDestination(topicName);
- sender.setSessionFactory(manager.getSessionFactory());
- sender.setPoolSize(manager.getProducerPoolSize());
- sender.setProducerTimeToLive(manager.getProducerTimeToLive());
- sender.setServiceManager(manager);
- sender.init();
- topicResource.setSender(sender);
-
- if (manager.getPushStore() != null) {
- push.setPushStore(manager.getPushStore());
- List<PushTopicRegistration> regs = manager.getPushStore().getByTopic(topicName);
- for (PushTopicRegistration reg : regs) {
- push.addRegistration(reg);
- }
- }
-
- getTopics().put(topicName, topicResource);
- topicResource.start();
- return topicResource;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicPushStore.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicPushStore.java
deleted file mode 100644
index 3348ac66dd..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicPushStore.java
+++ /dev/null
@@ -1,26 +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.
- */
-package org.apache.activemq.artemis.rest.topic;
-
-import java.util.List;
-
-import org.apache.activemq.artemis.rest.queue.push.PushStore;
-
-public interface TopicPushStore extends PushStore {
-
- List<PushTopicRegistration> getByTopic(String topic);
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicResource.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicResource.java
deleted file mode 100644
index 5dda207247..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicResource.java
+++ /dev/null
@@ -1,183 +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.
- */
-package org.apache.activemq.artemis.rest.topic;
-
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HEAD;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
-
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.rest.queue.DestinationResource;
-import org.apache.activemq.artemis.rest.queue.PostMessage;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class TopicResource extends DestinationResource {
-
- private static final Logger logger = LoggerFactory.getLogger(TopicResource.class);
-
- protected SubscriptionsResource subscriptions;
- protected PushSubscriptionsResource pushSubscriptions;
- private TopicDestinationsResource topicDestinationsResource;
-
- public void start() throws Exception {
- }
-
- public void stop() {
- subscriptions.stop();
- pushSubscriptions.stop();
- sender.cleanup();
- }
-
- @GET
- @Produces("application/xml")
- public Response get(@Context UriInfo uriInfo) {
- logger.debug("Handling GET request for \"" + uriInfo.getPath() + "\"");
-
- StringBuilder msg = new StringBuilder();
- msg.append("<topic>").append("<name>").append(destination).append("</name>").append("<atom:link rel=\"create\" href=\"").append(createSenderLink(uriInfo)).append("\"/>").append("<atom:link rel=\"create-with-id\" href=\"").append(createSenderWithIdLink(uriInfo)).append("\"/>").append("<atom:link rel=\"pull-consumers\" href=\"").append(createSubscriptionsLink(uriInfo)).append("\"/>").append("<atom:link rel=\"push-consumers\" href=\"").append(createPushSubscriptionsLink(uriInfo)).appe [...]
-
- .append("</topic>");
-
- Response.ResponseBuilder builder = Response.ok(msg.toString());
- setSenderLink(builder, uriInfo);
- setSenderWithIdLink(builder, uriInfo);
- setSubscriptionsLink(builder, uriInfo);
- setPushSubscriptionsLink(builder, uriInfo);
- return builder.build();
- }
-
- @HEAD
- @Produces("application/xml")
- public Response head(@Context UriInfo uriInfo) {
- logger.debug("Handling HEAD request for \"" + uriInfo.getPath() + "\"");
-
- Response.ResponseBuilder builder = Response.ok();
- setSenderLink(builder, uriInfo);
- setSenderWithIdLink(builder, uriInfo);
- setSubscriptionsLink(builder, uriInfo);
- setPushSubscriptionsLink(builder, uriInfo);
- return builder.build();
- }
-
- protected void setSenderLink(Response.ResponseBuilder response, UriInfo info) {
- String uri = createSenderLink(info);
- serviceManager.getLinkStrategy().setLinkHeader(response, "create", "create", uri, null);
- }
-
- protected String createSenderLink(UriInfo info) {
- UriBuilder builder = info.getRequestUriBuilder();
- builder.path("create");
- String uri = builder.build().toString();
- return uri;
- }
-
- protected void setSenderWithIdLink(Response.ResponseBuilder response, UriInfo info) {
- String uri = createSenderWithIdLink(info);
- serviceManager.getLinkStrategy().setLinkHeader(response, "create-with-id", "create-with-id", uri, null);
- }
-
- protected String createSenderWithIdLink(UriInfo info) {
- UriBuilder builder = info.getRequestUriBuilder();
- builder.path("create");
- String uri = builder.build().toString();
- uri += "/{id}";
- return uri;
- }
-
- protected void setSubscriptionsLink(Response.ResponseBuilder response, UriInfo info) {
- String uri = createSubscriptionsLink(info);
- serviceManager.getLinkStrategy().setLinkHeader(response, "pull-subscriptions", "pull-subscriptions", uri, null);
- }
-
- protected String createSubscriptionsLink(UriInfo info) {
- UriBuilder builder = info.getRequestUriBuilder();
- builder.path("pull-subscriptions");
- String uri = builder.build().toString();
- return uri;
- }
-
- protected void setPushSubscriptionsLink(Response.ResponseBuilder response, UriInfo info) {
- String uri = createPushSubscriptionsLink(info);
- serviceManager.getLinkStrategy().setLinkHeader(response, "push-subscriptions", "push-subscriptions", uri, null);
- }
-
- protected String createPushSubscriptionsLink(UriInfo info) {
- UriBuilder builder = info.getRequestUriBuilder();
- builder.path("push-subscriptions");
- String uri = builder.build().toString();
- return uri;
- }
-
- public void setSubscriptions(SubscriptionsResource subscriptions) {
- this.subscriptions = subscriptions;
- }
-
- @Path("create")
- public PostMessage post() throws Exception {
- return sender;
- }
-
- @Path("pull-subscriptions")
- public SubscriptionsResource getSubscriptions() {
- return subscriptions;
- }
-
- @Path("push-subscriptions")
- public PushSubscriptionsResource getPushSubscriptions() {
- return pushSubscriptions;
- }
-
- public void setPushSubscriptions(PushSubscriptionsResource pushSubscriptions) {
- this.pushSubscriptions = pushSubscriptions;
- }
-
- @DELETE
- public void deleteTopic(@Context UriInfo uriInfo) throws Exception {
- logger.debug("Handling DELETE request for \"" + uriInfo.getPath() + "\"");
-
- topicDestinationsResource.getTopics().remove(destination);
-
- try {
- stop();
- } catch (Exception ignored) {
- }
-
- ClientSession session = serviceManager.getSessionFactory().createSession(false, false, false);
- try {
- SimpleString topicName = new SimpleString(destination);
- session.deleteQueue(topicName);
- } finally {
- try {
- session.close();
- } catch (Exception ignored) {
- }
- }
-
- }
-
- public void setTopicDestinationsResource(TopicDestinationsResource topicDestinationsResource) {
- this.topicDestinationsResource = topicDestinationsResource;
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicServiceManager.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicServiceManager.java
deleted file mode 100644
index e4239a4fb2..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/topic/TopicServiceManager.java
+++ /dev/null
@@ -1,110 +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.
- */
-package org.apache.activemq.artemis.rest.topic;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.api.core.RoutingType;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.queue.DestinationServiceManager;
-
-public class TopicServiceManager extends DestinationServiceManager {
-
- protected TopicPushStore pushStore;
- protected List<TopicDeployment> topics = new ArrayList<>();
- protected TopicDestinationsResource destination;
-
- public TopicServiceManager(ConnectionFactoryOptions jmsOptions) {
- super(jmsOptions);
- }
-
- public TopicPushStore getPushStore() {
- return pushStore;
- }
-
- public void setPushStore(TopicPushStore pushStore) {
- this.pushStore = pushStore;
- }
-
- public List<TopicDeployment> getTopics() {
- return topics;
- }
-
- public void setTopics(List<TopicDeployment> topics) {
- this.topics = topics;
- }
-
- public TopicDestinationsResource getDestination() {
- return destination;
- }
-
- public void setDestination(TopicDestinationsResource destination) {
- this.destination = destination;
- }
-
- @Override
- public void start() throws Exception {
- initDefaults();
-
- started = true;
-
- if (pushStoreFile != null && pushStore == null) {
- pushStore = new FileTopicPushStore(pushStoreFile);
- }
-
- if (destination == null) {
- destination = new TopicDestinationsResource(this);
- }
-
- for (TopicDeployment topic : topics) {
- deploy(topic);
- }
- }
-
- public void deploy(TopicDeployment topicDeployment) throws Exception {
- if (!started) {
- throw new Exception("You must start() this class instance before deploying");
- }
- String queueName = topicDeployment.getName();
- boolean defaultDurable;
-
- try (ClientSession session = sessionFactory.createSession(false, false, false)) {
- defaultDurable = topicDeployment.isDurableSend();
- ClientSession.AddressQuery query = session.addressQuery(new SimpleString(queueName));
- if (!query.isExists())
- session.createAddress(SimpleString.toSimpleString(queueName), RoutingType.MULTICAST, true);
- }
-
- destination.createTopicResource(queueName, defaultDurable, topicDeployment.getConsumerSessionTimeoutSeconds(), topicDeployment.isDuplicatesAllowed());
- }
-
- @Override
- public void stop() {
- if (started == false)
- return;
- for (TopicResource topic : destination.getTopics().values()) {
- topic.stop();
- }
- try {
- sessionFactory.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/Constants.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/Constants.java
deleted file mode 100644
index 9eb990ae97..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/Constants.java
+++ /dev/null
@@ -1,23 +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.
- */
-package org.apache.activemq.artemis.rest.util;
-
-public interface Constants {
-
- String WAIT_HEADER = "Accept-Wait";
- String PATH_FOR_QUEUES = "/queues";
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/CustomHeaderLinkStrategy.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/CustomHeaderLinkStrategy.java
deleted file mode 100644
index 0f590c9dc0..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/CustomHeaderLinkStrategy.java
+++ /dev/null
@@ -1,39 +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.
- */
-package org.apache.activemq.artemis.rest.util;
-
-import javax.ws.rs.core.Response;
-
-public class CustomHeaderLinkStrategy implements LinkStrategy {
-
- @Override
- public void setLinkHeader(Response.ResponseBuilder builder, String title, String rel, String href, String type) {
- String headerName = null;
- if (title != null) {
- headerName = title;
- } else if (rel != null) {
- headerName = rel;
- } else {
- throw new RuntimeException("Cannot figure out header name");
- }
- headerName = "msg-" + headerName;
- builder.header(headerName, href);
- if (type != null) {
- builder.header(headerName + "-type", type);
- }
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/HttpMessageHelper.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/HttpMessageHelper.java
deleted file mode 100644
index 31eb787c46..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/HttpMessageHelper.java
+++ /dev/null
@@ -1,131 +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.
- */
-package org.apache.activemq.artemis.rest.util;
-
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MultivaluedMap;
-import java.io.ByteArrayInputStream;
-import java.util.List;
-import java.util.Map.Entry;
-
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
-import org.apache.activemq.artemis.rest.ActiveMQRestLogger;
-import org.apache.activemq.artemis.rest.HttpHeaderProperty;
-import org.apache.activemq.artemis.utils.ObjectInputStreamWithClassLoader;
-import org.jboss.resteasy.client.ClientRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.activemq.artemis.rest.HttpHeaderProperty.MESSAGE_PROPERTY_DISCRIMINATOR;
-
-public class HttpMessageHelper {
-
- private static final Logger logger = LoggerFactory.getLogger(HttpMessageHelper.class);
-
- public static final String POSTED_AS_HTTP_MESSAGE = "postedAsHttpMessage";
-
- public static boolean isTransferableHttpHeader(String key) {
- String lowerKey = key.toLowerCase();
- return lowerKey.toLowerCase().startsWith("content") || lowerKey.toLowerCase().equals("link");
- }
-
- public static boolean isMessageProperty( String key) {
- return key.toLowerCase().startsWith( MESSAGE_PROPERTY_DISCRIMINATOR );
- }
-
- public static void buildMessage(ClientMessage message,
- ClientRequest request,
- String contentType,
- ConnectionFactoryOptions jmsOptions) {
- for (SimpleString key : message.getPropertyNames()) {
- String k = key.toString();
- String headerName = HttpHeaderProperty.fromPropertyName(k);
- if (headerName == null || headerName.contains("content-length")) {
- continue;
- }
- String value = message.getStringProperty(k);
-
- request.header(headerName, value);
- logger.debug("Examining " + headerName + ": " + value);
- // override default content type if it is set as a message property
- if (headerName.equalsIgnoreCase("content-type")) {
- contentType = value;
- logger.debug("Using contentType: " + contentType);
- }
- }
- int size = message.getBodySize();
- if (size > 0) {
- Boolean aBoolean = message.getBooleanProperty(POSTED_AS_HTTP_MESSAGE);
- if (aBoolean != null && aBoolean.booleanValue()) {
- byte[] body = new byte[size];
- message.getBodyBuffer().readBytes(body);
- logger.debug("Building Message from HTTP message");
- request.body(contentType, body);
- } else {
- // assume posted as a JMS or ActiveMQ Artemis object message
- size = message.getBodyBuffer().readInt();
- byte[] body = new byte[size];
- message.getBodyBuffer().readBytes(body);
- ByteArrayInputStream bais = new ByteArrayInputStream(body);
- Object obj = null;
- try (ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(bais)) {
- if (jmsOptions != null) {
- ois.setBlackList(jmsOptions.getDeserializationBlackList());
- ois.setWhiteList(jmsOptions.getDeserializationWhiteList());
- }
- obj = ois.readObject();
- logger.debug("**** Building Message from object: " + obj.toString());
- request.body(contentType, obj);
- } catch (Exception e) {
- ActiveMQRestLogger.LOGGER.failedToBuildMessageFromObject(e);
- throw new RuntimeException(e);
- }
- }
- }
- }
-
- public static void writeHttpMessage(HttpHeaders headers, byte[] body, ClientMessage message) throws Exception {
-
- MultivaluedMap<String, String> hdrs = headers.getRequestHeaders();
- for (Entry<String, List<String>> entry : hdrs.entrySet()) {
- String key = entry.getKey();
- if (isTransferableHttpHeader(key) || isMessageProperty( key )) {
- List<String> vals = entry.getValue();
- String value = concatenateHeaderValue(vals);
- message.putStringProperty(HttpHeaderProperty.toPropertyName(key), value);
- }
- }
- message.putBooleanProperty(POSTED_AS_HTTP_MESSAGE, true);
- message.getBodyBuffer().writeBytes(body);
- }
-
- public static String concatenateHeaderValue(List<String> vals) {
- if (vals == null) {
- return "";
- }
- StringBuilder val = new StringBuilder();
- for (String v : vals) {
- if (val.length() > 0) {
- val.append(",");
- }
- val.append(v);
- }
- return val.toString();
- }
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/LinkHeaderLinkStrategy.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/LinkHeaderLinkStrategy.java
deleted file mode 100644
index 970d3070a4..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/LinkHeaderLinkStrategy.java
+++ /dev/null
@@ -1,55 +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.
- */
-package org.apache.activemq.artemis.rest.util;
-
-import javax.ws.rs.core.Response;
-
-import org.jboss.resteasy.spi.Link;
-
-public class LinkHeaderLinkStrategy implements LinkStrategy {
-
- /**
- * @param builder
- * @param title user friendly name
- * @param rel could be a link
- * @param href
- * @param type
- */
- @Override
- public void setLinkHeader(Response.ResponseBuilder builder, String title, String rel, String href, String type) {
- Link link = new Link(title, rel, href, type, null);
- setLinkHeader(builder, link);
- }
-
- public void setLinkHeader(Response.ResponseBuilder builder, Link link) {
- builder.header("Link", link);
- }
-
- /* proprietary, keep this around just in case
-
- public static void setLinkHeader(Response.ResponseBuilder builder, String rel, String href, String type)
- {
- String link = "Link-Href-" + rel;
- builder.header(link, href);
- if (type != null)
- {
- String typeHeader = "Link-Type-" + rel;
- builder.header(typeHeader, type);
- }
- }
- */
-}
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/LinkStrategy.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/LinkStrategy.java
deleted file mode 100644
index e49f8f5f4c..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/LinkStrategy.java
+++ /dev/null
@@ -1,24 +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.
- */
-package org.apache.activemq.artemis.rest.util;
-
-import javax.ws.rs.core.Response;
-
-public interface LinkStrategy {
-
- void setLinkHeader(Response.ResponseBuilder builder, String title, String rel, String href, String type);
-}
\ No newline at end of file
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/TimeoutTask.java b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/TimeoutTask.java
deleted file mode 100644
index da0fe740fc..0000000000
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/TimeoutTask.java
+++ /dev/null
@@ -1,164 +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.
- */
-package org.apache.activemq.artemis.rest.util;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class TimeoutTask implements Runnable {
-
- private static final Logger logger = LoggerFactory.getLogger( TimeoutTask.class );
-
- protected boolean running = true;
- protected int interval = 10;
- protected final Lock callbacksLock = new ReentrantLock();
- protected Map<String, Callback> callbacks = new HashMap<>();
- protected final Lock pendingCallbacksLock = new ReentrantLock();
- protected Map<String, Callback> pendingCallbacks = new HashMap<>();
- protected Thread thread;
-
- public TimeoutTask(int interval) {
- this.interval = interval;
- }
-
- public interface Callback {
-
- boolean testTimeout(String token, boolean autoShutdown);
-
- void shutdown(String token);
- }
-
- public synchronized void add(Callback callback, String token) {
- if (callbacksLock.tryLock()) {
- try {
- callbacks.put(token, callback);
- } finally {
- callbacksLock.unlock();
- }
- } else {
- pendingCallbacksLock.lock();
- try {
- pendingCallbacks.put(token, callback);
- } finally {
- pendingCallbacksLock.unlock();
- }
- }
- }
-
- public synchronized void remove(String token) {
- callbacksLock.lock();
- try {
- callbacks.remove(token);
- } finally {
- callbacksLock.unlock();
- }
- }
-
- public synchronized void stop() {
- running = false;
- if (thread != null) {
- thread.interrupt();
- }
- }
-
- public synchronized int getInterval() {
- return interval;
- }
-
- public synchronized void setInterval(int interval) {
- this.interval = interval;
- }
-
- public void start() {
- thread = new Thread(this);
- thread.start();
- }
-
- @Override
- public void run() {
- while (running) {
- try {
- Thread.sleep((long) interval * 1000);
- } catch (InterruptedException e) {
- running = false;
- break;
- }
-
- // First, test all known callbacks for timeouts.
- // If the timeout is true, then move it to a separate map.
- Map<String, Callback> expiredCallbacks = new HashMap<>();
-
- int liveConsumers = 0;
- int deadConsumers = 0;
-
- callbacksLock.lock();
- try {
- long startTime = System.currentTimeMillis();
- List<String> tokens = new ArrayList<>(callbacks.size());
- for (String token : callbacks.keySet()) {
- tokens.add(token);
- }
- for (String token : tokens) {
- Callback callback = callbacks.get(token);
- if (callback.testTimeout(token, false)) {
- deadConsumers += 1;
- expiredCallbacks.put(token, callback);
- callbacks.remove(token);
- } else {
- liveConsumers += 1;
- }
- }
- logger.debug("Finished testing callbacks for timeouts in " +
- (System.currentTimeMillis() - startTime) + "ms. " +
- "(Live: " + liveConsumers + ", Expired: " + deadConsumers + ")");
-
- // Next, move any pending callback additions to the main callbacks map.
- pendingCallbacksLock.lock();
- try {
- if (pendingCallbacks.size() > 0) {
- logger.debug("Found " + pendingCallbacks.size() + " callbacks to add.");
- callbacks.putAll(pendingCallbacks);
- pendingCallbacks.clear();
- }
- } finally {
- pendingCallbacksLock.unlock();
- }
- } finally {
- callbacksLock.unlock();
- }
-
- // Finally, freely shutdown all expired consumers.
- if (expiredCallbacks.size() > 0) {
- List<String> tokens = new ArrayList<>(expiredCallbacks.size());
- for (String token : expiredCallbacks.keySet()) {
- tokens.add(token);
- }
- for (String token : tokens) {
- Callback expired = expiredCallbacks.get(token);
- expired.shutdown(token);
- }
- }
- }
- }
-}
diff --git a/artemis-rest/src/main/resources/schema/artemis-rest.xsd b/artemis-rest/src/main/resources/schema/artemis-rest.xsd
deleted file mode 100644
index eebe77792c..0000000000
--- a/artemis-rest/src/main/resources/schema/artemis-rest.xsd
+++ /dev/null
@@ -1,119 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<xsd:schema xmlns="urn:activemq:rest" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:activemq:rest">
-
- <xsd:element name="rest-messaging">
- <xsd:complexType>
- <xsd:all>
- <xsd:element name="server-in-vm-id" type="xsd:string" minOccurs="0" maxOccurs="1">
- <xsd:annotation>
- <xsd:documentation>
- The ActiveMQ Artemis REST implementation uses the IN-VM transport to communicate
- with ActiveMQ Artemis. It uses the default server id, which is "0".
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element name="use-link-headers" type="xsd:boolean" minOccurs="0" maxOccurs="1">
- <xsd:annotation>
- <xsd:documentation>
- By default, all links (URLs) are published using custom headers.
- You can instead have the ActiveMQ Artemis REST implementation publish links
- using the Link Header specification instead if you desire.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element name="default-durable-send" type="xsd:boolean" minOccurs="0" maxOccurs="1">
- <xsd:annotation>
- <xsd:documentation>
- Whether a posted message should be persisted by default if the user
- does not specify a durable query parameter.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element name="dups-ok" type="xsd:boolean" minOccurs="0" maxOccurs="1">
- <xsd:annotation>
- <xsd:documentation>
- If this is true, no duplicate detection protocol will be enforced for
- message posting.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element name="topic-push-store-dir" type="xsd:string" minOccurs="0" maxOccurs="1">
- <xsd:annotation>
- <xsd:documentation>
- This must be a relative or absolute file system path. This is a
- directory where push registrations for topics are stored.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element name="queue-push-store-dir" type="xsd:string" minOccurs="0" maxOccurs="1">
- <xsd:annotation>
- <xsd:documentation>
- This must be a relative or absolute file system path. This is a
- directory where push registrations for queues are stored.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element name="producer-session-pool-size" type="xsd:int" minOccurs="0" maxOccurs="1">
- <xsd:annotation>
- <xsd:documentation>
- The REST implementation pools ActiveMQ Artemis sessions for sending messages.
- This is the size of the pool. That number of sessions will be created
- at startup time.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element name="producer-time-to-live" type="xsd:long" minOccurs="0" maxOccurs="1">
- <xsd:annotation>
- <xsd:documentation>
- Default time to live for posted messages. Default is no ttl.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element name="session-timeout-task-interval" type="xsd:int" minOccurs="0" maxOccurs="1">
- <xsd:annotation>
- <xsd:documentation>
- Pull consumers and pull subscriptions can time out. This is the
- interval the thread that checks for timed-out sessions will run at. A
- value of 1 means it will run every 1 second.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element name="consumer-session-timeout-seconds" type="xsd:int" minOccurs="0" maxOccurs="1">
- <xsd:annotation>
- <xsd:documentation>
- Timeout in seconds for pull consumers/subscriptions that remain idle
- for that amount of time.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element name="consumer-window-size" type="xsd:int" minOccurs="0" maxOccurs="1">
- <xsd:annotation>
- <xsd:documentation>
- For consumers, this config option is the same as the ActiveMQ Artemis one of the
- same name. It will be used by sessions created by the ActiveMQ Artemis REST
- implementation.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- </xsd:all>
- </xsd:complexType>
- </xsd:element>
-</xsd:schema>
-
diff --git a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/integration/EmbeddedRestActiveMQJMSTest.java b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/integration/EmbeddedRestActiveMQJMSTest.java
deleted file mode 100644
index c886c856dd..0000000000
--- a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/integration/EmbeddedRestActiveMQJMSTest.java
+++ /dev/null
@@ -1,199 +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.
- */
-package org.apache.activemq.artemis.rest.integration;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Session;
-import java.io.Serializable;
-
-import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
-import org.apache.activemq.artemis.core.config.impl.SecurityConfiguration;
-import org.apache.activemq.artemis.rest.HttpHeaderProperty;
-import org.apache.activemq.artemis.rest.test.TransformTest;
-import org.apache.activemq.artemis.rest.test.Util;
-import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
-import org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.spi.Link;
-import org.jboss.resteasy.test.TestPortProvider;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-public class EmbeddedRestActiveMQJMSTest {
- private static final Logger log = LoggerFactory.getLogger(EmbeddedRestActiveMQJMSTest.class);
-
- private static EmbeddedRestActiveMQ server;
- private static ConnectionFactory factory;
- private static Link consumeNext;
-
- @BeforeClass
- public static void startEmbedded() throws Exception {
- server = new EmbeddedRestActiveMQ(null);
- assertNotNull(server.getEmbeddedActiveMQ());
- server.getManager().setConfigResourcePath("activemq-rest.xml");
-
- SecurityConfiguration securityConfiguration = createDefaultSecurityConfiguration();
- ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfiguration);
- server.getEmbeddedActiveMQ().setSecurityManager(securityManager);
-
- server.start();
- factory = ActiveMQJMSClient.createConnectionFactory("vm://0", "cf");
-
- ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/queues/exampleQueue"));
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- assertEquals(200, response.getStatus());
- Link sender = response.getLinkHeader().getLinkByTitle("create");
- log.debug("create: " + sender);
- Link consumers = response.getLinkHeader().getLinkByTitle("pull-consumers");
- log.debug("pull: " + consumers);
- response = Util.setAutoAck(consumers, true);
- consumeNext = response.getLinkHeader().getLinkByTitle("consume-next");
- log.debug("consume-next: " + consumeNext);
- }
-
- @AfterClass
- public static void stopEmbedded() throws Exception {
- server.stop();
- server = null;
- }
-
- @Test
- public void shouldReturnStatusOK() throws Exception {
- TransformTest.Order order = createTestOrder("1", "$5.00");
- publish("exampleQueue", order, null);
-
- ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").accept("application/xml").post(String.class);
-
- assertEquals(200, res.getStatus());
- res.releaseConnection();
- }
-
- @Test
- public void shouldReturnPublishedEntity() throws Exception {
- TransformTest.Order order = createTestOrder("1", "$5.00");
-
- publish("exampleQueue", order, null);
- ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").accept("application/xml").post(String.class);
-
- TransformTest.Order order2 = res.getEntity(TransformTest.Order.class);
- assertEquals(order, order2);
- res.releaseConnection();
- }
-
- @Test
- public void shouldReturnLink() throws Exception {
- TransformTest.Order order = createTestOrder("1", "$5.00");
- publish("exampleQueue", order, null);
-
- ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").accept("application/xml").post(String.class);
-
- consumeNext = res.getLinkHeader().getLinkByTitle("consume-next");
- res.releaseConnection();
- assertNotNull(consumeNext);
- }
-
- @Test
- public void shouldUseXmlAcceptHeaderToSetContentType() throws Exception {
- TransformTest.Order order = createTestOrder("1", "$5.00");
- publish("exampleQueue", order, null);
-
- ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").accept("application/xml").post(String.class);
-
- Assert.assertTrue(res.getHeaders().getFirst("Content-Type").toString().toLowerCase().contains("application/xml"));
-
- consumeNext = res.getLinkHeader().getLinkByTitle("consume-next");
- res.releaseConnection();
- assertNotNull(consumeNext);
- }
-
- @Test
- public void shouldUseMessagePropertyToSetContentType() throws Exception {
- TransformTest.Order order = createTestOrder("2", "$15.00");
- publish("exampleQueue", order, "application/xml");
-
- ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").post(String.class);
-
- Assert.assertTrue(res.getHeaders().getFirst("Content-Type").toString().toLowerCase().contains("application/xml"));
-
- consumeNext = res.getLinkHeader().getLinkByTitle("consume-next");
- res.releaseConnection();
- assertNotNull(consumeNext);
- }
-
- @Test
- public void shouldUseJsonAcceptHeaderToSetContentType() throws Exception {
- TransformTest.Order order = createTestOrder("1", "$5.00");
- publish("exampleQueue", order, null);
-
- ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").accept("application/json").post(String.class);
- assertEquals("application/json", res.getHeaders().getFirst("Content-Type").toString().toLowerCase());
-
- consumeNext = res.getLinkHeader().getLinkByTitle("consume-next");
- res.releaseConnection();
- assertNotNull(consumeNext);
- }
-
- private static SecurityConfiguration createDefaultSecurityConfiguration() {
- SecurityConfiguration securityConfiguration = new SecurityConfiguration();
- securityConfiguration.addUser("guest", "guest");
- securityConfiguration.addRole("guest", "guest");
- securityConfiguration.setDefaultUser("guest");
- return securityConfiguration;
- }
-
- private TransformTest.Order createTestOrder(String name, String amount) {
- TransformTest.Order order = new TransformTest.Order();
- order.setName(name);
- order.setAmount(amount);
- return order;
- }
-
- private static void publish(String destination, Serializable object, String contentType) throws Exception {
- Connection conn = factory.createConnection();
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Destination dest = session.createQueue(destination);
-
- try {
- assertNotNull("Destination was null", dest);
- MessageProducer producer = session.createProducer(dest);
- ObjectMessage message = session.createObjectMessage();
-
- if (contentType != null) {
- message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType);
- }
- message.setObject(object);
-
- producer.send(message);
- } finally {
- conn.close();
- }
- }
-}
diff --git a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/AutoAckQueueTest.java b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/AutoAckQueueTest.java
deleted file mode 100644
index 8d9aa37321..0000000000
--- a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/AutoAckQueueTest.java
+++ /dev/null
@@ -1,88 +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.
- */
-package org.apache.activemq.artemis.rest.test;
-
-import org.apache.activemq.artemis.rest.queue.QueueDeployment;
-import org.apache.activemq.artemis.rest.util.Constants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.spi.Link;
-import org.jboss.resteasy.test.TestPortProvider;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class AutoAckQueueTest extends MessageTestBase {
- private static final Logger log = LoggerFactory.getLogger(AutoAckQueueTest.class);
-
- @Test
- public void testSuccessFirst() throws Exception {
- String testName = "testSuccessFirst";
- QueueDeployment deployment = new QueueDeployment();
- deployment.setDuplicatesAllowed(true);
- deployment.setDurableSend(false);
- deployment.setName(testName);
- manager.getQueueManager().deploy(deployment);
-
- ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/queues/" + testName));
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
- log.debug("create: " + sender);
- Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
- log.debug("pull: " + consumers);
- log.debug("create-with-id: " + getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create-with-id"));
- response = Util.setAutoAck(consumers, true);
- Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
- log.debug("poller: " + consumeNext);
-
- ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- log.debug("create-next: " + getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "create-next"));
-
- res = sender.request().body("text/plain", Integer.toString(2)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- res = consumeNext.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("1", res.getEntity(String.class));
- res.releaseConnection();
- Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
- log.debug("consumeNext: {}", consumeNext);
-
- res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("2", res.getEntity(String.class));
- res.releaseConnection();
- session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
- log.debug("consumeNext: " + consumeNext);
-
- res = session.request().delete();
- res.releaseConnection();
- Assert.assertEquals(204, res.getStatus());
- }
-
-}
\ No newline at end of file
diff --git a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/AutoAckTopicTest.java b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/AutoAckTopicTest.java
deleted file mode 100644
index 879e425c0a..0000000000
--- a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/AutoAckTopicTest.java
+++ /dev/null
@@ -1,217 +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.
- */
-package org.apache.activemq.artemis.rest.test;
-
-import org.apache.activemq.artemis.rest.topic.TopicDeployment;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.spi.Link;
-import org.jboss.resteasy.test.TestPortProvider;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class AutoAckTopicTest extends MessageTestBase {
- private static final Logger log = LoggerFactory.getLogger(AutoAckTopicTest.class);
-
- @Test
- public void testSuccessFirst() throws Exception {
- String testName = "AutoAckTopicTest.testSuccessFirst";
- TopicDeployment deployment = new TopicDeployment();
- deployment.setDuplicatesAllowed(true);
- deployment.setDurableSend(false);
- deployment.setName(testName);
- manager.getTopicManager().deploy(deployment);
-
- ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/topics/" + testName));
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
- Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");
-
- ClientResponse<?> res = subscriptions.request().post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- Link sub1 = res.getLocationLink();
- Assert.assertNotNull(sub1);
- Link consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
- Assert.assertNotNull(consumeNext1);
- log.debug("consumeNext1: " + consumeNext1);
-
- res = subscriptions.request().post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- Link sub2 = res.getLocationLink();
- Assert.assertNotNull(sub2);
- Link consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
- Assert.assertNotNull(consumeNext2);
- log.debug("consumeNext2: " + consumeNext2);
-
- res = sender.request().body("text/plain", "1").post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- res = sender.request().body("text/plain", "2").post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- res = consumeNext1.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("1", res.getEntity(String.class));
- res.releaseConnection();
- consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
-
- res = consumeNext1.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("2", res.getEntity(String.class));
- res.releaseConnection();
- consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
-
- res = consumeNext2.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("1", res.getEntity(String.class));
- res.releaseConnection();
- consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
-
- res = consumeNext2.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("2", res.getEntity(String.class));
- res.releaseConnection();
- consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
- Assert.assertEquals(204, sub1.request().delete().getStatus());
- Assert.assertEquals(204, sub2.request().delete().getStatus());
- }
-
- @Test
- public void testNewSubNotBlockedByTimeoutTask() throws Exception {
- // Default config is 1s interval, 300s timeout.
-
- // Create a topic
- String testName = "AutoAckTopicTest.testNewSubNotBlockedByTimeoutTask";
- TopicDeployment deployment = new TopicDeployment();
- deployment.setDuplicatesAllowed(true);
- deployment.setDurableSend(false);
- deployment.setName(testName);
- manager.getTopicManager().deploy(deployment);
-
- // Create a consumer
- ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/topics/" + testName));
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
- Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");
-
- // Create the pull-subscription itself.
- ClientResponse<?> res = subscriptions.request().post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- Link sub1 = res.getLocationLink();
- Assert.assertNotNull(sub1);
- Link consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
- Assert.assertNotNull(consumeNext1);
-
- // Pull on the topic for 8s (long enoguh to guarantee the rest of the test
- // will pass/fail due to the timeouttask + test operations)
- AcceptWaitListener awlistener = new AcceptWaitListener(consumeNext1.getHref());
- Thread t = new Thread(awlistener);
- t.start();
- // Wait 2 seconds to ensure a new TimeoutTask is running concurrently.
- Thread.sleep(2000);
- // Attempt to create a new pull-subscription. Validate that it takes no longer than 2 seconds
- // (it should take like 20ms, but give it a relatively huge amount of leeway)
- NewPullSubscriber nps = new NewPullSubscriber(subscriptions.getHref());
- Thread npsThread = new Thread(nps);
- npsThread.start();
- Thread.sleep(2000);
- Assert.assertTrue("NewPullSubscriber did not finish in 2 seconds!", nps.isFinished());
- Assert.assertFalse("AcceptWaitListener failed to open connection!", awlistener.isFailed());
- Assert.assertFalse("NewPullSubscriber failed to open new subscription!", nps.isFailed());
- npsThread.interrupt();
- t.interrupt();
- }
-
- private class NewPullSubscriber implements Runnable {
-
- private final String url;
- private boolean isFinished = false;
- private boolean failed = false;
-
- private NewPullSubscriber(String url) {
- this.url = url;
- }
-
- public boolean isFinished() {
- return isFinished;
- }
-
- public boolean isFailed() {
- return failed;
- }
-
- @Override
- public void run() {
- try {
- isFinished = false;
- ClientRequest request = new ClientRequest(url);
- ClientResponse<?> response = request.post();
- response.releaseConnection();
- log.debug("NPS response: " + response.getStatus());
- Assert.assertEquals(201, response.getStatus());
- isFinished = true;
- } catch (Exception e) {
- log.debug("Exception " + e);
- failed = true;
- }
- }
- }
-
- private class AcceptWaitListener implements Runnable {
-
- private final int acceptWaitTime = 8;
- private String url;
- private boolean isFinished = false;
- private boolean failed = false;
-
- private AcceptWaitListener(String url) {
- this.url = url;
- }
-
- public boolean isFinished() {
- return this.isFinished;
- }
-
- public boolean isFailed() {
- return this.failed;
- }
-
- @Override
- public void run() {
- try {
- ClientRequest req = new ClientRequest(url);
- req.header("Accept-Wait", acceptWaitTime);
- ClientResponse<?> response = req.post();
- response.releaseConnection();
- isFinished = true;
- } catch (Exception e) {
- failed = true;
- }
- }
- }
-}
diff --git a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/ClientAckQueueTest.java b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/ClientAckQueueTest.java
deleted file mode 100644
index 25b85fc1e3..0000000000
--- a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/ClientAckQueueTest.java
+++ /dev/null
@@ -1,376 +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.
- */
-package org.apache.activemq.artemis.rest.test;
-
-import org.apache.activemq.artemis.rest.queue.QueueDeployment;
-import org.apache.activemq.artemis.rest.util.Constants;
-import org.apache.activemq.artemis.rest.util.CustomHeaderLinkStrategy;
-import org.apache.activemq.artemis.rest.util.LinkHeaderLinkStrategy;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.spi.Link;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import static org.jboss.resteasy.test.TestPortProvider.generateURL;
-
-public class ClientAckQueueTest extends MessageTestBase {
- private static final Logger log = LoggerFactory.getLogger(ClientAckQueueTest.class);
-
- @BeforeClass
- public static void setup() throws Exception {
- QueueDeployment deployment1 = new QueueDeployment("testQueue", true);
- manager.getQueueManager().deploy(deployment1);
- }
-
- @Test
- public void testAckTimeoutX2() throws Exception {
- QueueDeployment deployment = new QueueDeployment();
- deployment.setConsumerSessionTimeoutSeconds(1);
- deployment.setDuplicatesAllowed(true);
- deployment.setDurableSend(false);
- deployment.setName("testAck");
- manager.getQueueManager().deploy(deployment);
-
- manager.getQueueManager().setLinkStrategy(new LinkHeaderLinkStrategy());
- testAckTimeout();
- manager.getQueueManager().setLinkStrategy(new CustomHeaderLinkStrategy());
- testAckTimeout();
- }
-
- private void testAckTimeout() throws Exception {
- ClientRequest request = new ClientRequest(generateURL("/queues/testAck"));
-
- ClientResponse<?> response = Util.head(request);
-
- Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
- log.debug("create: " + sender);
- Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
- log.debug("pull: " + consumers);
- response = Util.setAutoAck(consumers, false);
- Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
- log.debug("poller: " + consumeNext);
-
- {
- ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- res = consumeNext.request().post(String.class);
- res.releaseConnection();
- Assert.assertEquals(200, res.getStatus());
- Link ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- Assert.assertNotNull(ack);
- Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledge-next");
- log.debug("consumeNext: " + consumeNext);
-
- // test timeout
- Thread.sleep(2000);
-
- ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(412, ackRes.getStatus());
- log.debug("**** Successfully failed ack");
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), ackRes, "acknowledge-next");
- log.debug("consumeNext: " + consumeNext);
- }
- {
- ClientResponse<?> res = consumeNext.request().header(Constants.WAIT_HEADER, "2").post(String.class);
- res.releaseConnection();
- Assert.assertEquals(200, res.getStatus());
- Link ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- Assert.assertNotNull(ack);
- Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledge-next");
- log.debug("consumeNext: " + consumeNext);
-
- ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
- if (ackRes.getStatus() != 204) {
- log.debug("{}", ackRes.getEntity(String.class));
- }
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
-
- Assert.assertEquals(204, session.request().delete().getStatus());
- }
- }
-
- @Test
- public void testSuccessFirstX2() throws Exception {
- String testName = "testSuccessFirstX2";
-
- QueueDeployment queueDeployment = new QueueDeployment(testName, true);
- manager.getQueueManager().deploy(queueDeployment);
-
- manager.getQueueManager().setLinkStrategy(new LinkHeaderLinkStrategy());
- testSuccessFirst(1, testName);
- manager.getQueueManager().setLinkStrategy(new CustomHeaderLinkStrategy());
- testSuccessFirst(3, testName);
- }
-
- private void testSuccessFirst(int start, String queueName) throws Exception {
- ClientRequest request = new ClientRequest(generateURL(Util.getUrlPath(queueName)));
-
- ClientResponse<?> response = Util.head(request);
- Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
- log.debug("create: " + sender);
- Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
- log.debug("pull-consumers: " + consumers);
- response = Util.setAutoAck(consumers, false);
- Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
- log.debug("acknowledge-next: " + consumeNext);
-
- String data = Integer.toString(start);
- log.debug("Sending: " + data);
- ClientResponse<?> res = sender.request().body("text/plain", data).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- log.debug("call acknowledge-next");
- res = consumeNext.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals(Integer.toString(start++), res.getEntity());
- res.releaseConnection();
- Link ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- Assert.assertNotNull(ack);
- Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledge-next");
- log.debug("consumeNext: " + consumeNext);
- ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), ackRes, "acknowledge-next");
-
- log.debug("sending next...");
- String data2 = Integer.toString(start);
- log.debug("Sending: " + data2);
- res = sender.request().body("text/plain", data2).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- log.debug("{}", consumeNext);
- res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals(Integer.toString(start++), res.getEntity());
- res.releaseConnection();
- ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- Assert.assertNotNull(ack);
- session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), ackRes, "acknowledge-next");
- log.debug("consumeNext: " + consumeNext);
- res = consumeNext.request().post(String.class);
- res.releaseConnection();
-
- log.debug("{}", res.getStatus());
-
- Assert.assertEquals(204, session.request().delete().getStatus());
- }
-
- @Test
- public void testPullX2() throws Exception {
- String testName = "testPullX2";
-
- QueueDeployment queueDeployment = new QueueDeployment(testName, true);
- manager.getQueueManager().deploy(queueDeployment);
-
- manager.getQueueManager().setLinkStrategy(new LinkHeaderLinkStrategy());
- testPull(1, testName);
- manager.getQueueManager().setLinkStrategy(new CustomHeaderLinkStrategy());
- testPull(4, testName);
- }
-
- private void testPull(int start, String queueName) throws Exception {
- ClientRequest request = new ClientRequest(generateURL(Util.getUrlPath(queueName)));
-
- ClientResponse<?> response = Util.head(request);
- Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
- log.debug("create: " + sender);
- Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
- log.debug("pull: " + consumers);
- response = Util.setAutoAck(consumers, false);
- Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
- log.debug("poller: " + consumeNext);
-
- ClientResponse<String> res = consumeNext.request().post(String.class);
- res.releaseConnection();
- Assert.assertEquals(503, res.getStatus());
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledge-next");
- log.debug("{}", consumeNext);
- res = sender.request().body("text/plain", Integer.toString(start)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- res = consumeNext.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals(Integer.toString(start++), res.getEntity());
- res.releaseConnection();
- Link ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
- res = consumeNext.request().post();
- res.releaseConnection();
- Assert.assertEquals(503, res.getStatus());
- res = sender.request().body("text/plain", Integer.toString(start)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- res = sender.request().body("text/plain", Integer.toString(start + 1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- res = consumeNext.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals(Integer.toString(start++), res.getEntity());
- res.releaseConnection();
- ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
-
- res = consumeNext.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals(Integer.toString(start++), res.getEntity());
- res.releaseConnection();
- ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
- Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), ackRes, "consumer");
-
- res = consumeNext.request().post();
- res.releaseConnection();
- Assert.assertEquals(503, res.getStatus());
- log.debug("{}", session);
- res = session.request().delete();
- res.releaseConnection();
- Assert.assertEquals(204, res.getStatus());
- }
-
- @Test
- public void testReconnectX2() throws Exception {
- String testName = "testReconnectX2";
-
- QueueDeployment queueDeployment = new QueueDeployment(testName, true);
- manager.getQueueManager().deploy(queueDeployment);
-
- manager.getQueueManager().setLinkStrategy(new LinkHeaderLinkStrategy());
- testReconnect(testName);
- manager.getQueueManager().setLinkStrategy(new CustomHeaderLinkStrategy());
- testReconnect(testName);
- }
-
- private void testReconnect(String queueName) throws Exception {
- ClientRequest request = new ClientRequest(generateURL(Util.getUrlPath(queueName)));
-
- ClientResponse<?> response = Util.head(request);
- Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
- log.debug("create: " + sender);
- Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
- log.debug("pull: " + consumers);
- response = Util.setAutoAck(consumers, false);
- Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
- log.debug("poller: " + consumeNext);
-
- ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- res = consumeNext.request().post(String.class);
- res.releaseConnection();
- Assert.assertEquals(200, res.getStatus());
- Link ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- Assert.assertNotNull(ack);
- Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledge-next");
- log.debug("consumeNext: " + consumeNext);
- ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), ackRes, "acknowledge-next");
- log.debug("before close session consumeNext: " + consumeNext);
-
- // test reconnect with a disconnected acknowledge-next
- Assert.assertEquals(204, session.request().delete().getStatus());
-
- res = sender.request().body("text/plain", Integer.toString(2)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
- res.releaseConnection();
- Assert.assertEquals(200, res.getStatus());
- ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- Assert.assertNotNull(ack);
- ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
- session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), ackRes, "consumer");
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), ackRes, "acknowledge-next");
- log.debug("session: " + session);
-
- // test reconnect with disconnected acknowledge
-
- res = sender.request().body("text/plain", Integer.toString(3)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
- res.releaseConnection();
- Assert.assertEquals(200, res.getStatus());
- ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- Assert.assertNotNull(ack);
-
- Assert.assertEquals(204, session.request().delete().getStatus());
-
- ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(412, ackRes.getStatus());
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), ackRes, "acknowledge-next");
- res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
- res.releaseConnection();
- Assert.assertEquals(200, res.getStatus());
- ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- Assert.assertNotNull(ack);
- ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
- session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), ackRes, "consumer");
-
- Assert.assertEquals(204, session.request().delete().getStatus());
- }
-}
diff --git a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/ClientAckTopicTest.java b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/ClientAckTopicTest.java
deleted file mode 100644
index e17ec215af..0000000000
--- a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/ClientAckTopicTest.java
+++ /dev/null
@@ -1,319 +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.
- */
-package org.apache.activemq.artemis.rest.test;
-
-import org.apache.activemq.artemis.rest.topic.TopicDeployment;
-import org.apache.activemq.artemis.rest.util.Constants;
-import org.apache.activemq.artemis.rest.util.CustomHeaderLinkStrategy;
-import org.apache.activemq.artemis.rest.util.LinkHeaderLinkStrategy;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.spi.Link;
-import org.jboss.resteasy.test.TestPortProvider;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class ClientAckTopicTest extends MessageTestBase {
-
- private static final Logger log = LoggerFactory.getLogger(ClientAckTopicTest.class);
-
- @BeforeClass
- public static void setup() throws Exception {
- TopicDeployment deployment1 = new TopicDeployment("testQueue", true);
- manager.getTopicManager().deploy(deployment1);
- }
-
- @Test
- public void testAckTimeoutX2() throws Exception {
- TopicDeployment deployment = new TopicDeployment();
- deployment.setConsumerSessionTimeoutSeconds(1);
- deployment.setDuplicatesAllowed(true);
- deployment.setDurableSend(false);
- deployment.setName("testAck");
- manager.getTopicManager().deploy(deployment);
-
- manager.getTopicManager().setLinkStrategy(new LinkHeaderLinkStrategy());
- testAckTimeout();
- manager.getTopicManager().setLinkStrategy(new CustomHeaderLinkStrategy());
- testAckTimeout();
- }
-
- private void testAckTimeout() throws Exception {
-
- ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/topics/testAck"));
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
- log.debug("create: " + sender);
- Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");
- response = subscriptions.request().formParameter("autoAck", "false").formParameter("durable", "true").post();
- response.releaseConnection();
- Assert.assertEquals(201, response.getStatus());
- Link sub1 = response.getLocationLink();
- Assert.assertNotNull(sub1);
-
- Link consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "acknowledge-next");
- log.debug("poller: " + consumeNext);
-
- {
- ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- res = consumeNext.request().post(String.class);
- res.releaseConnection();
- Assert.assertEquals(200, res.getStatus());
- Link ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- Assert.assertNotNull(ack);
- Link session = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledge-next");
- log.debug("consumeNext: " + consumeNext);
-
- // test timeout
- Thread.sleep(2000);
-
- ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
- if (ackRes.getStatus() == 500) {
- log.debug("Failure: " + ackRes.getEntity(String.class));
- }
- ackRes.releaseConnection();
- Assert.assertEquals(412, ackRes.getStatus());
- log.debug("**** Successfully failed ack");
- consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), ackRes, "acknowledge-next");
- log.debug("consumeNext: " + consumeNext);
- }
- {
- ClientResponse<?> res = consumeNext.request().header(Constants.WAIT_HEADER, "2").post(String.class);
- res.releaseConnection();
- Assert.assertEquals(200, res.getStatus());
- Link ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- Assert.assertNotNull(ack);
- consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledge-next");
- log.debug("consumeNext: " + consumeNext);
-
- ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
- if (ackRes.getStatus() != 204 && log.isDebugEnabled()) {
- log.debug("Statuc is not 204, {}", ackRes.getEntity(String.class));
- }
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
- }
- Assert.assertEquals(204, sub1.request().delete().getStatus());
- }
-
- @Test
- public void testSuccessFirst() throws Exception {
- ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/topics/testQueue"));
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
- log.debug("create: " + sender);
-
- Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");
- response = subscriptions.request().formParameter("autoAck", "false").formParameter("durable", "true").post();
- response.releaseConnection();
- Assert.assertEquals(201, response.getStatus());
- Link sub1 = response.getLocationLink();
- Assert.assertNotNull(sub1);
- Link consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "acknowledge-next");
- log.debug("poller: " + consumeNext);
-
- ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- log.debug("call ack next");
- res = consumeNext.request().post(String.class);
- res.releaseConnection();
- Assert.assertEquals(200, res.getStatus());
- Link ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- Assert.assertNotNull(ack);
- Link session = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledge-next");
- log.debug("consumeNext: " + consumeNext);
- ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
- consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), ackRes, "acknowledge-next");
-
- log.debug("sending next...");
- res = sender.request().body("text/plain", Integer.toString(2)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- log.debug("{}", consumeNext);
- res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
- res.releaseConnection();
- Assert.assertEquals(200, res.getStatus());
- ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- Assert.assertNotNull(ack);
- getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledge-next");
- log.debug("consumeNext: " + consumeNext);
- ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
-
- Assert.assertEquals(204, sub1.request().delete().getStatus());
- }
-
- @Test
- public void testSuccessFirstNonDurable() throws Exception {
- ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/topics/testQueue"));
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
- log.debug("create: " + sender);
-
- Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");
- response = subscriptions.request().formParameter("autoAck", "false").formParameter("durable", "false").post();
- response.releaseConnection();
- Assert.assertEquals(201, response.getStatus());
- Link sub1 = response.getLocationLink();
- Assert.assertNotNull(sub1);
- Link consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "acknowledge-next");
- log.debug("poller: " + consumeNext);
-
- ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- log.debug("call ack next");
- res = consumeNext.request().post(String.class);
- res.releaseConnection();
- Assert.assertEquals(200, res.getStatus());
- Link ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- Assert.assertNotNull(ack);
- Link session = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledge-next");
- log.debug("consumeNext: " + consumeNext);
- ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
- consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), ackRes, "acknowledge-next");
-
- log.debug("sending next...");
- res = sender.request().body("text/plain", Integer.toString(2)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- log.debug("{}", consumeNext);
- res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
- res.releaseConnection();
- Assert.assertEquals(200, res.getStatus());
- ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- Assert.assertNotNull(ack);
- getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledge-next");
- log.debug("consumeNext: " + consumeNext);
- ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
-
- Assert.assertEquals(204, sub1.request().delete().getStatus());
- }
-
- @Test
- public void testPull() throws Exception {
- ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/topics/testQueue"));
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
- log.debug("create: " + sender);
- Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");
- response = subscriptions.request().formParameter("autoAck", "false").formParameter("durable", "true").post();
- response.releaseConnection();
- Assert.assertEquals(201, response.getStatus());
- Link sub1 = response.getLocationLink();
- Assert.assertNotNull(sub1);
- Link consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "acknowledge-next");
- log.debug("poller: " + consumeNext);
-
- ClientResponse<String> res = consumeNext.request().post(String.class);
- res.releaseConnection();
- Assert.assertEquals(503, res.getStatus());
- consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledge-next");
- log.debug("{}", consumeNext);
- res = sender.request().body("text/plain", Integer.toString(1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- res = consumeNext.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals(Integer.toString(1), res.getEntity());
- res.releaseConnection();
- Link ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
- res = consumeNext.request().post();
- res.releaseConnection();
- Assert.assertEquals(503, res.getStatus());
- res = sender.request().body("text/plain", Integer.toString(2)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- res = sender.request().body("text/plain", Integer.toString(3)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- res = consumeNext.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals(Integer.toString(2), res.getEntity());
- res.releaseConnection();
- ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
-
- res = consumeNext.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals(Integer.toString(3), res.getEntity());
- res.releaseConnection();
- ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
- log.debug("ack: " + ack);
- ackRes = ack.request().formParameter("acknowledge", "true").post();
- ackRes.releaseConnection();
- Assert.assertEquals(204, ackRes.getStatus());
-
- res = consumeNext.request().post();
- res.releaseConnection();
- Assert.assertEquals(503, res.getStatus());
- log.debug("{}", sub1);
- res = sub1.request().delete();
- res.releaseConnection();
- Assert.assertEquals(204, res.getStatus());
- }
-}
diff --git a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/CreateDestinationTest.java b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/CreateDestinationTest.java
deleted file mode 100644
index 84ff7d50dc..0000000000
--- a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/CreateDestinationTest.java
+++ /dev/null
@@ -1,180 +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.
- */
-package org.apache.activemq.artemis.rest.test;
-
-import org.apache.activemq.artemis.rest.util.Constants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.spi.Link;
-import org.jboss.resteasy.test.TestPortProvider;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class CreateDestinationTest extends MessageTestBase {
- private static final Logger log = LoggerFactory.getLogger(CreateDestinationTest.class);
-
- @BeforeClass
- public static void reg() {
- server.getJaxrsServer().getDeployment().getProviderFactory().registerProvider(org.jboss.resteasy.plugins.providers.DocumentProvider.class);
- }
-
- @Test
- public void testCreateQueue() throws Exception {
- String queueConfig = "<queue name=\"testQueue\"><durable>true</durable></queue>";
- ClientRequest create = new ClientRequest(TestPortProvider.generateURL("/queues"));
- ClientResponse cRes = create.body("application/activemq.jms.queue+xml", queueConfig).post();
- cRes.releaseConnection();
- Assert.assertEquals(201, cRes.getStatus());
- log.debug("Location: " + cRes.getLocationLink());
- ClientRequest request = cRes.getLocationLink().request();
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
- log.debug("create: " + sender);
- Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
- log.debug("pull: " + consumers);
- response = Util.setAutoAck(consumers, true);
- Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
- log.debug("poller: " + consumeNext);
-
- ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- res = consumeNext.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("1", res.getEntity(String.class));
- res.releaseConnection();
- Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
- log.debug("consumeNext: " + consumeNext);
-
- res = sender.request().body("text/plain", Integer.toString(2)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- log.debug("{}", consumeNext);
- res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("2", res.getEntity(String.class));
- res.releaseConnection();
- session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
- log.debug("consumeNext: " + consumeNext);
-
- res = session.request().delete();
- res.releaseConnection();
- Assert.assertEquals(204, res.getStatus());
- }
-
- @Test
- public void testCreateTopic() throws Exception {
- String queueConfig = "<topic name=\"testTopic\"></topic>";
- ClientRequest create = new ClientRequest(TestPortProvider.generateURL("/topics"));
- ClientResponse cRes = create.body("application/activemq.jms.topic+xml", queueConfig).post();
- cRes.releaseConnection();
- Assert.assertEquals(201, cRes.getStatus());
-
- ClientRequest request = cRes.getLocationLink().request();
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
- Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");
-
- ClientResponse<?> res = subscriptions.request().post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- Link sub1 = res.getLocationLink();
- Assert.assertNotNull(sub1);
- Link consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
- Assert.assertNotNull(consumeNext1);
- log.debug("consumeNext1: " + consumeNext1);
-
- res = subscriptions.request().post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- Link sub2 = res.getLocationLink();
- Assert.assertNotNull(sub2);
- Link consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
- Assert.assertNotNull(consumeNext1);
-
- res = sender.request().body("text/plain", Integer.toString(1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- res = sender.request().body("text/plain", Integer.toString(2)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- res = consumeNext1.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("1", res.getEntity(String.class));
- res.releaseConnection();
- consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
-
- res = consumeNext1.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("2", res.getEntity(String.class));
- res.releaseConnection();
- consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
-
- res = consumeNext2.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("1", res.getEntity(String.class));
- res.releaseConnection();
- consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
-
- res = consumeNext2.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("2", res.getEntity(String.class));
- res.releaseConnection();
- consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
- res = sub1.request().delete();
- res.releaseConnection();
- Assert.assertEquals(204, res.getStatus());
- res = sub2.request().delete();
- res.releaseConnection();
- Assert.assertEquals(204, res.getStatus());
- }
-
- @Test
- public void testCreateQueueWithBadContentType() throws Exception {
- String queueConfig = "<queue name=\"testQueue\"><durable>true</durable></queue>";
- ClientRequest create = new ClientRequest(TestPortProvider.generateURL("/queues"));
- ClientResponse cRes = create.body("application/x-www-form-urlencoded", queueConfig).post();
- cRes.releaseConnection();
-
- Assert.assertEquals(415, cRes.getStatus());
- }
-
- @Test
- public void testCreateTopicWithBadContentType() throws Exception {
- String queueConfig = "<topic name=\"testTopic\"></topic>";
- ClientRequest create = new ClientRequest(TestPortProvider.generateURL("/topics"));
- ClientResponse cRes = create.body("application/x-www-form-urlencoded", queueConfig).post();
- cRes.releaseConnection();
- Assert.assertEquals(415, cRes.getStatus());
- }
-}
\ No newline at end of file
diff --git a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/DupQueueTest.java b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/DupQueueTest.java
deleted file mode 100644
index e1cbfc2b52..0000000000
--- a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/DupQueueTest.java
+++ /dev/null
@@ -1,154 +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.
- */
-package org.apache.activemq.artemis.rest.test;
-
-import org.apache.activemq.artemis.rest.queue.QueueDeployment;
-import org.apache.activemq.artemis.rest.util.Constants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.spi.Link;
-import org.junit.Assert;
-import org.junit.Test;
-
-import static org.jboss.resteasy.test.TestPortProvider.generateURL;
-
-public class DupQueueTest extends MessageTestBase {
- private static final Logger log = LoggerFactory.getLogger(DupQueueTest.class);
-
- @Test
- public void testDup() throws Exception {
- String testName = "testDup";
- QueueDeployment deployment = new QueueDeployment();
- deployment.setDuplicatesAllowed(false);
- deployment.setDurableSend(false);
- deployment.setName(testName);
- manager.getQueueManager().deploy(deployment);
-
- ClientRequest request = new ClientRequest(generateURL("/queues/" + testName));
-
- ClientResponse<?> response = request.head();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
- log.debug("create: " + sender);
- Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
- log.debug("pull: " + consumers);
- response = Util.setAutoAck(consumers, true);
- Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
- log.debug("poller: " + consumeNext);
-
- ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
- Assert.assertEquals(307, res.getStatus());
- sender = res.getLocationLink();
- res.releaseConnection();
- log.debug("create-next: " + sender);
- Assert.assertNotNull(sender);
- res = sender.request().body("text/plain", Integer.toString(1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- res = sender.request().body("text/plain", Integer.toString(1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "create-next");
- res = sender.request().body("text/plain", Integer.toString(2)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- res = consumeNext.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("1", res.getEntity(String.class));
- res.releaseConnection();
- Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
- log.debug("consumeNext: " + consumeNext);
-
- res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
- Assert.assertEquals(200, res.getStatus());
- res.releaseConnection();
- session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
- log.debug("consumeNext: " + consumeNext);
- res = consumeNext.request().post(String.class);
- res.releaseConnection();
-
- res = session.request().delete();
- res.releaseConnection();
- Assert.assertEquals(204, res.getStatus());
- }
-
- @Test
- public void testDupWithId() throws Exception {
- String testName = "testDupWithId";
- QueueDeployment deployment = new QueueDeployment();
- deployment.setDuplicatesAllowed(false);
- deployment.setDurableSend(false);
- deployment.setName(testName);
- manager.getQueueManager().deploy(deployment);
-
- ClientRequest request = new ClientRequest(generateURL("/queues/" + testName));
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create-with-id");
- log.debug("create: " + sender);
- Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
- log.debug("pull: " + consumers);
- response = Util.setAutoAck(consumers, true);
- Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
- log.debug("poller: " + consumeNext);
-
- ClientResponse<?> res = sender.request().pathParameter("id", "1").body("text/plain", Integer.toString(1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- res = sender.request().body("text/plain", Integer.toString(1)).pathParameter("id", "1").post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "create-next");
- res = sender.request().body("text/plain", Integer.toString(2)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- res = consumeNext.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("1", res.getEntity(String.class));
- res.releaseConnection();
- Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
- log.debug("consumeNext: " + consumeNext);
-
- res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("2", res.getEntity(String.class));
- res.releaseConnection();
- session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
- log.debug("consumeNext: " + consumeNext);
- res = consumeNext.request().post(String.class);
- res.releaseConnection();
- Assert.assertEquals(503, res.getStatus());
-
- res = session.request().delete();
- res.releaseConnection();
- Assert.assertEquals(204, res.getStatus());
- }
-}
\ No newline at end of file
diff --git a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/Embedded.java b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/Embedded.java
deleted file mode 100644
index 4bd29f8eb3..0000000000
--- a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/Embedded.java
+++ /dev/null
@@ -1,94 +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.
- */
-package org.apache.activemq.artemis.rest.test;
-
-import org.apache.activemq.artemis.api.core.TransportConfiguration;
-import org.apache.activemq.artemis.core.config.Configuration;
-import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
-import org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory;
-import org.apache.activemq.artemis.core.server.ActiveMQServer;
-import org.apache.activemq.artemis.core.server.ActiveMQServers;
-import org.apache.activemq.artemis.rest.MessageServiceConfiguration;
-import org.apache.activemq.artemis.rest.MessageServiceManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.jboss.resteasy.plugins.server.tjws.TJWSEmbeddedJaxrsServer;
-import org.jboss.resteasy.test.TestPortProvider;
-
-public class Embedded {
- private static final Logger log = LoggerFactory.getLogger(Embedded.class);
-
- protected MessageServiceManager manager = new MessageServiceManager(null);
- protected MessageServiceConfiguration config = new MessageServiceConfiguration();
- protected ActiveMQServer activeMQServer;
- protected TJWSEmbeddedJaxrsServer tjws = new TJWSEmbeddedJaxrsServer();
-
- public Embedded() {
- int port = TestPortProvider.getPort();
- log.debug("default port is: " + port);
- tjws.setPort(port);
- tjws.setRootResourcePath("");
- tjws.setSecurityDomain(null);
- }
-
- public MessageServiceConfiguration getConfig() {
- return config;
- }
-
- public void setConfig(MessageServiceConfiguration config) {
- this.config = config;
- }
-
- public ActiveMQServer getActiveMQServer() {
- return activeMQServer;
- }
-
- public void setActiveMQServer(ActiveMQServer activeMQServer) {
- this.activeMQServer = activeMQServer;
- }
-
- public TJWSEmbeddedJaxrsServer getJaxrsServer() {
- return tjws;
- }
-
- public MessageServiceManager getManager() {
- return manager;
- }
-
- public void start() throws Exception {
- log.debug("\nStarting Embedded");
- if (activeMQServer == null) {
- Configuration configuration = new ConfigurationImpl().setPersistenceEnabled(false).setSecurityEnabled(false).addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
-
- activeMQServer = ActiveMQServers.newActiveMQServer(configuration);
- activeMQServer.start();
- }
- tjws.start();
- manager.setConfiguration(config);
- manager.start();
- tjws.getDeployment().getRegistry().addSingletonResource(manager.getQueueManager().getDestination());
- tjws.getDeployment().getRegistry().addSingletonResource(manager.getTopicManager().getDestination());
-
- }
-
- public void stop() throws Exception {
- log.debug("\nStopping Embedded");
- manager.stop();
- tjws.stop();
- activeMQServer.stop();
- }
-}
diff --git a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/EmbeddedTest.java b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/EmbeddedTest.java
deleted file mode 100644
index ab6bc0487b..0000000000
--- a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/EmbeddedTest.java
+++ /dev/null
@@ -1,157 +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.
- */
-package org.apache.activemq.artemis.rest.test;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Session;
-import java.io.Serializable;
-
-import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
-import org.apache.activemq.artemis.core.config.impl.SecurityConfiguration;
-import org.apache.activemq.artemis.rest.HttpHeaderProperty;
-import org.apache.activemq.artemis.rest.integration.EmbeddedRestActiveMQ;
-import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
-import org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.spi.Link;
-import org.jboss.resteasy.test.TestPortProvider;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class EmbeddedTest {
- private static final Logger log = LoggerFactory.getLogger(EmbeddedTest.class);
-
- public static EmbeddedRestActiveMQ server;
-
- @BeforeClass
- public static void startEmbedded() throws Exception {
- server = new EmbeddedRestActiveMQ(null);
- server.getManager().setConfigResourcePath("activemq-rest.xml");
- SecurityConfiguration securityConfiguration = new SecurityConfiguration();
- securityConfiguration.addUser("guest", "guest");
- securityConfiguration.addRole("guest", "guest");
- securityConfiguration.setDefaultUser("guest");
- ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfiguration);
- server.getEmbeddedActiveMQ().setSecurityManager(securityManager);
- server.start();
- }
-
- @AfterClass
- public static void stopEmbedded() throws Exception {
- server.stop();
- server = null;
- }
-
- public static void publish(String destination, Serializable object, String contentType) throws Exception {
- ConnectionFactory factory = ActiveMQJMSClient.createConnectionFactory("vm://0","cf");
- Connection conn = factory.createConnection();
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Destination dest = session.createQueue(destination);
-
- try {
- Assert.assertNotNull("Destination was null", dest);
- MessageProducer producer = session.createProducer(dest);
- ObjectMessage message = session.createObjectMessage();
-
- if (contentType != null) {
- message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType);
- }
- message.setObject(object);
-
- producer.send(message);
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testTransform() throws Exception {
-
- ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/queues/exampleQueue"));
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = response.getLinkHeader().getLinkByTitle("create");
- log.debug("create: " + sender);
- Link consumers = response.getLinkHeader().getLinkByTitle("pull-consumers");
- log.debug("pull: " + consumers);
- response = Util.setAutoAck(consumers, true);
- Link consumeNext = response.getLinkHeader().getLinkByTitle("consume-next");
- log.debug("consume-next: " + consumeNext);
-
- // test that Accept header is used to set content-type
- {
- TransformTest.Order order = new TransformTest.Order();
- order.setName("1");
- order.setAmount("$5.00");
- publish("exampleQueue", order, null);
-
- ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").accept("application/xml").post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertTrue(res.getHeaders().getFirst("Content-Type").toString().toLowerCase().contains("application/xml"));
- TransformTest.Order order2 = res.getEntity(TransformTest.Order.class);
- Assert.assertEquals(order, order2);
- consumeNext = res.getLinkHeader().getLinkByTitle("consume-next");
- res.releaseConnection();
- Assert.assertNotNull(consumeNext);
- }
-
- // test that Accept header is used to set content-type
- {
- TransformTest.Order order = new TransformTest.Order();
- order.setName("1");
- order.setAmount("$5.00");
- publish("exampleQueue", order, null);
-
- ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").accept("application/json").post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("application/json", res.getHeaders().getFirst("Content-Type").toString().toLowerCase());
- TransformTest.Order order2 = res.getEntity(TransformTest.Order.class);
- Assert.assertEquals(order, order2);
- consumeNext = res.getLinkHeader().getLinkByTitle("consume-next");
- res.releaseConnection();
- Assert.assertNotNull(consumeNext);
- }
-
- // test that message property is used to set content type
- {
- TransformTest.Order order = new TransformTest.Order();
- order.setName("2");
- order.setAmount("$15.00");
- publish("exampleQueue", order, "application/xml");
-
- ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertTrue(res.getHeaders().getFirst("Content-Type").toString().toLowerCase().contains("application/xml"));
- TransformTest.Order order2 = res.getEntity(TransformTest.Order.class);
- Assert.assertEquals(order, order2);
- consumeNext = res.getLinkHeader().getLinkByTitle("consume-next");
- res.releaseConnection();
- Assert.assertNotNull(consumeNext);
- }
- }
-}
diff --git a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/EmbeddedTestServer.java b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/EmbeddedTestServer.java
deleted file mode 100644
index e93591928c..0000000000
--- a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/EmbeddedTestServer.java
+++ /dev/null
@@ -1,95 +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.
- */
-package org.apache.activemq.artemis.rest.test;
-
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.TransportConfiguration;
-import org.apache.activemq.artemis.core.config.Configuration;
-import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
-import org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory;
-import org.apache.activemq.artemis.core.server.ActiveMQServer;
-import org.apache.activemq.artemis.core.server.ActiveMQServers;
-import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
-import org.apache.activemq.artemis.rest.MessageServiceConfiguration;
-import org.apache.activemq.artemis.rest.MessageServiceManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.jboss.resteasy.plugins.server.tjws.TJWSEmbeddedJaxrsServer;
-import org.jboss.resteasy.test.TestPortProvider;
-
-class EmbeddedTestServer {
- private static final Logger log = LoggerFactory.getLogger(EmbeddedTestServer.class);
-
- protected MessageServiceManager manager = new MessageServiceManager(null);
- protected MessageServiceConfiguration config = new MessageServiceConfiguration();
- private ActiveMQServer activeMQServer;
- private TJWSEmbeddedJaxrsServer tjws = new TJWSEmbeddedJaxrsServer();
-
- EmbeddedTestServer() {
- int port = TestPortProvider.getPort();
- log.debug("default port is: " + port);
- tjws.setPort(port);
- tjws.setRootResourcePath("");
- tjws.setSecurityDomain(null);
- }
-
- public MessageServiceConfiguration getConfig() {
- return config;
- }
-
- public void setConfig(MessageServiceConfiguration config) {
- this.config = config;
- }
-
- public ActiveMQServer getActiveMQServer() {
- return activeMQServer;
- }
-
- TJWSEmbeddedJaxrsServer getJaxrsServer() {
- return tjws;
- }
-
- public MessageServiceManager getManager() {
- return manager;
- }
-
- public void start() throws Exception {
- log.debug("\nStarting EmbeddedTestServer");
- if (activeMQServer == null) {
- Configuration configuration = new ConfigurationImpl().setPersistenceEnabled(false).setSecurityEnabled(false).addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
-
- activeMQServer = ActiveMQServers.newActiveMQServer(configuration);
- // set DLA and expiry to avoid spamming the log with warnings
- activeMQServer.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDeadLetterAddress(SimpleString.toSimpleString("DLA")).setExpiryAddress(SimpleString.toSimpleString("Expiry")));
-
- activeMQServer.start();
- }
- tjws.start();
- manager.setConfiguration(config);
- manager.start();
- tjws.getDeployment().getRegistry().addSingletonResource(manager.getQueueManager().getDestination());
- tjws.getDeployment().getRegistry().addSingletonResource(manager.getTopicManager().getDestination());
-
- }
-
- public void stop() throws Exception {
- log.debug("\nStopping EmbeddedTestServer");
- manager.stop();
- tjws.stop();
- activeMQServer.stop();
- }
-}
diff --git a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/FindDestinationTest.java b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/FindDestinationTest.java
deleted file mode 100644
index 417e52146c..0000000000
--- a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/FindDestinationTest.java
+++ /dev/null
@@ -1,135 +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.
- */
-package org.apache.activemq.artemis.rest.test;
-
-import org.apache.activemq.artemis.api.core.QueueConfiguration;
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.RoutingType;
-import org.apache.activemq.artemis.core.server.impl.AddressInfo;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.spi.Link;
-import org.jboss.resteasy.test.TestPortProvider;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class FindDestinationTest extends MessageTestBase {
- private static final Logger log = LoggerFactory.getLogger(FindDestinationTest.class);
-
- @Test
- public void testFindQueue() throws Exception {
- String testName = "testFindQueue";
- server.getActiveMQServer().addAddressInfo(new AddressInfo(SimpleString.toSimpleString(testName), RoutingType.MULTICAST));
- server.getActiveMQServer().createQueue(new QueueConfiguration(testName).setDurable(false));
-
- ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/queues/" + testName));
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
- log.debug("create: " + sender);
- Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
- log.debug("pull: " + consumers);
- response = Util.setAutoAck(consumers, true);
- Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
- log.debug("poller: " + consumeNext);
-
- ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- res = consumeNext.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("1", res.getEntity(String.class));
- res.releaseConnection();
- Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
- log.debug("session: " + session);
- Assert.assertEquals(204, session.request().delete().getStatus());
- }
-
- @Test
- public void testFindTopic() throws Exception {
- server.getActiveMQServer().addAddressInfo(new AddressInfo(SimpleString.toSimpleString("testTopic"), RoutingType.MULTICAST));
- server.getActiveMQServer().createQueue(new QueueConfiguration("testTopic")
- .setRoutingType(RoutingType.MULTICAST)
- .setDurable(false));
- ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/topics/testTopic"));
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
- Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");
-
- ClientResponse<?> res = subscriptions.request().post();
- Assert.assertEquals(201, res.getStatus());
- Link sub1 = res.getLocationLink();
- res.releaseConnection();
- Assert.assertNotNull(sub1);
- Link consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
- Assert.assertNotNull(consumeNext1);
- log.debug("consumeNext1: " + consumeNext1);
-
- res = subscriptions.request().post();
- Assert.assertEquals(201, res.getStatus());
- Link sub2 = res.getLocationLink();
- res.releaseConnection();
- Assert.assertNotNull(sub2);
- Link consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
- Assert.assertNotNull(consumeNext1);
-
- res = sender.request().body("text/plain", Integer.toString(1)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
- res = sender.request().body("text/plain", Integer.toString(2)).post();
- res.releaseConnection();
- Assert.assertEquals(201, res.getStatus());
-
- res = consumeNext1.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("1", res.getEntity(String.class));
- res.releaseConnection();
- consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
-
- res = consumeNext1.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("2", res.getEntity(String.class));
- res.releaseConnection();
-
- res = consumeNext2.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("1", res.getEntity(String.class));
- res.releaseConnection();
- consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
-
- res = consumeNext2.request().post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("2", res.getEntity(String.class));
- res.releaseConnection();
-
- res = sub1.request().delete();
- res.releaseConnection();
- Assert.assertEquals(204, res.getStatus());
-
- res = sub2.request().delete();
- res.releaseConnection();
- Assert.assertEquals(204, res.getStatus());
- }
-}
\ No newline at end of file
diff --git a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/JMSTest.java b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/JMSTest.java
deleted file mode 100644
index 430205c05e..0000000000
--- a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/JMSTest.java
+++ /dev/null
@@ -1,275 +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.
- */
-package org.apache.activemq.artemis.rest.test;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Session;
-import javax.xml.bind.annotation.XmlRootElement;
-import java.io.Serializable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
-import org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory;
-import org.apache.activemq.artemis.rest.HttpHeaderProperty;
-import org.apache.activemq.artemis.rest.Jms;
-import org.apache.activemq.artemis.rest.queue.QueueDeployment;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.spi.Link;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import static org.jboss.resteasy.test.TestPortProvider.generateURL;
-
-public class JMSTest extends MessageTestBase {
- private static final Logger log = LoggerFactory.getLogger(JMSTest.class);
-
- public static ConnectionFactory connectionFactory;
-
- @BeforeClass
- public static void setup() throws Exception {
- connectionFactory = new ActiveMQJMSConnectionFactory(manager.getQueueManager().getServerLocator());
- }
-
- @XmlRootElement
- public static class Order implements Serializable {
-
- private static final long serialVersionUID = 1397854679589606480L;
- private String name;
- private String amount;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getAmount() {
- return amount;
- }
-
- public void setAmount(String amount) {
- this.amount = amount;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- Order order = (Order) o;
-
- if (!amount.equals(order.amount)) {
- return false;
- }
- if (!name.equals(order.name)) {
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = name.hashCode();
- result = 31 * result + amount.hashCode();
- return result;
- }
- }
-
- public static Destination createDestination(String dest) {
- ActiveMQDestination destination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(dest);
- log.debug("SimpleAddress: " + destination.getSimpleAddress());
- return destination;
- }
-
- public static void publish(String dest, Serializable object, String contentType) throws Exception {
- Connection conn = connectionFactory.createConnection();
- try {
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Destination destination = createDestination(dest);
- MessageProducer producer = session.createProducer(destination);
- ObjectMessage message = session.createObjectMessage();
-
- if (contentType != null) {
- message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType);
- }
- message.setObject(object);
-
- producer.send(message);
- } finally {
- conn.close();
- }
- }
-
- public static class Listener implements MessageListener {
-
- public static Order order;
- public static String messageID = null;
- public static CountDownLatch latch = new CountDownLatch(1);
-
- @Override
- public void onMessage(Message message) {
- try {
- order = Jms.getEntity(message, Order.class);
- messageID = message.getJMSMessageID();
- } catch (Exception e) {
- e.printStackTrace();
- }
- latch.countDown();
- }
- }
-
- @Test
- public void testJmsConsumer() throws Exception {
- String queueName = "testQueue2";
- String prefixedQueueName = ActiveMQDestination.createQueueAddressFromName(queueName).toString();
- log.debug("Queue name: " + prefixedQueueName);
- QueueDeployment deployment = new QueueDeployment();
- deployment.setDuplicatesAllowed(true);
- deployment.setDurableSend(false);
- deployment.setName(queueName);
- manager.getQueueManager().deploy(deployment);
- Connection conn = connectionFactory.createConnection();
- try {
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Destination destination = createDestination(prefixedQueueName);
- MessageConsumer consumer = session.createConsumer(destination);
- consumer.setMessageListener(new Listener());
- conn.start();
-
- ClientRequest request = new ClientRequest(generateURL(Util.getUrlPath(queueName)));
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
- log.debug("create: " + sender);
- Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
- log.debug("consume-next: " + consumeNext);
-
- // test that Accept header is used to set content-type
- {
- Order order = new Order();
- order.setName("1");
- order.setAmount("$5.00");
- response = sender.request().body("application/xml", order).post();
- response.releaseConnection();
- Assert.assertEquals(201, response.getStatus());
-
- Listener.latch.await(1, TimeUnit.SECONDS);
- Assert.assertNotNull(Listener.order);
- Assert.assertEquals(order, Listener.order);
- Assert.assertNotNull(Listener.messageID);
- }
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testJmsProducer() throws Exception {
- String queueName = "testQueue";
- String prefixedQueueName = ActiveMQDestination.createQueueAddressFromName(queueName).toString();
- log.debug("Queue name: " + prefixedQueueName);
- QueueDeployment deployment = new QueueDeployment();
- deployment.setDuplicatesAllowed(true);
- deployment.setDurableSend(false);
- deployment.setName(queueName);
- manager.getQueueManager().deploy(deployment);
- ClientRequest request = new ClientRequest(generateURL(Util.getUrlPath(queueName)));
-
- ClientResponse<?> response = request.head();
- response.releaseConnection();
- Assert.assertEquals(200, response.getStatus());
- Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
- log.debug("create: " + sender);
- Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
- log.debug("pull: " + consumers);
- response = Util.setAutoAck(consumers, true);
- Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
- log.debug("consume-next: " + consumeNext);
-
- // test that Accept header is used to set content-type
- {
- Order order = new Order();
- order.setName("1");
- order.setAmount("$5.00");
- publish(prefixedQueueName, order, null);
-
- ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").accept("application/xml").post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertTrue(res.getHeaders().getFirst("Content-Type").toString().toLowerCase().contains("application/xml"));
- Order order2 = res.getEntity(Order.class);
- res.releaseConnection();
- Assert.assertEquals(order, order2);
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
- Assert.assertNotNull(consumeNext);
- }
-
- // test that Accept header is used to set content-type
- {
- Order order = new Order();
- order.setName("1");
- order.setAmount("$5.00");
- publish(prefixedQueueName, order, null);
-
- ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").accept("application/json").post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals("application/json", res.getHeaders().getFirst("Content-Type").toString().toLowerCase());
- Order order2 = res.getEntity(Order.class);
- res.releaseConnection();
- Assert.assertEquals(order, order2);
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
- Assert.assertNotNull(consumeNext);
- }
-
- // test that message property is used to set content type
- {
- Order order = new Order();
- order.setName("2");
- order.setAmount("$15.00");
- publish(prefixedQueueName, order, "application/xml");
-
- ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").post(String.class);
- Assert.assertEquals(200, res.getStatus());
- Assert.assertTrue(res.getHeaders().getFirst("Content-Type").toString().toLowerCase().contains("application/xml"));
- Order order2 = res.getEntity(Order.class);
- res.releaseConnection();
- Assert.assertEquals(order, order2);
- consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
- Assert.assertNotNull(consumeNext);
- }
- }
-}
diff --git a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/MessagePropertiesTest.java b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/MessagePropertiesTest.java
deleted file mode 100644
index 148ec08359..0000000000
--- a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/MessagePropertiesTest.java
+++ /dev/null
@@ -1,104 +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.
- */
-package org.apache.activemq.artemis.rest.test;
-
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.api.core.client.MessageHandler;
-import org.apache.activemq.artemis.rest.HttpHeaderProperty;
-import org.apache.activemq.artemis.rest.queue.QueueDeployment;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.spi.Link;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Set;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
... 9983 lines suppressed ...