Java Code Examples for org.mortbay.jetty.handler.ContextHandler#setContextPath()

The following examples show how to use org.mortbay.jetty.handler.ContextHandler#setContextPath() . 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: TestProtocolHttpClient.java    From anthelion with Apache License 2.0 6 votes vote down vote up
protected void setUp() throws Exception {

    ContextHandler context = new ContextHandler();
    context.setContextPath("/");
    context.setResourceBase(RES_DIR);
    ServletHandler sh = new ServletHandler();
    sh.addServlet("org.apache.jasper.servlet.JspServlet", "*.jsp");
    context.addHandler(sh);
    context.addHandler(new SessionHandler());

    server = new Server();
    server.addHandler(context);

    conf = new Configuration();
    conf.addResource("nutch-default.xml");
    conf.addResource("nutch-site-test.xml");
    
    http = new Http();
    http.setConf(conf);
  }
 
Example 2
Source File: TestProtocolHttpClient.java    From nutch-htmlunit with Apache License 2.0 6 votes vote down vote up
protected void setUp() throws Exception {

    ContextHandler context = new ContextHandler();
    context.setContextPath("/");
    context.setResourceBase(RES_DIR);
    ServletHandler sh = new ServletHandler();
    sh.addServlet("org.apache.jasper.servlet.JspServlet", "*.jsp");
    context.addHandler(sh);
    context.addHandler(new SessionHandler());

    server = new Server();
    server.addHandler(context);

    conf = new Configuration();
    conf.addResource("nutch-default.xml");
    conf.addResource("nutch-site-test.xml");
    
    http = new Http();
    http.setConf(conf);
  }
 
Example 3
Source File: JettyLauncher.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Server server = new Server();

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(PORT);
    server.addConnector(connector);
    server.setStopAtShutdown(true);

    // the orders of handlers is very important!
    ContextHandler contextHandler = new ContextHandler();
    contextHandler.setContextPath("/reports");
    contextHandler.setResourceBase("./reports/");
    contextHandler.addHandler(new ResourceHandler());
    server.addHandler(contextHandler);

    server.addHandler(new WebAppContext("webapp", "/nextreports-server"));

    long t = System.currentTimeMillis();
    server.start();
    t = System.currentTimeMillis() - t;
    String version = server.getClass().getPackage().getImplementationVersion();
    System.out.println("Started Jetty Server " + version + " on port " + PORT + " in " + t / 1000 + "s");
    
    server.join();
}
 
Example 4
Source File: CrawlDBTestUtil.java    From anthelion with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new JettyServer with one static root context
 * 
 * @param port port to listen to
 * @param staticContent folder where static content lives
 * @throws UnknownHostException 
 */
public static Server getServer(int port, String staticContent) throws UnknownHostException{
  Server webServer = new org.mortbay.jetty.Server();
  SocketConnector listener = new SocketConnector();
  listener.setPort(port);
  listener.setHost("127.0.0.1");
  webServer.addConnector(listener);
  ContextHandler staticContext = new ContextHandler();
  staticContext.setContextPath("/");
  staticContext.setResourceBase(staticContent);
  staticContext.addHandler(new ResourceHandler());
  webServer.addHandler(staticContext);
  return webServer;
}
 
Example 5
Source File: CrawlDBTestUtil.java    From nutch-htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new JettyServer with one static root context
 * 
 * @param port port to listen to
 * @param staticContent folder where static content lives
 * @throws UnknownHostException 
 */
public static Server getServer(int port, String staticContent) throws UnknownHostException{
  Server webServer = new org.mortbay.jetty.Server();
  SocketConnector listener = new SocketConnector();
  listener.setPort(port);
  listener.setHost("127.0.0.1");
  webServer.addConnector(listener);
  ContextHandler staticContext = new ContextHandler();
  staticContext.setContextPath("/");
  staticContext.setResourceBase(staticContent);
  staticContext.addHandler(new ResourceHandler());
  webServer.addHandler(staticContext);
  return webServer;
}
 
Example 6
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;
}