Ejemplo n.º 1
0
  public static void main(final String[] args) {
    try {

      DeploymentInfo servletBuilder =
          deployment()
              .setClassLoader(ServletServer.class.getClassLoader())
              .setContextPath(MYAPP)
              .setDeploymentName("test.war")
              .addServlets(
                  servlet("MessageServlet", MessageServlet.class)
                      .addInitParam("message", "Hello World")
                      .addMapping("/*"),
                  servlet("MyServlet", MessageServlet.class)
                      .addInitParam("message", "MyServlet")
                      .addMapping("/myservlet"));

      DeploymentManager manager = defaultContainer().addDeployment(servletBuilder);
      manager.deploy();

      HttpHandler servletHandler = manager.start();
      PathHandler path =
          Handlers.path(Handlers.redirect(MYAPP)).addPrefixPath(MYAPP, servletHandler);
      Undertow server = Undertow.builder().addListener(8080, "localhost").setHandler(path).build();
      server.start();
    } catch (ServletException e) {
      throw new RuntimeException(e);
    }
  }
Ejemplo n.º 2
0
 @BeforeClass
 public static void setup() {
   DefaultServer.setRootHandler(
       new PathHandler()
           .addPrefixPath(
               "/target",
               new HttpHandler() {
                 @Override
                 public void handleRequest(HttpServerExchange exchange) throws Exception {
                   message = exchange.getRequestURI();
                 }
               })
           .addPrefixPath(
               "/",
               predicateContext(
                   predicate(
                       Predicates.regex(
                           "%{REQUEST_URL}",
                           "/(aa.*?)c", RedirectTestCase.class.getClassLoader(), false),
                       Handlers.redirect("/target/matched/${1}"),
                       Handlers.redirect("/target%U")))));
 }