Mantis - Resin
Viewing Issue Advanced Details
4215 major always 09-16-10 06:48 11-15-10 09:12
olaf2010  
ferg  
normal  
closed 4.0.10  
fixed  
none    
none 4.0.13  
0004215: Conflict between jersey and resin (and again, with example war)
Hello reza,

you are faster with closing bugs then me is able to attach some code sample. :-)

Its related to:

- http://bugs.caucho.com/view.php?id=4188 [^]

The "jerseytest.war" you can get from here (uploading to mantis failed)

- http://www.ecopatz.de/jerseytest.war.bz2 [^]

I have checked it against resin4.0.10 and resin-4.0.s100819 as well, downloaded just a few secs ago.

I put the "jerseytest.war" into webapps directory, started resin and called:

http://localhost:8080/jerseytest/ [^]

"Hello World" should be printed, but i get the NPE instead.

So far there are only 3 dependencies in the war and nothing else. Needless to say, with resin2.1.17 it works.

java.lang.NullPointerException
    at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactory.<init>(CDIComponentProviderFactory.java:94)
    at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer.initialize(CDIComponentProviderFactoryInitializer.java:75)
    at com.sun.jersey.spi.container.servlet.WebComponent.configure(WebComponent.java:554)
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.configure(ServletContainer.java:280)
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:586)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:213)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:342)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:516)
    at javax.servlet.GenericServlet.init(GenericServlet.java:70)
    at com.caucho.server.dispatch.ServletConfigImpl.createServletImpl(ServletConfigImpl.java:1318)
    at com.caucho.server.dispatch.ServletConfigImpl.createServlet(ServletConfigImpl.java:1168)
    at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:98)
    at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:183)
    at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:92)
    at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:286)
    at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:789)
    at com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:662)
    at com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:625)
    at com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:576)
    at com.caucho.network.listen.TcpSocketLink$AcceptTask.doTask(TcpSocketLink.java:1159)
    at com.caucho.network.listen.TcpSocketLink$ConnectionReadTask.runThread(TcpSocketLink.java:1092)
    at com.caucho.network.listen.TcpSocketLink$AcceptTask.run(TcpSocketLink.java:1126)
    at com.caucho.env.thread.ResinThread.runTasks(ResinThread.java:170)
    at com.caucho.env.thread.ResinThread.run(ResinThread.java:126)


I hope you can reproduce it as well.

Notes
(0004819)
olaf2010   
11-04-10 11:30   
Jersey does not use its init process with a "thread local" variable anymore. Since resin (and other container) do the init stuff in a different thread.

So, instead they store their stuff now in a JNDI context named:

"/com.sun.jersey.config/CDIExtension"

This causes trouble:

[10-11-04 19:22:01.920] {resin-16} javax.naming.NameNotFoundException: /com.sun.jersey.config/CDIExtension
                                       at com.caucho.naming.ContextImpl.rebind(ContextImpl.java:525)
                                       at javax.naming.InitialContext.rebind(InitialContext.java:408)
                                       at com.sun.jersey.server.impl.cdi.CDIExtension.initialize(CDIExtension.java:189)
                                       at com.sun.jersey.server.impl.cdi.CDIExtension.beforeBeanDiscovery(CDIExtension.java:257)

I have changed the name to "com.sun.jersey.config/CDIExtension", same exception.

As soon as i change the name to "CDIExtension" only, it works.

Can it be, that com.caucho.naming.ContextImpl.rebind(ContextImpl.java:525) has a problem with slashes in the name?
(0004820)
olaf2010   
11-04-10 11:43   
Ok, it seems, in JNDI the "/" character is special and needs to be quoted, if used. I guess then, this is a jersey bug at all.

Nonetheless the exception from resin is confusing, since its not a "NameNotFoundException", its rather the name itself, which is broken.
(0004821)
olaf2010   
11-04-10 11:45   
And finally, jersey project seems to be locked now. I can not even file a bug/patch there. Hm
(0004824)
ferg   
11-09-10 16:34   
The slash in JNDI isn't illegal, exactly. It's like a directory, and the application is supposed to create the parent context/directory.

It would be easy for us to change that behavior to automatically create the directory, but we'd need to double check the JNDI (or see if there's some reason that jersey is trying to create that context and we're not allowing it.)
(0004826)
olaf2010   
11-10-10 04:07   
Jersey has finally moved and i can submit bugs there

- http://java.net/jira/browse/JERSEY-601 [^]

They have an CDIExtension, which has a method:

  void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event) {...}

Thats also where they store the CDIExtension instance in the JNDI context. This is their second try to workaround for something else, that doesnt work:

They tried to lookup CDIExtension in:

Object beanManager = ic.lookup("java:comp/BeanManager");

The beanManager itself is not null, but there is never an instance of CDIExtension.
(0004832)
ferg   
11-12-10 10:57   
That definitely looks like a Jersey bug.

From the JNDI JavaDoc: rebind() "Binds a name to an object, overwriting any existing binding. All intermediate contexts and the target context (that named by all but terminal atomic component of the name) must already exist."

The error is because Jersey never creates the "com.sun.jersey.config" component (and I can't really change Resin to use a non-conforming JNDI context.)

There is a workaround for Jersey, though. Set the following system-property in the resin.xml:

<resin ...>
...
<system-property
   com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager="true"/>
(0004834)
olaf2010   
11-12-10 16:15   
Thank you for the advice. But this creates the "original" NPE for which they have had to create the JNDI workaround (or former thread-local). They cant find for any obscure reason their "CDIExtension" instance in the BeanManager. So they go the way over JNDI and save the instance in that "beforeBeanDiscovery" method. Where they fail with resin, due to this rebind things.

Well, ok, i will try to change the source code, so that /com.sun.jersey.config/CDIExtension will be created as necessary. Maybe they like what they see. So far no reaction on my report there.
(0004835)
ferg   
11-12-10 18:23   
Please try 4.0.13, because 4.0.10 is old and the 4.0.13 release is more recent than the snapshot.
(0004836)
olaf2010   
11-13-10 08:41   
Good news.

With resin 4.0.13 it works again, when setting the system property:

com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager="true"

With resin 4.0.10 it does not work. I just checked once more.

Whatever changes you guys did: Thank you.
(0004840)
ferg   
11-15-10 09:12   
thanks for the update. I'm closing this as fixed.