You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by br...@apache.org on 2005/03/04 14:30:06 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/configuration/impl ConfigurationAbstractImpl.java

brianm      2005/03/04 05:30:06

  Modified:    src/java/org/apache/ojb/broker/metadata Tag: OJB_1_0_RELEASE
                        RepositoryPersistor.java
               src/java/org/apache/ojb/broker/util/configuration/impl Tag:
                        OJB_1_0_RELEASE ConfigurationAbstractImpl.java
  Log:
  Two patches from Ilkka Priha:
  
  Currently, OJB loads the OJB.properties file by getting an input stream from the corresponding URL. However, if the properties file is embedded in a jar archive, this method locks the corresponding jar and prevents it from being removed during undeployment of a web application (at least in Sun jdk under Windows). Some web containers (e.g. Tomcat) have non-standard configuration options to handle jar resources in a specific way to prevent locking, but a more general solution is to disable caching in the URL connection before opening the input stream.
  
  The locked jar problem with OJB.properties can also be caused by repository descriptors embedded in jar archives. The problem is caused by RepositoryPersistor passing a URL path to InputSource without disabling caching in the corresponding URL connection.
  
  Submitted by:	Ilkka Priha
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.24.2.2  +26 -3     db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryPersistor.java
  
  Index: RepositoryPersistor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryPersistor.java,v
  retrieving revision 1.24.2.1
  retrieving revision 1.24.2.2
  diff -u -r1.24.2.1 -r1.24.2.2
  --- RepositoryPersistor.java	11 Nov 2004 13:57:42 -0000	1.24.2.1
  +++ RepositoryPersistor.java	4 Mar 2005 13:30:05 -0000	1.24.2.2
  @@ -27,6 +27,7 @@
   import java.io.PrintWriter;
   import java.net.MalformedURLException;
   import java.net.URL;
  +import java.net.URLConnection;
   import java.util.Date;
   
   import org.apache.commons.lang.SerializationUtils;
  @@ -258,13 +259,35 @@
           arminw:
           strange, when using 'url.openStream()' argument repository
           could not be parsed
  +        ipriha:
  +        parser needs a base url to find referenced entities.
           */
           // InputSource source = new InputSource(url.openStream());
           
  -        String pathName = url.toString();
  +        String pathName = url.toExternalForm();
  +
           log.info("Building repository from :" + pathName);
           InputSource source = new InputSource(pathName);
  -        return readMetadataFromXML(source, targetRepository);
  +        URLConnection conn = url.openConnection();
  +        conn.setUseCaches(false);
  +        conn.connect();
  +        InputStream in = conn.getInputStream();
  +        source.setByteStream(in);
  +        try
  +		{
  +        	return readMetadataFromXML(source, targetRepository);
  +		}
  +        finally
  +		{
  +        	try
  +			{
  +        		in.close();
  +			}
  +        	catch (IOException x)
  +			{
  +                log.warn("unable to close repository input stream [" + x.getMessage() + "]", x);
  +			}
  +		}
       }
   
       /**
  
  
  
  No                   revision
  No                   revision
  1.15.2.1  +6 -3      db-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/Attic/ConfigurationAbstractImpl.java
  
  Index: ConfigurationAbstractImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/Attic/ConfigurationAbstractImpl.java,v
  retrieving revision 1.15
  retrieving revision 1.15.2.1
  diff -u -r1.15 -r1.15.2.1
  --- ConfigurationAbstractImpl.java	16 Jun 2004 20:34:22 -0000	1.15
  +++ ConfigurationAbstractImpl.java	4 Mar 2005 13:30:06 -0000	1.15.2.1
  @@ -25,6 +25,7 @@
   import java.io.FileNotFoundException;
   import java.io.InputStream;
   import java.net.URL;
  +import java.net.URLConnection;
   import java.util.Properties;
   import java.util.StringTokenizer;
   
  @@ -426,8 +427,10 @@
   
               logger.info("Loading OJB's properties from file " + url);
   
  -            InputStream strIn = url.openStream();
  -
  +            URLConnection conn = url.openConnection();
  +            conn.setUseCaches(false);
  +            conn.connect();
  +            InputStream strIn = conn.getInputStream();
               properties.load(strIn);
               strIn.close();
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org