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: */package org.apache.geronimo.console.jmsmanager.renderers;
017:
018: import java.io.IOException;
019: import java.lang.reflect.Field;
020: import java.util.ArrayList;
021: import java.util.Enumeration;
022: import java.util.List;
023:
024: import javax.jms.Connection;
025: import javax.jms.ConnectionFactory;
026: import javax.jms.Destination;
027: import javax.jms.Queue;
028: import javax.jms.QueueBrowser;
029: import javax.jms.Session;
030: import javax.management.ObjectName;
031: import javax.portlet.PortletException;
032: import javax.portlet.RenderRequest;
033: import javax.portlet.RenderResponse;
034:
035: //import org.activemq.service.DeadLetterPolicy;
036: import org.apache.geronimo.console.jmsmanager.AbstractJMSManager;
037: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
038: import org.apache.geronimo.gbean.AbstractName;
039: import org.apache.commons.logging.Log;
040: import org.apache.commons.logging.LogFactory;
041:
042: public class ViewDLQRenderer extends AbstractJMSManager implements
043: PortletRenderer {
044:
045: private static final Log log = LogFactory
046: .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
121: .hasMoreElements();) {
122: Object o = e.nextElement();
123: list.add(o);
124: }
125:
126: connection.stop();
127: dlqBrowser.close();
128: session.close();
129: connection.close();
130:
131: } catch (Exception e) {
132: log.error(e.getMessage(), e);
133: }
134:
135: return list;
136: }
137:
138: public String render(RenderRequest request, RenderResponse response)
139: throws PortletException, IOException {
140:
141: setup(request, response);
142: List dlqContents = getDLQContents(dlqBrowser);
143: request.setAttribute("dlqcontents", dlqContents);
144: request.setAttribute("dlqname", dlqName);
145:
146: return "/WEB-INF/view/jmsmanager/viewDLQ.jsp";
147: }
148:
149: }
|