How to prevent ServletHandler$Default404Servlet from being added

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to prevent ServletHandler$Default404Servlet from being added

Lothar Kimmeringer
Hi,

I updated from Jetty 9.0.x to 9.2.x and (as always) run into problems.
All ServletHandlers seem to be created with a default servlet
org.eclipse.jetty.servlet.ServletHandler$Default404Servlet

Problem is that I've got a configuration where there are files
residing on the file system with URL /xyz/abc/...
and a servlet that should be accessible via URL /xyz/def/...
With 9.2.9 I now receive a 404 when trying to access resources
at /xyz/abc.

How can I get back to the behavior the way it was with all
versions up to 9.0 (I skipped 9.1 so maybe the same happens
there already).


Best regards,

Lothar
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: How to prevent ServletHandler$Default404Servlet from being added

Joakim Erdfelt-9
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)

--
Joakim Erdfelt <[hidden email]>
Expert advice, services and support from from the Jetty & CometD experts

On Fri, Mar 27, 2015 at 6:27 AM, Lothar Kimmeringer <[hidden email]> wrote:
Hi,

I updated from Jetty 9.0.x to 9.2.x and (as always) run into problems.
All ServletHandlers seem to be created with a default servlet
org.eclipse.jetty.servlet.ServletHandler$Default404Servlet

Problem is that I've got a configuration where there are files
residing on the file system with URL /xyz/abc/...
and a servlet that should be accessible via URL /xyz/def/...
With 9.2.9 I now receive a 404 when trying to access resources
at /xyz/abc.

How can I get back to the behavior the way it was with all
versions up to 9.0 (I skipped 9.1 so maybe the same happens
there already).


Best regards,

Lothar
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: How to prevent ServletHandler$Default404Servlet from being added

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?


Cheers, Lothar
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: How to prevent ServletHandler$Default404Servlet from being added

Lothar Kimmeringer
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
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: How to prevent ServletHandler$Default404Servlet from being added

Jan Bartel-3
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 <[hidden email]> 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
> [hidden email]
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/jetty-users



--
Jan Bartel <[hidden email]>
www.webtide.com
'Expert Jetty/CometD developer,production,operations advice'
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: How to prevent ServletHandler$Default404Servlet from being added

Lothar Kimmeringer
Am 08.05.2015 um 01:23 schrieb Jan Bartel:

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

sorry. I thought the question Joakim asked me was enough as
clarification.

> 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);
>
[...]

> 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.

Thanks for that. The difference to my application is that the
main server configuration comes from the config-XML-file and
the e.g. AS2Server is accessing the server after its startup
and tries to add its own servlet. So the code looks something
like this:

            Server hs = null;
            hs = Server.getServer(_serverName);
            if (hs == null){
                logSystemError("HTTP-Server with name '" + _serverName + "' not found");
                return;
            }
            Handler handler = hs.getChildHandlerByClass(ContextHandlerCollection.class);
            if (handler == null){
                logSystemError("Unable to install servlet. The server contains no ContextHandlerCollection");
                return;
            }
            ContextHandlerCollection coll = (ContextHandlerCollection) handler;
            Handler[] schs = hs.getChildHandlersByClass(ServletContextHandler.class);
            if (schs == null){
                schs = new Handler[0];
            }
            ServletContextHandler hc = null;
            for (int i = 0; i < schs.length; i++){
                hc = (ServletContextHandler) schs[i];
                if (hc.getContextPath().equals(_contextName)){
                    break;
                }
            }
            if (hc == null){
                hc = new ServletContextHandler(ServletContextHandler.SESSIONS);
                hc.setContextPath(_contextName);
                coll.addHandler(hc);
            }
            logSystemMessage("Adding servlet to context");
            ServletHolder holder = new ServletHolder();
            holder.setClassName(AS2MessageReceiveServlet.class.getName());
            holder.setName("AS2ReceiveServlet");
            hc.addServlet(holder, _pathSpec);
            try{
                Server.removeDefault404Servlet(hc.getServletHandler());
            }
            catch(ServletException se){
                logSystemError("unable to remove default servlet", se);
            }

Your example needs a stopped server where in my case the server
is already started. In that case the Default404Servlet is already
added before I'm able to add my own. Before I ended up with the
code above (especially the call of removeDefault404Servlet at
the end) I tried a couple of things but always ended up in a
dead end.


Cheers, Lothar
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users