mirror of https://github.com/apache/activemq.git
fix up assembly xml configuration validtion tests - have them run by default. Pull out osgi isms to separate hook and add shutdown hook when jetty.xml is included so that it is shutdown on broker stop. Fix problems with the xml eposed by the tests
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1390204 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ec72fa6d51
commit
b469638171
|
@ -75,32 +75,27 @@ public class CommandAgent implements Service, ExceptionListener {
|
|||
*/
|
||||
@PreDestroy
|
||||
public void stop() throws Exception {
|
||||
ServiceStopper stopper = new ServiceStopper();
|
||||
if (consumer != null) {
|
||||
try {
|
||||
consumer.close();
|
||||
consumer = null;
|
||||
} catch (JMSException e) {
|
||||
stopper.onException(this, e);
|
||||
} catch (JMSException ignored) {
|
||||
}
|
||||
}
|
||||
if (session != null) {
|
||||
try {
|
||||
session.close();
|
||||
session = null;
|
||||
} catch (JMSException e) {
|
||||
stopper.onException(this, e);
|
||||
} catch (JMSException ignored) {
|
||||
}
|
||||
}
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
connection = null;
|
||||
} catch (JMSException e) {
|
||||
stopper.onException(this, e);
|
||||
} catch (JMSException ignored) {
|
||||
}
|
||||
}
|
||||
stopper.throwFirstException();
|
||||
}
|
||||
|
||||
// Properties
|
||||
|
|
|
@ -101,7 +101,7 @@
|
|||
-->
|
||||
|
||||
<shutdownHooks>
|
||||
<bean xmlns="http://www.springframework.org/schema/beans" id="hook" class="org.apache.activemq.hooks.SpringContextHook" />
|
||||
<bean xmlns="http://www.springframework.org/schema/beans" id="hook" class="org.apache.activemq.hooks.SpringOsgiContextHook" />
|
||||
</shutdownHooks>
|
||||
|
||||
<!-- The transport connectors ActiveMQ will listen to -->
|
||||
|
|
|
@ -16,32 +16,19 @@
|
|||
*/
|
||||
package org.apache.activemq.hooks;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.osgi.framework.BundleException;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
|
||||
|
||||
public class SpringContextHook implements Runnable, ApplicationContextAware {
|
||||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(SpringContextHook.class);
|
||||
ApplicationContext applicationContext;
|
||||
|
||||
public void run() {
|
||||
if (applicationContext instanceof ConfigurableApplicationContext) {
|
||||
((ConfigurableApplicationContext) applicationContext).close();
|
||||
}
|
||||
if (applicationContext instanceof OsgiBundleXmlApplicationContext){
|
||||
try {
|
||||
((OsgiBundleXmlApplicationContext)applicationContext).getBundle().stop();
|
||||
} catch (BundleException e) {
|
||||
LOG.info("Error stopping OSGi bundle " + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* 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.hooks;
|
||||
|
||||
import org.osgi.framework.BundleException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
|
||||
|
||||
public class SpringOsgiContextHook implements Runnable, ApplicationContextAware {
|
||||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(SpringOsgiContextHook.class);
|
||||
ApplicationContext applicationContext;
|
||||
|
||||
public void run() {
|
||||
if (applicationContext instanceof ConfigurableApplicationContext) {
|
||||
((ConfigurableApplicationContext) applicationContext).close();
|
||||
}
|
||||
if (applicationContext instanceof OsgiBundleXmlApplicationContext){
|
||||
try {
|
||||
((OsgiBundleXmlApplicationContext)applicationContext).getBundle().stop();
|
||||
} catch (BundleException e) {
|
||||
LOG.info("Error stopping OSGi bundle " + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
}
|
|
@ -125,10 +125,6 @@
|
|||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-spring</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-jetty</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-jms</artifactId>
|
||||
|
@ -293,6 +289,12 @@
|
|||
<artifactId>jasypt</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jasypt</groupId>
|
||||
<artifactId>jasypt-spring3</artifactId>
|
||||
<version>${jasypt-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
@ -341,6 +343,18 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>validate-config</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
|
@ -352,6 +366,9 @@
|
|||
</goals>
|
||||
<configuration>
|
||||
<forkMode>pertest</forkMode>
|
||||
<environmentVariables>
|
||||
<ACTIVEMQ_ENCRYPTION_PASSWORD>activemq</ACTIVEMQ_ENCRYPTION_PASSWORD>
|
||||
</environmentVariables>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
|
|
|
@ -127,7 +127,6 @@
|
|||
<includes>
|
||||
<include>org.apache.camel:camel-core</include>
|
||||
<include>org.apache.camel:camel-spring</include>
|
||||
<include>org.apache.camel:camel-jetty</include>
|
||||
<include>org.apache.camel:camel-jms</include>
|
||||
<include>org.apache.activemq:activemq-camel</include>
|
||||
</includes>
|
||||
|
@ -171,6 +170,7 @@
|
|||
<include>org.apache.velocity:velocity</include>
|
||||
<include>org.apache.servicemix.bundles:org.apache.servicemix.bundles.josql</include>
|
||||
<include>org.jasypt:jasypt</include>
|
||||
<include>org.jasypt:jasypt-spring3</include>
|
||||
<include>javax.jmdns:jmdns</include>
|
||||
</includes>
|
||||
</dependencySet>
|
||||
|
|
|
@ -145,6 +145,11 @@
|
|||
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireformat.maxFrameSize=104857600"/>
|
||||
</transportConnectors>
|
||||
|
||||
<!-- destroy the spring context on shutdown to stop jetty -->
|
||||
<shutdownHooks>
|
||||
<bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
|
||||
</shutdownHooks>
|
||||
|
||||
</broker>
|
||||
|
||||
<!--
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
- Change the brokerName attribute to something unique
|
||||
-->
|
||||
|
||||
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="amq-broker" useJmx="true" destroyApplicationContextOnStop="true">
|
||||
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="amq-broker" useJmx="true">
|
||||
|
||||
<!--
|
||||
Examples of destination-specific policies using destination
|
||||
|
@ -205,6 +205,11 @@
|
|||
<transportConnector name="xmpp" uri="xmpp://localhost:61222"/>
|
||||
</transportConnectors>
|
||||
|
||||
<!-- destroy the spring context on shutdown to stop jetty -->
|
||||
<shutdownHooks>
|
||||
<bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
|
||||
</shutdownHooks>
|
||||
|
||||
</broker>
|
||||
|
||||
<!--
|
||||
|
|
|
@ -70,9 +70,9 @@
|
|||
<property xmlns="http://www.springframework.org/schema/beans" name="environment">
|
||||
<map xmlns="http://www.springframework.org/schema/beans">
|
||||
<entry xmlns="http://www.springframework.org/schema/beans" key="jmx.remote.x.password.file"
|
||||
value="conf/jmx.password"/>
|
||||
value="${activemq.conf}/jmx.password"/>
|
||||
<entry xmlns="http://www.springframework.org/schema/beans" key="jmx.remote.x.access.file"
|
||||
value="conf/jmx.access"/>
|
||||
value="${activemq.conf}/jmx.access"/>
|
||||
</map>
|
||||
</property>
|
||||
</managementContext>
|
||||
|
@ -117,6 +117,11 @@
|
|||
<transportConnector name="default" uri="tcp://0.0.0.0:61616"/>
|
||||
</transportConnectors>
|
||||
|
||||
<!-- destroy the spring context on shutdown to stop jetty -->
|
||||
<shutdownHooks>
|
||||
<bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
|
||||
</shutdownHooks>
|
||||
|
||||
</broker>
|
||||
|
||||
<!--
|
||||
|
|
|
@ -28,11 +28,13 @@ import javax.jms.JMSException;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerContext;
|
||||
import org.apache.activemq.broker.BrokerFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.TransportConnection;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
import org.apache.activemq.transport.stomp.StompConnection;
|
||||
import org.apache.activemq.util.URISupport;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -68,7 +70,7 @@ public class BrokerXmlConfigStartTest extends TestCase {
|
|||
// alive, now try connect to connect
|
||||
try {
|
||||
for (TransportConnector transport : broker.getTransportConnectors()) {
|
||||
final URI UriToConnectTo = transport.getConnectUri();
|
||||
final URI UriToConnectTo = URISupport.removeQuery(transport.getConnectUri());
|
||||
|
||||
if (UriToConnectTo.getScheme().startsWith("stomp")) {
|
||||
LOG.info("validating alive with connection to: " + UriToConnectTo);
|
||||
|
@ -98,6 +100,9 @@ public class BrokerXmlConfigStartTest extends TestCase {
|
|||
|
||||
public void setUp() throws Exception {
|
||||
System.setProperty("activemq.base", "target");
|
||||
System.setProperty("activemq.home", "target"); // not a valid home but ok for xml validation
|
||||
System.setProperty("activemq.data", "target");
|
||||
System.setProperty("activemq.conf", "target/conf");
|
||||
secProps = new Properties();
|
||||
secProps.load(new FileInputStream(new File("target/conf/credentials.properties")));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue