Index: C:/workspace/AMQ-5.0.0/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java =================================================================== --- C:/workspace/AMQ-5.0.0/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java (revision 653816) +++ C:/workspace/AMQ-5.0.0/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java (working copy) @@ -86,6 +86,11 @@ if (name != null) { maximumMessages = (int)asLong(name); } + name = servletConfig.getServletContext().getInitParameter("com.apache.amq.selector.name"); + if (name != null) { + selectorName = (String) asString(name); + log.info("Selector name: "+name); + } } /** @@ -156,7 +161,7 @@ Map consumerDestinationMap = getConsumerDestinationNameMap(request); client.closeConsumer(destination); // drop any existing // consumer. - MessageAvailableConsumer consumer = (MessageAvailableConsumer)client.getConsumer(destination); + MessageAvailableConsumer consumer = (MessageAvailableConsumer) client.getConsumer(destination, request, selectorName); consumer.setAvailableListener(listener); consumerIdMap.put(consumer, message); @@ -167,7 +172,7 @@ } else if ("unlisten".equals(type)) { Map consumerIdMap = getConsumerIdMap(request); Map consumerDestinationMap = getConsumerDestinationNameMap(request); - MessageAvailableConsumer consumer = (MessageAvailableConsumer)client.getConsumer(destination); + MessageAvailableConsumer consumer = (MessageAvailableConsumer) client.getConsumer(destination, request, selectorName); consumer.setAvailableListener(null); consumerIdMap.remove(consumer); Index: C:/workspace/AMQ-5.0.0/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java =================================================================== --- C:/workspace/AMQ-5.0.0/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java (revision 653816) +++ C:/workspace/AMQ-5.0.0/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java (working copy) @@ -273,14 +273,40 @@ return getConsumer(destination, true); } - public synchronized MessageConsumer getConsumer(Destination destination, boolean create) throws JMSException { - MessageConsumer consumer = consumers.get(destination); + public synchronized MessageConsumer getConsumer(HttpServletRequest request, Destination destination, String selectorName, boolean create) throws JMSException { + MessageConsumer consumer = (MessageConsumer) consumers.get(destination); if (create && consumer == null) { - consumer = getSession().createConsumer(destination); + + if(request != null && selectorName != null && !selectorName.equals("")) { + log.info("getCustomSelector - name: "+selectorName); + String selector = getCustomSelector(request, selectorName); + if(selector != null && !selector.equals("")) { + String sql92Selector = selectorName +" = '"+ selector+"'"; + consumer = getSession().createConsumer(destination,sql92Selector); + log.info("Consumer created with selector: "+selector); + } else { + consumer = getSession().createConsumer(destination); + log.info("Consumer created without selector but selectorName was found."); + } + } else { + consumer = getSession().createConsumer(destination); + log.info("Consumer created without selector."); + } + consumers.put(destination, consumer); } return consumer; } + + private String getCustomSelector(HttpServletRequest request, String selectorName) { + String selector = request.getHeader(selectorName); //"TMUSERMSISDN" for telefonica + if(selector == null || selector.equals("")) { + HttpSession session = request.getSession(); + selector = (String)session.getAttribute(selectorName); + } + log.info("getCustomSelector: "+selector); + return selector; + } public synchronized void closeConsumer(Destination destination) throws JMSException { MessageConsumer consumer = consumers.get(destination);