You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/12/13 14:43:14 UTC
svn commit: r486650 - in
/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms:
JmsBootstrap.java JmsComponent.java JmsConfiguration.java
Author: gnodet
Date: Wed Dec 13 05:43:13 2006
New Revision: 486650
URL: http://svn.apache.org/viewvc?view=rev&rev=486650
Log:
Fix jms configuration: avoid NPE, load from classpath if available, prefix properties by component name
Modified:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsBootstrap.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsComponent.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsConfiguration.java
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsBootstrap.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsBootstrap.java?view=diff&rev=486650&r1=486649&r2=486650
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsBootstrap.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsBootstrap.java Wed Dec 13 05:43:13 2006
@@ -29,7 +29,6 @@
protected JmsConfiguration configuration;
public JmsBootstrap() {
- configuration = new JmsConfiguration();
}
public ObjectName getExtensionMBeanName() {
@@ -62,6 +61,10 @@
}
protected void doInit() throws Exception {
+ configuration = new JmsConfiguration();
+ configuration.setRootDir(this.context.getInstallRoot());
+ configuration.setComponentName(this.context.getComponentName());
+ configuration.load();
Object mbean = getExtensionMBean();
if (mbean != null) {
this.mbeanName = createExtensionMBeanName();
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsComponent.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsComponent.java?view=diff&rev=486650&r1=486649&r2=486650
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsComponent.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsComponent.java Wed Dec 13 05:43:13 2006
@@ -123,6 +123,7 @@
protected void doInit() throws Exception {
super.doInit();
configuration.setRootDir(context.getWorkspaceRoot());
+ configuration.setComponentName(this.context.getComponentName());
configuration.load();
// Lookup keystoreManager and authenticationService
if (configuration.getKeystoreManager() == null) {
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsConfiguration.java?view=diff&rev=486650&r1=486649&r2=486650
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsConfiguration.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsConfiguration.java Wed Dec 13 05:43:13 2006
@@ -20,6 +20,7 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Properties;
import javax.jms.ConnectionFactory;
@@ -29,13 +30,14 @@
/**
* @author gnodet
- *
+ * @org.apache.xbean.XBean element="configuration"
*/
public class JmsConfiguration implements JmsConfigurationMBean {
public final static String CONFIG_FILE = "component.properties";
private String rootDir;
+ private String componentName = "servicemix-jms";
private Properties properties = new Properties();
private String userName;
private String password;
@@ -60,6 +62,7 @@
/**
* @return Returns the rootDir.
+ * @org.apache.xbean.Property hidden="true"
*/
public String getRootDir() {
return rootDir;
@@ -73,6 +76,21 @@
}
/**
+ * @return Returns the componentName.
+ * @org.apache.xbean.Property hidden="true"
+ */
+ public String getComponentName() {
+ return componentName;
+ }
+
+ /**
+ * @param componentName The componentName to set.
+ */
+ public void setComponentName(String componentName) {
+ this.componentName = componentName;
+ }
+
+ /**
* @return the authenticationService
*/
public AuthenticationService getAuthenticationService() {
@@ -107,7 +125,6 @@
*/
public void setKeystoreManager(KeystoreManager keystoreManager) {
this.keystoreManager = keystoreManager;
- save();
}
/**
* @return the keystoreManagerName
@@ -216,14 +233,14 @@
public void save() {
- properties.setProperty("userName", userName);
- properties.setProperty("password", password);
- properties.setProperty("jndiInitialContextFactory", jndiInitialContextFactory);
- properties.setProperty("jndiProviderUrl", jndiProviderUrl);
- properties.setProperty("jndiName", jndiConnectionFactoryName);
- properties.setProperty("processorName", processorName);
- properties.setProperty("keystoreManagerName", keystoreManagerName);
- properties.setProperty("authenticationServiceName", authenticationServiceName);
+ setProperty(componentName + ".userName", userName);
+ setProperty(componentName + ".password", password);
+ setProperty(componentName + ".jndiInitialContextFactory", jndiInitialContextFactory);
+ setProperty(componentName + ".jndiProviderUrl", jndiProviderUrl);
+ setProperty(componentName + ".jndiName", jndiConnectionFactoryName);
+ setProperty(componentName + ".processorName", processorName);
+ setProperty(componentName + ".keystoreManagerName", keystoreManagerName);
+ setProperty(componentName + ".authenticationServiceName", authenticationServiceName);
if (rootDir != null) {
File f = new File(rootDir, CONFIG_FILE);
try {
@@ -234,41 +251,63 @@
}
}
+ protected void setProperty(String name, String value) {
+ if (value == null) {
+ properties.remove(name);
+ } else {
+ properties.setProperty(name, value);
+ }
+ }
+
public boolean load() {
- if (rootDir == null) {
- return false;
+ File f = null;
+ InputStream in = null;
+ if (rootDir != null) {
+ // try to find the property file in the workspace folder
+ f = new File(rootDir, CONFIG_FILE);
+ if (!f.exists()) {
+ f = null;
+ }
}
- File f = new File(rootDir, CONFIG_FILE);
- if (!f.exists()) {
- return false;
+ if (f == null) {
+ // find property file in classpath if it is not available in workspace
+ in = this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE);
+ if (in == null) {
+ return false;
+ }
}
+
try {
- properties.load(new FileInputStream(f));
+ if (f != null) {
+ properties.load(new FileInputStream(f));
+ } else {
+ properties.load(in);
+ }
} catch (IOException e) {
throw new RuntimeException("Could not load component configuration", e);
}
- if (properties.getProperty("userName") != null) {
+ if (properties.getProperty(componentName + ".userName") != null) {
userName = properties.getProperty("userName");
}
- if (properties.getProperty("password") != null) {
+ if (properties.getProperty(componentName + ".password") != null) {
password = properties.getProperty("password");
}
- if (properties.getProperty("jndiInitialContextFactory") != null) {
+ if (properties.getProperty(componentName + ".jndiInitialContextFactory") != null) {
jndiInitialContextFactory = properties.getProperty("jndiInitialContextFactory");
}
- if (properties.getProperty("jndiProviderUrl") != null) {
+ if (properties.getProperty(componentName + ".jndiProviderUrl") != null) {
jndiProviderUrl = properties.getProperty("jndiProviderUrl");
}
- if (properties.getProperty("jndiName") != null) {
+ if (properties.getProperty(componentName + ".jndiName") != null) {
jndiConnectionFactoryName = properties.getProperty("jndiName");
}
- if (properties.getProperty("processorName") != null) {
+ if (properties.getProperty(componentName + ".processorName") != null) {
processorName = properties.getProperty("processorName");
}
- if (properties.getProperty("keystoreManagerName") != null) {
+ if (properties.getProperty(componentName + ".keystoreManagerName") != null) {
keystoreManagerName = properties.getProperty("keystoreManagerName");
}
- if (properties.getProperty("authenticationServiceName") != null) {
+ if (properties.getProperty(componentName + ".authenticationServiceName") != null) {
authenticationServiceName = properties.getProperty("authenticationServiceName");
}
return true;