Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.web;
 
 import java.util.Map;
 
 
Renders the contents of a queue using some kind of view. The URI is assumed to be the queue. The following parameters can be used

  • view - specifies the type of the view such as simple, xml, rss
  • selector - specifies the SQL 92 selector to apply to the queue

Version:
$Revision: $
 
 public class QueueBrowseServlet extends HttpServlet {
     private static FactoryFinder factoryFinder = new FactoryFinder("META-INF/services/org/apache/activemq/web/view/");
 
     // Implementation methods
     // -------------------------------------------------------------------------
     protected void doGet(HttpServletRequest requestHttpServletResponse responsethrows ServletExceptionIOException {
         try {
             WebClient client = WebClient.getWebClient(request);
             Session session = client.getSession();
             Queue queue = getQueue(requestsession);
             if (queue == null) {
                 throw new ServletException("No queue URI specified");
             }
 
             String msgId = request.getParameter("msgId");
             if (msgId == null) {
                 MessageRenderer renderer = getMessageRenderer(request);
                 configureRenderer(requestrenderer);
 
                 String selector = getSelector(request);
                 QueueBrowser browser = session.createBrowser(queueselector);
                 renderer.renderMessages(requestresponsebrowser);
             }
             else {
                 XmlMessageRenderer renderer = new XmlMessageRenderer();
                 QueueBrowser browser = session.createBrowser(queue"JMSMessageID='" + msgId + "'");
                 if (!browser.getEnumeration().hasMoreElements()) {
                     response.sendError(.);
                     return;
                 }
                 Message message = (Messagebrowser.getEnumeration().nextElement();
 
                 PrintWriter writer = response.getWriter();
                 renderer.renderMessage(writerrequestresponsebrowsermessage);
                 writer.flush();
             }
         }
         catch (JMSException e) {
             throw new ServletException(e);
         }
     }
 
         String style = request.getParameter("view");
         if (style == null) {
             style = "simple";
         }
         try {
             return (MessageRenderer.newInstance(style);
        }
        catch (IllegalAccessException e) {
            throw new NoSuchViewStyleException(stylee);
        }
        catch (InstantiationException e) {
            throw new NoSuchViewStyleException(stylee);
        }
        catch (ClassNotFoundException e) {
            throw new NoSuchViewStyleException(stylee);
        }
    }
    @SuppressWarnings("unchecked")
    protected void configureRenderer(HttpServletRequest requestMessageRenderer renderer) {
        Map<StringStringproperties = new HashMap<StringString>();
        for (Enumeration<Stringiter = request.getParameterNames(); iter.hasMoreElements();) {
            String name = (Stringiter.nextElement();
            properties.put(namerequest.getParameter(name));
        }
        IntrospectionSupport.setProperties(rendererproperties);
    }
    protected String getSelector(HttpServletRequest request) {
        return request.getParameter("selector");
    }
    protected Queue getQueue(HttpServletRequest requestSession sessionthrows JMSException {
        String uri = request.getPathInfo();
        if (uri == null) {
            return null;
        }
        // replace URI separator with JMS destination separator
        if (uri.startsWith("/")) {
            uri = uri.substring(1);
            if (uri.length() == 0) {
                return null;
            }
        }
        uri = uri.replace('/''.');
        return session.createQueue(uri);
    }
New to GrepCode? Check out our FAQ X