Search in sources :

Example 1 with NginxArtifactServlet

use of com.datastax.fallout.service.artifacts.NginxArtifactServlet in project fallout by datastax.

the class FalloutServiceBase method addArtifactServlet.

private static void addArtifactServlet(FalloutConfiguration conf, Environment environment, RewriteHandler rewriteHandler) {
    Function<Path, Servlet> createArtifactServlet = conf.useNginxToServeArtifacts() ? NginxArtifactServlet::new : JettyArtifactServlet::new;
    final ServletRegistration.Dynamic registration = environment.servlets().addServlet("artifacts-servlet", createArtifactServlet.apply(Paths.get(conf.getArtifactPath())));
    registration.addMapping("/artifacts/*");
    // Redirect direct requests to the artifacts servlet URL to make sure users see (and share) the right path
    // in the browser; fallout used to make these URLs public, so some will have been shared in tickets etc.,
    // which means we should carry on handling them.
    rewriteHandler.addRule(new RedirectRegexRule("/artifacts/" + "(" + AccountResource.EMAIL_PATTERN + ")/" + "(" + TestResource.NAME_PATTERN + ")/" + "(" + TestResource.ID_PATTERN + ")/" + "(.*)", "/tests/ui/$1/$2/$3/artifacts/$4"));
    // Rewrite artifacts requests so that they're handled by the artifacts servlet
    rewriteHandler.addRule(new RewriteRegexRule("/tests/ui/" + "(" + AccountResource.EMAIL_PATTERN + ")/" + "(" + TestResource.NAME_PATTERN + ")/" + "(" + TestResource.ID_PATTERN + ")/" + "artifacts/(.+)", "/artifacts/$1/$2/$3/$4"));
    environment.servlets().addMimeMapping("log", "text/plain; charset=UTF-8");
}
Also used : Path(java.nio.file.Path) ServletRegistration(javax.servlet.ServletRegistration) RewriteRegexRule(org.eclipse.jetty.rewrite.handler.RewriteRegexRule) NginxArtifactServlet(com.datastax.fallout.service.artifacts.NginxArtifactServlet) Servlet(javax.servlet.Servlet) JettyArtifactServlet(com.datastax.fallout.service.artifacts.JettyArtifactServlet) JettyArtifactServlet(com.datastax.fallout.service.artifacts.JettyArtifactServlet) NginxArtifactServlet(com.datastax.fallout.service.artifacts.NginxArtifactServlet) RedirectRegexRule(org.eclipse.jetty.rewrite.handler.RedirectRegexRule)

Aggregations

JettyArtifactServlet (com.datastax.fallout.service.artifacts.JettyArtifactServlet)1 NginxArtifactServlet (com.datastax.fallout.service.artifacts.NginxArtifactServlet)1 Path (java.nio.file.Path)1 Servlet (javax.servlet.Servlet)1 ServletRegistration (javax.servlet.ServletRegistration)1 RedirectRegexRule (org.eclipse.jetty.rewrite.handler.RedirectRegexRule)1 RewriteRegexRule (org.eclipse.jetty.rewrite.handler.RewriteRegexRule)1