You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2013/08/28 22:32:20 UTC

svn commit: r1518373 - in /activemq/trunk/activemq-runtime-config/src: main/java/org/apache/activemq/plugin/ test/java/org/apache/activemq/ test/resources/org/apache/activemq/

Author: gtully
Date: Wed Aug 28 20:32:20 2013
New Revision: 1518373

URL: http://svn.apache.org/r1518373
Log:
https://issues.apache.org/jira/browse/AMQ-4682 - allow jaxb to validate with spring bean references - still need to pull schema from the classpath which needs a fix

Added:
    activemq/trunk/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java   (with props)
    activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-bean.xml   (with props)
Modified:
    activemq/trunk/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java

Modified: activemq/trunk/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java?rev=1518373&r1=1518372&r2=1518373&view=diff
==============================================================================
--- activemq/trunk/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java (original)
+++ activemq/trunk/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java Wed Aug 28 20:32:20 2013
@@ -37,6 +37,8 @@ import javax.xml.bind.Unmarshaller;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
 import org.apache.activemq.broker.Broker;
@@ -604,9 +606,18 @@ public class RuntimeConfigurationBroker 
 
     private Schema getSchema() throws SAXException {
         if (schema == null) {
+            // need to pull the spring schemas from the classpath and find reelvant
+            // constants for the system id etc something like ...
+            //PluggableSchemaResolver resolver =
+            //        new PluggableSchemaResolver(getClass().getClassLoader());
+            //InputSource springBeans = resolver.resolveEntity("http://www.springframework.org/schema/beans",
+            //                                                "http://www.springframework.org/schema/beans/spring-beans-2.0.xsd");
+            //LOG.trace("Beans schema:" + springBeans);
             SchemaFactory schemaFactory = SchemaFactory.newInstance(
                     XMLConstants.W3C_XML_SCHEMA_NS_URI);
-            schema = schemaFactory.newSchema(getClass().getResource("/activemq.xsd"));
+            schema = schemaFactory.newSchema(
+                    new Source[]{new StreamSource(getClass().getResource("/activemq.xsd").toExternalForm()),
+                            new StreamSource("http://www.springframework.org/schema/beans/spring-beans-2.0.xsd")});
         }
         return schema;
     }

Added: activemq/trunk/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java?rev=1518373&view=auto
==============================================================================
--- activemq/trunk/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java (added)
+++ activemq/trunk/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java Wed Aug 28 20:32:20 2013
@@ -0,0 +1,68 @@
+/**
+ * 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;
+
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import javax.management.ObjectName;
+import org.apache.activemq.plugin.RuntimeConfigurationBroker;
+import org.apache.activemq.plugin.jmx.RuntimeConfigurationViewMBean;
+import org.apache.activemq.util.IntrospectionSupport;
+import org.junit.Test;
+
+
+import static org.junit.Assert.*;
+
+public class SpringBeanTest extends RuntimeConfigTestSupport {
+
+    @Test
+    public void testUpdateNow() throws Exception {
+        final String brokerConfig =  "SpromgBeanTest-broker";
+        applyNewConfig(brokerConfig, "emptyUpdatableConfig1000-spring-bean");
+        startBroker(brokerConfig);
+        assertTrue("broker alive", brokerService.isStarted());
+
+        // apply via jmx
+        ObjectName objectName =
+                new ObjectName(brokerService.getBrokerObjectName().toString() +
+                        RuntimeConfigurationBroker.objectNamePropsAppendage);
+        RuntimeConfigurationViewMBean runtimeConfigurationView =
+                (RuntimeConfigurationViewMBean) brokerService.getManagementContext().newProxyInstance(objectName,
+                        RuntimeConfigurationViewMBean.class, false);
+
+        String propOfInterest = "modified";
+        HashMap<String, String> props = new HashMap<String, String>();
+        IntrospectionSupport.getProperties(runtimeConfigurationView, props, null);
+        LOG.info("mbean attributes before: " + props);
+
+        assertNotEquals("unknown", props.get(propOfInterest));
+
+        String result = runtimeConfigurationView.updateNow();
+
+        LOG.info("Result from update: " + result);
+
+        assertTrue("got sensible result", result.contains("No material change"));
+
+        HashMap<String, String> propsAfter = new HashMap<String, String>();
+        IntrospectionSupport.getProperties(runtimeConfigurationView, propsAfter, null);
+        LOG.info("mbean attributes after: " + propsAfter);
+
+        assertEquals("modified is same", props.get(propOfInterest), propsAfter.get(propOfInterest));
+    }
+
+}

Propchange: activemq/trunk/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-bean.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-bean.xml?rev=1518373&view=auto
==============================================================================
--- activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-bean.xml (added)
+++ activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-bean.xml Wed Aug 28 20:32:20 2013
@@ -0,0 +1,34 @@
+<?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"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
+
+  <broker xmlns="http://activemq.apache.org/schema/core" start="false" persistent="false" >
+    <plugins>
+      <runtimeConfigurationPlugin checkPeriod="1000" />
+    </plugins>
+
+    <!-- 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>
+</beans>

Propchange: activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-bean.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-bean.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-bean.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml