From 2ea02bc8fb4968f1fdf1a18b5d0596b4a86a9823 Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Wed, 28 Aug 2013 20:32:20 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1518373 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugin/RuntimeConfigurationBroker.java | 13 +++- .../org/apache/activemq/SpringBeanTest.java | 68 +++++++++++++++++++ .../emptyUpdatableConfig1000-spring-bean.xml | 34 ++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java create mode 100644 activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-bean.xml diff --git a/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java b/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java index 5e73a2a150..0b4e4345be 100644 --- a/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java +++ b/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java @@ -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 extends BrokerFilter { 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; } diff --git a/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java b/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java new file mode 100644 index 0000000000..1ed107ffe3 --- /dev/null +++ b/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java @@ -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 props = new HashMap(); + 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 propsAfter = new HashMap(); + IntrospectionSupport.getProperties(runtimeConfigurationView, propsAfter, null); + LOG.info("mbean attributes after: " + propsAfter); + + assertEquals("modified is same", props.get(propOfInterest), propsAfter.get(propOfInterest)); + } + +} diff --git a/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-bean.xml b/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-bean.xml new file mode 100644 index 0000000000..2047b96fb5 --- /dev/null +++ b/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-bean.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + +