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 Ilkka Priha <im...@surfeu.fi> on 2005/03/04 10:19:40 UTC

Repository descriptors may lock web app jars

Hello,

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. The patch is attached below.

-- Ilkka

PS. The public DTD address "http://db.apache.org/ojb/dtds/1.0/repository.dtd" 
mentioned in repository.xml comments doesn't seem to work, but 
"http://db.apache.org/ojb/repository.dtd" is currently accessible.


Index: RepositoryPersistor.java
===================================================================
RCS file: 
/home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryPersistor.java,v
retrieving revision 1.24.2.1
diff -u -r1.24.2.1 RepositoryPersistor.java
--- RepositoryPersistor.java	11 Nov 2004 13:57:42 -0000	1.24.2.1
+++ RepositoryPersistor.java	4 Mar 2005 09:09:34 -0000
@@ -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,33 @@
          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)
+			{
+			}
+		}
      }

      /**


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


Re: Repository descriptors may lock web app jars

Posted by Brian McCallister <br...@apache.org>.
Checked in to OJB_1_0_RELEASE and HEAD, thank you! Should be in 1.0.2  
any day now (when I get tests passing on postgres ;-)

-Brian

On Mar 4, 2005, at 4:19 AM, Ilkka Priha wrote:

> Hello,
>
> 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. The patch is  
> attached below.
>
> -- Ilkka
>
> PS. The public DTD address  
> "http://db.apache.org/ojb/dtds/1.0/repository.dtd" mentioned in  
> repository.xml comments doesn't seem to work, but  
> "http://db.apache.org/ojb/repository.dtd" is currently accessible.
>
>
> Index: RepositoryPersistor.java
> ===================================================================
> RCS file:  
> /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/metadata/ 
> RepositoryPersistor.java,v
> retrieving revision 1.24.2.1
> diff -u -r1.24.2.1 RepositoryPersistor.java
> --- RepositoryPersistor.java	11 Nov 2004 13:57:42 -0000	1.24.2.1
> +++ RepositoryPersistor.java	4 Mar 2005 09:09:34 -0000
> @@ -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,33 @@
>          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)
> +			{
> +			}
> +		}
>      }
>
>      /**
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>


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