From: <fg...@us...> - 2006-11-16 09:30:52
|
Revision: 121 http://svn.sourceforge.net/openutils/?rev=121&view=rev Author: fgiust Date: 2006-11-16 01:30:51 -0800 (Thu, 16 Nov 2006) Log Message: ----------- fix for httpUnit Modified Paths: -------------- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Modified: trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2006-11-15 17:47:26 UTC (rev 120) +++ trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2006-11-16 09:30:51 UTC (rev 121) @@ -1,6 +1,7 @@ package it.openutils.deployment.spring; import java.io.File; +import java.io.IOException; import java.net.InetAddress; import java.net.MalformedURLException; import java.net.URL; @@ -81,11 +82,22 @@ try { url = servletContext.getResource(resource); + + // check needed for servletUnit + // we need to check for a connection because getResource always returns a URL, also if the resource + // doesn't exists + url.openConnection().connect(); + } catch (MalformedURLException e) { log.error(e.getMessage(), e); } + catch (IOException e) + { + // ignore, URL is not a valid resource + url = null; + } } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2006-11-16 10:08:23
|
Revision: 125 http://svn.sourceforge.net/openutils/?rev=125&view=rev Author: fgiust Date: 2006-11-16 02:08:23 -0800 (Thu, 16 Nov 2006) Log Message: ----------- fix bad NPE with real appservers... Modified Paths: -------------- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Modified: trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2006-11-16 09:32:01 UTC (rev 124) +++ trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2006-11-16 10:08:23 UTC (rev 125) @@ -83,10 +83,13 @@ { url = servletContext.getResource(resource); - // check needed for servletUnit - // we need to check for a connection because getResource always returns a URL, also if the resource - // doesn't exists - url.openConnection().connect(); + if (url != null) + { + // check needed for servletUnit + // we need to check for a connection because getResource always returns a URL, also if the resource + // doesn't exists + url.openConnection().connect(); + } } catch (MalformedURLException e) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-01-27 19:55:11
|
Revision: 151 http://svn.sourceforge.net/openutils/?rev=151&view=rev Author: fgiust Date: 2007-01-27 11:55:11 -0800 (Sat, 27 Jan 2007) Log Message: ----------- check for null properties Modified Paths: -------------- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Modified: trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-01-27 19:44:34 UTC (rev 150) +++ trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-01-27 19:55:11 UTC (rev 151) @@ -100,10 +100,16 @@ log.error(e.getMessage()); // should not happen } - System.setProperty("env", hostname); + if (hostname != null) + { + System.setProperty("env", hostname); + } String applName = getApplicationName(); - System.setProperty("appl", applName); + if (applName != null) + { + System.setProperty("appl", applName); + } URL propertyUrl = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-01-27 20:18:07
|
Revision: 155 http://svn.sourceforge.net/openutils/?rev=155&view=rev Author: fgiust Date: 2007-01-27 12:18:08 -0800 (Sat, 27 Jan 2007) Log Message: ----------- use unqualified hostname Modified Paths: -------------- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Modified: trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-01-27 19:56:26 UTC (rev 154) +++ trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-01-27 20:18:08 UTC (rev 155) @@ -93,7 +93,9 @@ String hostname = null; try { - hostname = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); + hostname = StringUtils.substringBefore( + StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()), + "."); } catch (UnknownHostException e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-02-06 13:48:10
|
Revision: 230 http://svn.sourceforge.net/openutils/?rev=230&view=rev Author: fgiust Date: 2007-02-06 05:47:56 -0800 (Tue, 06 Feb 2007) Log Message: ----------- gracefully handle missing "/" in webapp resources Modified Paths: -------------- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Modified: trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-02-05 23:08:14 UTC (rev 229) +++ trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-02-06 13:47:56 UTC (rev 230) @@ -160,7 +160,14 @@ { try { - url = servletContext.getResource(resource); + if (resource != null && !resource.startsWith("/")) + { + url = servletContext.getResource("/" + resource); + } + else + { + url = servletContext.getResource(resource); + } if (url != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-02-06 14:33:02
|
Revision: 235 http://svn.sourceforge.net/openutils/?rev=235&view=rev Author: fgiust Date: 2007-02-06 06:32:57 -0800 (Tue, 06 Feb 2007) Log Message: ----------- handle missing file resources (check didn't work properly for non-classpath resources) Modified Paths: -------------- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Modified: trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-02-06 13:50:58 UTC (rev 234) +++ trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-02-06 14:32:57 UTC (rev 235) @@ -193,10 +193,12 @@ try { url = ResourceUtils.getURL(resource); + url.openStream().close(); // test if the resource actually exists } - catch (FileNotFoundException e) + catch (IOException e) { // ignore, can be normal + url = null; } } return url; @@ -215,7 +217,7 @@ return StringUtils.substringAfterLast(url, "/"); } - return null; + return StringUtils.EMPTY; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-02-21 17:25:06
|
Revision: 280 http://svn.sourceforge.net/openutils/?rev=280&view=rev Author: fgiust Date: 2007-02-21 09:25:06 -0800 (Wed, 21 Feb 2007) Log Message: ----------- new inherited property (true by default) to handle property overriding Modified Paths: -------------- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Modified: trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-02-21 17:22:17 UTC (rev 279) +++ trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-02-21 17:25:06 UTC (rev 280) @@ -2,13 +2,16 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.net.InetAddress; import java.net.MalformedURLException; import java.net.URL; import java.net.UnknownHostException; +import java.util.Properties; import javax.servlet.ServletContext; +import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,6 +57,11 @@ private String fileLocation; /** + * Are properties inherited from default configuration? default is true, + */ + private boolean inherit = true; + + /** * {@inheritDoc} */ public void setServletContext(ServletContext servletContext) @@ -71,6 +79,15 @@ } /** + * Sets the inherit. + * @param inherit the inherit to set + */ + public void setInherit(boolean inherit) + { + this.inherit = inherit; + } + + /** * Setter for <code>defaultEnvironment</code>. * @param defaultEnvironment The defaultEnvironment to set. * @deprecated use defaultLocation @@ -115,38 +132,81 @@ URL propertyUrl = null; - String replacedLocations = StringUtils.replace(fileLocation, PROPERTY_ENV, hostname); + String fileLocationFull = fileLocation; + + if (defaultEnvironment != null) + { + log.warn("Usage of \"defaultEnvironment\" is deprecated, please specify the fallback location " + + "as the last comma separated value in \"fileLocation\""); + fileLocationFull = fileLocationFull + + "," + + StringUtils.replace(fileLocationFull, PROPERTY_ENV, this.defaultEnvironment); + } + + String replacedLocations = StringUtils.replace(fileLocationFull, PROPERTY_ENV, hostname); replacedLocations = StringUtils.replace(replacedLocations, PROPERTY_APPL, applName); String[] locations = StringUtils.split(replacedLocations, ","); + if (inherit) + { + ArrayUtils.reverse(locations); + } + + Properties props = new Properties(); + boolean found = false; + for (String loc : locations) { propertyUrl = getResource(StringUtils.strip(loc)); if (propertyUrl != null) { - break; + found = true; + log.debug("Loading property file at {}", loc); + + Resource resource = new UrlResource(propertyUrl); + InputStream is = null; + + try + { + is = resource.getInputStream(); + props.load(is); + } + catch (IOException e) + { + log.error("Error loading " + propertyUrl.toString(), e); + } + finally + { + if (is != null) + { + try + { + is.close(); + } + catch (IOException e) + { + // ignore + } + } + } + + if (!inherit) + { + break; + } } log.debug("Property file not found at {}", loc); - } - if (propertyUrl == null && defaultEnvironment != null) - { - log.warn("Usage of \"defaultEnvironment\" is deprecated, please specify the fallback location " - + "as the last comma separated value in \"fileLocation\""); - propertyUrl = getResource(StringUtils.replace(fileLocation, PROPERTY_ENV, this.defaultEnvironment)); - } - if (propertyUrl == null) + if (!found) { log.error("No properties found at {}", replacedLocations); } - else - { - Resource resource = new UrlResource(propertyUrl); - super.setLocation(resource); - } + + super.setProperties(props); + } super.postProcessBeanFactory(beanFactory); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2008-02-03 21:02:47
|
Revision: 594 http://openutils.svn.sourceforge.net/openutils/?rev=594&view=rev Author: fgiust Date: 2008-02-03 13:02:50 -0800 (Sun, 03 Feb 2008) Log Message: ----------- try to avoid spring-web dependency Modified Paths: -------------- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Modified: trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2008-02-01 10:59:57 UTC (rev 593) +++ trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2008-02-03 21:02:50 UTC (rev 594) @@ -17,17 +17,19 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; import org.springframework.util.ResourceUtils; -import org.springframework.web.context.ServletContextAware; +import org.springframework.web.context.WebApplicationContext; /** * @author fgiust * @version $Id: $ */ -public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer implements ServletContextAware +public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer implements ApplicationContextAware { /** @@ -66,14 +68,6 @@ private boolean inherit = true; /** - * {@inheritDoc} - */ - public void setServletContext(ServletContext servletContext) - { - this.servletContext = servletContext; - } - - /** * Setter for <code>fileLocation</code>. * @param fileLocation The fileLocation to set. */ @@ -309,4 +303,21 @@ return properties.getProperty(key); } + /** + * {@inheritDoc} + */ + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException + { + try + { + if (applicationContext instanceof WebApplicationContext) + { + this.servletContext = ((WebApplicationContext) applicationContext).getServletContext(); + } + } + catch (NoClassDefFoundError e) + { + // ignore, we are not in a web project or spring web is not available + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2008-02-11 20:38:31
|
Revision: 606 http://openutils.svn.sourceforge.net/openutils/?rev=606&view=rev Author: fgiust Date: 2008-02-11 12:36:23 -0800 (Mon, 11 Feb 2008) Log Message: ----------- better handling of classpath resources Modified Paths: -------------- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Modified: trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2008-02-03 22:50:06 UTC (rev 605) +++ trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2008-02-11 20:36:23 UTC (rev 606) @@ -230,7 +230,7 @@ { URL url = null; - if (servletContext != null) + if (servletContext != null && !StringUtils.contains(resource, "classpath:")) { try { @@ -262,7 +262,7 @@ url = null; } } - else + if (url == null) { try { @@ -323,6 +323,7 @@ */ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + // don't implement ServletContextAware or it will fail if javax.servlet dependency is not available try { if (applicationContext instanceof WebApplicationContext) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |