Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 360871 - MalformedURLException on deployed WAR with eclipse 3.7
Summary: MalformedURLException on deployed WAR with eclipse 3.7
Status: CLOSED DUPLICATE of bug 355484
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-13 13:03 EDT by Nikolas Falco CLA
Modified: 2022-06-09 10:08 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nikolas Falco CLA 2011-10-13 13:03:38 EDT
Build Identifier: 2.3.0.v20110604-r9504

I upgrade my application to RAP 1.4 that is based on eclipse 3.7 indingo.

In PDE (workspace) mode all works well, but when create and deploy WAR MalformedURLException was thrown when xerces parse persistence.xml.
After hours of investigations if found the problem.
PersistenceUnitProcessor.computePURootURL() doesn't handle URL of type bundleresource, it pass URL forward as is.
When ArchiveFactoryImpl.createArchive(URL,String,Map) create the Archive object, it switch on url protocol and the method isJarInputStream() under eclipse 3.6.2 return false but under eclipse 3.7 return true. So with eclipse 3.6.2 ArchiveFactoryImpl return a URLArchive instead under eclipse 3.7 return a JarInputStreamURLArchive.

isJarInputStream test if is a jar or not as the follow:

    protected boolean isJarInputStream(URL url) throws IOException {
        InputStream in = null;
        try {
        	in = url.openStream();
            if (in == null) { // for directories, we may get InputStream as null
            	return false;
            }
        ...

in eclipse the final object that connect and open the stream is a DirZipBundleEntry class that when is invoked getInputStream() return always null under eclipse 3.6.2:
	public InputStream getInputStream() throws IOException {
		return null;
	}

in eclipse 3.7 it return a empty array of ByteArrayInputStream
	public InputStream getInputStream() throws IOException {
		return new ByteArrayInputStream(new byte[0]);
	}

When JarInputStreamURLArchive should compute entries it returns none and break the XML parser of persistence.xml

This problem happens with builds of eclipselink 2.1.2 to 2.3.0
This is blocking to deploy applications with eclipse 3.7.

Reproducible: Always
Comment 1 Nikolas Falco CLA 2011-10-14 05:24:17 EDT
To avoid this problem and deploy, I have implement a new ArchiveFactory that extends ArchiveFactoryImpl in a new fragment (due to classloader method used into persistence.jpa plugin). This new Factory only override createArchive method.

public class OSGiArchiveFactoryImpl extends ArchiveFactoryImpl {
...
   @Override
   public Archive createArchive ... 
...
        if (rootUrl == null) {
            return null;
        }

        Archive result = null;
        String protocol = rootUrl.getProtocol();
        logger.logp(Level.FINER, sourceClass, "createArchive", "protocol = {0}", protocol);

        if ("file".equals(protocol) || "jar".equals(protocol)) { // NOI18N
        	return super.createArchive(rootUrl, descriptorLocation, properties);
        } else if ("bundleresource".equals(protocol)) {
        	rootUrl = FileLocator.resolve(rootUrl);
        	protocol = rootUrl.getProtocol();
        	if (!"bundleresource".equals(protocol))
        		result = createArchive(rootUrl, descriptorLocation, properties);
        	else
        		result = new URLArchive(rootUrl, descriptorLocation);
        } else {
            result = new URLArchive(rootUrl, descriptorLocation);
        }

        logger.exiting(sourceClass, "createArchive", result);

        return result;
	}
}
Comment 2 Nikolas Falco CLA 2011-10-14 05:33:44 EDT
Sorry, I press "Save Changes" button with a combo of tab+space -_-

Missing define a JVM property -Declipselink.archive.factory=my.OSGiArchiveFactoryImpl into WebSphere or jetty application (better if a standard META-INF/service mechanism was used, or a different method to read also OSGi property).

In my case is not possible define the system property into an activator, because is to late (and fragment can't have activator).
Comment 3 Tom Ware CLA 2011-10-14 09:07:03 EDT
'any chance this is a duplicate of:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=355484
Comment 4 Nikolas Falco CLA 2011-10-14 11:12:47 EDT
yes, with eclipselink 2.3.1 (not yet published) works without my workaround.
Comment 5 Tom Ware CLA 2011-10-14 11:28:29 EDT

*** This bug has been marked as a duplicate of bug 355484 ***
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:08:36 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink