Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] How to prevent ServletHandler$Default404Servlet from being added

Hi Lothar,

The thing is, you haven't really provided enough information for
anyone to determine exactly what is going wrong for you.

Maybe this will help you. I've modified one of the standard embedded
examples (original here:
https://github.com/eclipse/jetty.project/blob/master/examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneServletContext.java)
to show what happens to the configuration of the ServletHandler at
various stages:

        Server server = new Server(8080);

        ServletContextHandler context = new ServletContextHandler(
                ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        context.setResourceBase(System.getProperty("java.io.tmpdir"));
        server.setHandler(context);

        System.err.println(context.getServletHandler().isEnsureDefaultServlet());
        System.err.println(context.getServletHandler().getServletMapping("/"));
        // Add dump servlet
        context.addServlet(DumpServlet.class, "/dump/*");
        // Add default servlet
        //context.addServlet(DefaultServlet.class, "/");
        System.err.println(context.getServletHandler().isEnsureDefaultServlet());
        System.err.println(context.getServletHandler().getServletMapping("/"));
        server.start();
        System.err.println(context.getServletHandler().isEnsureDefaultServlet());
        System.err.println(context.getServletHandler().getServletMapping("/"));
        server.join();

As you can see, if there is no servlet mapped to "/", then the
ServletHandler will instantiate a ServletHandler.Default404Servlet.
If, however, you provide a mapping yourself, that is used instead.
Maybe you can use the above to verify against your setup.

regards
Jan


On 28 March 2015 at 01:35, Lothar Kimmeringer <job@xxxxxxxxxxxxxx> wrote:
> Am 27.03.2015 um 14:51 schrieb Lothar Kimmeringer:
>> Am 27.03.2015 um 14:45 schrieb Joakim Erdfelt:
>>> You are using ServletContextHandler and its various .addServlet() methods, right?
>>> You really shouldn't be using ServletHandler directly (that's an internal class
>>> for ServletContextHandler)
>>
>> I'm calling servletContextHandler.addServlet(servletHolder, pathSpec)
>>
>> So the answer is, no?
>
> So is there a way to prevent the default404-servlet from being added?
> As far as I can see, I don't use any internal APIs for the adding of
> servlets. By looking into ServletHandler I see that there is a method
> servletHandler.setEnsureDefaultServlet, that allows to disable that
> functionality, but it seems to never been called within Jetty and
> setting it for myself would contradict your statement that the class
> is internal. When I call getServletHandler before I add a servlet
> myself, the result is null. When I call it after adding the servlet,
> the default servlet is already added.
>
> I more and more see that as a bug. This feature breaks existing
> setups and can't be changed without using internal classes you
> discourage using.
>
>
> Cheers, Lothar
> _______________________________________________
> jetty-users mailing list
> jetty-users@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/jetty-users



-- 
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
'Expert Jetty/CometD developer,production,operations advice'


Back to the top