Search in sources :

Example 1 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project jetty.project by eclipse.

the class MinimalServlets method main.

public static void main(String[] args) throws Exception {
    // Create a basic jetty server object that will listen on port 8080.
    // Note that if you set this to port 0 then a randomly available port
    // will be assigned that you can either look in the logs for the port,
    // or programmatically obtain it for use in test cases.
    Server server = new Server(8080);
    // The ServletHandler is a dead simple way to create a context handler
    // that is backed by an instance of a Servlet.
    // This handler then needs to be registered with the Server object.
    ServletHandler handler = new ServletHandler();
    server.setHandler(handler);
    // Passing in the class for the Servlet allows jetty to instantiate an
    // instance of that Servlet and mount it on a given context path.
    // IMPORTANT:
    // This is a raw Servlet, not a Servlet that has been configured
    // through a web.xml @WebServlet annotation, or anything similar.
    handler.addServletWithMapping(HelloServlet.class, "/*");
    // Start things up!
    server.start();
    // The use of server.join() the will make the current thread join and
    // wait until the server is done executing.
    // See
    // http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
    server.join();
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server)

Example 2 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project druid by druid-io.

the class AsyncQueryForwardingServletTest method makeTestDeleteServer.

private static Server makeTestDeleteServer(int port, final CountDownLatch latch) {
    Server server = new Server(port);
    ServletHandler handler = new ServletHandler();
    handler.addServletWithMapping(new ServletHolder(new HttpServlet() {

        @Override
        protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            latch.countDown();
            resp.setStatus(200);
        }
    }), "/default/*");
    server.setHandler(handler);
    return server;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 3 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project lucene-solr by apache.

the class HttpReplicatorTest method startServer.

private void startServer() throws Exception {
    ServletHandler replicationHandler = new ServletHandler();
    ReplicationService service = new ReplicationService(Collections.singletonMap("s1", serverReplicator));
    replicationServlet = new ReplicationServlet(service);
    ServletHolder servlet = new ServletHolder(replicationServlet);
    replicationHandler.addServletWithMapping(servlet, ReplicationService.REPLICATION_CONTEXT + "/*");
    server = newHttpServer(replicationHandler);
    port = serverPort(server);
    host = serverHost(server);
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder)

Example 4 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project nifi by apache.

the class PutSlackTest method init.

@Before
public void init() throws Exception {
    testRunner = TestRunners.newTestRunner(PutSlack.class);
    // set up web service
    ServletHandler handler = new ServletHandler();
    handler.addServletWithMapping(CaptureServlet.class, "/*");
    // create the service
    server = new TestServer();
    server.addHandler(handler);
    server.startServer();
    servlet = (CaptureServlet) handler.getServlets()[0].getServlet();
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) TestServer(org.apache.nifi.processors.standard.TestServer) Before(org.junit.Before)

Example 5 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project nifi by apache.

the class TestGetHTTP method testDynamicHeaders.

@Test
public final void testDynamicHeaders() throws Exception {
    // set up web service
    ServletHandler handler = new ServletHandler();
    handler.addServletWithMapping(UserAgentTestingServlet.class, "/*");
    // create the service
    TestServer server = new TestServer();
    server.addHandler(handler);
    try {
        server.startServer();
        String destination = server.getUrl();
        // set up NiFi mock controller
        controller = TestRunners.newTestRunner(GetHTTP.class);
        controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs");
        controller.setProperty(GetHTTP.URL, destination);
        controller.setProperty(GetHTTP.FILENAME, "testFile");
        controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json");
        controller.setProperty(GetHTTP.USER_AGENT, "testUserAgent");
        controller.setProperty("Static-Header", "StaticHeaderValue");
        controller.setProperty("EL-Header", "${now()}");
        controller.run();
        controller.assertTransferCount(GetHTTP.REL_SUCCESS, 1);
    // shutdown web service
    } finally {
        server.shutdownServer();
    }
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Test(org.junit.Test)

Aggregations

ServletHandler (org.eclipse.jetty.servlet.ServletHandler)54 Server (org.eclipse.jetty.server.Server)23 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)22 ServerConnector (org.eclipse.jetty.server.ServerConnector)11 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)10 Test (org.junit.Test)10 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)8 MockFlowFile (org.apache.nifi.util.MockFlowFile)5 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)5 HashMap (java.util.HashMap)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 FilterMapping (org.eclipse.jetty.servlet.FilterMapping)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InetSocketAddress (java.net.InetSocketAddress)3 HttpServlet (javax.servlet.http.HttpServlet)3 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)3 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2