Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-dev] Servlet Initialization in Jetty 9.0.2

Gunnar,

The ServletHolder.doStart() method used to call Servlet.init(). There was a change to add a new method on ServletHolder called initialize() that did it instead. This method is invoked from the ServletHandler.initialize() method, around line 744 for 9.0.2 source. ServletHandler.initialize() can be called from a number of different places, one of them is ServletContextHandler.startContext(), see line 278 of the 9.0.2 source - check that your subclass is calling ServletHandler.initialize().

cheers
Jan


On 17 May 2013 15:14, Gunnar Wagenknecht <gunnar@xxxxxxxxxxxxxxx> wrote:

Hi Jan,


That's not an issue. There is no NPE at this place. The ApplicationContext is created within ApplicationHandler#startContext too. Right before the ApplicationServletHandler. Thus, it's never null when this code is used.


The issue really is that the Servlet#init method of any servlet being registered is not called anymore. It has been called in 9.0.0 but not in 9.0.2.


-Gunnar


On 2013-05-17 02:30:48 +0000, Jan Bartel said:


Gunnar,


The ServletHandler (in your case ApplicationServletHandler) is only created in ApplicationHandler.startContext(). So, if the ApplicationHandler has not been started, the ApplicationServletHandler does not exist, and so ApplicationContext line 310 should throw a null pointer when you try to add a ServletHolder.  Any reason why you can't create the ApplicationServletHandler in the constructor of ApplicationHandler - or maybe even better - override ServletContextHandler.newServletHandler() to return an instance of your ApplicationServletHandler class instead?


Jan



On 17 May 2013 11:52, Jan Bartel <janb@xxxxxxxxxxx> wrote:

Thanks Gunnar,


Looking at the code you provided the link to now. Do you have any output of a run with logging level DEBUG enabled?


thanks

Jan



On 17 May 2013 10:33, Gunnar Wagenknecht <gunnar@xxxxxxxxxxxxxxx> wrote:

On 2013-05-16 23:07:18 +0000, Jan Bartel said:


Can you post the code that sets up the servlets?  There were some changes to jetty-9 about how the holders are started, but I wouldn't have thought it could affect you, but if you post the code, then I'll have a better idea.


It's here:

http://git.eclipse.org/c/gyrex/gyrex-platform.git/tree/bundles/org.eclipse.gyrex.http.jetty/src/org/eclipse/gyrex/http/jetty/internal/app/ApplicationContext.java 


Starting at line 304.


// create holder

final ServletHolder holder = new ServletHolder(servletClass);

if (null != initparams) {

        holder.setInitParameters(initparams);

}


// register servlet

applicationHandler.getServletHandler().addServletWithMapping(holder, pathSpec);



With Jetty 8 I had to do the following as well, because Jetty did not start the holders when the handler was already started.


if (applicationHandler.getServletHandler().isStarted() || applicationHandler.getServletHandler().isStarting()) {

try {

        holder.start();

} catch (final Exception e) {

        …

}






-Gunnar





-- 

Gunnar Wagenknecht

gunnar@xxxxxxxxxxxxxxx



_______________________________________________

jetty-dev mailing list

jetty-dev@xxxxxxxxxxx

https://dev.eclipse.org/mailman/listinfo/jetty-dev




-- 

Jan Bartel <janb@xxxxxxxxxxx>

www.webtide.com – Developer advice, services and support 

from the Jetty & CometD experts.




-- 

Jan Bartel <janb@xxxxxxxxxxx>

www.webtide.com – Developer advice, services and support 

from the Jetty & CometD experts.

_______________________________________________

jetty-dev mailing list

jetty-dev@xxxxxxxxxxx

https://dev.eclipse.org/mailman/listinfo/jetty-dev



-- 

Gunnar Wagenknecht

gunnar@xxxxxxxxxxxxxxx


_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-dev




--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com – Developer advice, services and support
from the Jetty & CometD experts.

Back to the top