org.mortbay.jetty.Handler Java Examples

The following examples show how to use org.mortbay.jetty.Handler. 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: Jetty6PluginServer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Set up the handler structure to receive a webapp. Also put in a DefaultHandler so we get a nice page than a 404
 * if we hit the root and the webapp's context isn't at root.
 */
public void configureHandlers() throws Exception {
    this.defaultHandler = new DefaultHandler();
    this.requestLogHandler = new RequestLogHandler();
    if (this.requestLog != null) {
        this.requestLogHandler.setRequestLog(this.requestLog);
    }

    this.contexts = (ContextHandlerCollection) server.getChildHandlerByClass(ContextHandlerCollection.class);
    if (this.contexts == null) {
        this.contexts = new ContextHandlerCollection();
        this.handlers = (HandlerCollection) server.getChildHandlerByClass(HandlerCollection.class);
        if (this.handlers == null) {
            this.handlers = new HandlerCollection();
            this.server.setHandler(handlers);
            this.handlers.setHandlers(new Handler[]{this.contexts, this.defaultHandler, this.requestLogHandler});
        } else {
            this.handlers.addHandler(this.contexts);
        }
    }
}
 
Example #2
Source File: Jetty6PluginServer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Set up the handler structure to receive a webapp. Also put in a DefaultHandler so we get a nice page than a 404
 * if we hit the root and the webapp's context isn't at root.
 */
public void configureHandlers() throws Exception {
    this.defaultHandler = new DefaultHandler();
    this.requestLogHandler = new RequestLogHandler();
    if (this.requestLog != null) {
        this.requestLogHandler.setRequestLog(this.requestLog);
    }

    this.contexts = (ContextHandlerCollection) server.getChildHandlerByClass(ContextHandlerCollection.class);
    if (this.contexts == null) {
        this.contexts = new ContextHandlerCollection();
        this.handlers = (HandlerCollection) server.getChildHandlerByClass(HandlerCollection.class);
        if (this.handlers == null) {
            this.handlers = new HandlerCollection();
            this.server.setHandler(handlers);
            this.handlers.setHandlers(new Handler[]{this.contexts, this.defaultHandler, this.requestLogHandler});
        } else {
            this.handlers.addHandler(this.contexts);
        }
    }
}
 
Example #3
Source File: Jetty6PluginServer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Set up the handler structure to receive a webapp. Also put in a DefaultHandler so we get a nice page than a 404
 * if we hit the root and the webapp's context isn't at root.
 */
public void configureHandlers() throws Exception {
    this.defaultHandler = new DefaultHandler();
    this.requestLogHandler = new RequestLogHandler();
    if (this.requestLog != null) {
        this.requestLogHandler.setRequestLog(this.requestLog);
    }

    this.contexts = (ContextHandlerCollection) server.getChildHandlerByClass(ContextHandlerCollection.class);
    if (this.contexts == null) {
        this.contexts = new ContextHandlerCollection();
        this.handlers = (HandlerCollection) server.getChildHandlerByClass(HandlerCollection.class);
        if (this.handlers == null) {
            this.handlers = new HandlerCollection();
            this.server.setHandler(handlers);
            this.handlers.setHandlers(new Handler[]{this.contexts, this.defaultHandler, this.requestLogHandler});
        } else {
            this.handlers.addHandler(this.contexts);
        }
    }
}
 
Example #4
Source File: MyriadWebServer.java    From incubator-myriad with Apache License 2.0 6 votes vote down vote up
public void start() throws Exception {
  this.jetty.addConnector(connector);

  ServletHandler servletHandler = new ServletHandler();

  String filterName = "MyriadGuiceFilter";
  FilterHolder holder = new FilterHolder(filter);
  holder.setName(filterName);

  FilterMapping filterMapping = new FilterMapping();
  filterMapping.setPathSpec("/*");
  filterMapping.setDispatches(Handler.ALL);
  filterMapping.setFilterName(filterName);

  servletHandler.addFilter(holder, filterMapping);

  Context context = new Context();
  context.setServletHandler(servletHandler);
  context.addServlet(DefaultServlet.class, "/");

  String staticDir = this.getClass().getClassLoader().getResource("webapp/public").toExternalForm();
  context.setResourceBase(staticDir);

  this.jetty.addHandler(context);
  this.jetty.start();
}
 
Example #5
Source File: HttpServer.java    From tajo with Apache License 2.0 6 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication. 
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberized
 * filters) are not enabled. 
 * 
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 */
public void addInternalServlet(String name, String pathSpec, 
    Class<? extends HttpServlet> clazz, boolean requireAuth) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  webAppContext.addServlet(holder, pathSpec);
  
  if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
     LOG.info("Adding Kerberos filter to " + name);
     ServletHandler handler = webAppContext.getServletHandler();
     FilterMapping fmap = new FilterMapping();
     fmap.setPathSpec(pathSpec);
     fmap.setFilterName("krb5Filter");
     fmap.setDispatches(Handler.ALL);
     handler.addFilterMapping(fmap);
  }
}
 
Example #6
Source File: HttpServer.java    From incubator-tajo with Apache License 2.0 6 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication. 
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberized
 * filters) are not enabled. 
 * 
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 */
public void addInternalServlet(String name, String pathSpec, 
    Class<? extends HttpServlet> clazz, boolean requireAuth) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  webAppContext.addServlet(holder, pathSpec);
  
  if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
     LOG.info("Adding Kerberos filter to " + name);
     ServletHandler handler = webAppContext.getServletHandler();
     FilterMapping fmap = new FilterMapping();
     fmap.setPathSpec(pathSpec);
     fmap.setFilterName("krb5Filter");
     fmap.setDispatches(Handler.ALL);
     handler.addFilterMapping(fmap);
  }
}
 
Example #7
Source File: HttpServer2.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 +   * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param requireAuth Require Kerberos authenticate to access servlet
 */
public void addInternalServlet(String name, String pathSpec,
    Class<? extends HttpServlet> clazz, boolean requireAuth) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  webAppContext.addServlet(holder, pathSpec);

  if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
     LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
     ServletHandler handler = webAppContext.getServletHandler();
     FilterMapping fmap = new FilterMapping();
     fmap.setPathSpec(pathSpec);
     fmap.setFilterName(SPNEGO_FILTER);
     fmap.setDispatches(Handler.ALL);
     handler.addFilterMapping(fmap);
  }
}
 
Example #8
Source File: EmbeddedServer.java    From xdocreport.samples with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8081 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/reporting" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );

    server.start();
    server.join();
}
 
Example #9
Source File: HttpServer.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication. 
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 +   * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled. 
 * 
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param requireAuth Require Kerberos authenticate to access servlet
 */
public void addInternalServlet(String name, String pathSpec, 
    Class<? extends HttpServlet> clazz, boolean requireAuth) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  webAppContext.addServlet(holder, pathSpec);

  if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
     LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
     ServletHandler handler = webAppContext.getServletHandler();
     FilterMapping fmap = new FilterMapping();
     fmap.setPathSpec(pathSpec);
     fmap.setFilterName(SPNEGO_FILTER);
     fmap.setDispatches(Handler.ALL);
     handler.addFilterMapping(fmap);
  }
}
 
Example #10
Source File: EmbeddedServer.java    From xdocreport.samples with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8081 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/reporting" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );

    server.start();
    server.join();
}
 
Example #11
Source File: PspTestCase.java    From reladomo with Apache License 2.0 6 votes vote down vote up
protected void setupServerWithHandler(
        Handler handler) throws Exception
{
    this.port = (int) (Math.random() * 10000.0 + 10000.0);
    this.pspUrl = "http://localhost:" + this.port + "/PspServlet";
    this.server = new Server(this.port);
    Context context = new Context(server, "/", Context.SESSIONS);
    if (handler != null)
    {
        context.addHandler(handler);
    }
    ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet");
    holder.setInitParameter("serviceInterface.Echo", "com.gs.fw.common.mithra.test.tinyproxy.Echo");
    holder.setInitParameter("serviceClass.Echo", "com.gs.fw.common.mithra.test.tinyproxy.EchoImpl");
    holder.setInitOrder(10);

    this.server.start();
    this.servlet = (PspServlet) holder.getServlet();
}
 
Example #12
Source File: EmbeddedServer.java    From xdocreport.samples with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/xdocreport-webapp" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );

    // JSP Servlet + Context
    Context jsp_ctx = new Context( servlet_contexts, "/jsp", Context.SESSIONS );
    jsp_ctx.addServlet( new ServletHolder( new org.apache.jasper.servlet.JspServlet() ), "*.jsp" );

    server.start();
    server.join();
}
 
Example #13
Source File: EmbeddedServer.java    From xdocreport.samples with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8081 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/reporting" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );

    server.start();
    server.join();
}
 
Example #14
Source File: HttpServer2.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 +   * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param requireAuth Require Kerberos authenticate to access servlet
 */
public void addInternalServlet(String name, String pathSpec,
    Class<? extends HttpServlet> clazz, boolean requireAuth) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  webAppContext.addServlet(holder, pathSpec);

  if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
     LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
     ServletHandler handler = webAppContext.getServletHandler();
     FilterMapping fmap = new FilterMapping();
     fmap.setPathSpec(pathSpec);
     fmap.setFilterName(SPNEGO_FILTER);
     fmap.setDispatches(Handler.ALL);
     handler.addFilterMapping(fmap);
  }
}
 
Example #15
Source File: HttpServer.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Define a filter for a context and set up default url mappings.
 */
public void defineFilter(Context ctx, String name,
    String classname, Map<String,String> parameters, String[] urls) {

  FilterHolder holder = new FilterHolder();
  holder.setName(name);
  holder.setClassName(classname);
  holder.setInitParameters(parameters);
  FilterMapping fmap = new FilterMapping();
  fmap.setPathSpecs(urls);
  fmap.setDispatches(Handler.ALL);
  fmap.setFilterName(name);
  ServletHandler handler = ctx.getServletHandler();
  handler.addFilter(holder, fmap);
}
 
Example #16
Source File: HttpServer.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication. 
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 +   * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled. 
 * 
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param requireAuth Require Kerberos authenticate to access servlet
 */
public void addInternalServlet(String name, String pathSpec, 
    Class<? extends HttpServlet> clazz, boolean requireAuth) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  webAppContext.addServlet(holder, pathSpec);

  if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
     LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
     ServletHandler handler = webAppContext.getServletHandler();
     FilterMapping fmap = new FilterMapping();
     fmap.setPathSpec(pathSpec);
     fmap.setFilterName(SPNEGO_FILTER);
     fmap.setDispatches(Handler.ALL);
     handler.addFilterMapping(fmap);
  }
}
 
Example #17
Source File: Jetty6PluginServer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Set up the handler structure to receive a webapp. Also put in a DefaultHandler so we get a nice page than a 404
 * if we hit the root and the webapp's context isn't at root.
 */
public void configureHandlers() throws Exception {
    this.defaultHandler = new DefaultHandler();
    this.requestLogHandler = new RequestLogHandler();
    if (this.requestLog != null) {
        this.requestLogHandler.setRequestLog(this.requestLog);
    }

    this.contexts = (ContextHandlerCollection) server.getChildHandlerByClass(ContextHandlerCollection.class);
    if (this.contexts == null) {
        this.contexts = new ContextHandlerCollection();
        this.handlers = (HandlerCollection) server.getChildHandlerByClass(HandlerCollection.class);
        if (this.handlers == null) {
            this.handlers = new HandlerCollection();
            this.server.setHandler(handlers);
            this.handlers.setHandlers(new Handler[]{this.contexts, this.defaultHandler, this.requestLogHandler});
        } else {
            this.handlers.addHandler(this.contexts);
        }
    }
}
 
Example #18
Source File: HttpServer.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * Define a filter for a context and set up default url mappings.
 */
protected void defineFilter(Context ctx, String name,
    String classname, Map<String,String> parameters, String[] urls) {

  FilterHolder holder = new FilterHolder();
  holder.setName(name);
  holder.setClassName(classname);
  holder.setInitParameters(parameters);
  FilterMapping fmap = new FilterMapping();
  fmap.setPathSpecs(urls);
  fmap.setDispatches(Handler.ALL);
  fmap.setFilterName(name);
  ServletHandler handler = ctx.getServletHandler();
  handler.addFilter(holder, fmap);
}
 
Example #19
Source File: HttpServer.java    From RDFS 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,
    Context webAppCtx) {
  ServletHandler handler = webAppCtx.getServletHandler();
  for(String name : filterNames) {
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(name);
    fmap.setDispatches(Handler.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example #20
Source File: HttpServer.java    From incubator-tajo 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,
    Context webAppCtx) {
  ServletHandler handler = webAppCtx.getServletHandler();
  for(String name : filterNames) {
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(name);
    fmap.setDispatches(Handler.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example #21
Source File: AbstractServerMojo.java    From opoopress with Apache License 2.0 5 votes vote down vote up
protected Server createJettyServer(Site site){
    Server server = new Server();
    //FIXME
    server.setStopAtShutdown(true);

    Connector defaultConnector = createConnector(null, port);
    server.setConnectors( new Connector[] { defaultConnector } );

    String root = site.getRoot();
    String resourceBase = site.getDestination().getPath();
    getLog().info("Server resource base: " + resourceBase);

    if("".equals(root)){
        ResourceHandler resourceHandler = new ResourceHandler();
        //resourceHandler.setDirectoriesListed(true);
        resourceHandler.setWelcomeFiles(new String[]{"index.html"});

        resourceHandler.setResourceBase(resourceBase/*site.getDestination().getPath()*/);

        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[] { resourceHandler, new DefaultHandler()});
        server.setHandler(handlers);
        //server.setHandlers(new Handler[]{handlers, logHandler});
        //getLog().info( "Startisng preview server on http://localhost:" + port + "/" );
    } else {
        getLog().info("Using " + ContextHandler.class.getName());
        ContextHandler contextHandler = new ContextHandler();
        contextHandler.setContextPath(root);
        contextHandler.setHandler(new ResourceHandler());
        contextHandler.setResourceBase(resourceBase/*site.getDestination().getPath()*/);
        //server.setHandler(contextHandler);
        server.setHandlers(new Handler[]{contextHandler, new DefaultHandler()});
        //server.setHandlers(new Handler[]{contextHandler, logHandler});
        //log.info( "Starting preview server on http://localhost:" + port + root );
    }
    return server;
}
 
Example #22
Source File: AdminResourcesContainer.java    From karyon with Apache License 2.0 5 votes vote down vote up
private void applyAdditionalFilters(final Context contextHandler, List<Filter> additionalFilters) {
    if (additionalFilters != null && !additionalFilters.isEmpty()) {
        for(Filter f : additionalFilters) {
            contextHandler.addFilter(new FilterHolder(f), "/*", Handler.DEFAULT);
        }
    }
}
 
Example #23
Source File: HttpServer.java    From tajo 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,
    Context webAppCtx) {
  ServletHandler handler = webAppCtx.getServletHandler();
  for(String name : filterNames) {
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(name);
    fmap.setDispatches(Handler.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example #24
Source File: HttpServer.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
/**
 * Define a filter for a context and set up default url mappings.
 */
protected void defineFilter(Context ctx, String name,
    String classname, Map<String,String> parameters, String[] urls) {

  FilterHolder holder = new FilterHolder();
  holder.setName(name);
  holder.setClassName(classname);
  holder.setInitParameters(parameters);
  FilterMapping fmap = new FilterMapping();
  fmap.setPathSpecs(urls);
  fmap.setDispatches(Handler.ALL);
  fmap.setFilterName(name);
  ServletHandler handler = ctx.getServletHandler();
  handler.addFilter(holder, fmap);
}
 
Example #25
Source File: Main.java    From blog-codes with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception
{
	Server server = new Server(PORT);
	
	// Static file handler
	Context fileContext = new Context(server, "/mxgraph", Context.SESSIONS);
	ResourceHandler fileHandler = new ResourceHandler();
	fileHandler.setResourceBase(".");
	fileContext.setHandler(fileHandler);

	// Servlets
	Context context = new Context(server, "/", Context.SESSIONS);
	context.addServlet(new ServletHolder(new Roundtrip()), "/Roundtrip");
	context.addServlet(new ServletHolder(new ServerView()), "/ServerView");
	context.addServlet(new ServletHolder(new ExportServlet()), "/Export");
	context.addServlet(new ServletHolder(new EchoServlet()), "/Echo");
	context.addServlet(new ServletHolder(new Deploy()), "/Deploy");
	context.addServlet(new ServletHolder(new Link()), "/Link");
	context.addServlet(new ServletHolder(new EmbedImage()), "/EmbedImage");
	context.addServlet(new ServletHolder(new Backend()), "/Backend");

	HandlerList handlers = new HandlerList();
	handlers.setHandlers(new Handler[] { new RedirectHandler(),
			fileContext, context, new DefaultHandler() });
	server.setHandler(handlers);

	System.out.println("Go to http://localhost:" + PORT + "/");
	
	server.start();
	server.join();
}
 
Example #26
Source File: HttpServer.java    From hadoop-gpu 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,
    Context webAppCtx) {
  ServletHandler handler = webAppCtx.getServletHandler();
  for(String name : filterNames) {
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(name);
    fmap.setDispatches(Handler.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example #27
Source File: JettyContainer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void start() {
    String serverPort = ConfigUtils.getProperty(JETTY_PORT);
    int port;
    if (serverPort == null || serverPort.length() == 0) {
        port = DEFAULT_JETTY_PORT;
    } else {
        port = Integer.parseInt(serverPort);
    }
    connector = new SelectChannelConnector();
    connector.setPort(port);
    ServletHandler handler = new ServletHandler();
    
    String resources = ConfigUtils.getProperty(JETTY_DIRECTORY);
    if (resources != null && resources.length() > 0) {
        FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT);
        resourceHolder.setInitParameter("resources", resources);
    }
    
    ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*");
    pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES));
    pageHolder.setInitOrder(2);
    
    Server server = new Server();
    server.addConnector(connector);
    server.addHandler(handler);
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e);
    }
}
 
Example #28
Source File: JettyContainer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void start() {
    String serverPort = ConfigUtils.getProperty(JETTY_PORT);
    int port;
    if (serverPort == null || serverPort.length() == 0) {
        port = DEFAULT_JETTY_PORT;
    } else {
        port = Integer.parseInt(serverPort);
    }
    connector = new SelectChannelConnector();
    connector.setPort(port);
    ServletHandler handler = new ServletHandler();
    
    String resources = ConfigUtils.getProperty(JETTY_DIRECTORY);
    if (resources != null && resources.length() > 0) {
        FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT);
        resourceHolder.setInitParameter("resources", resources);
    }
    
    ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*");
    pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES));
    pageHolder.setInitOrder(2);
    
    Server server = new Server();
    server.addConnector(connector);
    server.addHandler(handler);
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e);
    }
}
 
Example #29
Source File: RequestTracingFilterOldServletComponentTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
private static Handler generateServletContextHandler() throws IOException {
    ServletHandler servletHandler = new ServletHandler();

    servletHandler.addServletWithMapping(BlockingServlet.class, BLOCKING_PATH);
    servletHandler.addServletWithMapping(BlockingForwardServlet.class, BLOCKING_FORWARD_PATH);
    servletHandler.addFilterWithMapping(RequestTracingFilter.class.getName(), "/*", Handler.ALL);

    Context context = new Context(null, null, null, servletHandler, null);
    context.setContextPath("/");
    return context;
}
 
Example #30
Source File: HttpServer2.java    From big-c 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,
    Context webAppCtx) {
  ServletHandler handler = webAppCtx.getServletHandler();
  for(String name : filterNames) {
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(name);
    fmap.setDispatches(Handler.ALL);
    handler.addFilterMapping(fmap);
  }
}