https://issues.apache.org/jira/browse/AMQ-4034 - osgi web console, laying down foundations for config admin configuration

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1441064 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2013-01-31 16:59:49 +00:00
parent dc3eb911fa
commit 0d27c49bbf
6 changed files with 150 additions and 6 deletions

View File

@ -66,7 +66,6 @@
<bundle>mvn:org.apache.activemq/activemq-karaf/${project.version}</bundle>
<bundle dependency="true">mvn:org.scala-lang/scala-library/${scala-version}</bundle>
<feature version="${project.version}">activemq-http</feature>
<feature version="${project.version}">activemq-web-console</feature>
</feature>
<feature name="activemq-http" version="${project.version}" resolver="(obr)" start-level="50">
@ -90,6 +89,7 @@
<feature name="activemq-web-console" version="${project.version}" resolver="(obr)" start-level="50">
<feature>war</feature>
<feature>eventadmin</feature>
<bundle>mvn:org.apache.activemq/activemq-web-console/${project.version}/war</bundle>
</feature>

View File

@ -141,6 +141,8 @@
javax.management,
javax.management.openmbean,
javax.net,
org.osgi.framework,
org.osgi.service.cm,
org.apache.commons.logging;version="[1.1,2)";resolution:=optional,
org.slf4j;version="[1.6,2)";resolution:=optional,
org.slf4j.spi;version="[1.6,2)";resolution:=optional,
@ -270,11 +272,19 @@
<scope>test</scope>
</dependency>
<!-- Derby SQL DB used for testing JDBC message store -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>4.2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -16,17 +16,26 @@
*/
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;
/**
* Starts the WebConsole.
*
@ -48,7 +57,15 @@ public class WebConsoleStarter implements ServletContextListener {
}
private WebApplicationContext createWebapplicationContext(ServletContext servletContext) {
String webconsoleType = System.getProperty("webconsole.type", "embedded");
// detect osgi
if (FrameworkUtil.getBundle(getClass()) != null) {
webconsoleType = "osgi";
}
String configuration = "/WEB-INF/webconsole-" + webconsoleType + ".xml";
XmlWebApplicationContext context = new XmlWebApplicationContext();

View File

@ -0,0 +1,78 @@
/**
* 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.config;
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.ConfigurationException;
import org.osgi.service.cm.ManagedService;
import javax.jms.ConnectionFactory;
import javax.management.remote.JMXServiceURL;
import java.util.Collection;
import java.util.Dictionary;
import java.util.Hashtable;
public class OsgiConfiguration extends AbstractConfiguration implements ManagedService {
private ServiceRegistration service;
private String jmxUrl = "service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root";
private String jmxUser = "karaf";
private String jmxPassword = "karaf";
private String jmsUrl = "tcp://localhost:61616";
private String jmsUser = "karaf";
private String jmsPassword = "karaf";
public OsgiConfiguration() {
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
Dictionary properties = new Hashtable();
properties.put(Constants.SERVICE_PID, "org.apache.activemq.server");
service = context.registerService(ManagedService.class.getName(),
this, properties);
}
@Override
public String getJmxPassword() {
return jmxPassword;
}
@Override
public Collection<JMXServiceURL> getJmxUrls() {
return makeJmxUrls(jmxUrl);
}
@Override
public String getJmxUser() {
return jmxUser;
}
@Override
public ConnectionFactory getConnectionFactory() {
return makeConnectionFactory(jmsUrl, jmsUser, jmsPassword);
}
@Override
public void updated(Dictionary dictionary) throws ConfigurationException {
//TODO update properties
}
}

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
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.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<import resource="webconsole-query.xml"/>
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
<bean id="sessionPool" class="org.apache.activemq.web.SessionPool">
<property name="connectionFactory" ref="connectionFactory"/>
</bean>
<bean id="configuration" class="org.apache.activemq.web.config.OsgiConfiguration"/>
<bean id="brokerQuery" class="org.apache.activemq.web.RemoteJMXBrokerFacade" autowire="constructor" destroy-method="shutdown">
<property name="configuration" ref="configuration"/>
<property name="brokerName"><null/></property>
</bean>
<bean id="connectionFactory" factory-bean="configuration" factory-method="getConnectionFactory"/>
</beans>

View File

@ -73,7 +73,7 @@ public class RemoteJMXBrokerFacade extends BrokerFacadeSupport {
public void shutdown() {
closeConnection();
}
private ObjectName getBrokerObjectName(MBeanServerConnection connection)
throws IOException, MalformedObjectNameException {
Set<ObjectName> brokers = findBrokers(connection);
@ -197,7 +197,7 @@ public class RemoteJMXBrokerFacade extends BrokerFacadeSupport {
throws IOException, MalformedObjectNameException {
ObjectName name;
if (this.brokerName == null) {
name = new ObjectName("org.apache.activemq:type=Broker,*");
name = new ObjectName("org.apache.activemq:type=Broker,brokerName=*");
} else {
name = new ObjectName("org.apache.activemq:brokerName="
+ this.brokerName + ",Type=broker");