dev@glassfish.java.net

Re: addServlet question (glassfish v3)

From: Jan Luehe <Jan.Luehe_at_Sun.COM>
Date: Thu, 18 Jun 2009 11:46:56 -0700

On 06/15/09 10:26 AM, Sahoo wrote:
> Sounds like a bug to me. Pl. file an issue.

I'm unable to reproduce the issue with the latest build.
Reik, which version of GlassFish are you using?

There may have been an issue in the past, but it has been fixed
in the meantime.

We actually have a unit test for this very feature, see

https://svn.dev.java.net/svn/glassfish-svn/trunk/v2/appserv-tests/devtests/web/servlet-3.0/servletContextAddServletAndFilterByInstance

which instantiates, configures, and registers a servlet, and then checks
to make sure
that the custom configuration is available when the servlet is accessed.


Jan


> Reik Schatz wrote:
>> I am using the servletContext.addServlet method that was added in
>> Servlet 3.0 to dynamically add a new servlet. I wrote a
>> ServletContextListener and in the contextInitialized method, I
>> instantiate, initialize and add the Servlet. I expected that
>> Glassfish would use this instance when serving requests mapped to the
>> servlet. But this is not the case. Glassfish will create another
>> instance instead. It looks like it does that when I request the URL
>> path and a Thread is picked from the ThreadPool to handle the
>> request. This is a bit unfortunate since the new instance lacks my
>> manual initialization.
>>
>> Why does Glassfish instantiate another object when I call
>> servletContext.addServlet(String, Servlet) with a pre-intantiated
>> Servlet?
>> /Reik
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>