Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Jetty from showing context related information

Tags:

jetty

I am using Jetty to deploy a production website. Let's assume my website is foo.com When I point my browser to a context which does not exist (say foo.com/notavailable), Jetty shows an error page with information of all the contexts which are deployed on it.

It looks something like this:

No context on this server matched or handled this request. Contexts known to this server are:

  • /test ---> org.mortbay.jetty.webapp.WebAppContext@6910fe28{/test,/root/webserver/jetty-6.1.4/webapps/test}

I want to prevent Jetty from showing this message because it contains the full path to the context on the server.

Is there a way to do this?

like image 781
Parag Avatar asked Nov 17 '10 07:11

Parag


People also ask

What is context path in Jetty?

The context path is the prefix of a URL path that is used to select the web application to which an incoming request is routed. Typically a URL in a Java servlet server is of the format http://hostname.com/contextPath/servletPath/pathInfo, where each of the path elements may be zero or more / separated elements.

How do I disable directory listing in Jetty?

To disable indexing/listing: If using the DefaultServlet (provided by default on a standard WebApp/WAR), you'll set the dirAllowed init-param to false. Alternatively, you'll edit your configured web descriptor default (usually declared as webdefault. xml) or your web descriptor override-web.

Where is the jetty XML file located?

jetty. xml is the default configuration file for Jetty, typically located at $JETTY_HOME/etc/jetty.


1 Answers

When configuring Jetty XML you can set showContexts to false on the DefaultHandler.

If you are using older Jetty versions replace org.eclipse.jetty on my example with the old org.mortbay.jetty package structure.

  <Configure id="Server" class="org.eclipse.jetty.server.Server">

  <!-- =========================================================== -->
  <!-- Set handler Collection Structure -->
  <!-- =========================================================== -->
  <Set name="handler">
    <!-- the collection of handlers that will handle the request -->
    <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
      <Set name="handlers">
        <Array type="org.eclipse.jetty.server.Handler">
          <!-- primarily handles the request and maps the request to a ContextHandler -->
          <Item>
            <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
          </Item>

          <!-- The default handler ... handles the request if not yet handled -->
          <Item>
            <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
          </Item>

          <!-- The handler for your request logs -->
          <Item>
            <New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/>
          </Item>
        </Array>
      </Set>
    </New>
  </Set>

  <!-- ===================== -->
  <!-- DefaultHandler config -->
  <!-- ===================== -->

  <Ref id="DefaultHandler">
    <Set name="showContexts">false</Set>
  </Ref>

</Configure>

Maybe you'll also be wanting to prevent directory browsing configuring the DefaultServlet of your web.xml,

  <servlet>
    <servlet-name>default</servlet-name>
    <servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
    <init-param>
      <param-name>dirAllowed</param-name>
      <param-value>false</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>
like image 98
theTestTube Avatar answered Oct 01 '22 21:10

theTestTube