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();
}
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;
}
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);
}
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();
}
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();
}
}
Aggregations