bootique / bootique-jetty

Provides Jetty integration with Bootique

Home Page:https://bootique.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unified API for mapping static servlets

andrus opened this issue · comments

(jakarta only)

Currently, to map a "static" servlet, i.e. the one serving files instead of dynamic content, one needs to configure it in the code first, and then also specify the directory mapping in configuration:

JettyModule.extend(binder).useDefaultServlet();
jetty:
  staticResourceBase: "classpath:com/example/docroot"

In theory, that allows to point the app to an arbitrary folder on the filesystem, but very often we are dealing with "classpath:" folders that are known upfront, and it would be great to be able to specify those right in the code (so we'd normally resort to BQCoreModule.extend(..).setProperty(..)). Let's devise a more straightforward unified API for this case, but preserving all the existing configuration options, and the ability to override stuff from parameters. E.g.:

// no more arbitrary distinction between "default" static servlet and other static servlets
MappedServlet<?> ss = MappedServlet
  .ofStatic("/")

  // optional, the default is taken from "jetty.staticResourceBase" config
  // or from "jetty.servlets.[name].params.resourceBase" (the latter one, if present, will override this value)
  .resourceBase("classpath:com/example/docroot")

  // optional, default is false
  .pathInfoOnly()

  // optional name. Only needed if we expect servlet params to be passed in config
  .name("default")
  .build();

JettyModule.extend(binder).addMappedServlet(ss);

This will deprecate addStaticServlet(String name, String... urlPatterns) and useDefaultServlet()