Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instantiating JavaBackend inside a Weblogic 10 application fails #808

Closed
ruifigueira opened this issue Dec 12, 2014 · 3 comments
Closed

Comments

@ruifigueira
Copy link
Contributor

I'm experiencing the following error when I try to instanciate a JavaBackend inside a webapp deployed in Weblogic 10:

Caused by: java.lang.IllegalArgumentException: Not a file or directory: /opt/apps/test-webapp/WEB-INF/lib/cucumber-core-1.2.0.jar!/cucumber/api
  at cucumber.runtime.io.FileResourceIterator$FileIterator.<init>(FileResourceIterator.java:54) ~[cucumber-core-1.2.0.jar:na]
  at cucumber.runtime.io.FileResourceIterator.<init>(FileResourceIterator.java:20) ~[cucumber-core-1.2.0.jar:na]
  at cucumber.runtime.io.FileResourceIteratorFactory.createIterator(FileResourceIteratorFactory.java:37) ~[cucumber-core-1.2.0.jar:na]
  at cucumber.runtime.io.ZipThenFileResourceIteratorFallback.createIterator(ZipThenFileResourceIteratorFallback.java:41) ~[cucumber-core-1.2.0.jar:na]
  at cucumber.runtime.io.DelegatingResourceIteratorFactory.createIterator(DelegatingResourceIteratorFactory.java:64) ~[cucumber-core-1.2.0.jar:na]
  at cucumber.runtime.io.ClasspathIterable.iterator(ClasspathIterable.java:34) ~[cucumber-core-1.2.0.jar:na]
  at cucumber.runtime.io.ResourceLoaderClassFinder.getDescendants(ResourceLoaderClassFinder.java:22) ~[cucumber-core-1.2.0.jar:na]
  at cucumber.runtime.java.MethodScanner.findCucumberAnnotationClasses(MethodScanner.java:75) ~[cucumber-java-1.2.0.jar:na]
  at cucumber.runtime.java.MethodScanner.<init>(MethodScanner.java:23) ~[cucumber-java-1.2.0.jar:na]
  at cucumber.runtime.java.JavaBackend.<init>(JavaBackend.java:43) ~[cucumber-java-1.2.0.jar:na]

After some debugging, I found out that the ClassLoader willl return classpath resources with zip protocol instead of jar, so when we run the following code there we'll get Protocol=zip:

Enumeration<URL> resources = cl.getResources("cucumber/api");
while (resources.hasMoreElements()) {
  URL url = (URL) resources.nextElement();
  System.out.printf("[Protocol=%s]  %s\n", url.getProtocol()", url.toString());
}

This will then affect ZipThenFileResourceIteratorFallback because it won't use a ZipResourceIteratorFactoryto scan those resources. ZipResourceIteratorFactory.isFactoryFor method is defined as:

@Override
public boolean isFactoryFor(URL url) {
    return "jar".equals(url.getProtocol());
}
@ruifigueira
Copy link
Contributor Author

I forgot to mention the JVM:

java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Oracle JRockit(R) (build R28.2.5-20-152429-1.6.0_37-20120927-1915-linux-x86_64, compiled mode)

@ruifigueira
Copy link
Contributor Author

Looking at Spring code, they actually handle zip protocol URLs:

/**
 * Determine whether the given URL points to a resource in a jar file,
 * that is, has protocol "jar", "zip", "vfszip" or "wsjar".
 * @param url the URL to check
 * @return whether the URL has been identified as a JAR URL
 */
public static boolean isJarURL(URL url) {
  String protocol = url.getProtocol();
  return (URL_PROTOCOL_JAR.equals(protocol) || URL_PROTOCOL_ZIP.equals(protocol) ||
      URL_PROTOCOL_VFSZIP.equals(protocol) || URL_PROTOCOL_WSJAR.equals(protocol));
}

Source:
https://github.com/spring-projects/spring-framework/blob/33d85d2a134c93deb4452e112fb2f86ff751467b/spring-core/src/main/java/org/springframework/util/ResourceUtils.java#L277

ruifigueira added a commit to ruifigueira/cucumber-jvm that referenced this issue Dec 25, 2014
@dkowis dkowis closed this as completed in cfd70af Jan 8, 2015
dkowis added a commit that referenced this issue Jan 8, 2015
Handles zip and wsjar protocols properly (fixes #808)
@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant