geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r813742 [1/2] - in /geronimo/server/branches/2.2/plugins: activemq/activemq-portlets/src/main/i18n-resources/ activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/ activemq/activemq-portlets/src/main/java/org/apac...
Date Fri, 11 Sep 2009 09:38:28 GMT
Author: xuhaihong
Date: Fri Sep 11 09:38:26 2009
New Revision: 813742

URL: http://svn.apache.org/viewvc?rev=813742&view=rev
Log:
GERONIMO-4625 JMS statistics does not work correctly while the server url is of vm protocol

Added:
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/DestinationType.java   (with props)
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/JMSDestinationInfo.java   (with props)
Modified:
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/i18n-resources/portletinfo_en.properties
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/i18n-resources/portletinfo_zh.properties
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/JMSMessageInfo.java
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/AmqJMSMessageHelper.java
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/JMSMessageHelper.java
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/JMSMessageHelperFactory.java
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/AbstractHandler.java
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/JMSResourcePortlet.java
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/ListScreenHandler.java
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/MessageDetailsHandler.java
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/SendMessageHandler.java
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/ViewMessageHandler.java
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/webapp/WEB-INF/view/jmsmanager/sendMessage.jsp
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/webapp/WEB-INF/view/jmsmanager/viewmessages.jsp
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/webapp/WEB-INF/view/jmswizard/list.jsp
    geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/webapp/WEB-INF/view/jmswizard/provider.jsp
    geronimo/server/branches/2.2/plugins/console/console-core/src/main/java/org/apache/geronimo/console/util/PortletManager.java

Modified: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/i18n-resources/portletinfo_en.properties
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/i18n-resources/portletinfo_en.properties?rev=813742&r1=813741&r2=813742&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/i18n-resources/portletinfo_en.properties (original)
+++ geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/i18n-resources/portletinfo_en.properties Fri Sep 11 09:38:26 2009
@@ -26,6 +26,8 @@
 
 activemq.errorMsg01 = Error encountered while sending message.
 activemq.errorMsg02 = Deployer operation failed!
+activemq.errorMsg03 = Error encountered while browsing message.
+activemq.errorMsg04 = Error encountered while purging message destination {0}
 activemq.infoMsg01  = Message sent successfully.
 activemq.infoMsg02  = Deployment completed successfully!
 activemq.warnMsg01  = Can not count Consumer Count/Queue Size of {0} for the server url is not belong to an embedded broker

Modified: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/i18n-resources/portletinfo_zh.properties
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/i18n-resources/portletinfo_zh.properties?rev=813742&r1=813741&r2=813742&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/i18n-resources/portletinfo_zh.properties (original)
+++ geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/i18n-resources/portletinfo_zh.properties Fri Sep 11 09:38:26 2009
@@ -26,6 +26,8 @@
 
 activemq.errorMsg01 = 发送消息时遇到错误。
 activemq.errorMsg02 = 部署失败!
+activemq.errorMsg03 = 浏览消息时遇到错误。
+activemq.errorMsg04 = 清空消息队列 {0} 时遇到错误。
 activemq.infoMsg01  = 成功发送消息。
 activemq.infoMsg02  = 部署成功!
 activemq.warnMsg01  = 因为对应的地址不属于任何一个内嵌的 Broker, 所以不能对 {0} 的消费者总数和队列大小进行统计

Added: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/DestinationType.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/DestinationType.java?rev=813742&view=auto
==============================================================================
--- geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/DestinationType.java (added)
+++ geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/DestinationType.java Fri Sep 11 09:38:26 2009
@@ -0,0 +1,66 @@
+/**
+ *  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.geronimo.console.jmsmanager;
+
+import javax.jms.Destination;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public enum DestinationType {
+    Queue {
+
+        @Override
+        public String[] getConnectionFactoryInterfaces() {
+            return new String[] { "javax.jms.QueueConnectionFactory", "javax.jms.ConnectionFactory" };
+        }
+
+        @Override
+        public String getDestinationInterface() {
+            return "javax.jms.Queue";
+        }
+
+        @Override
+        public Class<? extends Destination> getTypeClass() {
+            return javax.jms.Queue.class;
+        }
+    },
+    Topic {
+
+        @Override
+        public String[] getConnectionFactoryInterfaces() {
+            return new String[] { "javax.jms.TopicConnectionFactory", "javax.jms.ConnectionFactory" };
+        }
+
+        @Override
+        public String getDestinationInterface() {
+            return "javax.jms.Topic";
+        }
+
+        @Override
+        public Class<? extends Destination> getTypeClass() {
+            return javax.jms.Topic.class;
+        }
+    };
+
+    public abstract String getDestinationInterface();
+
+    public abstract String[] getConnectionFactoryInterfaces();
+
+    public abstract Class<? extends Destination> getTypeClass();
+}
\ No newline at end of file

Propchange: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/DestinationType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/DestinationType.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/DestinationType.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/JMSDestinationInfo.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/JMSDestinationInfo.java?rev=813742&view=auto
==============================================================================
--- geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/JMSDestinationInfo.java (added)
+++ geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/JMSDestinationInfo.java Fri Sep 11 09:38:26 2009
@@ -0,0 +1,83 @@
+/**
+ *  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.geronimo.console.jmsmanager;
+
+import java.net.URI;
+
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletRequest;
+
+import org.apache.geronimo.gbean.AbstractName;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JMSDestinationInfo {
+
+    private AbstractName resourceAdapterModuleAbName;
+
+    private String physicalName;
+
+    private DestinationType type;
+
+    public String getPhysicalName() {
+        return physicalName;
+    }
+
+    public AbstractName getResourceAdapterModuleAbName() {
+        return resourceAdapterModuleAbName;
+    }
+
+    public DestinationType getType() {
+        return type;
+    }
+
+    public void setResourceAdapterModuleAbName(String resourceAdapterModuleName) {
+        this.resourceAdapterModuleAbName = new AbstractName(URI.create(resourceAdapterModuleName));
+    }
+
+    public void setPhysicalName(String physicalName) {
+        this.physicalName = physicalName;
+    }
+
+    public void setResourceAdapterModuleAbName(AbstractName resourceAdapterModuleAbName) {
+        this.resourceAdapterModuleAbName = resourceAdapterModuleAbName;
+    }
+
+    public void setType(DestinationType type) {
+        this.type = type;
+    }
+
+    public void setType(String type) {
+        this.type = DestinationType.valueOf(type);
+    }
+
+    public static JMSDestinationInfo create(PortletRequest actionRequest) {
+        JMSDestinationInfo jmsDestinationInfo = new JMSDestinationInfo();
+        jmsDestinationInfo.setPhysicalName(actionRequest.getParameter("physicalName"));
+        jmsDestinationInfo.setType(DestinationType.valueOf(actionRequest.getParameter("adminObjType")));
+        jmsDestinationInfo.setResourceAdapterModuleAbName(actionRequest.getParameter("resourceAdapterModuleName"));
+        return jmsDestinationInfo;
+    }
+
+    public void setRenderParameters(ActionResponse actionResponse) {
+        actionResponse.setRenderParameter("physicalName", physicalName);
+        actionResponse.setRenderParameter("adminObjType", type.name());
+        actionResponse.setRenderParameter("resourceAdapterModuleName", resourceAdapterModuleAbName.toString());
+    }
+}

Propchange: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/JMSDestinationInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/JMSDestinationInfo.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/JMSDestinationInfo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/JMSMessageInfo.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/JMSMessageInfo.java?rev=813742&r1=813741&r2=813742&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/JMSMessageInfo.java (original)
+++ geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/JMSMessageInfo.java Fri Sep 11 09:38:26 2009
@@ -16,16 +16,12 @@
  */
 package org.apache.geronimo.console.jmsmanager;
 
-import java.io.Serializable;
 
 /**
  * @version $Rev$ $Date$
  */
-public class JMSMessageInfo implements Serializable{
-    private String adminObjName;
-    private String adminObjType;
-    private String physicalName;
-    private String adapterObjectName;
+public class JMSMessageInfo{
+
     private String correlationId;
     private boolean isPersistent;
     private String replyTo;
@@ -77,31 +73,7 @@
     public void setMessage(String message) {
         this.message = message;
     }
-
-    public String getAdapterObjectName() {
-        return adapterObjectName;
-    }
-
-    public void setAdapterObjectName(String adapterObjectName) {
-        this.adapterObjectName = adapterObjectName;
-    }
-
-    public String getAdminObjName() {
-        return adminObjName;
-    }
-
-    public void setAdminObjName(String adminObjName) {
-        this.adminObjName = adminObjName;
-    }
-
-    public String getAdminObjType() {
-        return adminObjType;
-    }
-
-    public void setAdminObjType(String adminObjType) {
-        this.adminObjType = adminObjType;
-    }
-
+   
     public String getCorrelationId() {
         return correlationId;
     }
@@ -126,14 +98,6 @@
         this.jmsType = jmsType;
     }
 
-    public String getPhysicalName() {
-        return physicalName;
-    }
-
-    public void setPhysicalName(String physicalName) {
-        this.physicalName = physicalName;
-    }
-
     public int getPriority() {
         return priority;
     }

Modified: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/AmqJMSMessageHelper.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/AmqJMSMessageHelper.java?rev=813742&r1=813741&r2=813742&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/AmqJMSMessageHelper.java (original)
+++ geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/AmqJMSMessageHelper.java Fri Sep 11 09:38:26 2009
@@ -14,26 +14,39 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
+
 package org.apache.geronimo.console.jmsmanager.helper;
 
+import java.util.Date;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Set;
 
-import javax.jms.Destination;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
 import javax.management.MBeanServer;
 import javax.management.MBeanServerInvocationHandler;
+import javax.management.MalformedObjectNameException;
 import javax.management.ObjectInstance;
 import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
 import javax.portlet.PortletRequest;
-import javax.portlet.RenderRequest;
 
+import org.apache.activemq.ActiveMQConnection;
+import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.jmx.BrokerViewMBean;
+import org.apache.activemq.broker.jmx.CompositeDataConstants;
 import org.apache.activemq.broker.jmx.DestinationViewMBean;
 import org.apache.activemq.broker.jmx.QueueViewMBean;
 import org.apache.activemq.broker.jmx.TopicViewMBean;
+import org.apache.activemq.command.BrokerInfo;
 import org.apache.geronimo.console.jmsmanager.DestinationStatistics;
+import org.apache.geronimo.console.jmsmanager.DestinationType;
+import org.apache.geronimo.console.jmsmanager.JMSDestinationInfo;
 import org.apache.geronimo.console.jmsmanager.JMSMessageInfo;
+import org.apache.geronimo.console.util.PortletManager;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
 import org.apache.geronimo.system.jmx.MBeanServerReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,61 +55,105 @@
  * @version $Rev$ $Date$
  */
 public class AmqJMSMessageHelper extends JMSMessageHelper {
-    private static final Logger log = LoggerFactory.getLogger(AmqJMSMessageHelper.class);
 
-    public void purge(PortletRequest renderRequest, String brokerName, String type, String physicalQName) {
+    private static final Logger logger = LoggerFactory.getLogger(AmqJMSMessageHelper.class);
+
+    @SuppressWarnings("unchecked")
+    public void purge(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException {
         try {
-            MBeanServer server = getMBeanServer();
-            ObjectName objName = new ObjectName("org.apache.activemq" + ":BrokerName=" + brokerName + ",Type=" + type + ",Destination=" + physicalQName);
-            if (QUEUE_TYPE.equals(type)) {
+            if (destinationInfo.getType().equals(DestinationType.Queue)) {
+                BrokerInfo brokerInfo = getBrokerInfo(portletRequest, destinationInfo);
+                if (brokerInfo == null || !isInLocalMBeanServer(brokerInfo)) {
+                    throw new JMSException("Currently, only queue belong to local broker is supported");
+                }
+                MBeanServer server = getMBeanServer();
+                ObjectName destinationObjectName = createDestinationObjectName(brokerInfo.getBrokerName(), destinationInfo.getType().name(), destinationInfo.getPhysicalName());
                 QueueViewMBean proxy;
-                if (!server.isRegistered(objName)) {
+                if (!server.isRegistered(destinationObjectName)) {
                     // mbean is not yet registered.Adding the destination to activemq broker.
-                    ObjectName brokerObj = new ObjectName("org.apache.activemq" + ":BrokerName=" + brokerName + ",Type=Broker");
-                    Set set = server.queryMBeans(brokerObj, null);
+                    ObjectName brokerObjectName = createBrokerObjectName(brokerInfo.getBrokerName());
+                    Set set = server.queryMBeans(brokerObjectName, null);
                     Iterator it = set.iterator();
                     if (it.hasNext()) {
                         ObjectInstance instance = (ObjectInstance) it.next();
-                        brokerObj = instance.getObjectName();
+                        brokerObjectName = instance.getObjectName();
                     }
-                    BrokerViewMBean brokerMBean = (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance(server, brokerObj, BrokerViewMBean.class, true);
-                    brokerMBean.addQueue(physicalQName);
+                    BrokerViewMBean brokerMBean = (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance(server, brokerObjectName, BrokerViewMBean.class, true);
+                    brokerMBean.addQueue(destinationInfo.getPhysicalName());
                 }
-                proxy = (QueueViewMBean) MBeanServerInvocationHandler.newProxyInstance(server, objName, QueueViewMBean.class, true);
+                proxy = (QueueViewMBean) MBeanServerInvocationHandler.newProxyInstance(server, destinationObjectName, QueueViewMBean.class, true);
                 proxy.purge();
+            } else {
+                throw new JMSException("Purge action on topic is not supported");
+            }
+        } catch (MalformedObjectNameException e) {
+            throw createJMSException("Fail to find the target object name", e);
+        } catch (JMSException e) {
+            throw e;
+        } catch (Exception e) {
+            throw createJMSException("Error occured in the purge action", e);
+        }
+    }
 
+    private JMSException createJMSException(String reason, Exception e) {
+        JMSException jmsException = new JMSException(reason);
+        jmsException.setLinkedException(e);
+        return jmsException;
+    }
+
+    protected ObjectName createDestinationObjectName(String brokerName, String destinationType, String destinactionPhysicalName) throws MalformedObjectNameException {
+        return new ObjectName("org.apache.activemq" + ":BrokerName=" + brokerName + ",Type=" + destinationType + ",Destination=" + destinactionPhysicalName);
+    }
+
+    protected ObjectName createBrokerObjectName(String brokerName) throws MalformedObjectNameException {
+        return new ObjectName("org.apache.activemq" + ":BrokerName=" + brokerName + ",Type=Broker");
+    }
+
+    @Override
+    protected ConnectionFactory getConnectionFactory(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException{
+        ConnectionFactory connectionFactory = super.getConnectionFactory(portletRequest, destinationInfo);
+        if (connectionFactory == null) {
+            connectionFactory = createActiveMQConnectionFactory(portletRequest, destinationInfo);
+        }
+        return connectionFactory;
+    }
+
+    private ActiveMQConnectionFactory createActiveMQConnectionFactory(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException {
+        try {
+            Kernel kernel = PortletManager.getKernel();
+            ResourceAdapterModule resourceAdapterModule = (ResourceAdapterModule) PortletManager.getManagementHelper(portletRequest).getObject(destinationInfo.getResourceAdapterModuleAbName());
+            AbstractName resourceAdapterAbstractName = PortletManager.getNameFor(portletRequest, resourceAdapterModule.getResourceAdapterInstances()[0].getJCAResourceImplementations()[0]
+                    .getResourceAdapterInstances()[0]);
+            if (kernel.isRunning(resourceAdapterAbstractName)) {
+                String serverUrl = (String) kernel.getAttribute(resourceAdapterAbstractName, "ServerUrl");
+                String userName = (String) kernel.getAttribute(resourceAdapterAbstractName, "UserName");
+                String password = (String) kernel.getAttribute(resourceAdapterAbstractName, "Password");
+                return new ActiveMQConnectionFactory(userName, password, serverUrl);
             }
-        } catch (Exception ex) {
-            // ignoring the exception
-            log.error("Failed to purge", ex);
+            throw new JMSException("Fail to create ActiveMQConnectionFactory for the resource adapter module is not in running status");
+        } catch (JMSException e) {
+            throw e;
+        } catch (Exception e) {
+            logger.error("Fail to create ActiveMQConnectionFactory", e);
+            throw createJMSException("Fail to create ActiveMQConnectionFactory", e);
         }
     }
 
-    protected List<JMSMessageInfo> getMessagesFromTopic(RenderRequest request, Destination destination,
-            String adapterObjectName, String adminObjName, String physicalName) throws Exception {
-        /*
-         * MBeanServer server = getMBeanServer(); ObjectName objName = new
-         * ObjectName("org.apache.activemq"+":BrokerName=localhost,Type="+type+",Destination="+physicalQName);
-         * if(!server.isRegistered(objName)){ //mbean is not yet registered.Adding the destination to activemq broker.
-         * ObjectName brokerObj = new ObjectName("org.apache.activemq"+":BrokerName=localhost,Type=Broker");
-         * BrokerViewMBean brokerMBean = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(server,
-         * brokerObj, BrokerViewMBean.class, true); brokerMBean.addTopic(physicalQName); } TopicViewMBean mbean =
-         * (TopicViewMBean)MBeanServerInvocationHandler.newProxyInstance(server, objName, TopicViewMBean.class, true);
-         * return mbean.browseMessages();
-         */
-        return null;
-    }
-    
-    public DestinationStatistics getDestinationStatistics(String brokerName, String destType, String physicalName) {
-        DestinationStatistics stat = new DestinationStatistics();        
+    @Override
+    public DestinationStatistics getDestinationStatistics(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException {
+        DestinationStatistics stat = new DestinationStatistics();
         try {
+            BrokerInfo brokerInfo = getBrokerInfo(portletRequest, destinationInfo);
+            if (brokerInfo == null || !isInLocalMBeanServer(brokerInfo)) {
+                return stat;
+            }
             MBeanServer server = getMBeanServer();
-            ObjectName objName = new ObjectName("org.apache.activemq" + ":BrokerName=" + brokerName + ",Type=" + destType + ",Destination=" + physicalName);
+            ObjectName objName = createDestinationObjectName(brokerInfo.getBrokerName(), destinationInfo.getType().name(), destinationInfo.getPhysicalName());
             DestinationViewMBean proxy;
-            if (QUEUE_TYPE.equals(destType)) {
+            if (destinationInfo.getType().equals(DestinationType.Queue)) {
                 if (!server.isRegistered(objName)) {
                     // mbean is not yet registered.Adding the destination to activemq broker.
-                    ObjectName brokerObj = new ObjectName("org.apache.activemq" + ":BrokerName=" + brokerName + ",Type=Broker");
+                    ObjectName brokerObj = createBrokerObjectName(brokerInfo.getBrokerName());
                     Set set = server.queryMBeans(brokerObj, null);
                     Iterator it = set.iterator();
                     if (it.hasNext()) {
@@ -104,13 +161,13 @@
                         brokerObj = instance.getObjectName();
                     }
                     BrokerViewMBean brokerMBean = (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance(server, brokerObj, BrokerViewMBean.class, true);
-                    brokerMBean.addQueue(physicalName);
+                    brokerMBean.addQueue(destinationInfo.getPhysicalName());
                 }
                 proxy = (DestinationViewMBean) MBeanServerInvocationHandler.newProxyInstance(server, objName, QueueViewMBean.class, true);
-            }else{
+            } else {
                 if (!server.isRegistered(objName)) {
                     // mbean is not yet registered.Adding the destination to activemq broker.
-                    ObjectName brokerObj = new ObjectName("org.apache.activemq" + ":BrokerName=" + brokerName + ",Type=Broker");
+                    ObjectName brokerObj = createBrokerObjectName(brokerInfo.getBrokerName());
                     Set set = server.queryMBeans(brokerObj, null);
                     Iterator it = set.iterator();
                     if (it.hasNext()) {
@@ -118,7 +175,7 @@
                         brokerObj = instance.getObjectName();
                     }
                     BrokerViewMBean brokerMBean = (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance(server, brokerObj, BrokerViewMBean.class, true);
-                    brokerMBean.addTopic(physicalName);
+                    brokerMBean.addTopic(destinationInfo.getPhysicalName());
                 }
                 proxy = (DestinationViewMBean) MBeanServerInvocationHandler.newProxyInstance(server, objName, TopicViewMBean.class, true);
             }
@@ -127,14 +184,92 @@
             stat.setDequeueCount(proxy.getDequeueCount());
             stat.setQueueSize(proxy.getQueueSize());
         } catch (Exception ex) {
-            // ignoring the exception
-            log.warn("Failed to get ActiveMQ stats", ex);
+            logger.warn("Failed to get ActiveMQ stats", ex);
         }
         return stat;
     }
 
-    private MBeanServer getMBeanServer() throws Exception {
-        MBeanServerReference ref = kernel.getGBean(MBeanServerReference.class);
-        return ref.getMBeanServer();
-    }    
+    protected JMSMessageInfo[] getMessagesFromTopic(PortletRequest portletRequest, JMSDestinationInfo destinationInfo, String selector) throws JMSException {
+        BrokerInfo brokerInfo = getBrokerInfo(portletRequest, destinationInfo);
+        if (brokerInfo == null || !isInLocalMBeanServer(brokerInfo)) {
+            return new JMSMessageInfo[0];
+        }
+        try {
+            ObjectName destinationObjectName = createDestinationObjectName(brokerInfo.getBrokerName(), destinationInfo.getType().name(), destinationInfo.getPhysicalName());
+            MBeanServer mBeanServer = getMBeanServer();
+            ObjectInstance objectInstance = mBeanServer.getObjectInstance(destinationObjectName);
+            CompositeData[] compositeData = (CompositeData[]) mBeanServer.invoke(objectInstance.getObjectName(), "browse", new Object[] { selector }, new String[] { String.class.getName() });
+            if (compositeData.length > 0) {
+                JMSMessageInfo[] messageInfos = new JMSMessageInfo[compositeData.length];
+                for (int i = 0; i < compositeData.length; i++) {
+                    JMSMessageInfo jmsMessageInfo = new JMSMessageInfo();
+                    CompositeData data = compositeData[i];
+                    if (compositeData[0].getCompositeType().getTypeName().equals("org.apache.activemq.command.ActiveMQTextMessage")) {
+                        jmsMessageInfo.setMessage((String) data.get(CompositeDataConstants.MESSAGE_TEXT));
+                    } else {
+                        jmsMessageInfo.setMessage("Only Text Messages will be displayed..");
+                    }
+                    jmsMessageInfo.setPriority((Integer) data.get("JMSPriority"));
+                    jmsMessageInfo.setMessageId((String) data.get("JMSMessageID"));
+                    jmsMessageInfo.setDestination((String) data.get("JMSDestination"));
+                    jmsMessageInfo.setTimeStamp(((Date) data.get("JMSTimestamp")).getTime());
+                    jmsMessageInfo.setExpiration((Long) data.get("JMSExpiration"));
+                    jmsMessageInfo.setJmsType((String) data.get("JMSType"));
+                    jmsMessageInfo.setReplyTo((String) data.get("JMSReplyTo"));
+                    jmsMessageInfo.setCorrelationId((String) data.get("JMSCorrelationID"));
+                    messageInfos[i] = jmsMessageInfo;
+                }
+                return messageInfos;
+            }
+            return new JMSMessageInfo[0];
+        } catch (Exception e) {
+            throw createJMSException("Fail to get messages of the topic " + destinationInfo.getPhysicalName(), e); 
+        }
+    }
+
+    protected MBeanServer getMBeanServer() {
+        MBeanServerReference ref;
+        try {
+            ref = kernel.getGBean(MBeanServerReference.class);
+            return ref.getMBeanServer();
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    private boolean isInLocalMBeanServer(BrokerInfo brokerInfo) {
+        try {
+            ObjectName brokerObjectNameQuery = new ObjectName("org.apache.activemq" + ":*,Type=Broker");
+            MBeanServer mBeanServer = getMBeanServer();
+            Set<ObjectInstance> brokerObjectInstances = mBeanServer.queryMBeans(brokerObjectNameQuery, null);
+            String targetBrokerId = brokerInfo.getBrokerId().getValue();
+            for (ObjectInstance objectInstance : brokerObjectInstances) {
+                String brokerId = (String) mBeanServer.getAttribute(objectInstance.getObjectName(), "BrokerId");
+                if (targetBrokerId.equals(brokerId)) {
+                    return true;
+                }
+            }
+        } catch (Exception e) {
+            logger.error("Fail to check the broker in local mbeanserver", e);
+            return false;
+        }
+        return false;
+    }
+
+    private BrokerInfo getBrokerInfo(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException {
+        ActiveMQConnectionFactory connectionFactory = createActiveMQConnectionFactory(portletRequest, destinationInfo);
+        ActiveMQConnection connection = null;
+        try {
+            connection = (ActiveMQConnection) connectionFactory.createConnection();
+            connection.start();
+            return connection.getBrokerInfo();
+        } finally {
+            if (connection != null) {
+                try {
+                    connection.close();
+                } catch (Exception e) {
+                }
+            }
+        }
+    }
 }

Modified: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/JMSMessageHelper.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/JMSMessageHelper.java?rev=813742&r1=813741&r2=813742&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/JMSMessageHelper.java (original)
+++ geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/JMSMessageHelper.java Fri Sep 11 09:38:26 2009
@@ -14,13 +14,15 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
+
 package org.apache.geronimo.console.jmsmanager.helper;
 
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Enumeration;
+import java.util.LinkedList;
 import java.util.List;
 
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
 import javax.jms.DeliveryMode;
 import javax.jms.Destination;
 import javax.jms.JMSException;
@@ -28,20 +30,15 @@
 import javax.jms.MessageProducer;
 import javax.jms.Queue;
 import javax.jms.QueueBrowser;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
 import javax.jms.QueueSession;
 import javax.jms.Session;
 import javax.jms.TextMessage;
-import javax.jms.Topic;
-import javax.jms.TopicConnection;
-import javax.jms.TopicConnectionFactory;
-import javax.jms.TopicSession;
 import javax.management.ObjectName;
 import javax.portlet.PortletRequest;
-import javax.portlet.RenderRequest;
 
 import org.apache.geronimo.console.jmsmanager.DestinationStatistics;
+import org.apache.geronimo.console.jmsmanager.DestinationType;
+import org.apache.geronimo.console.jmsmanager.JMSDestinationInfo;
 import org.apache.geronimo.console.jmsmanager.JMSMessageInfo;
 import org.apache.geronimo.console.util.PortletManager;
 import org.apache.geronimo.gbean.AbstractName;
@@ -59,209 +56,118 @@
  * @version $Rev$ $Date$
  */
 public abstract class JMSMessageHelper {
+
     protected static final Kernel kernel = KernelRegistry.getSingleKernel();
-    private static final Logger log = LoggerFactory.getLogger(JMSMessageHelper.class);
 
-    public static final String QUEUE_TYPE = "Queue";
-    
-    public static final String TOPIC_TYPE = "Topic";
-    
-    public void sendMessage(RenderRequest request, JMSMessageInfo messageInfo) throws Exception {
-        Destination dest = getDestination(request, messageInfo.getAdapterObjectName(), messageInfo.getPhysicalName());
-        if (dest == null) {
-            log.error("Unable to find the destination....Not sending message");
-            return;
+    private static final Logger logger = LoggerFactory.getLogger(JMSMessageHelper.class);
+
+    public void sendMessage(PortletRequest portletRequest, JMSDestinationInfo destinationInfo, JMSMessageInfo messageInfo) throws JMSException {
+        Destination destination = getDestination(portletRequest, destinationInfo);
+        if (destination == null) {
+            throw new JMSException("Unable to find the destination....Not sending message");
+        }
+        ConnectionFactory connectionFactory = getConnectionFactory(portletRequest, destinationInfo);
+        if (connectionFactory == null) {
+            throw new JMSException("Unable to find the Connection Factory....Not sending message");
         }
-        if ("Queue".equals(messageInfo.getAdminObjType())) {
-            Queue destination = (Queue) dest;
-            QueueConnectionFactory connectionFactory = (QueueConnectionFactory) getJCAManagedConnectionFactory(request,
-                    messageInfo.getAdapterObjectName(), messageInfo.getAdminObjType()).getConnectionFactory();
-            if (connectionFactory == null) {
-                log.error("Unable to find Queue Connection factory...Not sending message");
-                return;
-            }
-            QueueConnection connection = null;
-            QueueSession session = null;
-            try {
-                connection = connectionFactory.createQueueConnection();
-                connection.start();
-                session = connection.createQueueSession(true, Session.DUPS_OK_ACKNOWLEDGE);
-
-                MessageProducer producer = session.createProducer(destination);
-                int deliveryMode = 0;
-                if (messageInfo.isPersistent()) {
-                    deliveryMode = DeliveryMode.PERSISTENT;
-                } else {
-                    deliveryMode = DeliveryMode.NON_PERSISTENT;
-                }
-                producer.setDeliveryMode(deliveryMode);
-                TextMessage msg = session.createTextMessage();
-                msg.setText(messageInfo.getMessage());
-                msg.setJMSCorrelationID(messageInfo.getCorrelationId());
-                msg.setJMSPriority(messageInfo.getPriority());
-                msg.setJMSType(messageInfo.getJmsType());
-                producer.send(msg,deliveryMode,messageInfo.getPriority(),TextMessage.DEFAULT_TIME_TO_LIVE);
-                session.commit();
-            } finally {
-                if (session != null)
-                    try {
-                        session.close();
-                    } catch (Exception e) {
-                    }
-                if (connection != null)
-                    try {
-                        connection.close();
-                    } catch (Exception e) {
-                    }                
-            }
-        } else {
-            Topic destination = (Topic) dest;
-            TopicConnectionFactory connectionFactory = (TopicConnectionFactory) getJCAManagedConnectionFactory(request,
-                    messageInfo.getAdapterObjectName(), messageInfo.getAdminObjType()).getConnectionFactory();
-            if (connectionFactory == null) {
-                log.error("Unable to find Topic Connection factory...Not sending message");
-                return;
-            }
-            TopicConnection connection = null;
-            TopicSession session = null;
-            try {
-                connection = connectionFactory.createTopicConnection();
-                connection.start();
-                session = connection.createTopicSession(true, Session.DUPS_OK_ACKNOWLEDGE);
-
-                MessageProducer producer = session.createProducer(destination);
-                int deliveryMode = 0;
-                if (messageInfo.isPersistent()) {
-                    deliveryMode = DeliveryMode.PERSISTENT;
-                } else {
-                    deliveryMode = DeliveryMode.NON_PERSISTENT;
+        Connection connection = null;
+        Session session = null;
+        try {
+            connection = connectionFactory.createConnection();
+            connection.start();
+            session = connection.createSession(true, Session.DUPS_OK_ACKNOWLEDGE);
+            MessageProducer producer = session.createProducer(destination);
+            int deliveryMode = 0;
+            if (messageInfo.isPersistent()) {
+                deliveryMode = DeliveryMode.PERSISTENT;
+            } else {
+                deliveryMode = DeliveryMode.NON_PERSISTENT;
+            }
+            producer.setDeliveryMode(deliveryMode);
+            TextMessage msg = session.createTextMessage();
+            msg.setText(messageInfo.getMessage());
+            msg.setJMSCorrelationID(messageInfo.getCorrelationId());
+            msg.setJMSPriority(messageInfo.getPriority());
+            msg.setJMSType(messageInfo.getJmsType());
+            producer.send(msg, deliveryMode, messageInfo.getPriority(), TextMessage.DEFAULT_TIME_TO_LIVE);
+            session.commit();
+        } finally {
+            if (connection != null)
+                try {
+                    connection.close();
+                } catch (Exception e) {
                 }
-                producer.setDeliveryMode(deliveryMode);
-                TextMessage msg = session.createTextMessage();
-                msg.setText(messageInfo.getMessage());
-                msg.setJMSCorrelationID(messageInfo.getCorrelationId());
-                msg.setJMSPriority(messageInfo.getPriority());
-                msg.setJMSType(messageInfo.getJmsType());
-                producer.send(msg,deliveryMode,messageInfo.getPriority(),TextMessage.DEFAULT_TIME_TO_LIVE);
-                session.commit();
-            } finally {
-                if (session != null)
-                    try {
-                        session.close();
-                    } catch (Exception e) {
-                    }
-                if (connection != null)
-                    try {
-                        connection.close();
-                    } catch (Exception e) {
-                    }
-            }
         }
     }
 
-    public List<JMSMessageInfo> getMessagesList(RenderRequest request, String adapterObjectName, String adminObjName,
-            String physicalName, String type) throws Exception {
-        Destination destination = getDestination(request, adapterObjectName, physicalName);
-        if (destination == null)
-            return Collections.emptyList();
-        if ("Queue".equals(type)) {
-            return getMessageFromQueue(request, destination, adapterObjectName, adminObjName, physicalName);
+    public JMSMessageInfo[] getMessagesList(PortletRequest portletRequest, JMSDestinationInfo jmsDestinationInfo, String selector) throws JMSException {
+        Destination destination = getDestination(portletRequest, jmsDestinationInfo);
+        if (destination == null) {
+            throw new JMSException("Fail to find the destination " + jmsDestinationInfo.getPhysicalName());
+        }
+        if (jmsDestinationInfo.getType().equals(DestinationType.Queue)) {
+            return getMessageFromQueue(portletRequest, jmsDestinationInfo, selector);
         } else {
-            return getMessagesFromTopic(request, destination, adapterObjectName, adminObjName, physicalName);
+            return getMessagesFromTopic(portletRequest, jmsDestinationInfo, selector);
         }
     }
 
-    private JCAManagedConnectionFactory getJCAManagedConnectionFactory(RenderRequest renderRequest, String objectName,
-            String type) {
-        ResourceAdapterModule[] modules = PortletManager.getOutboundRAModules(renderRequest,
-                new String[] { "javax.jms.ConnectionFactory", "javax.jms.QueueConnectionFactory",
-                        "javax.jms.TopicConnectionFactory", });
-        for (int i = 0; i < modules.length; i++) {
-            ResourceAdapterModule module = modules[i];
-            String objectNameTemp = module.getObjectName();
-            if (objectName != null && objectName.equals(objectNameTemp)) {
-                JCAManagedConnectionFactory[] factories = null;
-                if (QUEUE_TYPE.equals(type)) {
-                    factories = PortletManager.getOutboundFactoriesForRA(renderRequest, module,
-                            new String[] { "javax.jms.QueueConnectionFactory" });
-                } else if (TOPIC_TYPE.equals(type)) {
-                    factories = PortletManager.getOutboundFactoriesForRA(renderRequest, module,
-                            new String[] { "javax.jms.TopicConnectionFactory" });
-                }
-                if (factories == null || factories.length == 0) {
-                    factories = PortletManager.getOutboundFactoriesForRA(renderRequest, module,
-                            new String[] { "javax.jms.ConnectionFactory" });
-                }
-                if (factories != null && factories.length != 0) {
-                    return factories[0];
-                }
-
+    protected ConnectionFactory getConnectionFactory(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException {
+        JCAManagedConnectionFactory[] jcaManagedConnectionFactories = PortletManager.getOutboundFactoriesForRA(portletRequest, destinationInfo.getResourceAdapterModuleAbName(), destinationInfo
+                .getType().getConnectionFactoryInterfaces());
+        if (jcaManagedConnectionFactories != null && jcaManagedConnectionFactories.length > 0) {
+            try {
+                return (ConnectionFactory) (jcaManagedConnectionFactories[0].getConnectionFactory());
+            } catch (Exception e) {
             }
         }
         return null;
-
     }
 
-    private Destination getDestination(RenderRequest renderRequest, String objectName, String physicalName) {
+    protected Destination getDestination(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) {
         Destination dest = null;
         try {
-            ResourceAdapterModule[] modules = PortletManager.getOutboundRAModules(renderRequest, new String[] {
-                    "javax.jms.ConnectionFactory", "javax.jms.QueueConnectionFactory",
-                    "javax.jms.TopicConnectionFactory", });
-            for (int i = 0; i < modules.length; i++) {
-                ResourceAdapterModule module = modules[i];
-                String objectNameTemp = module.getObjectName();
-                if (objectName != null && objectName.equals(objectNameTemp)) {
-                    JCAAdminObject[] admins = PortletManager.getAdminObjectsForRA(renderRequest, module, new String[] {
-                            "javax.jms.Queue", "javax.jms.Topic" });
-                    for (int j = 0; j < admins.length; j++) {
-                        GeronimoManagedBean bean = (GeronimoManagedBean) admins[j];
-                        ObjectName name = ObjectName.getInstance(bean.getObjectName());
-                        String queueName = name.getKeyProperty(NameFactory.J2EE_NAME);
-                        String physicalNameTemp = null;
-                        try {
-                            physicalNameTemp = (String) admins[j].getConfigProperty("PhysicalName");
-                        } catch (Exception e) {
-                            log.warn("PhysicalName undefined, using queueName as PhysicalName");
-                            physicalNameTemp = queueName;
-                        }
-                        if (physicalName != null && physicalName.equals(physicalNameTemp)) {
-                            AbstractName absName = kernel.getAbstractNameFor(bean);
-                            dest = (Destination) kernel.invoke(absName, "$getResource");
-                            return dest;
-                        }
-                    }
+            ResourceAdapterModule resourceAdapterModule = (ResourceAdapterModule) PortletManager.getManagementHelper(portletRequest).getObject(destinationInfo.getResourceAdapterModuleAbName());
+            JCAAdminObject[] jcaAdminObjects = PortletManager.getAdminObjectsForRA(portletRequest, resourceAdapterModule, new String[] { destinationInfo.getType().getDestinationInterface() });
+            String targetPhysicalName = destinationInfo.getPhysicalName() == null ? "" : destinationInfo.getPhysicalName();
+            for (JCAAdminObject jcaAdminObject : jcaAdminObjects) {
+                GeronimoManagedBean bean = (GeronimoManagedBean) jcaAdminObject;
+                ObjectName name = ObjectName.getInstance(bean.getObjectName());
+                String queueName = name.getKeyProperty(NameFactory.J2EE_NAME);
+                String currentPhysicalName = null;
+                try {
+                    currentPhysicalName = (String) jcaAdminObject.getConfigProperty("PhysicalName");
+                } catch (Exception e) {
+                    logger.warn("PhysicalName undefined, using queueName as PhysicalName");
+                    currentPhysicalName = queueName;
+                }
+                if (targetPhysicalName.equals(currentPhysicalName)) {
+                    AbstractName absName = kernel.getAbstractNameFor(bean);
+                    dest = (Destination) kernel.invoke(absName, "$getResource");
+                    return dest;
                 }
             }
         } catch (Exception ex) {
-            // ignore exception
-            log.error("Failed to get destination", ex);
+            logger.error("Failed to get destination", ex);
         }
         return dest;
     }
 
-    protected abstract List<JMSMessageInfo> getMessagesFromTopic(RenderRequest request, Destination destination,
-            String adapterObjectName, String adminObjName, String physicalName) throws Exception;
+    protected abstract JMSMessageInfo[] getMessagesFromTopic(PortletRequest portletRequest, JMSDestinationInfo destinationInfo, String selector) throws JMSException;
 
-    protected List<JMSMessageInfo> getMessageFromQueue(RenderRequest request, Destination destination,
-            String adapterObjectName, String adminObjName, String physicalName) throws Exception {
-        List<JMSMessageInfo> ret = new ArrayList<JMSMessageInfo>();
-        Queue queue = (Queue) destination;
-        QueueConnectionFactory qConFactory = null;
-        QueueConnection qConnection = null;
-        QueueSession qSession = null;
-        QueueBrowser qBrowser = null;
+    @SuppressWarnings("unchecked")
+    protected JMSMessageInfo[] getMessageFromQueue(PortletRequest portletRequest, JMSDestinationInfo jmsDestinationInfo, String selector) throws JMSException {
+        Connection connection = null;
         try {
-            qConFactory = (QueueConnectionFactory) getJCAManagedConnectionFactory(request, adapterObjectName, QUEUE_TYPE)
-                    .getConnectionFactory();
-            if (qConFactory == null)
-                return ret;
-            qConnection = qConFactory.createQueueConnection();
-            qSession = qConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
-            qBrowser = qSession.createBrowser(queue);
-            qConnection.start();
+            ConnectionFactory connectionFactory = getConnectionFactory(portletRequest, jmsDestinationInfo);            
+            Queue queue = (Queue) getDestination(portletRequest, jmsDestinationInfo);
+            List<JMSMessageInfo> messages = new LinkedList<JMSMessageInfo>();
+            connection = connectionFactory.createConnection();
+            connection.start();
+            Session session = connection.createSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+            QueueBrowser qBrowser = session.createBrowser(queue);
             for (Enumeration e = qBrowser.getEnumeration(); e.hasMoreElements();) {
-                Message message = (Message)e.nextElement();
+                Message message = (Message) e.nextElement();
                 JMSMessageInfo messageInfo = new JMSMessageInfo();
                 messageInfo.setPriority(message.getJMSPriority());
                 messageInfo.setMessageId(message.getJMSMessageID());
@@ -269,44 +175,30 @@
                 messageInfo.setTimeStamp(message.getJMSTimestamp());
                 messageInfo.setExpiration(message.getJMSExpiration());
                 messageInfo.setJmsType(message.getJMSType());
-                messageInfo.setReplyTo(message.getJMSReplyTo()==null?"":message.getJMSReplyTo().toString());
+                messageInfo.setReplyTo(message.getJMSReplyTo() == null ? "" : message.getJMSReplyTo().toString());
                 messageInfo.setCorrelationId(message.getJMSCorrelationID());
                 if (message instanceof TextMessage) {
                     messageInfo.setMessage(((TextMessage) message).getText());
                 } else {
                     messageInfo.setMessage("Only Text Messages will be displayed..");
                 }
-                ret.add(messageInfo);
+                messages.add(messageInfo);
             }
-            qConnection.stop();
-        } catch (Exception e) {
-            log.error(e.getMessage(), e);
+            return messages.toArray(new JMSMessageInfo[0]);
+        } catch (JMSException e) {
+            logger.error(e.getMessage(), e);
+            throw e;
         } finally {
-            if (qBrowser != null) {
+            if (connection != null) {
                 try {
-                    qBrowser.close();
-                } catch (JMSException ignore) {
-                }
-            }
-            if (qSession != null) {
-                try {
-                    qSession.close();
-                } catch (JMSException ignore) {
-                }
-            }
-            if (qConnection != null) {
-                try {
-                    qConnection.close();
-                } catch (JMSException ignore) {
+                    connection.close();
+                } catch (Exception e) {
                 }
             }
         }
-        return ret;
     }
-    
-    public abstract void purge(PortletRequest request, String adapterObjectName, String adminObjName,
-            String physicalName) throws Exception;
-    
-    public abstract DestinationStatistics getDestinationStatistics(String brokerName, String destType,String physicalName);
 
+    public abstract void purge(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException;
+
+    public abstract DestinationStatistics getDestinationStatistics(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException;
 }

Modified: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/JMSMessageHelperFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/JMSMessageHelperFactory.java?rev=813742&r1=813741&r2=813742&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/JMSMessageHelperFactory.java (original)
+++ geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/helper/JMSMessageHelperFactory.java Fri Sep 11 09:38:26 2009
@@ -16,17 +16,18 @@
  */
 package org.apache.geronimo.console.jmsmanager.helper;
 
-import java.util.List;
+import java.net.URI;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
-import javax.jms.Destination;
+import javax.jms.JMSException;
 import javax.portlet.PortletRequest;
-import javax.portlet.RenderRequest;
 
 import org.apache.geronimo.console.jmsmanager.DestinationStatistics;
+import org.apache.geronimo.console.jmsmanager.JMSDestinationInfo;
 import org.apache.geronimo.console.jmsmanager.JMSMessageInfo;
 import org.apache.geronimo.console.util.PortletManager;
+import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,20 +50,18 @@
             vendorNameJMSMessageHelperMap.put(DEFAULT_JMS_MESSAGEHELPER, new JMSMessageHelper() {
 
                 @Override
-                public DestinationStatistics getDestinationStatistics(String brokerName, String destType,
-                        String physicalName) {
-                    return null;
+                public DestinationStatistics getDestinationStatistics(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException {
+                    return new DestinationStatistics();
                 }
 
                 @Override
-                protected List<JMSMessageInfo> getMessagesFromTopic(RenderRequest request, Destination destination,
-                        String adapterObjectName, String adminObjName, String physicalName) throws Exception {
-                    return null;
+                protected JMSMessageInfo[] getMessagesFromTopic(PortletRequest portletRequest, JMSDestinationInfo destinationInfo, String selector) throws JMSException {
+                    return new JMSMessageInfo[0];
                 }
 
                 @Override
-                public void purge(PortletRequest request, String adapterObjectName, String adminObjName,
-                        String physicalName) throws Exception {
+                public void purge(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException {
+                    throw new UnsupportedOperationException("purge action is not supported for current vendor");
                 }
             });
         } catch (Exception e) {
@@ -70,18 +69,11 @@
         }
     }
 
-    public static JMSMessageHelper getMessageHelper(PortletRequest renderRequest, String raName) {
-        ResourceAdapterModule[] modules = PortletManager.getOutboundRAModules(renderRequest, new String[] {
-                "javax.jms.ConnectionFactory",
-                "javax.jms.QueueConnectionFactory",
-                "javax.jms.TopicConnectionFactory" });
+    public static JMSMessageHelper getMessageHelper(PortletRequest renderRequest, String resourceAdapterModuleName) {
         String vendorName = null;
-        for (int i = 0; i < modules.length; i++) {
-            ResourceAdapterModule module = modules[i];
-            String objectNameTemp = module.getObjectName();
-            if (raName != null && raName.equals(objectNameTemp)) {
-                vendorName = module.getVendorName();
-            }
+        ResourceAdapterModule module = (ResourceAdapterModule)PortletManager.getManagementHelper(renderRequest).getObject(new AbstractName(URI.create(resourceAdapterModuleName)));
+        if(module != null) {
+            vendorName = module.getVendorName();
         }
         return getJMSMessageHelper(vendorName);
     }

Modified: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/AbstractHandler.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/AbstractHandler.java?rev=813742&r1=813741&r2=813742&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/AbstractHandler.java (original)
+++ geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/AbstractHandler.java Fri Sep 11 09:38:26 2009
@@ -97,6 +97,7 @@
     protected final static String MESSAGE_ID = "messageId";
     protected final static String MESSAGE_TXT="messageTxt";
     protected final static String BROKER_NAME = "brokerName";
+    protected final static String RESOURCE_ADAPTER_MODULE_NAME = "resourceAdapterModuleName";
 
     protected final static String PROVIDER_PARAMETER="provider";
     protected final static String RAR_FILE_PARAMETER="rar";

Modified: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/JMSResourcePortlet.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/JMSResourcePortlet.java?rev=813742&r1=813741&r2=813742&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/JMSResourcePortlet.java (original)
+++ geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/JMSResourcePortlet.java Fri Sep 11 09:38:26 2009
@@ -40,8 +40,8 @@
         addHelper(new ShowPlanHandler(this), config);
         addHelper(new DeployHandler(this), config);
         addHelper(new ReviewHandler(), config);
-        addHelper(new ViewMessageHandler(), config);
-        addHelper(new MessageDetailsHandler(), config);
+        addHelper(new ViewMessageHandler(this), config);
+        addHelper(new MessageDetailsHandler(this), config);
         addHelper(new SendMessageHandler(this), config);
     }
 

Modified: geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/ListScreenHandler.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/ListScreenHandler.java?rev=813742&r1=813741&r2=813742&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/ListScreenHandler.java (original)
+++ geronimo/server/branches/2.2/plugins/activemq/activemq-portlets/src/main/java/org/apache/geronimo/console/jmsmanager/wizard/ListScreenHandler.java Fri Sep 11 09:38:26 2009
@@ -18,17 +18,11 @@
 
 import java.io.IOException;
 import java.io.Serializable;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Enumeration;
 import java.util.List;
 
+import javax.jms.JMSException;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 import javax.portlet.ActionRequest;
@@ -38,25 +32,19 @@
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 
-import org.apache.geronimo.activemq.BrokerServiceGBean;
-import org.apache.geronimo.activemq.management.ActiveMQManagerGBean;
 import org.apache.geronimo.console.BasePortlet;
 import org.apache.geronimo.console.MultiPageModel;
 import org.apache.geronimo.console.jmsmanager.DestinationStatistics;
+import org.apache.geronimo.console.jmsmanager.JMSDestinationInfo;
 import org.apache.geronimo.console.jmsmanager.helper.JMSMessageHelper;
 import org.apache.geronimo.console.jmsmanager.helper.JMSMessageHelperFactory;
 import org.apache.geronimo.console.util.PortletManager;
-import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
-import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.management.State;
 import org.apache.geronimo.kernel.proxy.GeronimoManagedBean;
 import org.apache.geronimo.management.geronimo.JCAAdminObject;
 import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory;
 import org.apache.geronimo.management.geronimo.JCAResource;
-import org.apache.geronimo.management.geronimo.JMSBroker;
-import org.apache.geronimo.management.geronimo.JMSManager;
-import org.apache.geronimo.management.geronimo.NetworkConnector;
 import org.apache.geronimo.management.geronimo.ResourceAdapter;
 import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
 import org.slf4j.Logger;
@@ -78,18 +66,18 @@
         super(LIST_MODE, "/WEB-INF/view/jmswizard/list.jsp", basePortlet);
     }
     
-    public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
-        String purgeStr = request.getParameter(PURGE);
+    public String actionBeforeView(ActionRequest actionRequest, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
+        String purgeStr = actionRequest.getParameter(PURGE);
         if (purgeStr != null) {
-            String physicalName = request.getParameter(PHYSICAL_NAME);
-            String adminObjType = request.getParameter(ADMIN_OBJ_TYPE);
-            String adapterObjectName = request.getParameter(RA_ADAPTER_OBJ_NAME);
-            String brokerName = request.getParameter(BROKER_NAME);
-            response.setRenderParameter(ADMIN_OBJ_TYPE, adminObjType);
-            response.setRenderParameter(PHYSICAL_NAME, physicalName);
-            response.setRenderParameter(RA_ADAPTER_OBJ_NAME, adapterObjectName);
-            response.setRenderParameter(BROKER_NAME, brokerName);
-            response.setRenderParameter(PURGE, purgeStr);
+            String physicalName = actionRequest.getParameter(PHYSICAL_NAME);
+            String resourceAdapterModuleName = actionRequest.getParameter(RESOURCE_ADAPTER_MODULE_NAME);
+            JMSMessageHelper helper = JMSMessageHelperFactory.getMessageHelper(actionRequest, resourceAdapterModuleName);
+            try {
+                helper.purge(actionRequest, JMSDestinationInfo.create(actionRequest));
+            } catch (Exception e) {
+                portlet.addErrorMessage(actionRequest, portlet.getLocalizedString(actionRequest, "activemq.errorMsg04", physicalName), e.getMessage());
+                logger.error("Fail to purge message destination " + physicalName, e);
+            }
         }
         return getMode();
     }
@@ -111,22 +99,7 @@
     }
 
 
-    private void populateExistingList(PortletRequest renderRequest) throws PortletException {
-        String purgeStr = renderRequest.getParameter(PURGE);
-        if (purgeStr != null) {
-            String physicalName = renderRequest.getParameter(PHYSICAL_NAME);
-            String adminObjType = renderRequest.getParameter(ADMIN_OBJ_TYPE);
-            String adapterObjectName = renderRequest.getParameter(RA_ADAPTER_OBJ_NAME);
-            String brokerName = renderRequest.getParameter(BROKER_NAME);
-            JMSMessageHelper helper = JMSMessageHelperFactory.getMessageHelper(renderRequest, adapterObjectName);
-            try {
-                helper.purge(renderRequest, brokerName, adminObjType, physicalName);
-            } catch (Exception e) {
-                logger.error("Fail to purge the messages in [" + brokerName + "." + physicalName + "]", e);
-                throw new PortletException("Fail to purge the messages in [" + brokerName + "." + physicalName + "]",e);
-            }
-        }                
-        
+    private void populateExistingList(PortletRequest renderRequest) throws PortletException {       
         // Prepare a list of JMS configurations
         List<JMSResourceSummary> resources = new ArrayList<JMSResourceSummary>();
 
@@ -156,12 +129,11 @@
                     if (name == null) {
                         name = ObjectName.getInstance(module.getObjectName()).getKeyProperty(NameFactory.J2EE_NAME);
                     }
-                    String sServerUrl = adapters.length > 0 ? getServerUrl(renderRequest, module) : "";
-                    target = new JMSResourceSummary(PortletManager.getConfigurationFor(renderRequest, PortletManager.getNameFor(renderRequest, module)).toString(), module.getObjectName(), name,
-                            ((GeronimoManagedBean) module).getState(), getBrokerName(renderRequest, sServerUrl, name));
+                    String configurationName = PortletManager.getConfigurationFor(renderRequest, PortletManager.getNameFor(renderRequest, module)).toString();
+                    String resourceAdapterModuleName = PortletManager.getNameFor(renderRequest, module).toString();
+                    target = new JMSResourceSummary(configurationName, module.getObjectName(), resourceAdapterModuleName, name, ((GeronimoManagedBean) module).getState());
                     resources.add(target);
                 }
-
                 JCAManagedConnectionFactory[] factories = PortletManager.getOutboundFactoriesForRA(renderRequest, module, new String[]{
                         "javax.jms.ConnectionFactory", "javax.jms.QueueConnectionFactory", "javax.jms.TopicConnectionFactory",});
                 for (int j = 0; j < factories.length; j++) {
@@ -169,6 +141,13 @@
                     ObjectName name = ObjectName.getInstance(factory.getObjectName());
                     target.getConnectionFactories().add(new ConnectionFactorySummary(factory.getObjectName(), name.getKeyProperty(NameFactory.J2EE_NAME),
                             ((GeronimoManagedBean) factory).getState()));
+                    String factoryInterface = factory.getConnectionInterface();
+                    if (!target.isQueueConnectionFactoryContained()) {                        
+                        target.setQueueConnectionFactoryContained(factoryInterface.equals("javax.jms.ConnectionFactory") || factoryInterface.equals("javax.jms.QueueConnectionFactory"));
+                    }
+                    if (!target.isTopicConnectionFactoryContained()) {                       
+                        target.setQueueConnectionFactoryContained(factoryInterface.equals("javax.jms.ConnectionFactory") || factoryInterface.equals("javax.jms.TopicConnectionFactory"));
+                    }
                 }
             }
 
@@ -197,11 +176,13 @@
                     if (name == null) {
                         name = ObjectName.getInstance(module.getObjectName()).getKeyProperty(NameFactory.J2EE_NAME);
                     }
-                    String sServerUrl = adapters.length > 0 ? getServerUrl(renderRequest,module) : "";
-                    target = new JMSResourceSummary(PortletManager.getConfigurationFor(renderRequest, PortletManager.getNameFor(renderRequest, module)).toString(), module.getObjectName(), name,
-                            ((GeronimoManagedBean) module).getState(), getBrokerName(renderRequest, sServerUrl, name));
+                    String configurationName = PortletManager.getConfigurationFor(renderRequest, PortletManager.getNameFor(renderRequest, module)).toString();
+                    String resourceAdapterModuleName = PortletManager.getNameFor(renderRequest, module).toString();
+                    target = new JMSResourceSummary(configurationName, module.getObjectName(), resourceAdapterModuleName, name, ((GeronimoManagedBean) module).getState());
                     resources.add(target);
                 }
+                
+                boolean activeMQAdapter = module.getVendorName().equals("activemq.org");                
 
                 JCAAdminObject[] admins = PortletManager.getAdminObjectsForRA(renderRequest, module, new String[]{"javax.jms.Queue", "javax.jms.Topic"});
                 for (int j = 0; j < admins.length; j++) {
@@ -218,14 +199,33 @@
                     String destType = admins[j].getAdminObjectInterface().indexOf("Queue") > -1 ? "Queue" : "Topic";
                     String vendorName = module.getVendorName();
                     DestinationStatistics destinationStat = null;
-                    if (target.getBrokerName() == null || physicalName == null) {
-                        destinationStat = new DestinationStatistics();
+                    if (physicalName != null) {                        
+                        try {
+                            JMSDestinationInfo jmsDestinationInfo = new JMSDestinationInfo();
+                            jmsDestinationInfo.setPhysicalName(physicalName);
+                            jmsDestinationInfo.setType(destType);
+                            jmsDestinationInfo.setResourceAdapterModuleAbName(PortletManager.getNameFor(renderRequest, module));
+                            destinationStat = JMSMessageHelperFactory.getJMSMessageHelper(vendorName).getDestinationStatistics(renderRequest, jmsDestinationInfo);
+                        } catch (JMSException e) {
+                            destinationStat = new DestinationStatistics();
+                        }
+                    }
+                    AdminObjectSummary adminObjectSummary = new AdminObjectSummary(bean.getObjectName(), queueName, physicalName, destType, bean.getState(), destinationStat);                                        
+                    if(activeMQAdapter) {
+                        adminObjectSummary.setBrowserSupported(true);
+                        adminObjectSummary.setSendMessageSupported(true);
+                        if(destType.equals("Queue")) {
+                            adminObjectSummary.setPurgeSupported(true);
+                        }
                     } else {
-                        destinationStat = JMSMessageHelperFactory.getJMSMessageHelper(vendorName).getDestinationStatistics(target.getBrokerName(), destType, physicalName);
+                        if(destType.equals("Queue") && target.isQueueConnectionFactoryContained()) {
+                            adminObjectSummary.setSendMessageSupported(true);
+                            adminObjectSummary.setBrowserSupported(true);
+                        } else if(destType.equals("Topic") && target.isTopicConnectionFactoryContained()) {
+                            adminObjectSummary.setSendMessageSupported(true);                            
+                        }
                     }
-                    target.getAdminObjects().add(
-                            new AdminObjectSummary(bean.getObjectName(), queueName, physicalName,destType , bean
-                                    .getState(),destinationStat));
+                    target.getAdminObjects().add(adminObjectSummary);
                 }
             }
         } catch (MalformedObjectNameException e) {
@@ -238,153 +238,26 @@
         renderRequest.setAttribute("providers", JMSProviderData.getAllProviders());
     }
     
-    private String getServerUrl(PortletRequest portletRequest, ResourceAdapterModule resourceAdapterModule) {
-        try {
-            Kernel kernel = PortletManager.getKernel();
-            AbstractName resourceAdapterAbstractName = PortletManager.getNameFor(portletRequest, resourceAdapterModule.getResourceAdapterInstances()[0].getJCAResourceImplementations()[0].getResourceAdapterInstances()[0]);
-            if (kernel.isRunning(resourceAdapterAbstractName)) {
-                return (String) kernel.getAttribute(resourceAdapterAbstractName, "ServerUrl");
-            }
-            return "";
-        } catch (Exception e) {
-            logger.error("Fail to get server URL of the JMS resource",e);
-            return "";
-        }
-    }
-    
-    private String getBrokerName(PortletRequest portletRequest, String serverURL, String resourceName) throws PortletException {
-        try {
-            GeronimoManagedBean[] geronimoManagedBeans = PortletManager.getManagedBeans(portletRequest,
-                    ActiveMQManagerGBean.class);
-            if (geronimoManagedBeans == null || geronimoManagedBeans.length == 0)
-                throw new PortletException("Could not find the ActiveMQ Manager");
-            if (geronimoManagedBeans.length > 1)
-                logger.warn("More than one ActiveMQ Manager exist in kernel");            
-            JMSManager activeMQManager = (JMSManager) geronimoManagedBeans[0];            
-            JMSBroker targetJMSBroker = null;
-            URI uri = new URI(serverURL);            
-            String sResourceHostName = uri.getHost();
-            if(!isLocalMachine(sResourceHostName)) {
-                //The resource adapter may connect to the broker running on other servers, let's directly return null
-                portlet.addWarningMessage(portletRequest, portlet.getLocalizedString(portletRequest, "activemq.warnMsg01", resourceName));
-                return null;
-            }               
-            for (JMSBroker jmsBroker : (JMSBroker[]) activeMQManager.getContainers()) {
-                NetworkConnector[] connectors = activeMQManager.getConnectorsForContainer(jmsBroker, uri.getScheme());
-                for (NetworkConnector connector : connectors) {                                       
-                    if(connector.getPort() != uri.getPort()) {
-                        continue;
-                    }
-                    boolean findJMSBroker = false;
-                    String sConnectorHostName = connector.getHost();
-                    /*
-                     * If the broker is binding on all the interfaces, it is the one we want.
-                     * else if the broker is listening on loop back address, the host name of the resource adapter should also be loop back address. 
-                     * else if the host name of resource adapter is local host name, it is the one we want.
-                     * else let us compare whether those two host name are the same textual presentation 
-                     * */
-                    if (isBindOnAllInterfaces(sConnectorHostName)) {
-                        findJMSBroker = true;
-                    } else if (isLoopbackAddress(sConnectorHostName)) {
-                        if (isLoopbackAddress(sResourceHostName)) {
-                            findJMSBroker = true;
-                        } else {
-                            continue;
-                        }
-                    } else if (sResourceHostName.equals(getLocalHostName()) || sResourceHostName.equals(getFullLocalHostName())) {
-                        findJMSBroker = true;
-                    } else if (sResourceHostName.equals(sConnectorHostName)) {
-                        findJMSBroker = true;
-                    }
-                    if (findJMSBroker) {
-                        targetJMSBroker = jmsBroker;
-                    }
-                }
-                if (targetJMSBroker != null)
-                    return ((BrokerServiceGBean) targetJMSBroker).getBrokerName();
-            }
-            logger.warn("Could not find the broker according to the url [" + serverURL + "]");
-            return null;
-        } catch (URISyntaxException e) {
-            logger.error("Unrecognized server URL [" + serverURL + "]", e);
-            return null;
-        }
-    }
-    
-    private boolean isLoopbackAddress(String hostName) {
-        try {
-            return InetAddress.getByName(hostName).isLoopbackAddress();
-        } catch (UnknownHostException e) {
-            return false;
-        }
-    }    
-    
-    private boolean isBindOnAllInterfaces(String hostName) {
-        if (hostName.equals("0.0.0.0") || hostName.equals(getLocalHostName())
-                || hostName.equals(getFullLocalHostName())) {
-            return true;
-        }
-        return false;
-    }
-
-    private String getLocalHostName() {
-        try {
-            return InetAddress.getLocalHost().getHostName();
-        } catch (UnknownHostException e) {
-            return null;
-        }
-    }
-    
-    private String getFullLocalHostName() {
-        try {
-            return InetAddress.getLocalHost().getCanonicalHostName();
-        } catch (UnknownHostException e) {
-            return null;
-        }
-    }
     
-    private boolean isLocalMachine(String hostName) {
-        try {
-            InetAddress hostAddress = InetAddress.getByName(hostName);
-            if (hostAddress.isAnyLocalAddress() || hostAddress.isLoopbackAddress() || hostName.equals(getLocalHostName()) || hostName.equals(getFullLocalHostName())) {
-                return true;
-            } else {
-                Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
-                while (en.hasMoreElements()) {
-                    NetworkInterface iface = en.nextElement();
-                    Enumeration<InetAddress> ien = iface.getInetAddresses();
-                    while (ien.hasMoreElements()) {
-                        InetAddress address = ien.nextElement();
-                        if (address.equals(hostAddress)) {
-                            return true;
-                        }
-                    }
-                }
-                return false;
-            }
-        } catch (SocketException e) {
-            return false;
-        } catch (UnknownHostException e) {
-            return false;
-        }
-    }
     
     public static class JMSResourceSummary implements Serializable, Comparable<JMSResourceSummary> {
         private static final long serialVersionUID = -2788803234448047035L;
         private final String configurationName;
         private final String adapterObjectName;
+        private final String resourceAdapterModuleName;
         private final String name;
         private final String parentName;
         private final int state;
-        private final String brokerName;
         private final List<ConnectionFactorySummary> connectionFactories = new ArrayList<ConnectionFactorySummary>();
         private final List<AdminObjectSummary> adminObjects = new ArrayList<AdminObjectSummary>();
+        private boolean topicConnectionFactoryContained = false;
+        private boolean queueConnectionFactoryContained = false;
 
-        public JMSResourceSummary(String configurationName, String adapterObjectName, String name, int state, String brokerName) {
+        public JMSResourceSummary(String configurationName, String adapterObjectName, String resourceAdapterModuleName, String name, int state) {
             this.configurationName = configurationName;
             this.adapterObjectName = adapterObjectName;
-            this.state = state;
-            this.brokerName = brokerName;
+            this.resourceAdapterModuleName = resourceAdapterModuleName;
+            this.state = state;            
             try {
                 ObjectName objectName = ObjectName.getInstance(adapterObjectName);
                 String parent = objectName.getKeyProperty(NameFactory.J2EE_APPLICATION);
@@ -406,6 +279,10 @@
             return adapterObjectName;
         }
 
+        public String getResourceAdapterModuleName() {
+            return resourceAdapterModuleName;
+        }
+
         public String getName() {
             return name;
         }
@@ -430,10 +307,6 @@
             return State.toString(state);
         }
         
-        public String getBrokerName() {
-            return brokerName;
-        }
-        
         public int compareTo(JMSResourceSummary o) {            
             int names = name.toLowerCase().compareTo(o.name.toLowerCase());
             if (parentName == null) {
@@ -455,6 +328,24 @@
                 }
             }
         }
+
+        public boolean isTopicConnectionFactoryContained() {
+            return topicConnectionFactoryContained;
+        }
+
+        public void setTopicConnectionFactoryContained(boolean topicConnectionFactoryContained) {
+            this.topicConnectionFactoryContained = topicConnectionFactoryContained;
+        }
+
+        public boolean isQueueConnectionFactoryContained() {
+            return queueConnectionFactoryContained;
+        }
+
+        public void setQueueConnectionFactoryContained(boolean queueConnectionFactoryContained) {
+            this.queueConnectionFactoryContained = queueConnectionFactoryContained;
+        }
+        
+        
     }
 
     public static class ConnectionFactorySummary implements Serializable, Comparable<ConnectionFactorySummary> {
@@ -499,6 +390,9 @@
         private final int state;
         private final String physicalName;
         private final DestinationStatistics destinationStat;
+        private boolean browserSupported = false;
+        private boolean sendMessageSupported = false;
+        private boolean purgeSupported = false;
         
         public AdminObjectSummary(String adminObjectName, String name, String physicalName, String type, int state,DestinationStatistics destinationStat) {
             this.adminObjectName = adminObjectName;
@@ -512,6 +406,7 @@
         public DestinationStatistics getdestinationStat(){
             return this.destinationStat;
         }
+
         public String getAdminObjectName() {
             return adminObjectName;
         }
@@ -540,5 +435,29 @@
             int result = name.compareTo(o.name);
             return result == 0 ? type.compareTo(o.type) : result;
         }
+
+        public boolean isBrowserSupported() {
+            return browserSupported;
+        }
+
+        public boolean isSendMessageSupported() {
+            return sendMessageSupported;
+        }
+
+        public boolean isPurgeSupported() {
+            return purgeSupported;
+        }
+
+        public void setBrowserSupported(boolean browserSupported) {
+            this.browserSupported = browserSupported;
+        }
+
+        public void setSendMessageSupported(boolean sendMessageSupported) {
+            this.sendMessageSupported = sendMessageSupported;
+        }
+
+        public void setPurgeSupported(boolean purgeSupported) {
+            this.purgeSupported = purgeSupported;
+        }
     }
 }



Mime
View raw message