Directory listing vs welcomeServlet issue in Jetty 8

578 Views Asked by At

We have a servlet 3 Spring MVC web application deployed on Tomcat in production.

The application (with minor tweaking) should also be able to run on Jetty 8. Currently this is only used in dev - environment and primarily for integration-testing on dev machines.

On our CI-system the war is deployed on Tomcat and the application is working and passing all tests.

When running on Jetty 8 all tests that GET a url ending in / will fail, because a directory listing is returned rather than the welcome-file.

To work around this we tried disallowing dir listing by configuring the Jetty DefaultServlet:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">

<!-- Configure Jetty DefaultServlet to disallow dir listing and explicitly allow welcomeservlets (a welcomeservlet in jetty terms is a <welcome-file> tag in web.xml that is pointing to a URI(file name) matched by a servlet)
    NOTE: all init-params supported by org.eclipse.jetty.servlet.DefaultServlet can be set directly on the WebAppContext using setInitParameter and prefixing the init-param with  'org.eclipse.jetty.servlet.Default.' - e.g. 'org.eclipse.jetty.servlet.Default.dirAllowed'
-->
<Call name="setInitParameter">
    <Arg>org.eclipse.jetty.servlet.Default.dirAllowed</Arg>
    <Arg>false</Arg>
</Call>
<Call name="setInitParameter">
    <Arg>org.eclipse.jetty.servlet.Default.welcomeServlets</Arg>
    <Arg>true</Arg>
</Call>
<Call name="setInitParameter">
    <Arg>org.eclipse.jetty.servlet.Default.redirectWelcome</Arg>
    <Arg>true</Arg>
</Call>

And referencing that from our pom:

<plugin>
                        <groupId>org.mortbay.jetty</groupId>
                        <artifactId>jetty-maven-plugin</artifactId>
                        <version>${jetty.maven.plugin.version}</version>
                        <configuration>
                            <contextXml>${basedir}/src/test/resources/jetty-context.xml</contextXml>
                        ...
                        </configuration>
</plugin>

However now we get 404 not found when GET /citizen/ is performed by a test. If we manually add index.html to the URL the file is served just fine by our Spring static resource-handler.

Are there more init-params I can set on Jetty to make it behave like Tomcat does regarding the welcome-file?

0

There are 0 best solutions below