Home » geronimo-2.2-source-release » org.apache.geronimo.console.jmsmanager.renderers » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package org.apache.geronimo.console.jmsmanager.renderers;
   19   
   20   import java.io.IOException;
   21   import java.lang.reflect.Field;
   22   import java.util.ArrayList;
   23   import java.util.Enumeration;
   24   import java.util.List;
   25   
   26   import javax.jms.Connection;
   27   import javax.jms.ConnectionFactory;
   28   import javax.jms.Destination;
   29   import javax.jms.Queue;
   30   import javax.jms.QueueBrowser;
   31   import javax.jms.Session;
   32   import javax.management.ObjectName;
   33   import javax.portlet.PortletException;
   34   import javax.portlet.RenderRequest;
   35   import javax.portlet.RenderResponse;
   36   
   37   //import org.activemq.service.DeadLetterPolicy;
   38   import org.apache.geronimo.console.jmsmanager.AbstractJMSManager;
   39   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   40   import org.apache.geronimo.gbean.AbstractName;
   41   import org.slf4j.Logger;
   42   import org.slf4j.LoggerFactory;
   43   
   44   public class ViewDLQRenderer extends AbstractJMSManager implements PortletRenderer {
   45   
   46       private static final Logger log = LoggerFactory.getLogger(ViewDLQRenderer.class);
   47   
   48       private Destination dlq = null;
   49   
   50       private QueueBrowser dlqBrowser = null;
   51   
   52       private Connection connection = null;
   53   
   54       private Session session = null;
   55   
   56       private String dlqName;
   57   
   58       public ViewDLQRenderer() {
   59       }
   60   
   61       public void setup(RenderRequest request, RenderResponse response) {
   62       	/*
   63           String destinationApplicationName = request
   64                   .getParameter("destinationApplicationName");
   65           String destinationModuleName = request
   66                   .getParameter("destinationModuleName");
   67           String destinationName = request.getParameter("destinationName");
   68   
   69           try {
   70               //TODO configid disabled
   71               AbstractName adminObjectName = null;//NameFactory.getComponentName(null,
   72   //                    null, destinationApplicationName, NameFactory.JCA_RESOURCE,
   73   //                    destinationModuleName, destinationName, null, baseContext);
   74               Destination destination = (Destination) kernel.invoke(adminObjectName,
   75                       "$getResource");
   76               ConnectionFactory connectionFactory = (ConnectionFactory) kernel
   77                       .invoke(JCA_MANAGED_CONNECTION_FACTORY_NAME,
   78                               "$getResource");
   79               connection = connectionFactory.createConnection();
   80               session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   81   
   82               DeadLetterPolicy dlp = new DeadLetterPolicy();
   83   
   84               //dlqName =
   85               // dlp.getDeadLetterNameFromDestination((ActiveMQDestination)
   86               // destination);
   87               // This is a hack to get around the fact that the code commented
   88               // above throws a ClassCastException due to ClassLoader weirdness.
   89               Field f = dlp.getClass().getDeclaredField(
   90                       "deadLetterPerDestinationName");
   91               f.setAccessible(true);
   92               boolean deadLetterPerDestinationName = f.getBoolean(dlp);
   93               f = dlp.getClass().getDeclaredField("deadLetterPrefix");
   94               f.setAccessible(true);
   95               String deadLetterPrefix = "" + f.get(dlp);
   96               if (deadLetterPerDestinationName) {
   97                   dlqName = deadLetterPrefix
   98                           + destination.getClass().getMethod("getPhysicalName",
   99                                   null).invoke(destination, null);
  100               } else {
  101                   dlqName = deadLetterPrefix + deadLetterPrefix;
  102               }
  103   
  104               dlq = session.createQueue(dlqName);
  105               dlqBrowser = session.createBrowser((Queue) dlq);
  106   
  107               connection.start();
  108   
  109           } catch (Exception e) {
  110               log.error(e.getMessage(), e);
  111           }
  112           */
  113       }
  114   
  115       public List getDLQContents(QueueBrowser qb) {
  116   
  117           List list = new ArrayList();
  118   
  119           try {
  120               for (Enumeration e = qb.getEnumeration(); e.hasMoreElements();) {
  121                   Object o = e.nextElement();
  122                   list.add(o);
  123               }
  124   
  125               connection.stop();
  126               dlqBrowser.close();
  127               session.close();
  128               connection.close();
  129   
  130           } catch (Exception e) {
  131               log.error(e.getMessage(), e);
  132           }
  133   
  134           return list;
  135       }
  136   
  137       public String render(RenderRequest request, RenderResponse response)
  138               throws PortletException, IOException {
  139   
  140           setup(request, response);
  141           List dlqContents = getDLQContents(dlqBrowser);
  142           request.setAttribute("dlqcontents", dlqContents);
  143           request.setAttribute("dlqname", dlqName);
  144   
  145           return "/WEB-INF/view/jmsmanager/viewDLQ.jsp";
  146       }
  147   
  148   }

Home » geronimo-2.2-source-release » org.apache.geronimo.console.jmsmanager.renderers » [javadoc | source]