mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-3268 - Cannot use <SslContext> 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
This commit is contained in:
parent
951d87066c
commit
7fdd58e5b2
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue