From a05e84eea35be54b5c08e696cbedce5dc0d9a733 Mon Sep 17 00:00:00 2001 From: Bosanac Dejan Date: Thu, 6 May 2010 11:39:32 +0000 Subject: [PATCH] https://issues.apache.org/activemq/browse/AMQ-1547 - support for configurable selector header name git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@941673 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/test/java/org/apache/activemq/web/RestTest.java | 2 +- .../org/apache/activemq/web/MessageListenerServlet.java | 4 ++-- .../java/org/apache/activemq/web/MessageServlet.java | 4 ++-- .../org/apache/activemq/web/MessageServletSupport.java | 2 +- .../src/main/java/org/apache/activemq/web/WebClient.java | 9 ++++++++- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java b/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java index dceb311f54..db23419a81 100644 --- a/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java +++ b/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java @@ -35,7 +35,7 @@ public class RestTest extends JettyTestSupport { ContentExchange contentExchange = new ContentExchange(); httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); contentExchange.setURL("http://localhost:8080/message/test?timeout=1000&type=queue"); - contentExchange.setRequestHeader(WebClient.SELECTOR_NAME, "test=2"); + contentExchange.setRequestHeader("selector", "test=2"); httpClient.send(contentExchange); contentExchange.waitForDone(); assertEquals("test2", contentExchange.getResponseContent()); diff --git a/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java b/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java index 091a163726..ce5d6cf256 100644 --- a/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java +++ b/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java @@ -156,7 +156,7 @@ public class MessageListenerServlet extends MessageServletSupport { Map consumerDestinationMap = getConsumerDestinationNameMap(request); client.closeConsumer(destination); // drop any existing // consumer. - MessageAvailableConsumer consumer = (MessageAvailableConsumer)client.getConsumer(destination, request.getHeader(WebClient.SELECTOR_NAME)); + MessageAvailableConsumer consumer = (MessageAvailableConsumer)client.getConsumer(destination, request.getHeader(WebClient.selectorName)); consumer.setAvailableListener(listener); consumerIdMap.put(consumer, message); @@ -167,7 +167,7 @@ public class MessageListenerServlet extends MessageServletSupport { } else if ("unlisten".equals(type)) { Map consumerIdMap = getConsumerIdMap(request); Map consumerDestinationMap = getConsumerDestinationNameMap(request); - MessageAvailableConsumer consumer = (MessageAvailableConsumer)client.getConsumer(destination, request.getHeader(WebClient.SELECTOR_NAME)); + MessageAvailableConsumer consumer = (MessageAvailableConsumer)client.getConsumer(destination, request.getHeader(WebClient.selectorName)); consumer.setAvailableListener(null); consumerIdMap.remove(consumer); diff --git a/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java b/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java index 46495fb911..3c364c425b 100644 --- a/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java +++ b/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java @@ -180,7 +180,7 @@ public class MessageServlet extends MessageServletSupport { LOG.debug("Receiving message(s) from: " + destination + " with timeout: " + timeout); } - MessageAvailableConsumer consumer = (MessageAvailableConsumer)client.getConsumer(destination, request.getHeader(WebClient.SELECTOR_NAME)); + MessageAvailableConsumer consumer = (MessageAvailableConsumer)client.getConsumer(destination, request.getHeader(WebClient.selectorName)); Continuation continuation = null; Listener listener = null; Message message = null; @@ -297,7 +297,7 @@ public class MessageServlet extends MessageServletSupport { LOG.debug("Receiving message(s) from: " + destination + " with timeout: " + timeout); } - MessageAvailableConsumer consumer = (MessageAvailableConsumer)client.getConsumer(destination, request.getHeader(WebClient.SELECTOR_NAME)); + MessageAvailableConsumer consumer = (MessageAvailableConsumer)client.getConsumer(destination, request.getHeader(WebClient.selectorName)); Message message = null; // write a responds diff --git a/activemq-web/src/main/java/org/apache/activemq/web/MessageServletSupport.java b/activemq-web/src/main/java/org/apache/activemq/web/MessageServletSupport.java index c751e87a11..59c265864a 100644 --- a/activemq-web/src/main/java/org/apache/activemq/web/MessageServletSupport.java +++ b/activemq-web/src/main/java/org/apache/activemq/web/MessageServletSupport.java @@ -355,6 +355,6 @@ public abstract class MessageServletSupport extends HttpServlet { } protected String getSelector(HttpServletRequest request) throws IOException { - return request.getHeader(WebClient.SELECTOR_NAME); + return request.getHeader(WebClient.selectorName); } } diff --git a/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java b/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java index d891afa488..40c4715b43 100644 --- a/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java +++ b/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java @@ -70,7 +70,7 @@ public class WebClient implements HttpSessionActivationListener, HttpSessionBind public static final String CONNECTION_FACTORY_PREFETCH_PARAM = "org.apache.activemq.connectionFactory.prefetch"; public static final String CONNECTION_FACTORY_OPTIMIZE_ACK_PARAM = "org.apache.activemq.connectionFactory.optimizeAck"; public static final String BROKER_URL_INIT_PARAM = "org.apache.activemq.brokerURL"; - public static final String SELECTOR_NAME = "org.apache.activemq.selector"; + public static final String SELECTOR_NAME = "org.apache.activemq.selectorName"; private static final Log LOG = LogFactory.getLog(WebClient.class); @@ -81,6 +81,7 @@ public class WebClient implements HttpSessionActivationListener, HttpSessionBind private transient Session session; private transient MessageProducer producer; private int deliveryMode = DeliveryMode.NON_PERSISTENT; + public static String selectorName; private final Semaphore semaphore = new Semaphore(1); @@ -122,6 +123,12 @@ public class WebClient implements HttpSessionActivationListener, HttpSessionBind public static void initContext(ServletContext context) { initConnectionFactory(context); context.setAttribute("webClients", new HashMap()); + if (selectorName == null) { + selectorName = context.getInitParameter(SELECTOR_NAME); + } + if (selectorName == null) { + selectorName = "selector"; + } } public int getDeliveryMode() {