From 7fdd58e5b251c1400fe62a077e4436e2eb4aa2e9 Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Tue, 5 Apr 2011 09:47:19 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-3268 - Cannot use tag in blueprint configuration. Pull Resource from the api such that that string schema matches the java api. A resource is still used in the implementation such that a local or relative path or uri is supported git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1088944 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/spring/SpringSslContext.java | 22 +++++----- .../org/apache/activemq/spring/Utils.java | 41 +++++++++++++++++++ .../activemq/xbean/XBeanBrokerFactory.java | 14 ++----- 3 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 activemq-core/src/main/java/org/apache/activemq/spring/Utils.java diff --git a/activemq-core/src/main/java/org/apache/activemq/spring/SpringSslContext.java b/activemq-core/src/main/java/org/apache/activemq/spring/SpringSslContext.java index 50f4a9e359..cb72ceeea9 100644 --- a/activemq-core/src/main/java/org/apache/activemq/spring/SpringSslContext.java +++ b/activemq-core/src/main/java/org/apache/activemq/spring/SpringSslContext.java @@ -17,6 +17,7 @@ package org.apache.activemq.spring; import java.io.InputStream; +import java.net.MalformedURLException; import java.security.KeyStore; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; @@ -30,7 +31,6 @@ import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import org.apache.activemq.broker.SslContext; -import org.springframework.core.io.Resource; /** * Extends the SslContext so that it's easier to configure from spring. @@ -48,8 +48,8 @@ public class SpringSslContext extends SslContext { private String keyStoreAlgorithm=KeyManagerFactory.getDefaultAlgorithm(); private String trustStoreAlgorithm=TrustManagerFactory.getDefaultAlgorithm(); - private Resource keyStore; - private Resource trustStore; + private String keyStore; + private String trustStore; private String keyStorePassword; private String trustStorePassword; @@ -100,7 +100,7 @@ public class SpringSslContext extends SslContext { } KeyStore ks = KeyStore.getInstance(trustStoreType); - InputStream is=trustStore.getInputStream(); + InputStream is=Utils.resourceFromString(trustStore).getInputStream(); try { ks.load(is, trustStorePassword==null? null : trustStorePassword.toCharArray()); } finally { @@ -115,7 +115,7 @@ public class SpringSslContext extends SslContext { } KeyStore ks = KeyStore.getInstance(keyStoreType); - InputStream is=keyStore.getInputStream(); + InputStream is=Utils.resourceFromString(keyStore).getInputStream(); try { ks.load(is, keyStorePassword==null? null : keyStorePassword.toCharArray()); } finally { @@ -132,20 +132,20 @@ public class SpringSslContext extends SslContext { return keyStoreType; } - public Resource getKeyStore() { + public String getKeyStore() { return keyStore; } - public void setKeyStore(Resource keyResource) { - this.keyStore = keyResource; + public void setKeyStore(String keyStore) throws MalformedURLException { + this.keyStore = keyStore; } - public Resource getTrustStore() { + public String getTrustStore() { return trustStore; } - public void setTrustStore(Resource trustResource) { - this.trustStore = trustResource; + public void setTrustStore(String trustStore) throws MalformedURLException { + this.trustStore = trustStore; } public String getKeyStoreAlgorithm() { diff --git a/activemq-core/src/main/java/org/apache/activemq/spring/Utils.java b/activemq-core/src/main/java/org/apache/activemq/spring/Utils.java new file mode 100644 index 0000000000..0f7ac1ac7d --- /dev/null +++ b/activemq-core/src/main/java/org/apache/activemq/spring/Utils.java @@ -0,0 +1,41 @@ +/** + * 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.spring; + +import java.io.File; +import java.net.MalformedURLException; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.FileSystemResource; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; +import org.springframework.util.ResourceUtils; + +public class Utils { + + public static Resource resourceFromString(String uri) throws MalformedURLException { + Resource resource; + File file = new File(uri); + if (file.exists()) { + resource = new FileSystemResource(uri); + } else if (ResourceUtils.isUrl(uri)) { + resource = new UrlResource(uri); + } else { + resource = new ClassPathResource(uri); + } + return resource; + } +} diff --git a/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerFactory.java b/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerFactory.java index 28942ac609..93f21418c7 100644 --- a/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerFactory.java @@ -24,6 +24,7 @@ import java.util.Map; import org.apache.activemq.broker.BrokerFactoryHandler; import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.spring.Utils; import org.apache.activemq.util.IntrospectionSupport; import org.apache.activemq.util.URISupport; import org.slf4j.Logger; @@ -100,17 +101,8 @@ public class XBeanBrokerFactory implements BrokerFactoryHandler { } protected ApplicationContext createApplicationContext(String uri) throws MalformedURLException { - LOG.debug("Now attempting to figure out the type of resource: " + uri); - - Resource resource; - File file = new File(uri); - if (file.exists()) { - resource = new FileSystemResource(uri); - } else if (ResourceUtils.isUrl(uri)) { - resource = new UrlResource(uri); - } else { - resource = new ClassPathResource(uri); - } + Resource resource = Utils.resourceFromString(uri); + LOG.debug("Using " + resource + " from " + uri); return new ResourceXmlApplicationContext(resource) { @Override protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {