コード例 #1
0
  @Test
  public void testBasicPathHanding() throws IOException {
    TestHttpClient client = new TestHttpClient();
    try {
      final PathHandler handler = new PathHandler();
      handler.addPath("a", new RemainingPathHandler("/a"));
      handler.addPath("/aa", new RemainingPathHandler("/aa"));
      handler.addPath("/aa/anotherSubPath", new RemainingPathHandler("/aa/anotherSubPath"));

      final PathHandler sub = new PathHandler();

      handler.addPath("/path", sub);
      sub.addPath("/subpath", new RemainingPathHandler("/subpath"));
      sub.setDefaultHandler(new RemainingPathHandler("/path"));

      DefaultServer.setRootHandler(handler);

      HttpGet get = new HttpGet(DefaultServer.getDefaultServerAddress() + "/notamatchingpath");
      HttpResponse result = client.execute(get);
      Assert.assertEquals(404, result.getStatusLine().getStatusCode());
      HttpClientUtils.readResponse(result);

      get = new HttpGet(DefaultServer.getDefaultServerAddress() + "/");
      result = client.execute(get);
      Assert.assertEquals(404, result.getStatusLine().getStatusCode());
      HttpClientUtils.readResponse(result);

      runPathTest(client, "/path", "/path", "");
      runPathTest(client, "/path/a", "/path", "/a");
      runPathTest(client, "/path/subpath", "/subpath", "");
      runPathTest(client, "/path/subpath/", "/subpath", "/");
      runPathTest(client, "/path/subpath/foo", "/subpath", "/foo");
      runPathTest(client, "/a", "/a", "");
      runPathTest(client, "/aa/anotherSubPath", "/aa/anotherSubPath", "");
      runPathTest(client, "/aa/anotherSubPath/bob", "/aa/anotherSubPath", "/bob");
      runPathTest(client, "/aa?a=b", "/aa", "", Collections.singletonMap("a", "b"));

    } finally {
      client.getConnectionManager().shutdown();
    }
  }
コード例 #2
0
  private void deployServlet(final ServerWebSocketContainer deployment) throws ServletException {

    final DeploymentInfo builder;
    builder =
        new DeploymentInfo()
            .setClassLoader(getClass().getClassLoader())
            .setContextPath("/")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("websocket.war")
            .addFilter(new FilterInfo("filter", JsrWebSocketFilter.class))
            .addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST)
            .addServletContextAttribute(
                javax.websocket.server.ServerContainer.class.getName(), deployment);

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
  }
コード例 #3
0
  private static void setupOpenListener(
      HttpOpenListener listener,
      ModelController modelController,
      ConsoleMode consoleMode,
      String consoleSlot,
      ControlledProcessStateService controlledProcessStateService,
      int securePort,
      SecurityRealm securityRealm,
      final ChannelUpgradeHandler upgradeHandler) {

    CanonicalPathHandler canonicalPathHandler = new CanonicalPathHandler();
    listener.setRootHandler(canonicalPathHandler);

    PathHandler pathHandler = new PathHandler();
    HttpHandler current = pathHandler;
    if (securePort > 0) {
      current = new SinglePortConfidentialityHandler(current, securePort);
    }
    // caching handler, used for static resources
    current =
        new CacheHandler(
            new DirectBufferCache(
                1024, 1024 * 10, 1024 * 1000, BufferAllocator.BYTE_BUFFER_ALLOCATOR),
            current);
    current = new SimpleErrorPageHandler(current);

    if (upgradeHandler != null) {
      upgradeHandler.setNonUpgradeHandler(current);
      current = upgradeHandler;
    }
    canonicalPathHandler.setNext(current);

    ResourceHandlerDefinition consoleHandler = null;
    try {
      consoleHandler = consoleMode.createConsoleHandler(consoleSlot);
    } catch (ModuleLoadException e) {
      ROOT_LOGGER.consoleModuleNotFound(consoleSlot == null ? "main" : consoleSlot);
    }

    try {
      pathHandler.addPath(
          ErrorContextHandler.ERROR_CONTEXT, ErrorContextHandler.createErrorContext(consoleSlot));
    } catch (ModuleLoadException e) {
      ROOT_LOGGER.error(consoleSlot == null ? "main" : consoleSlot);
    }

    ManagementRootConsoleRedirectHandler rootConsoleRedirectHandler =
        new ManagementRootConsoleRedirectHandler(consoleHandler);
    DomainApiCheckHandler domainApiHandler =
        new DomainApiCheckHandler(modelController, controlledProcessStateService);
    pathHandler.addPath("/", rootConsoleRedirectHandler);
    if (consoleHandler != null) {
      HttpHandler readinessHandler =
          new RedirectReadinessHandler(
              securityRealm, consoleHandler.getHandler(), ErrorContextHandler.ERROR_CONTEXT);
      pathHandler.addPath(consoleHandler.getContext(), readinessHandler);
    }

    HttpHandler readinessHandler =
        new DmrFailureReadinessHandler(
            securityRealm,
            secureDomainAccess(domainApiHandler, securityRealm),
            ErrorContextHandler.ERROR_CONTEXT);
    pathHandler.addPath(DomainApiCheckHandler.PATH, readinessHandler);

    if (securityRealm != null) {
      pathHandler.addPath(LogoutHandler.PATH, new LogoutHandler(securityRealm.getName()));
    }
  }