3

We're migrating an existing application to Spring Boot. The application in question (Genie) acts as a distributed, scalable client for data processing clusters like Hadoop or Presto. As such we need to output results of queries to disk and allow users access to their data. In the past we've done this by enabling directory listing in Tomcat where we would deploy our war and allowing users to browse and access their files using the DefaultServlet.

I tried exporting the directory using resource handlers like so:

@SpringBootApplication
public class GenieWeb extends WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter {

    // Other configuration

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        super.addResourceHandlers(registry);

        final String myExternalFilePath = "file:///path/to/dir/";

        registry
            .addResourceHandler("/urlPath/*")
            .setCachePeriod(0)
            .addResourceLocations(myExternalFilePath);
    }
}

This works fine when the URI of the resource is known but any request for a directory returns a 404. Ideally this would behave the same way the DefaultServlet in standalone Tomcat behaves when listings is set to true as an init parameter.

I've tried various ways to access the Tomcat configuration and the DefaultServlet in particular but have had no luck enabling directory listing via the typical "listing" property.

Excessive searching didn't turn up any results so I was curious if anyone knew if this was possible before I resign myself to going back to a WAR build or fronting with Apache. The main reason I don't want to do this is to make deploying our application as painless as possible and having everything self contained in one jar file has a lot of appeal.

Thanks in advance!

tgianos
  • 31
  • 1
  • 4
  • If Tomcat's DefaultServlet does the job, have you tried using it in your app with an appropriately configured ServletRegistrationBean? – Andy Wilkinson Dec 19 '15 at 07:25
  • 1
    @AndyWilkinson yes I tried that: `@Bean public ServletRegistrationBean servletRegistrationBean() { final DefaultServlet servlet = new DefaultServlet(); final ServletRegistrationBean bean = new ServletRegistrationBean(servlet, "/{location}/*"); bean.addInitParameter("listings", "true"); bean.setLoadOnStartup(1); return bean; }` However I see no way to map the URL to the location on disk in that API. I also tried configuring Tomcat factory to add webapp. `tomcat.addWebapp("/URL", "/location/on/disk");` No luck so far – tgianos Dec 21 '15 at 21:25
  • 1
    Refer to solution in the following [post](https://stackoverflow.com/questions/35004870/embedded-tomcat-directory-listing-for-spring-boot-application/46509688#46509688) – Raghavan Iyer Oct 01 '17 at 06:12

0 Answers0