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 index e7a2806243..0d93574b63 100644 --- 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 @@ -16,25 +16,17 @@ */ package org.apache.activemq.web; -import javax.imageio.spi.ServiceRegistry; -import javax.jms.ConnectionFactory; -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.Constants; import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceRegistration; -import org.osgi.service.cm.ManagedService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import org.springframework.web.context.support.XmlWebApplicationContext; -import java.util.Dictionary; -import java.util.Hashtable; +import javax.jms.ConnectionFactory; +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; /** * Starts the WebConsole. @@ -61,13 +53,18 @@ public class WebConsoleStarter implements ServletContextListener { String webconsoleType = System.getProperty("webconsole.type", "embedded"); // detect osgi - if (FrameworkUtil.getBundle(getClass()) != null) { - webconsoleType = "osgi"; + try { + if (OsgiUtil.isOsgi()) { + webconsoleType = "osgi"; + } + } catch (NoClassDefFoundError ignore) { } String configuration = "/WEB-INF/webconsole-" + webconsoleType + ".xml"; + LOG.info("Web console type: " + webconsoleType); + XmlWebApplicationContext context = new XmlWebApplicationContext(); context.setServletContext(servletContext); context.setConfigLocations(new String[] { @@ -95,4 +92,10 @@ public class WebConsoleStarter implements ServletContextListener { // do nothing, since the context is destroyed anyway } + static class OsgiUtil { + static boolean isOsgi() { + return (FrameworkUtil.getBundle(WebConsoleStarter.class) != null); + } + } + } diff --git a/activemq-web-console/src/main/java/org/apache/activemq/web/config/OsgiConfiguration.java b/activemq-web-console/src/main/java/org/apache/activemq/web/config/OsgiConfiguration.java index 5a5dbd6f36..235442dae0 100644 --- a/activemq-web-console/src/main/java/org/apache/activemq/web/config/OsgiConfiguration.java +++ b/activemq-web-console/src/main/java/org/apache/activemq/web/config/OsgiConfiguration.java @@ -22,6 +22,7 @@ import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceRegistration; import org.osgi.service.cm.ConfigurationException; import org.osgi.service.cm.ManagedService; +import sun.util.LocaleServiceProviderPool; import javax.jms.ConnectionFactory; import javax.management.remote.JMXServiceURL; @@ -73,14 +74,16 @@ public class OsgiConfiguration extends AbstractConfiguration implements ManagedS @Override public void updated(Dictionary dictionary) throws ConfigurationException { - jmxUrl = dictionary != null ? (String)dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMX_URL) : null; - if (jmxUrl == null) { - throw new IllegalArgumentException("A JMS-url must be specified (system property " + SystemPropertiesConfiguration.PROPERTY_JMX_URL); + if (dictionary != null) { + jmxUrl = (String) dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMX_URL); + if (jmxUrl == null) { + throw new IllegalArgumentException("A JMS-url must be specified (system property " + SystemPropertiesConfiguration.PROPERTY_JMX_URL); + } + jmxUser = (String) dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMX_USER); + jmxPassword = (String) dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMX_PASSWORD); + jmsUrl = (String) dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMS_URL); + jmsUser = (String) dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMS_USER); + jmsPassword = (String) dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMS_PASSWORD); } - jmxUser = (String)dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMX_USER); - jmxPassword = (String)dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMX_PASSWORD); - jmxUrl = (String)dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMS_URL); - jmsUser = (String)dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMS_USER); - jmsPassword = (String)dictionary.get(SystemPropertiesConfiguration.PROPERTY_JMS_PASSWORD); } }