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
This commit is contained in:
Gary Tully 2013-08-28 20:32:20 +00:00
parent 84ce96b2dd
commit 2ea02bc8fb
3 changed files with 114 additions and 1 deletions

View File

@ -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;
}

View File

@ -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));
}
}

View File

@ -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>