Java Code Examples for org.mortbay.jetty.Server#setHandler()
The following examples show how to use
org.mortbay.jetty.Server#setHandler() .
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: EmbeddedServer.java From xdocreport.samples with GNU Lesser General Public License v3.0 | 6 votes |
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 2
Source File: EmbeddedServer.java From xdocreport.samples with GNU Lesser General Public License v3.0 | 6 votes |
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 3
Source File: EmbeddedServer.java From xdocreport.samples with GNU Lesser General Public License v3.0 | 6 votes |
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 4
Source File: EmbeddedServer.java From xdocreport.samples with GNU Lesser General Public License v3.0 | 6 votes |
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 5
Source File: GitkitExample.java From identity-toolkit-java with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Server server = new Server(4567); ServletHandler servletHandler = new ServletHandler(); SessionHandler sessionHandler = new SessionHandler(); sessionHandler.setHandler(servletHandler); server.setHandler(sessionHandler); servletHandler.addServletWithMapping(LoginServlet.class, "/login"); servletHandler.addServletWithMapping(WidgetServlet.class, "/gitkit"); servletHandler.addServletWithMapping(LoginServlet.class, "/"); server.start(); server.join(); }
Example 6
Source File: Main.java From hbase-indexer with Apache License 2.0 | 6 votes |
private void startHttpServer() throws Exception { server = new Server(); SelectChannelConnector selectChannelConnector = new SelectChannelConnector(); selectChannelConnector.setPort(11060); server.setConnectors(new Connector[]{selectChannelConnector}); PackagesResourceConfig packagesResourceConfig = new PackagesResourceConfig("com/ngdata/hbaseindexer/rest"); ServletHolder servletHolder = new ServletHolder(new ServletContainer(packagesResourceConfig)); servletHolder.setName("HBase-Indexer"); Context context = new Context(server, "/", Context.NO_SESSIONS); context.addServlet(servletHolder, "/*"); context.setContextPath("/"); context.setAttribute("indexerModel", indexerModel); context.setAttribute("indexerSupervisor", indexerSupervisor); server.setHandler(context); server.start(); }
Example 7
Source File: TestWebDelegationToken.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testExternalDelegationTokenSecretManager() throws Exception { DummyDelegationTokenSecretManager secretMgr = new DummyDelegationTokenSecretManager(); final Server jetty = createJettyServer(); Context context = new Context(); context.setContextPath("/foo"); jetty.setHandler(context); context.addFilter(new FilterHolder(AFilter.class), "/*", 0); context.addServlet(new ServletHolder(PingServlet.class), "/bar"); try { secretMgr.startThreads(); context.setAttribute(DelegationTokenAuthenticationFilter. DELEGATION_TOKEN_SECRET_MANAGER_ATTR, secretMgr); jetty.start(); URL authURL = new URL(getJettyURL() + "/foo/bar?authenticated=foo"); DelegationTokenAuthenticatedURL.Token token = new DelegationTokenAuthenticatedURL.Token(); DelegationTokenAuthenticatedURL aUrl = new DelegationTokenAuthenticatedURL(); aUrl.getDelegationToken(authURL, token, FOO_USER); Assert.assertNotNull(token.getDelegationToken()); Assert.assertEquals(new Text("fooKind"), token.getDelegationToken().getKind()); } finally { jetty.stop(); secretMgr.stopThreads(); } }
Example 8
Source File: DevServer.java From yawp with MIT License | 5 votes |
protected void startServer() { try { server = new Server(); server.addConnector(createConnector()); server.setHandler(helper.createWebApp()); server.start(); } catch (Exception e) { throw new RuntimeException(e); } }
Example 9
Source File: HttpServer.java From hadoop-gpu with Apache License 2.0 | 5 votes |
/** * Create a status server on the given port. * The jsp scripts are taken from src/webapps/<name>. * @param name The name of the server * @param port The port to use on the server * @param findPort whether the server should start at the given port and * increment by 1 until it finds a free port. * @param conf Configuration */ public HttpServer(String name, String bindAddress, int port, boolean findPort, Configuration conf) throws IOException { webServer = new Server(); this.findPort = findPort; listener = createBaseListener(conf); listener.setHost(bindAddress); listener.setPort(port); webServer.addConnector(listener); webServer.setThreadPool(new QueuedThreadPool()); final String appDir = getWebAppsPath(); ContextHandlerCollection contexts = new ContextHandlerCollection(); webServer.setHandler(contexts); webAppContext = new WebAppContext(); webAppContext.setContextPath("/"); webAppContext.setWar(appDir + "/" + name); webServer.addHandler(webAppContext); addDefaultApps(contexts, appDir); final FilterInitializer[] initializers = getFilterInitializers(conf); if (initializers != null) { for(FilterInitializer c : initializers) { c.initFilter(this); } } addDefaultServlets(); }
Example 10
Source File: AuthenticatorTestCase.java From registry with Apache License 2.0 | 5 votes |
protected void startJetty() throws Exception { server = new Server(0); context = new Context(); context.setContextPath("/foo"); server.setHandler(context); context.addFilter(new FilterHolder(TestFilter.class), "/*", 0); context.addServlet(new ServletHolder(TestServlet.class), "/bar"); host = "localhost"; port = getLocalPort(); server.getConnectors()[0].setHost(host); server.getConnectors()[0].setPort(port); server.start(); System.out.println("Running embedded servlet container at: http://" + host + ":" + port); }
Example 11
Source File: AuthenticatorTestCase.java From big-c with Apache License 2.0 | 5 votes |
protected void startJetty() throws Exception { server = new Server(0); context = new Context(); context.setContextPath("/foo"); server.setHandler(context); context.addFilter(new FilterHolder(TestFilter.class), "/*", 0); context.addServlet(new ServletHolder(TestServlet.class), "/bar"); host = "localhost"; port = getLocalPort(); server.getConnectors()[0].setHost(host); server.getConnectors()[0].setPort(port); server.start(); System.out.println("Running embedded servlet container at: http://" + host + ":" + port); }
Example 12
Source File: TestWebDelegationToken.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testFallbackToPseudoDelegationTokenAuthenticator() throws Exception { final Server jetty = createJettyServer(); Context context = new Context(); context.setContextPath("/foo"); jetty.setHandler(context); context.addFilter(new FilterHolder(PseudoDTAFilter.class), "/*", 0); context.addServlet(new ServletHolder(UserServlet.class), "/bar"); try { jetty.start(); final URL url = new URL(getJettyURL() + "/foo/bar"); UserGroupInformation ugi = UserGroupInformation.createRemoteUser(FOO_USER); ugi.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { DelegationTokenAuthenticatedURL.Token token = new DelegationTokenAuthenticatedURL.Token(); DelegationTokenAuthenticatedURL aUrl = new DelegationTokenAuthenticatedURL(); HttpURLConnection conn = aUrl.openConnection(url, token); Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); List<String> ret = IOUtils.readLines(conn.getInputStream()); Assert.assertEquals(1, ret.size()); Assert.assertEquals(FOO_USER, ret.get(0)); aUrl.getDelegationToken(url, token, FOO_USER); Assert.assertNotNull(token.getDelegationToken()); Assert.assertEquals(new Text("token-kind"), token.getDelegationToken().getKind()); return null; } }); } finally { jetty.stop(); } }
Example 13
Source File: Main.java From blog-codes with Apache License 2.0 | 5 votes |
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 14
Source File: AuthenticatorTestCase.java From hadoop with Apache License 2.0 | 5 votes |
protected void startJetty() throws Exception { server = new Server(0); context = new Context(); context.setContextPath("/foo"); server.setHandler(context); context.addFilter(new FilterHolder(TestFilter.class), "/*", 0); context.addServlet(new ServletHolder(TestServlet.class), "/bar"); host = "localhost"; port = getLocalPort(); server.getConnectors()[0].setHost(host); server.getConnectors()[0].setPort(port); server.start(); System.out.println("Running embedded servlet container at: http://" + host + ":" + port); }
Example 15
Source File: TestWebDelegationToken.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testFallbackToPseudoDelegationTokenAuthenticator() throws Exception { final Server jetty = createJettyServer(); Context context = new Context(); context.setContextPath("/foo"); jetty.setHandler(context); context.addFilter(new FilterHolder(PseudoDTAFilter.class), "/*", 0); context.addServlet(new ServletHolder(UserServlet.class), "/bar"); try { jetty.start(); final URL url = new URL(getJettyURL() + "/foo/bar"); UserGroupInformation ugi = UserGroupInformation.createRemoteUser(FOO_USER); ugi.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { DelegationTokenAuthenticatedURL.Token token = new DelegationTokenAuthenticatedURL.Token(); DelegationTokenAuthenticatedURL aUrl = new DelegationTokenAuthenticatedURL(); HttpURLConnection conn = aUrl.openConnection(url, token); Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); List<String> ret = IOUtils.readLines(conn.getInputStream()); Assert.assertEquals(1, ret.size()); Assert.assertEquals(FOO_USER, ret.get(0)); aUrl.getDelegationToken(url, token, FOO_USER); Assert.assertNotNull(token.getDelegationToken()); Assert.assertEquals(new Text("token-kind"), token.getDelegationToken().getKind()); return null; } }); } finally { jetty.stop(); } }
Example 16
Source File: TestWebDelegationToken.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testExternalDelegationTokenSecretManager() throws Exception { DummyDelegationTokenSecretManager secretMgr = new DummyDelegationTokenSecretManager(); final Server jetty = createJettyServer(); Context context = new Context(); context.setContextPath("/foo"); jetty.setHandler(context); context.addFilter(new FilterHolder(AFilter.class), "/*", 0); context.addServlet(new ServletHolder(PingServlet.class), "/bar"); try { secretMgr.startThreads(); context.setAttribute(DelegationTokenAuthenticationFilter. DELEGATION_TOKEN_SECRET_MANAGER_ATTR, secretMgr); jetty.start(); URL authURL = new URL(getJettyURL() + "/foo/bar?authenticated=foo"); DelegationTokenAuthenticatedURL.Token token = new DelegationTokenAuthenticatedURL.Token(); DelegationTokenAuthenticatedURL aUrl = new DelegationTokenAuthenticatedURL(); aUrl.getDelegationToken(authURL, token, FOO_USER); Assert.assertNotNull(token.getDelegationToken()); Assert.assertEquals(new Text("fooKind"), token.getDelegationToken().getKind()); } finally { jetty.stop(); secretMgr.stopThreads(); } }
Example 17
Source File: TestWebAppProxyServlet.java From hadoop with Apache License 2.0 | 5 votes |
/** * Simple http server. Server should send answer with status 200 */ @BeforeClass public static void start() throws Exception { server = new Server(0); Context context = new Context(); context.setContextPath("/foo"); server.setHandler(context); context.addServlet(new ServletHolder(TestServlet.class), "/bar"); server.getConnectors()[0].setHost("localhost"); server.start(); originalPort = server.getConnectors()[0].getLocalPort(); LOG.info("Running embedded servlet container at: http://localhost:" + originalPort); }
Example 18
Source File: TestWebDelegationToken.java From big-c with Apache License 2.0 | 4 votes |
@Test public void testHttpUGI() throws Exception { final Server jetty = createJettyServer(); Context context = new Context(); context.setContextPath("/foo"); jetty.setHandler(context); context.addFilter(new FilterHolder(PseudoDTAFilter.class), "/*", 0); context.addServlet(new ServletHolder(UGIServlet.class), "/bar"); try { jetty.start(); final URL url = new URL(getJettyURL() + "/foo/bar"); UserGroupInformation ugi = UserGroupInformation.createRemoteUser(FOO_USER); ugi.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { DelegationTokenAuthenticatedURL.Token token = new DelegationTokenAuthenticatedURL.Token(); DelegationTokenAuthenticatedURL aUrl = new DelegationTokenAuthenticatedURL(); // user foo HttpURLConnection conn = aUrl.openConnection(url, token); Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); List<String> ret = IOUtils.readLines(conn.getInputStream()); Assert.assertEquals(1, ret.size()); Assert.assertEquals("remoteuser=" + FOO_USER+ ":ugi=" + FOO_USER, ret.get(0)); // user ok-user via proxyuser foo conn = aUrl.openConnection(url, token, OK_USER); Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); ret = IOUtils.readLines(conn.getInputStream()); Assert.assertEquals(1, ret.size()); Assert.assertEquals("realugi=" + FOO_USER +":remoteuser=" + OK_USER + ":ugi=" + OK_USER, ret.get(0)); return null; } }); } finally { jetty.stop(); } }
Example 19
Source File: TestWebDelegationToken.java From hadoop with Apache License 2.0 | 4 votes |
@Test public void testHttpUGI() throws Exception { final Server jetty = createJettyServer(); Context context = new Context(); context.setContextPath("/foo"); jetty.setHandler(context); context.addFilter(new FilterHolder(PseudoDTAFilter.class), "/*", 0); context.addServlet(new ServletHolder(UGIServlet.class), "/bar"); try { jetty.start(); final URL url = new URL(getJettyURL() + "/foo/bar"); UserGroupInformation ugi = UserGroupInformation.createRemoteUser(FOO_USER); ugi.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { DelegationTokenAuthenticatedURL.Token token = new DelegationTokenAuthenticatedURL.Token(); DelegationTokenAuthenticatedURL aUrl = new DelegationTokenAuthenticatedURL(); // user foo HttpURLConnection conn = aUrl.openConnection(url, token); Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); List<String> ret = IOUtils.readLines(conn.getInputStream()); Assert.assertEquals(1, ret.size()); Assert.assertEquals("remoteuser=" + FOO_USER+ ":ugi=" + FOO_USER, ret.get(0)); // user ok-user via proxyuser foo conn = aUrl.openConnection(url, token, OK_USER); Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); ret = IOUtils.readLines(conn.getInputStream()); Assert.assertEquals(1, ret.size()); Assert.assertEquals("realugi=" + FOO_USER +":remoteuser=" + OK_USER + ":ugi=" + OK_USER, ret.get(0)); return null; } }); } finally { jetty.stop(); } }
Example 20
Source File: SLSWebApp.java From hadoop with Apache License 2.0 | 4 votes |
public void start() throws Exception { // static files final ResourceHandler staticHandler = new ResourceHandler(); staticHandler.setResourceBase("html"); Handler handler = new AbstractHandler() { @Override public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) { try{ // timeunit int timeunit = 1000; // second, divide millionsecond / 1000 String timeunitLabel = "second"; if (request.getParameter("u")!= null && request.getParameter("u").equalsIgnoreCase("m")) { timeunit = 1000 * 60; timeunitLabel = "minute"; } // http request if (target.equals("/")) { printPageIndex(request, response); } else if (target.equals("/simulate")) { printPageSimulate(request, response, timeunit, timeunitLabel); } else if (target.equals("/track")) { printPageTrack(request, response, timeunit, timeunitLabel); } else // js/css request if (target.startsWith("/js") || target.startsWith("/css")) { response.setCharacterEncoding("utf-8"); staticHandler.handle(target, request, response, dispatch); } else // json request if (target.equals("/simulateMetrics")) { printJsonMetrics(request, response); } else if (target.equals("/trackMetrics")) { printJsonTrack(request, response); } } catch (Exception e) { e.printStackTrace(); } } }; server = new Server(port); server.setHandler(handler); server.start(); }