Java Code Examples for org.eclipse.jetty.servlet.ServletContextHandler#getServletHandler()

The following examples show how to use org.eclipse.jetty.servlet.ServletContextHandler#getServletHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebServer.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
public WebServer(@NotNull SharedContext context, @NotNull Server server, @Nullable URL baseUrl, @NotNull EncryptionFactory tokenFactory) throws URISyntaxException {
  this.context = context;
  this.server = server;
  this.baseUrl = baseUrl == null ? null : baseUrl.toURI();
  this.tokenFactory = tokenFactory;
  final ServletContextHandler contextHandler = new ServletContextHandler();
  contextHandler.setContextPath("/");
  handler = contextHandler.getServletHandler();

  final RequestLogHandler logHandler = new RequestLogHandler();
  logHandler.setRequestLog((request, response) -> {
    final User user = (User) request.getAttribute(User.class.getName());
    final String username = (user == null || user.isAnonymous()) ? "" : user.getUsername();
    log.info("{}:{} - {} - \"{} {}\" {} {}", request.getRemoteHost(), request.getRemotePort(), username, request.getMethod(), request.getHttpURI(), response.getStatus(), response.getReason());
  });

  final HandlerCollection handlers = new HandlerCollection();
  handlers.addHandler(contextHandler);
  handlers.addHandler(logHandler);
  server.setHandler(handlers);
}
 
Example 2
Source File: HttpServer2.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Add the path spec to the filter path mapping.
 * @param pathSpec The path spec
 * @param webAppCtx The WebApplicationContext to add to
 */
private void addFilterPathMapping(String pathSpec,
    ServletContextHandler webAppCtx) {
  ServletHandler handler = webAppCtx.getServletHandler();
  for (String name : filterNames) {
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(name);
    fmap.setDispatches(FilterMapping.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example 3
Source File: HttpServer2.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Add the path spec to the filter path mapping.
 * @param pathSpec The path spec
 * @param webAppCtx The WebApplicationContext to add to
 */
protected void addFilterPathMapping(String pathSpec,
                                    ServletContextHandler webAppCtx) {
  ServletHandler handler = webAppCtx.getServletHandler();
  for(String name : filterNames) {
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(name);
    fmap.setDispatches(FilterMapping.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example 4
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Add the path spec to the filter path mapping.
 * @param pathSpec The path spec
 * @param webAppCtx The WebApplicationContext to add to
 */
protected void addFilterPathMapping(String pathSpec,
                                    ServletContextHandler webAppCtx) {
  ServletHandler handler = webAppCtx.getServletHandler();
  for(String name : filterNames) {
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(name);
    fmap.setDispatches(FilterMapping.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example 5
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Add the path spec to the filter path mapping.
 * @param pathSpec The path spec
 * @param webAppCtx The WebApplicationContext to add to
 */
protected void addFilterPathMapping(String pathSpec,
                                    ServletContextHandler webAppCtx) {
  ServletHandler handler = webAppCtx.getServletHandler();
  for(String name : filterNames) {
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(name);
    fmap.setDispatches(FilterMapping.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example 6
Source File: HttpServer2.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
/**
 * Define a filter for a context and set up default url mappings.
 */
private static void defineFilter(ServletContextHandler ctx,
    FilterHolder holder, FilterMapping fmap) {
  ServletHandler handler = ctx.getServletHandler();
  handler.addFilter(holder, fmap);
}
 
Example 7
Source File: HttpServer2.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * Define a filter for a context and set up default url mappings.
 */
private static void defineFilter(ServletContextHandler ctx,
                                 FilterHolder holder, FilterMapping fmap) {
  ServletHandler handler = ctx.getServletHandler();
  handler.addFilter(holder, fmap);
}
 
Example 8
Source File: HttpServer2.java    From knox with Apache License 2.0 4 votes vote down vote up
private static void defineFilter(ServletContextHandler ctx,
                                 FilterHolder holder, FilterMapping fmap) {
  ServletHandler handler = ctx.getServletHandler();
  handler.addFilter(holder, fmap);
}
 
Example 9
Source File: HttpServer2.java    From knox with Apache License 2.0 4 votes vote down vote up
private static void defineFilter(ServletContextHandler ctx,
                                 FilterHolder holder, FilterMapping fmap) {
  ServletHandler handler = ctx.getServletHandler();
  handler.addFilter(holder, fmap);
}