import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
-
import org.collectionspace.services.common.api.Tools;
import org.collectionspace.services.jaxb.AbstractCommonList;
-
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor;
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// FIXME: Deprecated classes that need to be updated
* Instantiates a new abstract service client impl.
* @throws Exception
*/
- public AbstractServiceClientImpl(Properties properties) {
+ public AbstractServiceClientImpl(Properties properties) throws Exception {
setClientProperties(properties, false);
}
* Helps initialize a new abstract service client impl instance.
* @throws Exception
*/
- private void init() {
- if (this.properties.isEmpty() == true) {
- throw new RuntimeException("Client connection properties are empty. Cannot proceed.");
+ private void init() throws Exception {
+ if (properties.isEmpty() == true) {
+ throw new Exception("Client connection properties are empty. Cannot proceed.");
}
try {
}
@Override
- public void setClientProperties(Properties inProperties) {
+ public void setClientProperties(Properties inProperties) throws Exception {
setClientProperties(inProperties, false);
}
* @param inProperties
* @throws Exception
*/
- protected void setClientProperties(Properties inProperties, boolean overrideWithSystemValues) {
- properties = inProperties;
+ protected void setClientProperties(Properties inProperties, boolean overrideWithSystemValues) throws Exception {
+ properties = Tools.filterPropertiesWithEnvVars(inProperties); // Look for environment variables and substitute values if found
if (overrideWithSystemValues == true) {
String spec = System.getProperty(URL_PROPERTY);
Properties result = loadProperties(clientPropertiesFilename);
if (filterPasswords) {
- result = filterPasswordsWithEnvVars(result);
+ result = filterPropertiesWithEnvVars(result);
}
return result;
}
- static public Properties filterPasswordsWithEnvVars(Properties inProperties) throws Exception {
+ /**
+ * Looks for property values if the form ${foo} and tries to find environment property "foo" value to replace with.
+ *
+ * For example, a property value of "${foo}" would be replaced with the value of the environment variable "foo" if a
+ * value for "foo" exists in the current environment.
+ *
+ * @param inProperties
+ * @return
+ * @throws Exception
+ */
+ static public Properties filterPropertiesWithEnvVars(Properties inProperties) throws Exception {
+ final String filteredFlag = "fe915b1b-7411-4aaa-887f";
+ final String filteredKey = filteredFlag;
Properties result = inProperties;
- if (inProperties != null && inProperties.size() > 0) {
- for (String key : inProperties.stringPropertyNames()) {
- String propertyValue = inProperties.getProperty(key);
- String newPropertyValue = Tools.getPasswordFromEnv(propertyValue);
- if (newPropertyValue != null) { // non-null result means the property value was the name of an environment variable
- inProperties.setProperty(key, newPropertyValue);
+ if (inProperties.containsKey(filteredKey) == false) {
+ // Only process the properties once
+ if (inProperties != null && inProperties.size() > 0) {
+ for (String key : inProperties.stringPropertyNames()) {
+ String propertyValue = inProperties.getProperty(key);
+ String newPropertyValue = Tools.getValueFromEnv(propertyValue);
+ if (newPropertyValue != null) { // non-null result means the property value was the name of an environment variable
+ inProperties.setProperty(key, newPropertyValue);
+ }
}
+ inProperties.setProperty(filteredKey, filteredFlag); // set to indicated we've already process these properties
}
}
}
/**
- * Try to find the value of a password variable in the system or JVM environment. This code substitutes only environment variables formed
+ * Try to find the value of a property variable in the system or JVM environment. This code substitutes only property values formed
* like ${cspace.password.mysecret} or ${cspace_password_mysecret_secret}. The corresponding environment variables would
* be "cspace.password.mysecret" and "cspace.password.mysecret.secret".
*
- * Returns null if the passed in propertyValue is not a password variable -i.e., not something of the form {$cspace.password.foo}
+ * Returns null if the passed in property value is not a property variable -i.e., not something of the form {$cspace.password.foo}
*
- * Throws an exception if the passed in propertyValue has a valid variable form but the corresponding environment variable is not
+ * Throws an exception if the passed in property value has a valid variable form but the corresponding environment variable is not
* set.
*
* @param propertyValue
* @return
* @throws Exception
*/
- static private String getPasswordFromEnv(String propertyValue) throws Exception {
+ static public String getValueFromEnv(String propertyValue) throws Exception {
String result = null;
//
// Replace things like ${cspace.password.cow} with values from either the environment