openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Florent BENOIT (JIRA)" <>
Subject [jira] Commented: (OPENJPA-148) Parsing exception while using an "exploded" archive
Date Sat, 17 Feb 2007 17:15:05 GMT


Florent BENOIT commented on OPENJPA-148:

Here is a follow up for explaining the process that OpenJPA is using on exploded jar files:

The PersistenceUnitInfo object build by the EJB3 container(EasyBeans in my testcase) is sent
to OpenJPA.
Then, in the method toOpenJPAProperties of org.apache.openjpa.persistence.PersistenceUnitInfoImpl

The getPersistenceUnitRootUrl() URL (which is the directory URL
 file:/home/florent/workspace/easybeans/ejb3s/entitybean.jar/) is transformed
 into /home/florent/workspace/easybeans/ejb3s/entitybean.jar/ as it is a "file:" URL

Then, the getJarFileUrls() is returning the same URL (file:/home/florent/workspace/easybeans/ejb3s/entitybean.jar/)
This URL is an exploded JAR file URL which is valid for this method as said in the specification
 "Returns a list of URLs for the jar files or exploded jar file directories that the persistence
provider [...]"
 (It has been clarified between the proposed final specification and the final specification)

The PersistenceUnitInfoImpl class is then transforming these two URLs into:
  - "Files" property with the value /home/florent/workspace/easybeans/ejb3s/entitybean.jar/
  - "URLs" property with the value file:/home/florent/workspace/easybeans/ejb3s/entitybean.jar/

Then, these values will be analyzed in  parsePersistentTypeNames(ClassLoader loader) method
 the class org.apache.openjpa.meta.AbstractCFMetaDataFactory

1/ First, the "Files" property is analyzed:
As /home/florent/workspace/easybeans/ejb3s/entitybean.jar/ is a directory, it goes in:

                if (file.isDirectory()) {
                    if (log.isTraceEnabled())
                        log.trace(_loc.get("scanning-directory", file));
                    scan(new FileMetaDataIterator(dir, newMetaDataFilter()),
                        cparser, names, true, file);

which found...nothing. (I have done another test with a file for the PersistenceUnitRootUrl
 (and not a directory) and in this case the scan of the file finds the Entity class while
it doesn't
 find the entity class in directory mode).
Also here, dir is null, if dir = file, it finds the entity class.

The corresponding debug trace is:
[TRACE] MetaData - Scanning directory "/home/florent/workspace/easybeans/ejb3s/entitybean.jar"
for persistent types.

2/ Then, the "URLs" property is analyzed:
It's not a .jar file so the case "else if (url.getPath().endsWith(".jar"))" is not used and
it fallbacks
 in the default case:

                } else {
                    if (log.isTraceEnabled())
                        log.trace(_loc.get("scanning-url", url));
                    clss = cparser.parseTypeNames(new URLMetaDataIterator(url));
                    if (log.isTraceEnabled())
                        log.trace(_loc.get("scan-found-names", clss, url));
                    mapPersistentTypeNames(url, clss);

And mapPersistentTypeNames method do the following:
_unparsed.add((URL) rsrc);

so, the URL which is referencing an exploded jar is considered as an unparsed URL from now.

The corresponding traces are:
[TRACE] MetaData - Scanning URL "file:/home/florent/workspace/easybeans/ejb3s/entitybean.jar/"
for persistent types.
[TRACE] MetaData - Scan of "file:/home/florent/workspace/easybeans/ejb3s/entitybean.jar/"
found persistent types [Ljava.lang.String;@14c7cd.
[TRACE] MetaData - Mapping resource location "file:/home/florent/workspace/easybeans/ejb3s/entitybean.jar/"
to persistent types "[]".

(with [Ljava.lang.String;@14c7cd. being an empty array.)

When a class needs to be loaded by the load(Class cls, int mode, ClassLoader envLoader) method
of org.apache.openjpa.persistence.PersistenceMetaDataFactory class, there is a check on the
_unparsed attribute.

And in this case, it tries to parse the URL as an XML file:
  for (URL url : _unparsed)
    parseXML(url, cls, mode, envLoader);

And we can imagine the result of parsing a directory as an XML file.

The result is:
[WARN] Enhance - An exception was thrown while attempting to perform class file transformation
on "org/objectweb/easybeans/examples/entitybean/SessionFacadeRemote": <<0|false|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.util.GeneralException: org.xml.sax.SAXException: file:/home/florent/workspace/easybeans/ejb3s/entitybean.jar/
[Location: Line: 1, C: 1]: org.xml.sax.SAXParseException: Content is not allowed in prolog.><0|false|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.util.GeneralException: org.xml.sax.SAXException: file:/home/florent/workspace/easybeans/ejb3s/entitybean.jar/
[Location: Line: 1, C: 1]: org.xml.sax.SAXParseException: Content is not allowed in prolog.
	at org.apache.openjpa.persistence.PersistenceMetaDataFactory.parseXML(

So, I think that you have now a complete report and that you're understanding why OpenJPA
is failing.

> Parsing exception while using an "exploded" archive
> ---------------------------------------------------
>                 Key: OPENJPA-148
>                 URL:
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>         Environment: Sun JDK 5.0 / EasyBeans / OpenJPA snapshot 0.9.7
>            Reporter: Florent BENOIT
>         Attachments: debug_traces_directorymode.txt, stacktrace-error.txt, steps.txt
> This happens when using OpenJPA as persistence provider for the EasyBeans ObjectWeb container.
> The error is happening with "exploded" archive.
> Exploded means that there is a directory, named "entitybean.jar" with a folder META-INF
which contains a file named persistence.xml, and other directories/files for the classes.
> It seems that when using this mode, OpenJPA is trying to parse the directory inputstream
(which is failing).
> This exception is not occuring if a jar file is used instead of the "exploded" mode,
but the exploded mode is the default mode for EasyBeans.
> Note also that this exception don't occur by using Hibernate Entity Manager or Oracle
TopLink Essentials as persistence provider.
> I will attach to this issue a stack trace (with the exploded directory) which fails and
at the end with a jar file (which work)
> And 4 steps used to reproduce this problem

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message