001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.geronimo.console.jmsmanager.renderers; 019 020 import java.io.IOException; 021 import java.lang.reflect.Field; 022 import java.util.ArrayList; 023 import java.util.Enumeration; 024 import java.util.List; 025 026 import javax.jms.Connection; 027 import javax.jms.ConnectionFactory; 028 import javax.jms.Destination; 029 import javax.jms.Queue; 030 import javax.jms.QueueBrowser; 031 import javax.jms.Session; 032 import javax.management.ObjectName; 033 import javax.portlet.PortletException; 034 import javax.portlet.RenderRequest; 035 import javax.portlet.RenderResponse; 036 037 //import org.activemq.service.DeadLetterPolicy; 038 import org.apache.geronimo.console.jmsmanager.AbstractJMSManager; 039 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 040 import org.apache.geronimo.gbean.AbstractName; 041 import org.apache.commons.logging.Log; 042 import org.apache.commons.logging.LogFactory; 043 044 public class ViewDLQRenderer extends AbstractJMSManager implements PortletRenderer { 045 046 private static final Log log = LogFactory.getLog(ViewDLQRenderer.class); 047 048 private Destination dlq = null; 049 050 private QueueBrowser dlqBrowser = null; 051 052 private Connection connection = null; 053 054 private Session session = null; 055 056 private String dlqName; 057 058 public ViewDLQRenderer() { 059 } 060 061 public void setup(RenderRequest request, RenderResponse response) { 062 /* 063 String destinationApplicationName = request 064 .getParameter("destinationApplicationName"); 065 String destinationModuleName = request 066 .getParameter("destinationModuleName"); 067 String destinationName = request.getParameter("destinationName"); 068 069 try { 070 //TODO configid disabled 071 AbstractName adminObjectName = null;//NameFactory.getComponentName(null, 072 // null, destinationApplicationName, NameFactory.JCA_RESOURCE, 073 // destinationModuleName, destinationName, null, baseContext); 074 Destination destination = (Destination) kernel.invoke(adminObjectName, 075 "$getResource"); 076 ConnectionFactory connectionFactory = (ConnectionFactory) kernel 077 .invoke(JCA_MANAGED_CONNECTION_FACTORY_NAME, 078 "$getResource"); 079 connection = connectionFactory.createConnection(); 080 session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 081 082 DeadLetterPolicy dlp = new DeadLetterPolicy(); 083 084 //dlqName = 085 // dlp.getDeadLetterNameFromDestination((ActiveMQDestination) 086 // destination); 087 // This is a hack to get around the fact that the code commented 088 // above throws a ClassCastException due to ClassLoader weirdness. 089 Field f = dlp.getClass().getDeclaredField( 090 "deadLetterPerDestinationName"); 091 f.setAccessible(true); 092 boolean deadLetterPerDestinationName = f.getBoolean(dlp); 093 f = dlp.getClass().getDeclaredField("deadLetterPrefix"); 094 f.setAccessible(true); 095 String deadLetterPrefix = "" + f.get(dlp); 096 if (deadLetterPerDestinationName) { 097 dlqName = deadLetterPrefix 098 + destination.getClass().getMethod("getPhysicalName", 099 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 }