Java Code Examples for org.mortbay.jetty.servlet.ServletHandler#addServlet()

The following examples show how to use org.mortbay.jetty.servlet.ServletHandler#addServlet() . 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: VmBoundServiceTest.java    From jrpip with Apache License 2.0 6 votes vote down vote up
private void setupServer() throws Exception
{
    this.server = new HttpServer();
    SocketListener listener = new SocketListener();
    listener.setPort(PORT);
    this.server.addListener(listener);
    HttpContext context = new HttpContext();
    context.setContextPath("/");

    ServletHandler servletHandler = new ServletHandler();
    context.addHandler(servletHandler);

    // Map a servlet onto the container
    ServletHolder holder =
            servletHandler.addServlet("JrpipServlet", "/JrpipServlet", "com.gs.jrpip.server.JrpipServlet");
    holder.put("serviceInterface.Echo", "com.gs.jrpip.Echo");
    holder.put("vmBoundServiceClass.Echo", "com.gs.jrpip.EchoImpl");
    holder.setInitOrder(10);

    this.server.addContext(context);

    this.server.start();
    this.servlet = (JrpipServlet) holder.getServlet();
}
 
Example 2
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 3
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 4
Source File: TestObjectFactory.java    From incubator-myriad with Apache License 2.0 5 votes vote down vote up
public static Server getJettyServer() {
  Server server = new Server();
  ServletHandler context = new ServletHandler();
  ServletHolder holder = new ServletHolder(DefaultServlet.class);
  holder.setInitParameter("resourceBase", System.getProperty("user.dir"));
  holder.setInitParameter("dirAllowed", "true");
  context.setServer(server);
  context.addServlet(holder);
  server.setHandler(context);    

  return server;
}
 
Example 5
Source File: AbstractJettyTest.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * @return
 */
private ServletHandler createServletHandler() {
    final ServletHandler servlets = new ServletHandler();
    servlets.addServlet("FetcherTestServlet", FetcherTestServlet.SERVLET_MAPPING, "com.rometools.fetcher.FetcherTestServlet");
    servlets.addServlet("FetcherTestServlet", FetcherTestServlet.SERVLET_MAPPING2, "com.rometools.fetcher.FetcherTestServlet");
    return servlets;
}
 
Example 6
Source File: JrpipTestCase.java    From jrpip with Apache License 2.0 4 votes vote down vote up
protected void setupServerWithHandler(
        HttpHandler handler,
        SecurityConstraint constraint,
        UserRealm realm) throws Exception
{
    this.port = (int) (Math.random() * 10000.0 + 10000.0);
    this.jrpipUrl = "http://localhost:" + this.port + "/JrpipServlet";
    this.server = new HttpServer();
    SocketListener listener = new SocketListener();
    listener.setPort(this.port);
    this.server.addListener(listener);
    HttpContext context = new HttpContext();
    context.setContextPath("/");

    if (realm != null)
    {
        context.setRealm(realm);
    }

    if (constraint != null)
    {
        context.addSecurityConstraint("/", constraint);
    }

    if (handler != null)
    {
        context.addHandler(handler);
    }

    ServletHandler servletHandler = new ServletHandler();
    context.addHandler(servletHandler);

    ServletHolder holder = servletHandler.addServlet("JrpipServlet", "/JrpipServlet", "com.gs.jrpip.server.JrpipServlet");
    holder.put("serviceInterface.Echo", "com.gs.jrpip.Echo");
    holder.put("serviceClass.Echo", "com.gs.jrpip.EchoImpl");

    this.addCustomConfiguration(holder);

    holder.setInitOrder(10);

    this.server.addContext(context);
    this.server.start();
    this.servlet = (JrpipServlet) holder.getServlet();
}
 
Example 7
Source File: AtomClientServerTest.java    From rome with Apache License 2.0 4 votes vote down vote up
private ServletHandler createServletHandler() {
    System.setProperty("com.rometools.propono.atom.server.AtomHandlerFactory", "com.rometools.propono.atom.server.TestAtomHandlerFactory");
    final ServletHandler servlets = new ServletHandler();
    servlets.addServlet("app", "/app/*", "com.rometools.propono.atom.server.AtomServlet");
    return servlets;
}