eclipse-ee4j / eclipse-ee4j/jersey
Stuck in loop in ResourceConfig.scanClasses
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I'm new with Jersey and I'm trying to run a jersey/grizzley based server in the Apache Karaf OSGI container.
In short, I have a resource directory with static files (well, only one so far) in the JAR. When ResourceConfig scans, it gets stuck in an infinite loop on this directory.
In long:
I have a pretty basic project, which fails to load. The relevant code is more or less from the tutorials:
```
log.info("Hello, starting!");
final ResourceConfig rc = new ResourceConfig().packages("testproject");
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
```
I use basic iPOJO component to get something runnable.
In addition, i have a directory with static files under "testproject/www".
During component activation, I get stuck inside createHttpServer forever:
```
Name: [iPOJO] pool-1-thread-1
State: RUNNABLE
Total blocked: 9 Total waited: 3
Stack trace:
org.glassfish.jersey.server.ResourceConfig.scanClasses(ResourceConfig.java:905)
org.glassfish.jersey.server.ResourceConfig._getClasses(ResourceConfig.java:849)
org.glassfish.jersey.server.ResourceConfig.getClasses(ResourceConfig.java:755)
org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.(ResourceConfig.java:1184)
org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.(ResourceConfig.java:1157)
org.glassfish.jersey.server.ResourceConfig.createRuntimeConfig(ResourceConfig.java:1153)
org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:322)
org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:289)
org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.(GrizzlyHttpContainer.java:331)
org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:119)
asd.Main.startServer(Main.java:55)
asd.Main.__M_start(Main.java:89)
asd.Main.start(Main.java)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.apache.felix.ipojo.util.Callback.call(Callback.java:237)
org.apache.felix.ipojo.util.Callback.call(Callback.java:193)
org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallback.call(LifecycleCallback.java:86)
org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__M_stateChanged(LifecycleCallbackHandler.java:162)
org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.stateChanged(LifecycleCallbackHandler.java)
org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:560)
org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:440)
org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:179)
org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:319)
- locked org.apache.felix.ipojo.ComponentFactory@46737f42
org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:240)
org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:312)
org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:306)
org.apache.felix.ipojo.extender.internal.queue.JobInfoCallable.call(JobInfoCallable.java:114)
java.util.concurrent.FutureTask.run(FutureTask.java:262)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:745)
```
This was on jersey 2.15\. I tried master, same issue. Modified the code a bit to see what's going on (patch against master):
```
index edc3c24..bd52cbd 100644
--- a/core-server/src/main/java/org/glassfish/jersey/server/ResourceConfig.java
+++ b/core-server/src/main/java/org/glassfish/jersey/server/ResourceConfig.java
@@ -887,6 +887,7 @@ public class ResourceConfig extends Application implements Configurable " + rfs);
final InputStream in = resourceFinder.open();
try {
afl.process(next, in);
@@ -894,12 +895,14 @@ public class ResourceConfig extends Application implements Configurable " + rfs);
}
}
```
This gives me the following output:
```
2015-02-12 14:42:15,170 | INFO | pool-1-thread-1 | Main | 146 - testproject - 1.0.0.SNAPSHOT | Hello, starting!
2015-02-12 14:42:15,170 | INFO | pool-1-thread-1 | ResourceConfig | 269 - org.glassfish.jersey.core.jersey-server - 2.16.0.SNAPSHOT | Not loading resource /asd/www/ from finder class java.util.HashSet -> [org.glassfish.jersey.server.internal.scanning.PackageNamesScanner@23b9b99d]
2015-02-12 14:42:15,170 | INFO | pool-1-thread-1 | ResourceConfig | 269 - org.glassfish.jersey.core.jersey-server - 2.16.0.SNAPSHOT | Not loading resource /asd/www/ from finder class java.util.HashSet -> [org.glassfish.jersey.server.internal.scanning.PackageNamesScanner@23b9b99d]
2015-02-12 14:42:15,171 | INFO | pool-1-thread-1 | ResourceConfig | 269 - org.glassfish.jersey.core.jersey-server - 2.16.0.SNAPSHOT | Not loading resource /asd/www/ from finder class java.util.HashSet -> [org.glassfish.jersey.server.internal.scanning.PackageNamesScanner@23b9b99d]
```
And on it goes.. forever, until JVM is killed. So, for some reason the ResourceFinder keeps giving me that directory over and over.
If i remove the www directory from my package, everything starts up perfectly fine.
As a side note, to anyone else trying to get OSGI/Jersey working: I kept getting the following exception:
```
java.lang.IllegalStateException: No generator was provided and there is no default generator registered
at org.glassfish.hk2.internal.ServiceLocatorFactoryImpl.internalCreate(ServiceLocatorFactoryImpl.java:266)
at org.glassfish.hk2.internal.ServiceLocatorFactoryImpl.create(ServiceLocatorFactoryImpl.java:230)
at org.glassfish.jersey.internal.inject.Injections._createLocator(Injections.java:138)
at org.glassfish.jersey.internal.inject.Injections.createLocator(Injections.java:123)
at org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:308)
at org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:289)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.(GrizzlyHttpContainer.java:331)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:119)
```
until I ensured that org.glassfish.hk2.locator was installed. In my maven-bundle-plugin instructions I added "<_include>src/main/resources/bundle.osgi", which contains "Require-Bundle: org.glassfish.hk2.locator".
Is there any better way to do this? Require-bundle seems non-recommended..
#### Environment
Jersey 2.15, and 2bc1fcb
Apache Karaf 3.0.3
#### Affected Versions
[2.15, 2.16]
Contributor guide
Assessment
This issue has not been assessed yet.