You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by de...@apache.org on 2009/07/07 14:05:56 UTC

svn commit: r791804 - in /activemq/sandbox/activemq-flow: activemq-all/src/test/java/org/apache/activemq/jaxb/ activemq-all/src/test/resources/ activemq-broker/ activemq-broker/src/main/java/org/apache/activemq/apollo/jaxb/ activemq-broker/src/test/jav...

Author: dejanb
Date: Tue Jul  7 12:05:56 2009
New Revision: 791804

URL: http://svn.apache.org/viewvc?rev=791804&view=rev
Log:
adding support for embedding system properties into xml config

Added:
    activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/jaxb/PropertiesReader.java
Modified:
    activemq/sandbox/activemq-flow/activemq-all/src/test/java/org/apache/activemq/jaxb/JAXBComplexConfigTest.java
    activemq/sandbox/activemq-flow/activemq-all/src/test/resources/activemq.xml
    activemq/sandbox/activemq-flow/activemq-broker/pom.xml
    activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/jaxb/JAXBBrokerFactory.java
    activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/apollo/jaxb/JAXBConfigTest.java

Modified: activemq/sandbox/activemq-flow/activemq-all/src/test/java/org/apache/activemq/jaxb/JAXBComplexConfigTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-all/src/test/java/org/apache/activemq/jaxb/JAXBComplexConfigTest.java?rev=791804&r1=791803&r2=791804&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-all/src/test/java/org/apache/activemq/jaxb/JAXBComplexConfigTest.java (original)
+++ activemq/sandbox/activemq-flow/activemq-all/src/test/java/org/apache/activemq/jaxb/JAXBComplexConfigTest.java Tue Jul  7 12:05:56 2009
@@ -50,6 +50,7 @@
 		assertNotNull(broker);
 		assertEquals("tcp://localhost:61616?wireFormat=openwire", broker.getTransportServers().get(0).getConnectURI().toString());
 		KahaDBStore store = (KahaDBStore)broker.getDefaultVirtualHost().getDatabase().getStore();
+		assertEquals(System.getProperty("user.dir") + "/target/" + System.getProperty("user.name") + "/${x}/activemq-data", store.getDirectory().getPath());
 	}
 
     protected Broker createBroker() throws Exception {

Modified: activemq/sandbox/activemq-flow/activemq-all/src/test/resources/activemq.xml
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-all/src/test/resources/activemq.xml?rev=791804&r1=791803&r2=791804&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-all/src/test/resources/activemq.xml (original)
+++ activemq/sandbox/activemq-flow/activemq-all/src/test/resources/activemq.xml Tue Jul  7 12:05:56 2009
@@ -25,7 +25,7 @@
     <host-name>localhost</host-name>
     <host-name>test.localhost</host-name>
     
-    <kahadb-store/>
+    <kahadb-store directory="${user.dir}/target/${user.name}/${x}/activemq-data"/>
   </virtual-host>
 
 </broker>
\ No newline at end of file

Modified: activemq/sandbox/activemq-flow/activemq-broker/pom.xml
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/pom.xml?rev=791804&r1=791803&r2=791804&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/pom.xml (original)
+++ activemq/sandbox/activemq-flow/activemq-broker/pom.xml Tue Jul  7 12:05:56 2009
@@ -109,6 +109,11 @@
       <scope>test</scope>
     </dependency>
 
+   <dependency>
+    <groupId>org.codehaus.woodstox</groupId>
+    <artifactId>wstx-asl</artifactId>
+    <version>4.0.0</version>
+   </dependency>
   </dependencies>
 
   <build>
@@ -263,7 +268,7 @@
         </dependency>
       </dependencies>
     </profile>
-    <profile>
+   <profile>
       <id>default-tools.jar</id>
       <activation>
         <jdk>1.5</jdk>

Modified: activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/jaxb/JAXBBrokerFactory.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/jaxb/JAXBBrokerFactory.java?rev=791804&r1=791803&r2=791804&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/jaxb/JAXBBrokerFactory.java (original)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/jaxb/JAXBBrokerFactory.java Tue Jul  7 12:05:56 2009
@@ -23,6 +23,8 @@
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.UnmarshalException;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
 
 import org.apache.activemq.apollo.broker.Broker;
 import org.apache.activemq.apollo.broker.BrokerFactory;
@@ -47,8 +49,11 @@
 		if (configURL == null) {
 			throw new IOException("Cannot create broker from non-existent URI: " + brokerURI);
 		}
+		XMLInputFactory factory = XMLInputFactory.newInstance();
+		XMLStreamReader reader = factory.createXMLStreamReader(configURL.openStream());
+		XMLStreamReader properties = new PropertiesReader(reader);
 		try {
-			BrokerXml xml = (BrokerXml) unmarshaller.unmarshal(configURL);
+			BrokerXml xml = (BrokerXml) unmarshaller.unmarshal(properties);
 			return xml.createMessageBroker();
 		} catch (UnmarshalException e) {
 			throw new IOException("Cannot create broker from URI: " + brokerURI + ", reason: " + e.getCause());

Added: activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/jaxb/PropertiesReader.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/jaxb/PropertiesReader.java?rev=791804&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/jaxb/PropertiesReader.java (added)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/jaxb/PropertiesReader.java Tue Jul  7 12:05:56 2009
@@ -0,0 +1,72 @@
+/**
+ * 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.apollo.jaxb;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.util.StreamReaderDelegate;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * 
+ * Changes ${system.property} with System.getProperty("system.property") in attribute values
+ *
+ */
+public class PropertiesReader extends StreamReaderDelegate {
+	
+	Log LOG = LogFactory.getLog(PropertiesReader.class);
+	
+	Pattern pattern = Pattern.compile("\\$\\{([a-zA-Z0-9\\.]*)\\}");
+	
+	public PropertiesReader(XMLStreamReader parent) {
+		super(parent);
+	}
+
+	public String getAttributeValue(int index) {
+		String value = super.getAttributeValue(index);
+		String replaced = replaceSystemProperties(value);
+		return replaced;
+	}
+	
+	
+	public String replaceSystemProperties(String str) {
+		int start = 0;
+		while (true) {
+			Matcher matcher = pattern.matcher(str);
+			if (!matcher.find(start)) {
+				break;
+			}
+			String property = System.getProperty(matcher.group(1));
+			if (property != null) {
+				str = matcher.replaceFirst(property);
+			} else {
+				if (LOG.isDebugEnabled()) {
+					LOG.debug("System property " + matcher.group(1) + " not found");
+				}
+				start = matcher.end();
+			}
+		}
+		return str;
+	}
+
+	
+	
+}

Modified: activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/apollo/jaxb/JAXBConfigTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/apollo/jaxb/JAXBConfigTest.java?rev=791804&r1=791803&r2=791804&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/apollo/jaxb/JAXBConfigTest.java (original)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/apollo/jaxb/JAXBConfigTest.java Tue Jul  7 12:05:56 2009
@@ -21,6 +21,8 @@
 import java.net.URI;
 import java.util.ArrayList;
 
+import junit.framework.TestCase;
+
 import org.apache.activemq.apollo.broker.Broker;
 import org.apache.activemq.apollo.broker.BrokerFactory;
 import org.apache.activemq.broker.store.memory.MemoryStore;
@@ -30,7 +32,7 @@
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-public class JAXBConfigTest {
+public class JAXBConfigTest extends TestCase {
 
     private static final Log LOG = LogFactory.getLog(JAXBConfigTest.class);