gmuecke / reflections

Automatically exported from code.google.com/p/reflections
Do What The F*ck You Want To Public License
0 stars 0 forks source link

Add support for weblogic zip URL type (jar files) #124

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
- What steps will reproduce the problem?

1. When the classes are located at a jar file, weblogic uses it own "zip" 
protocol.
2. None of the current URLType default implementations matches with that 
protocol.

- What is the expected output? 

It should handle weblogic zip protocol when the file is actually a jar file.

- What do you see instead?

This exception message: "SEVERE: could not create Vfs.Dir from url. ignoring 
the exception and continuing
org.reflections.ReflectionsException: could not create Vfs.Dir from url, no 
matching UrlType was found 
[zip:/bea/user_projects/domains/lepanto/servers/ulysses/tmp/_WL_user/ulysses/aq2
tjo/war/WEB-INF/lib/ulysses.jar!/]
either use fromURL(final URL url, final List<UrlType> urlTypes) or use the 
static setDefaultURLTypes(final List<UrlType> urlTypes) or 
addDefaultURLTypes(UrlType urlType) with your specialized UrlType."

- What version of the product are you using? 

0.9.8

- On what operating system?

Ubuntu 11.10 / JDK 1.5.0_22 / Weblogic Server 10

- Please provide any additional information below.

The attached URLType implementation try to resolve the problem with non-jar 
protocol ULRs for actual jar files. It is a fail-safe solution that suits 
weblogic implementation, intended as an additional default URLType.

PS: The solution is similar to the previous 0.9.5 version implementation.

Original issue reported on code.google.com by aquipor...@gmail.com on 1 Aug 2012 at 3:58

Attachments:

GoogleCodeExporter commented 8 years ago
Any updates on this issue? 
I am currently deploying a war in weblogic 10.3.5. and I assume I am having the 
same problem.
Weblogic compiles all the classes from WEB-INF\classes\ into 1 single jar.
When you instantiate Reflections it detecs the URL for that jar but can't find 
the classes in it. 

Original comment by oliveira...@gmail.com on 7 Sep 2012 at 3:25

GoogleCodeExporter commented 8 years ago
I've done the following.  First, I created a class VfsUtilExporter to export 
the getFile from package private to public.  I then added the following code 
before constructing Reflections:

        Vfs.addDefaultURLTypes(new Vfs.UrlType() {

            public boolean matches(URL url) {
                return "zip".equals(url.getProtocol());
            }

            public Dir createDir(final URL url) throws Exception {
                return new ZipDir(new JarFile(VfsUtilExporter.getFile(url)));
            } 

        });

Seems to work here so far...

Original comment by ja...@pollock.ca on 15 Oct 2012 at 8:25

GoogleCodeExporter commented 8 years ago
Jason, 

would you mind explaining what VfsUtilExporter.getFile is doing? I'm not sure I 
understood your comment 'export the getFile from package private to public'

I'm having the same issue with weblogic 10.3.5/6 and I'd like to try your 
solution before I give up and rewrite my annotations discovery code.

Many Thanks

Original comment by justinma...@googlemail.com on 30 Oct 2012 at 6:13

GoogleCodeExporter commented 8 years ago
I added this to my jar. :)  It wraps the getFile method, which is package 
private and makes it visible.

package org.reflections.vfs;

import java.net.URL;

/**
 * Export a single method from package private to public.
 */
public final class VfsUtilExporter {

    /** Default constructor, private because this is a utility class. */
    private VfsUtilExporter() { }

    /**
     * Call Vfs.getFile.
     * @param url The url to convert to a file.
     * @return The file represented by the URL.
     */
    public static java.io.File getFile(final URL url) {
        return Vfs.getFile(url);
    }

}

Original comment by ja...@pollock.ca on 30 Oct 2012 at 7:52

GoogleCodeExporter commented 8 years ago
:) duh...obviously going soft in the head after trying to (finally) migrate 
from OC4J to WebLogic

Thanks for quick response. I'll try what you've posted but I also found an 
alternative solution through spring utils which is OK for my app as it's Spring 
based.

http://www.docjar.com/html/api/org/springframework/util/ResourceUtils.java.html

It looks like it handles more edge cases than Vfs.getFile (weblogic, oc4j, 
websphere) so could be useful to other people experiencing a similar issue with 
those app servers where the Vfs solution won't necessarily work.

Thanks again, J

Original comment by justinma...@googlemail.com on 31 Oct 2012 at 3:13

GoogleCodeExporter commented 8 years ago
Just ran into the same problem, using the workaround documented here. I vote 
for an update of the reflections library. Maybe the UrlType should not be added 
to the defaultUrlTypes on behalf of the reflections library, but at least an 
implementation of some class ZipJarUrlType implements UrlType should be added 
to the reflections library so that it can easily be added to the 
defaultUrlTypes by the programmer when needed.

Original comment by post.at....@googlemail.com on 12 Dec 2012 at 1:05

GoogleCodeExporter commented 8 years ago
fixed on trunk, comments are welcomed

Original comment by ronm...@gmail.com on 20 Feb 2013 at 9:04

GoogleCodeExporter commented 8 years ago
Hi 

Using the reflections api (version 0.9.8) and ran into this issue when 
deploying on weblogic (it works fine when running on tomcat). Used the solution 
proivded by @pollock.ca and it works fine Thanks.

Could you let us know when a new version will be out since the issue has been 
fixed now in the trunk?

Thanks

O.

Original comment by OFad...@gmail.com on 25 Feb 2013 at 11:08

GoogleCodeExporter commented 8 years ago
I am also having this issue with weblogic, and I am pleased to read that this 
has been "fixed on trunk". 

Do you have a nightliy snapshot build somewhere, or do I need to download the 
source and compile it with my project?

Thanks for help
Stefan

Original comment by sniffert...@gmail.com on 4 Mar 2013 at 1:01

GoogleCodeExporter commented 8 years ago
Stefan,
for now only on the trunk. would you be kind and check if it works for you and 
comment here?

svn checkout http://reflections.googlecode.com/svn/trunk/ reflections
cd reflections
mvn install

Original comment by r...@jfrog.com on 4 Mar 2013 at 1:04

GoogleCodeExporter commented 8 years ago
Worked fine.
But you should put a snapshot build to a public nexus instance somewhere...

Thanks

Original comment by sniffert...@gmail.com on 7 Mar 2013 at 10:40

GoogleCodeExporter commented 8 years ago
Any update about uber jar containing this fix?

Original comment by he...@platfora.com on 22 Jul 2013 at 6:50

GoogleCodeExporter commented 8 years ago
Have created a workaround / fix for OC4J. 

Its on github: https://github.com/keesvandieren/reflections-oc4j

It depends on the Spring Framework to do some resource classloading for OC4J.

Original comment by keesvand...@gmail.com on 29 Jul 2013 at 6:55

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Handling the ZIP protocol worked for me.. thanks!

Original comment by dmanye...@gmail.com on 27 Sep 2013 at 2:06