From 87f75b2de77aa57c4e708cee181725ade8227ca4 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Thu, 24 May 2007 14:14:49 +0000 Subject: [PATCH] applied patch for AMQ-1241 to allow the web console to be run against an embedded, invm, properties or remote broker. Many thanks to Mario Siegenthaler for the patch! git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@541306 13f79535-47bb-0310-9956-ffa450edef68 --- activemq-web-console/pom.xml | 14 ++ .../apache/activemq/web/JMXBrokerFacade.java | 73 ------ .../activemq/web/RemoteJMXBrokerFacade.java | 222 +++++++++++++++++ .../org/apache/activemq/web/SessionPool.java | 106 ++++---- .../activemq/web/WebConsoleStarter.java | 83 +++++++ .../activemq/web/controller/SendMessage.java | 2 - .../src/main/webapp/WEB-INF/web.xml | 226 ++++++++++-------- ...ionContext.xml => webconsole-embedded.xml} | 15 +- .../main/webapp/WEB-INF/webconsole-invm.xml | 43 ++++ .../main/webapp/WEB-INF/webconsole-jndi.xml | 46 ++++ .../webapp/WEB-INF/webconsole-properties.xml | 43 ++++ .../activemq/web/QueueBrowseServlet.java | 22 +- .../org/apache/activemq/web/WebClient.java | 19 +- assembly/pom.xml | 4 + assembly/src/main/descriptors/unix-bin.xml | 5 +- assembly/src/main/descriptors/windows-bin.xml | 5 +- ...ionContext.xml => webconsole-embedded.xml} | 12 +- pom.xml | 9 +- 18 files changed, 691 insertions(+), 258 deletions(-) delete mode 100644 activemq-web-console/src/main/java/org/apache/activemq/web/JMXBrokerFacade.java create mode 100644 activemq-web-console/src/main/java/org/apache/activemq/web/RemoteJMXBrokerFacade.java create mode 100644 activemq-web-console/src/main/java/org/apache/activemq/web/WebConsoleStarter.java rename activemq-web-console/src/main/webapp/WEB-INF/{applicationContext.xml => webconsole-embedded.xml} (88%) create mode 100644 activemq-web-console/src/main/webapp/WEB-INF/webconsole-invm.xml create mode 100644 activemq-web-console/src/main/webapp/WEB-INF/webconsole-jndi.xml create mode 100644 activemq-web-console/src/main/webapp/WEB-INF/webconsole-properties.xml rename assembly/src/release/webapps/admin/WEB-INF/{applicationContext.xml => webconsole-embedded.xml} (86%) diff --git a/activemq-web-console/pom.xml b/activemq-web-console/pom.xml index b3b6ab7e05..f963e4c0c7 100755 --- a/activemq-web-console/pom.xml +++ b/activemq-web-console/pom.xml @@ -52,6 +52,20 @@ com.sun.management.jmxremote + 10 diff --git a/activemq-web-console/src/main/java/org/apache/activemq/web/JMXBrokerFacade.java b/activemq-web-console/src/main/java/org/apache/activemq/web/JMXBrokerFacade.java deleted file mode 100644 index 6e943ec615..0000000000 --- a/activemq-web-console/src/main/java/org/apache/activemq/web/JMXBrokerFacade.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.web; - -import org.apache.activemq.broker.jmx.BrokerViewMBean; -import org.apache.activemq.broker.jmx.ManagementContext; -import org.apache.activemq.command.ActiveMQDestination; - -import javax.management.MBeanServerConnection; -import javax.management.MBeanServerInvocationHandler; -import javax.management.MalformedObjectNameException; -import javax.management.ObjectName; - -/** - * A {@link BrokerFacade} which uses JMX to communicate with a remote broker - * - * @version $Revision$ - */ -public class JMXBrokerFacade extends BrokerFacadeSupport { - private ManagementContext managementContext; - private ObjectName brokerName; - - public BrokerViewMBean getBrokerAdmin() throws Exception { - MBeanServerConnection mbeanServer = getManagementContext().getMBeanServer(); - return (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance(mbeanServer, getBrokerName(), BrokerViewMBean.class, true); - } - - public void purgeQueue(ActiveMQDestination destination) throws Exception { - /** TODO */ - } - - public ManagementContext getManagementContext() { - if (managementContext == null) { - managementContext = new ManagementContext(); - managementContext.setCreateConnector(true); - } - return managementContext; - } - - public void setManagementContext(ManagementContext managementContext) { - this.managementContext = managementContext; - } - - public ObjectName getBrokerName() throws MalformedObjectNameException { - if (brokerName == null) { - brokerName = createBrokerName(); - } - return brokerName; - } - - public void setBrokerName(ObjectName brokerName) { - this.brokerName = brokerName; - } - - protected ObjectName createBrokerName() throws MalformedObjectNameException { - return new ObjectName(getManagementContext().getJmxDomainName() + ":Type=Broker"); - } -} diff --git a/activemq-web-console/src/main/java/org/apache/activemq/web/RemoteJMXBrokerFacade.java b/activemq-web-console/src/main/java/org/apache/activemq/web/RemoteJMXBrokerFacade.java new file mode 100644 index 0000000000..52c4590e23 --- /dev/null +++ b/activemq-web-console/src/main/java/org/apache/activemq/web/RemoteJMXBrokerFacade.java @@ -0,0 +1,222 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.web; + +import org.apache.activemq.broker.jmx.BrokerViewMBean; +import org.apache.activemq.broker.jmx.ManagementContext; +import org.apache.activemq.broker.jmx.QueueViewMBean; +import org.apache.activemq.command.ActiveMQDestination; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.management.MBeanServerConnection; +import javax.management.MBeanServerInvocationHandler; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; + +/** + * A {@link BrokerFacade} which uses a JMX-Connection to communicate with a + * broker + * + * @version $Revision: 1.1 $ + */ +public class RemoteJMXBrokerFacade extends BrokerFacadeSupport { + private static final transient Log log = LogFactory.getLog(RemoteJMXBrokerFacade.class); + private String jmxUrl; + private String brokerName; + private JMXConnector connector; + + public void setBrokerName(String brokerName) { + this.brokerName = brokerName; + } + + public void setJmxUrl(String url) { + this.jmxUrl = url; + } + + /** + * Shutdown this facade aka close any open connection. + */ + public void shutdown() { + closeConnection(); + } + + public BrokerViewMBean getBrokerAdmin() throws Exception { + MBeanServerConnection connection = getConnection(); + + Set brokers = findBrokers(connection); + if (brokers.size() == 0) { + throw new IOException("No broker could be found in the JMX."); + } + ObjectName name = (ObjectName) brokers.iterator().next(); + BrokerViewMBean mbean = (BrokerViewMBean) MBeanServerInvocationHandler + .newProxyInstance(connection, name, BrokerViewMBean.class, true); + return mbean; + } + + protected MBeanServerConnection getConnection() throws IOException { + JMXConnector connector = this.connector; + if (isConnectionActive(connector)) { + return connector.getMBeanServerConnection(); + } + + synchronized (this) { + closeConnection(); + + log.debug("Creating a new JMX-Connection to the broker"); + this.connector = createConnection(); + return this.connector.getMBeanServerConnection(); + } + } + + protected boolean isConnectionActive(JMXConnector connector) { + if (connector == null) { + return false; + } + + try { + MBeanServerConnection connection = connector + .getMBeanServerConnection(); + int brokerCount = findBrokers(connection).size(); + return brokerCount > 0; + } + catch (Exception e) { + return false; + } + } + + protected JMXConnector createConnection() { + String[] urls = this.jmxUrl.split(","); + if (urls == null || urls.length == 0) { + urls = new String[]{this.jmxUrl}; + } + + Exception exception = null; + for (int i = 0; i < urls.length; i++) { + try { + JMXConnector connector = JMXConnectorFactory + .connect(new JMXServiceURL(urls[i])); + connector.connect(); + MBeanServerConnection connection = connector + .getMBeanServerConnection(); + + Set brokers = findBrokers(connection); + if (brokers.size() > 0) { + log + .info("Connected via JMX to the broker at " + + urls[i]); + return connector; + } + } + catch (Exception e) { + // Keep the exception for later + exception = e; + } + } + if (exception != null) { + if (exception instanceof RuntimeException) { + throw (RuntimeException) exception; + } + else { + throw new RuntimeException(exception); + } + } + throw new IllegalStateException( + "No broker is found at any of the urls " + this.jmxUrl); + } + + protected synchronized void closeConnection() { + if (connector != null) { + try { + log.debug("Closing a connection to a broker (" + + connector.getConnectionId() + ")"); + + connector.close(); + } + catch (IOException e) { + // Ignore the exception, since it most likly won't matter + // anymore + } + } + } + + /** + * Finds all ActiveMQ-Brokers registered on a certain JMX-Server or, if a + * JMX-BrokerName has been set, the broker with that name. + * + * @param connection not null + * @return Set with ObjectName-elements + * @throws IOException + * @throws MalformedObjectNameException + */ + protected Set findBrokers(MBeanServerConnection connection) + throws IOException, MalformedObjectNameException { + ObjectName name; + if (this.brokerName == null) { + name = new ObjectName("org.apache.activemq:Type=Broker,*"); + } + else { + name = new ObjectName("org.apache.activemq:BrokerName=" + + this.brokerName + ",Type=Broker"); + } + + Set brokers = connection.queryNames(name, null); + return brokers; + } + + public void purgeQueue(ActiveMQDestination destination) throws Exception { + QueueViewMBean queue = getQueue(destination.getPhysicalName()); + queue.purge(); + } + + public ManagementContext getManagementContext() { + throw new IllegalStateException("not supported"); + } + + protected Collection getManagedObjects(ObjectName[] names, Class type) { + MBeanServerConnection connection; + try { + connection = getConnection(); + } + catch (IOException e) { + throw new RuntimeException(e); + } + + List answer = new ArrayList(); + if (connection != null) { + for (int i = 0; i < names.length; i++) { + ObjectName name = names[i]; + Object value = MBeanServerInvocationHandler.newProxyInstance( + connection, name, type, true); + if (value != null) { + answer.add(value); + } + } + } + return answer; + } + +} diff --git a/activemq-web-console/src/main/java/org/apache/activemq/web/SessionPool.java b/activemq-web-console/src/main/java/org/apache/activemq/web/SessionPool.java index ec00bbad40..6527bcd3a2 100644 --- a/activemq-web-console/src/main/java/org/apache/activemq/web/SessionPool.java +++ b/activemq-web-console/src/main/java/org/apache/activemq/web/SessionPool.java @@ -16,13 +16,12 @@ */ package org.apache.activemq.web; -import org.apache.activemq.ActiveMQConnectionFactory; +import java.util.LinkedList; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.JMSException; import javax.jms.Session; -import java.util.LinkedList; /** * A simple pool of JMS Session objects intended for use by Queue browsers. @@ -31,58 +30,71 @@ import java.util.LinkedList; */ public class SessionPool { - private ConnectionFactory connectionFactory; - private Connection connection; - private LinkedList sessions = new LinkedList(); + private ConnectionFactory connectionFactory; + private Connection connection; + private LinkedList sessions = new LinkedList(); - public Connection getConnection() throws JMSException { - if (connection == null) { - connection = getConnectionFactory().createConnection(); - connection.start(); - } - return connection; - } + public Connection getConnection() throws JMSException { + if (checkConnection()) + return connection; - public void setConnection(Connection connection) { - this.connection = connection; - } + synchronized (this) { + connection = getConnectionFactory().createConnection(); + connection.start(); + return connection; + } + } - public ConnectionFactory getConnectionFactory() { - if (connectionFactory == null) { - // TODO support remote brokers too - connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); - } - return connectionFactory; - } + private boolean checkConnection() { + if (connection == null) + return false; - public void setConnectionFactory(ConnectionFactory connectionFactory) { - this.connectionFactory = connectionFactory; - } + try { + connection.getMetaData(); + return true; + } catch (JMSException e) { + return false; + } + } + public void setConnection(Connection connection) { + this.connection = connection; + } - public Session borrowSession() throws JMSException { - Session answer = null; - synchronized (sessions) { - if (sessions.isEmpty()) { - answer = createSession(); - } - else { - answer = (Session) sessions.removeLast(); - } - } - return answer; - } + public ConnectionFactory getConnectionFactory() { + if (connectionFactory == null) { + throw new IllegalStateException( + "No ConnectionFactory has been set for the session pool"); + } + return connectionFactory; + } - protected void returnSession(Session session) { - if (session != null) { - synchronized (sessions) { - sessions.add(session); - } - } - } + public void setConnectionFactory(ConnectionFactory connectionFactory) { + this.connectionFactory = connectionFactory; + } - protected Session createSession() throws JMSException { - return getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); - } + public Session borrowSession() throws JMSException { + Session answer = null; + synchronized (sessions) { + if (sessions.isEmpty()) { + answer = createSession(); + } else { + answer = (Session) sessions.removeLast(); + } + } + return answer; + } + + public void returnSession(Session session) { + if (session != null) { + synchronized (sessions) { + sessions.add(session); + } + } + } + + protected Session createSession() throws JMSException { + return getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); + } } diff --git a/activemq-web-console/src/main/java/org/apache/activemq/web/WebConsoleStarter.java b/activemq-web-console/src/main/java/org/apache/activemq/web/WebConsoleStarter.java new file mode 100644 index 0000000000..a9cc2d4699 --- /dev/null +++ b/activemq-web-console/src/main/java/org/apache/activemq/web/WebConsoleStarter.java @@ -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.activemq.web; + +import javax.jms.ConnectionFactory; +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; +import org.springframework.web.context.support.XmlWebApplicationContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Starts the WebConsole. + * + * @version $Revision: 1.1 $ + */ +public class WebConsoleStarter implements ServletContextListener { + private static final transient Log log = LogFactory.getLog(WebConsoleStarter.class); + + public void contextInitialized(ServletContextEvent event) { + log.debug("Initializing ActiveMQ WebConsole..."); + + ServletContext servletContext = event.getServletContext(); + WebApplicationContext context = createWebapplicationContext(servletContext); + + initializeWebClient(servletContext, context); + + log.info("ActiveMQ WebConsole initialized."); + } + + private WebApplicationContext createWebapplicationContext(ServletContext servletContext) { + String webconsoleType = System.getProperty("webconsole.type", "embedded"); + String configuration = "/WEB-INF/webconsole-" + webconsoleType + ".xml"; + + XmlWebApplicationContext context = new XmlWebApplicationContext(); + context.setServletContext(servletContext); + context.setConfigLocations(new String[] { configuration }); + context.refresh(); + context.start(); + + servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); + + return context; + } + + private void initializeWebClient(ServletContext servletContext, WebApplicationContext context) { + ConnectionFactory connectionFactory = (ConnectionFactory) context + .getBean("connectionFactory"); + servletContext.setAttribute(WebClient.connectionFactoryAttribute, + connectionFactory); + } + + public void contextDestroyed(ServletContextEvent event) { + XmlWebApplicationContext context = (XmlWebApplicationContext) WebApplicationContextUtils + .getWebApplicationContext(event.getServletContext()); + if (context != null) + { + context.stop(); + context.destroy(); + } + // do nothing, since the context is destoyed anyway + } + +} diff --git a/activemq-web-console/src/main/java/org/apache/activemq/web/controller/SendMessage.java b/activemq-web-console/src/main/java/org/apache/activemq/web/controller/SendMessage.java index 365d938f36..67863c9c19 100644 --- a/activemq-web-console/src/main/java/org/apache/activemq/web/controller/SendMessage.java +++ b/activemq-web-console/src/main/java/org/apache/activemq/web/controller/SendMessage.java @@ -78,8 +78,6 @@ public class SendMessage extends DestinationFacade implements Controller { } client.send(dest, message, JMSPersistent, JMSPriority, JMSTimeToLive); - - System.out.println("Sent message: " + message); } } diff --git a/activemq-web-console/src/main/webapp/WEB-INF/web.xml b/activemq-web-console/src/main/webapp/WEB-INF/web.xml index 68bf8d2528..dc96d1af9c 100755 --- a/activemq-web-console/src/main/webapp/WEB-INF/web.xml +++ b/activemq-web-console/src/main/webapp/WEB-INF/web.xml @@ -22,117 +22,141 @@ http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> - - Apache ActiveMQ Web Console - - ActiveMQ Console + + Apache ActiveMQ Web Console + + ActiveMQ Console - - - - - sitemesh - com.opensymphony.module.sitemesh.filter.PageFilter - + + + + + sitemesh + com.opensymphony.module.sitemesh.filter.PageFilter + - - sitemesh - /* - - - - - - - spring - org.apache.activemq.web.filter.ApplicationContextFilter - + + sitemesh + /* + - - spring - /* - + + + + + spring + org.apache.activemq.web.filter.ApplicationContextFilter + - - - - - - - AjaxServlet - org.apache.activemq.web.AjaxServlet - 1 - - - AjaxServlet - /ajax/* - + + spring + /* + - - SendServlet - org.apache.activemq.web.MessageServlet - 1 - - - SendServlet - /send/* - + + + - - - QueueBrowseServlet - org.apache.activemq.web.QueueBrowseServlet - - - QueueBrowseServlet - /queueBrowse/* - + + + AjaxServlet + org.apache.activemq.web.AjaxServlet + 1 + + + AjaxServlet + /ajax/* + - - - session - org.apache.activemq.web.SessionFilter - - - - session - /* - + + SendServlet + org.apache.activemq.web.MessageServlet + 1 + + + SendServlet + /send/* + - - - - - - org.springframework.web.context.ContextLoaderListener - + + + QueueBrowseServlet + org.apache.activemq.web.QueueBrowseServlet + + + QueueBrowseServlet + /queueBrowse/* + - - - - - dispatcher - org.springframework.web.servlet.DispatcherServlet - 2 - + + + session + org.apache.activemq.web.SessionFilter + - - dispatcher - *.action - + + spring-rq + org.springframework.web.filter.RequestContextFilter + - - index.html - index.jsp - + + session + /* + + + spring-rq + /* + - - - - - - *.jsp - /WEB-INF/jspf/headertags.jspf - - + + + + + + org.apache.activemq.web.WebConsoleStarter + + + + + + + + dispatcher + org.springframework.web.servlet.DispatcherServlet + 2 + + + + dispatcher + *.action + + + + index.html + index.jsp + + + + + + + + + + + + *.jsp + /WEB-INF/jspf/headertags.jspf + + diff --git a/activemq-web-console/src/main/webapp/WEB-INF/applicationContext.xml b/activemq-web-console/src/main/webapp/WEB-INF/webconsole-embedded.xml similarity index 88% rename from activemq-web-console/src/main/webapp/WEB-INF/applicationContext.xml rename to activemq-web-console/src/main/webapp/WEB-INF/webconsole-embedded.xml index f9a99616b4..2c22998822 100644 --- a/activemq-web-console/src/main/webapp/WEB-INF/applicationContext.xml +++ b/activemq-web-console/src/main/webapp/WEB-INF/webconsole-embedded.xml @@ -20,20 +20,23 @@ - - - - + + + - - + + + + + + diff --git a/activemq-web-console/src/main/webapp/WEB-INF/webconsole-invm.xml b/activemq-web-console/src/main/webapp/WEB-INF/webconsole-invm.xml new file mode 100644 index 0000000000..b81bd2c1e5 --- /dev/null +++ b/activemq-web-console/src/main/webapp/WEB-INF/webconsole-invm.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/activemq-web-console/src/main/webapp/WEB-INF/webconsole-jndi.xml b/activemq-web-console/src/main/webapp/WEB-INF/webconsole-jndi.xml new file mode 100644 index 0000000000..5e328ab7ba --- /dev/null +++ b/activemq-web-console/src/main/webapp/WEB-INF/webconsole-jndi.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/activemq-web-console/src/main/webapp/WEB-INF/webconsole-properties.xml b/activemq-web-console/src/main/webapp/WEB-INF/webconsole-properties.xml new file mode 100644 index 0000000000..ad1f48231c --- /dev/null +++ b/activemq-web-console/src/main/webapp/WEB-INF/webconsole-properties.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/activemq-web/src/main/java/org/apache/activemq/web/QueueBrowseServlet.java b/activemq-web/src/main/java/org/apache/activemq/web/QueueBrowseServlet.java index 30886d6b32..65f81402e0 100644 --- a/activemq-web/src/main/java/org/apache/activemq/web/QueueBrowseServlet.java +++ b/activemq-web/src/main/java/org/apache/activemq/web/QueueBrowseServlet.java @@ -16,10 +16,11 @@ */ package org.apache.activemq.web; -import org.apache.activemq.ActiveMQConnectionFactory; -import org.apache.activemq.util.FactoryFinder; -import org.apache.activemq.util.IntrospectionSupport; -import org.apache.activemq.web.view.MessageRenderer; +import java.io.IOException; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; import javax.jms.Connection; import javax.jms.ConnectionFactory; @@ -32,11 +33,9 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map; +import org.apache.activemq.util.FactoryFinder; +import org.apache.activemq.util.IntrospectionSupport; +import org.apache.activemq.web.view.MessageRenderer; /** * Renders the contents of a queue using some kind of view. The URI is assumed @@ -49,6 +48,8 @@ import java.util.Map; * * @version $Revision: $ */ +//TODO Why do we implement our own session pool? +//TODO This doesn't work, since nobody will be setting the connection factory (because nobody is able to). Just use the WebClient? public class QueueBrowseServlet extends HttpServlet { private static FactoryFinder factoryFinder = new FactoryFinder("META-INF/services/org/apache/activemq/web/view/"); @@ -71,8 +72,7 @@ public class QueueBrowseServlet extends HttpServlet { public ConnectionFactory getConnectionFactory() { if (connectionFactory == null) { - // TODO support remote brokers too - connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); + throw new IllegalStateException("missing ConnectionFactory in QueueBrowserServlet"); } return connectionFactory; } diff --git a/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java b/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java index da51cc71dd..8ed940cfba 100644 --- a/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java +++ b/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java @@ -28,6 +28,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.DeliveryMode; import javax.jms.Destination; @@ -44,9 +45,7 @@ import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionBindingListener; import javax.servlet.http.HttpSessionEvent; -import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; -import org.apache.activemq.ActiveMQSession; import org.apache.activemq.MessageAvailableConsumer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -75,8 +74,8 @@ public class WebClient implements HttpSessionActivationListener, HttpSessionBind private static transient ConnectionFactory factory; private transient Map consumers = new HashMap(); - private transient ActiveMQConnection connection; - private transient ActiveMQSession session; + private transient Connection connection; + private transient Session session; private transient MessageProducer producer; private int deliveryMode = DeliveryMode.NON_PERSISTENT; @@ -221,15 +220,15 @@ public class WebClient implements HttpSessionActivationListener, HttpSessionBind return session; } - public ActiveMQConnection getConnection() throws JMSException { + public Connection getConnection() throws JMSException { if (connection == null) { - connection = (ActiveMQConnection) factory.createConnection(); + connection = factory.createConnection(); connection.start(); } return connection; } - public static synchronized void initConnectionFactory(ServletContext servletContext) { + protected static synchronized void initConnectionFactory(ServletContext servletContext) { if (factory == null) factory = (ConnectionFactory) servletContext.getAttribute(connectionFactoryAttribute); if (factory == null) { @@ -239,7 +238,7 @@ public class WebClient implements HttpSessionActivationListener, HttpSessionBind log.debug("Value of: " + brokerUrlInitParam + " is: " + brokerURL); if (brokerURL == null) { - brokerURL = "vm://localhost"; + throw new IllegalStateException("missing brokerURL (specified via "+brokerUrlInitParam+" init-Param"); } ActiveMQConnectionFactory amqfactory = new ActiveMQConnectionFactory(brokerURL); @@ -302,8 +301,8 @@ public class WebClient implements HttpSessionActivationListener, HttpSessionBind return new ArrayList(consumers.values()); } - protected ActiveMQSession createSession() throws JMSException { - return (ActiveMQSession) getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); + protected Session createSession() throws JMSException { + return getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); } public Semaphore getSemaphore() { diff --git a/assembly/pom.xml b/assembly/pom.xml index 022c109e5f..eaf92cccc3 100755 --- a/assembly/pom.xml +++ b/assembly/pom.xml @@ -208,6 +208,10 @@ + + org.slf4j + slf4j-api + org.slf4j slf4j-jcl diff --git a/assembly/src/main/descriptors/unix-bin.xml b/assembly/src/main/descriptors/unix-bin.xml index 6a7fe0c7a3..676cea1556 100644 --- a/assembly/src/main/descriptors/unix-bin.xml +++ b/assembly/src/main/descriptors/unix-bin.xml @@ -105,7 +105,7 @@ /webapps/admin **/activemq.xml - **/applicationContext.xml + **/webconsole-embedded.xml @@ -122,7 +122,7 @@ /webapps/demo **/activemq.xml - **/applicationContext.xml + **/webconsole-embedded.xml @@ -188,6 +188,7 @@ org.mortbay.jetty:jetty-util org.mortbay.jetty:jetty-xbean org.mortbay.jetty:servlet-api-2.5 + org.slf4j:slf4j-api org.slf4j:slf4j-jcl diff --git a/assembly/src/main/descriptors/windows-bin.xml b/assembly/src/main/descriptors/windows-bin.xml index 54d2bb81e7..a2cf10c83e 100644 --- a/assembly/src/main/descriptors/windows-bin.xml +++ b/assembly/src/main/descriptors/windows-bin.xml @@ -109,7 +109,7 @@ /webapps/admin **/activemq.xml - **/applicationContext.xml + **/webconsole-embedded.xml @@ -127,7 +127,7 @@ /webapps/demo **/activemq.xml - **/applicationContext.xml + **/webconsole-embedded.xml @@ -196,6 +196,7 @@ org.mortbay.jetty:jetty-util org.mortbay.jetty:jetty-xbean org.mortbay.jetty:servlet-api-2.5 + org.slf4j:slf4j-api org.slf4j:slf4j-jcl diff --git a/assembly/src/release/webapps/admin/WEB-INF/applicationContext.xml b/assembly/src/release/webapps/admin/WEB-INF/webconsole-embedded.xml similarity index 86% rename from assembly/src/release/webapps/admin/WEB-INF/applicationContext.xml rename to assembly/src/release/webapps/admin/WEB-INF/webconsole-embedded.xml index 9b0c51fe41..8746db7e28 100644 --- a/assembly/src/release/webapps/admin/WEB-INF/applicationContext.xml +++ b/assembly/src/release/webapps/admin/WEB-INF/webconsole-embedded.xml @@ -20,12 +20,18 @@ - - - + + + + + + + + + diff --git a/pom.xml b/pom.xml index 414c017cf5..da76b3886f 100755 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,8 @@ 1.1.2 1.3 0.8 + 1.4.0 + 1.1.1-dev 2.6.0 2.0.0-beta1 @@ -794,10 +796,15 @@ ${jxta-version} + + org.slf4j + slf4j-api + ${slf4j-version} + org.slf4j slf4j-jcl - 1.0-rc5 + ${slf4j-version} opensymphony