org.mortbay.jetty.servlet.ServletHolder Java Examples
The following examples show how to use
org.mortbay.jetty.servlet.ServletHolder.
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: HttpServer2.java From big-c with Apache License 2.0 | 6 votes |
/** * Add an internal servlet in the server, specifying whether or not to * protect with Kerberos authentication. * Note: This method is to be used for adding servlets that facilitate * internal communication and not for user facing functionality. For + * servlets added using this method, filters (except internal Kerberos * filters) are not enabled. * * @param name The name of the servlet (can be passed as null) * @param pathSpec The path spec for the servlet * @param clazz The servlet class * @param requireAuth Require Kerberos authenticate to access servlet */ public void addInternalServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz, boolean requireAuth) { ServletHolder holder = new ServletHolder(clazz); if (name != null) { holder.setName(name); } webAppContext.addServlet(holder, pathSpec); if(requireAuth && UserGroupInformation.isSecurityEnabled()) { LOG.info("Adding Kerberos (SPNEGO) filter to " + name); ServletHandler handler = webAppContext.getServletHandler(); FilterMapping fmap = new FilterMapping(); fmap.setPathSpec(pathSpec); fmap.setFilterName(SPNEGO_FILTER); fmap.setDispatches(Handler.ALL); handler.addFilterMapping(fmap); } }
Example #2
Source File: StaticResourceServlet.java From nomulus with Apache License 2.0 | 6 votes |
/** * Creates a servlet holder for this servlet so it can be used with Jetty. * * @param prefix servlet path starting with a slash and ending with {@code "/*"} if {@code root} * is a directory * @param root file or root directory to serve */ public static ServletHolder create(String prefix, Path root) { root = root.toAbsolutePath(); checkArgument(Files.exists(root), "Root must exist: %s", root); checkArgument(prefix.startsWith("/"), "Prefix must start with a slash: %s", prefix); ServletHolder holder = new ServletHolder(StaticResourceServlet.class); holder.setInitParameter("root", root.toString()); if (Files.isDirectory(root)) { checkArgument(prefix.endsWith("/*"), "Prefix (%s) must end with /* since root (%s) is a directory", prefix, root); holder.setInitParameter("prefix", prefix.substring(0, prefix.length() - 1)); } else { holder.setInitParameter("prefix", prefix); } return holder; }
Example #3
Source File: TestServer.java From nomulus with Apache License 2.0 | 6 votes |
private Context createHandler( Map<String, Path> runfiles, ImmutableList<Route> routes, ImmutableList<Class<? extends Filter>> filters) { Context context = new Context(server, CONTEXT_PATH, Context.SESSIONS); context.addServlet(new ServletHolder(HealthzServlet.class), "/healthz"); for (Map.Entry<String, Path> runfile : runfiles.entrySet()) { context.addServlet( StaticResourceServlet.create(runfile.getKey(), runfile.getValue()), runfile.getKey()); } for (Route route : routes) { context.addServlet( new ServletHolder(wrapServlet(route.servletClass(), filters)), route.path()); } ServletHolder holder = new ServletHolder(DefaultServlet.class); holder.setInitParameter("aliases", "1"); context.addServlet(holder, "/*"); return context; }
Example #4
Source File: HttpServer2.java From hadoop with Apache License 2.0 | 6 votes |
/** * Add an internal servlet in the server, specifying whether or not to * protect with Kerberos authentication. * Note: This method is to be used for adding servlets that facilitate * internal communication and not for user facing functionality. For + * servlets added using this method, filters (except internal Kerberos * filters) are not enabled. * * @param name The name of the servlet (can be passed as null) * @param pathSpec The path spec for the servlet * @param clazz The servlet class * @param requireAuth Require Kerberos authenticate to access servlet */ public void addInternalServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz, boolean requireAuth) { ServletHolder holder = new ServletHolder(clazz); if (name != null) { holder.setName(name); } webAppContext.addServlet(holder, pathSpec); if(requireAuth && UserGroupInformation.isSecurityEnabled()) { LOG.info("Adding Kerberos (SPNEGO) filter to " + name); ServletHandler handler = webAppContext.getServletHandler(); FilterMapping fmap = new FilterMapping(); fmap.setPathSpec(pathSpec); fmap.setFilterName(SPNEGO_FILTER); fmap.setDispatches(Handler.ALL); handler.addFilterMapping(fmap); } }
Example #5
Source File: CacheReplicationTestCase.java From reladomo with Apache License 2.0 | 6 votes |
protected void setupPspMithraService() { server = new Server(this.getApplicationPort1()); Context context = new Context (server,"/",Context.SESSIONS); ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet"); holder.setInitParameter("serviceInterface.MasterCacheService", "com.gs.fw.common.mithra.cache.offheap.MasterCacheService"); holder.setInitParameter("serviceClass.MasterCacheService", "com.gs.fw.common.mithra.cache.offheap.MasterCacheServiceImpl"); holder.setInitOrder(10); // System.out.println(holder.getServlet().getClass().getName()); try { server.start(); } catch (Exception e) { throw new RuntimeException("could not start server", e); } finally { } }
Example #6
Source File: HttpServer2.java From hadoop with Apache License 2.0 | 6 votes |
private static WebAppContext createWebAppContext(String name, Configuration conf, AccessControlList adminsAcl, final String appDir) { WebAppContext ctx = new WebAppContext(); ctx.setDefaultsDescriptor(null); ServletHolder holder = new ServletHolder(new DefaultServlet()); Map<String, String> params = ImmutableMap. <String, String> builder() .put("acceptRanges", "true") .put("dirAllowed", "false") .put("gzip", "true") .put("useFileMappedBuffer", "true") .build(); holder.setInitParameters(params); ctx.setWelcomeFiles(new String[] {"index.html"}); ctx.addServlet(holder, "/"); ctx.setDisplayName(name); ctx.setContextPath("/"); ctx.setWar(appDir + "/" + name); ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, conf); ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl); addNoCacheFilter(ctx); return ctx; }
Example #7
Source File: HttpServer.java From hadoop with Apache License 2.0 | 6 votes |
/** * Add an internal servlet in the server, specifying whether or not to * protect with Kerberos authentication. * Note: This method is to be used for adding servlets that facilitate * internal communication and not for user facing functionality. For + * servlets added using this method, filters (except internal Kerberos * filters) are not enabled. * * @param name The name of the servlet (can be passed as null) * @param pathSpec The path spec for the servlet * @param clazz The servlet class * @param requireAuth Require Kerberos authenticate to access servlet */ public void addInternalServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz, boolean requireAuth) { ServletHolder holder = new ServletHolder(clazz); if (name != null) { holder.setName(name); } webAppContext.addServlet(holder, pathSpec); if(requireAuth && UserGroupInformation.isSecurityEnabled()) { LOG.info("Adding Kerberos (SPNEGO) filter to " + name); ServletHandler handler = webAppContext.getServletHandler(); FilterMapping fmap = new FilterMapping(); fmap.setPathSpec(pathSpec); fmap.setFilterName(SPNEGO_FILTER); fmap.setDispatches(Handler.ALL); handler.addFilterMapping(fmap); } }
Example #8
Source File: PspTestCase.java From reladomo with Apache License 2.0 | 6 votes |
protected void setupServerWithHandler( Handler handler) throws Exception { this.port = (int) (Math.random() * 10000.0 + 10000.0); this.pspUrl = "http://localhost:" + this.port + "/PspServlet"; this.server = new Server(this.port); Context context = new Context(server, "/", Context.SESSIONS); if (handler != null) { context.addHandler(handler); } ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet"); holder.setInitParameter("serviceInterface.Echo", "com.gs.fw.common.mithra.test.tinyproxy.Echo"); holder.setInitParameter("serviceClass.Echo", "com.gs.fw.common.mithra.test.tinyproxy.EchoImpl"); holder.setInitOrder(10); this.server.start(); this.servlet = (PspServlet) holder.getServlet(); }
Example #9
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 #10
Source File: TestStringsWithRestEasy.java From curator with Apache License 2.0 | 6 votes |
@BeforeMethod public void setup() throws Exception { RestEasyApplication.singletonsRef.set(new RestEasySingletons()); ResteasyProviderFactory.setInstance(new ResteasyProviderFactory()); HttpServletDispatcher dispatcher = new HttpServletDispatcher(); port = InstanceSpec.getRandomPort(); server = new Server(port); Context root = new Context(server, "/", Context.SESSIONS); root.getInitParams().put("javax.ws.rs.Application", RestEasyApplication.class.getName()); root.addServlet(new ServletHolder(dispatcher), "/*"); root.addEventListener(new ResteasyBootstrap()); server.start(); }
Example #11
Source File: HttpServer.java From big-c with Apache License 2.0 | 6 votes |
/** * Add an internal servlet in the server, specifying whether or not to * protect with Kerberos authentication. * Note: This method is to be used for adding servlets that facilitate * internal communication and not for user facing functionality. For + * servlets added using this method, filters (except internal Kerberos * filters) are not enabled. * * @param name The name of the servlet (can be passed as null) * @param pathSpec The path spec for the servlet * @param clazz The servlet class * @param requireAuth Require Kerberos authenticate to access servlet */ public void addInternalServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz, boolean requireAuth) { ServletHolder holder = new ServletHolder(clazz); if (name != null) { holder.setName(name); } webAppContext.addServlet(holder, pathSpec); if(requireAuth && UserGroupInformation.isSecurityEnabled()) { LOG.info("Adding Kerberos (SPNEGO) filter to " + name); ServletHandler handler = webAppContext.getServletHandler(); FilterMapping fmap = new FilterMapping(); fmap.setPathSpec(pathSpec); fmap.setFilterName(SPNEGO_FILTER); fmap.setDispatches(Handler.ALL); handler.addFilterMapping(fmap); } }
Example #12
Source File: HttpServer2.java From big-c with Apache License 2.0 | 6 votes |
private static WebAppContext createWebAppContext(String name, Configuration conf, AccessControlList adminsAcl, final String appDir) { WebAppContext ctx = new WebAppContext(); ctx.setDefaultsDescriptor(null); ServletHolder holder = new ServletHolder(new DefaultServlet()); Map<String, String> params = ImmutableMap. <String, String> builder() .put("acceptRanges", "true") .put("dirAllowed", "false") .put("gzip", "true") .put("useFileMappedBuffer", "true") .build(); holder.setInitParameters(params); ctx.setWelcomeFiles(new String[] {"index.html"}); ctx.addServlet(holder, "/"); ctx.setDisplayName(name); ctx.setContextPath("/"); ctx.setWar(appDir + "/" + name); ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, conf); ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl); addNoCacheFilter(ctx); return ctx; }
Example #13
Source File: JackrabbitMain.java From commons-vfs with Apache License 2.0 | 6 votes |
private void prepareWebapp(final File file, final File repository, final File tmp) { webapp.setContextPath("/"); webapp.setWar(file.getPath()); webapp.setClassLoader(JackrabbitMain.class.getClassLoader()); // we use a modified web.xml which has some servlets remove (which produce random empty directories) final URL res = getResource("/jcrweb.xml"); if (res != null) { webapp.setDescriptor(res.toString()); } webapp.setExtractWAR(false); webapp.setTempDirectory(tmp); final ServletHolder servlet = new ServletHolder(JackrabbitRepositoryServlet.class); servlet.setInitOrder(1); servlet.setInitParameter("repository.home", repository.getAbsolutePath()); final String conf = command.getOptionValue("conf"); if (conf != null) { servlet.setInitParameter("repository.config", conf); } webapp.addServlet(servlet, "/repository.properties"); }
Example #14
Source File: VmBoundServiceTest.java From jrpip with Apache License 2.0 | 6 votes |
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 #15
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 #16
Source File: RemoteMithraServerTestCase.java From reladomo with Apache License 2.0 | 6 votes |
protected void setupPspMithraService() { server = new Server(this.getApplicationPort1()); Context context = new Context (server,"/",Context.SESSIONS); ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet"); holder.setInitParameter("serviceInterface.RemoteMithraService", "com.gs.fw.common.mithra.remote.RemoteMithraService"); holder.setInitParameter("serviceClass.RemoteMithraService", "com.gs.fw.common.mithra.remote.RemoteMithraServiceImpl"); holder.setInitOrder(10); try { server.start(); } catch (Exception e) { throw new RuntimeException("could not start server", e); } finally { } }
Example #17
Source File: JettyContainer.java From dubbox with Apache License 2.0 | 5 votes |
public void start() { String serverPort = ConfigUtils.getProperty(JETTY_PORT); int port; if (serverPort == null || serverPort.length() == 0) { port = DEFAULT_JETTY_PORT; } else { port = Integer.parseInt(serverPort); } connector = new SelectChannelConnector(); connector.setPort(port); ServletHandler handler = new ServletHandler(); String resources = ConfigUtils.getProperty(JETTY_DIRECTORY); if (resources != null && resources.length() > 0) { FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT); resourceHolder.setInitParameter("resources", resources); } ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*"); pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES)); pageHolder.setInitOrder(2); Server server = new Server(); server.addConnector(connector); server.addHandler(handler); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e); } }
Example #18
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 #19
Source File: ConsumerAndProviderTest.java From openid4java with Apache License 2.0 | 5 votes |
public ConsumerAndProviderTest(final String testName) throws Exception { super(testName); int servletPort = Integer.parseInt(System.getProperty("SERVLET_PORT", "8989")); _server = new Server(servletPort); Context context = new Context(_server, "/", Context.SESSIONS); _baseUrl = "http://localhost:" + servletPort; // + // context.getContextPath(); SampleConsumer consumer = new SampleConsumer(_baseUrl + "/loginCallback"); context.addServlet(new ServletHolder(new LoginServlet(consumer)), "/login"); context.addServlet(new ServletHolder(new LoginCallbackServlet(consumer)), "/loginCallback"); context.addServlet(new ServletHolder(new UserInfoServlet()), "/user"); SampleServer server = new SampleServer(_baseUrl + "/provider") { protected List userInteraction(ParameterList request) throws ServerException { List back = new ArrayList(); back.add("userSelectedClaimedId"); // userSelectedClaimedId back.add(Boolean.TRUE); // authenticatedAndApproved back.add("[email protected]"); // email return back; } }; context.addServlet(new ServletHolder(new ProviderServlet(server)), "/provider"); }
Example #20
Source File: TestObjectFactory.java From incubator-myriad with Apache License 2.0 | 5 votes |
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 #21
Source File: TestStringsWithJersey.java From curator with Apache License 2.0 | 5 votes |
@BeforeMethod public void setup() throws Exception { context = new StringDiscoveryContext(new MockServiceDiscovery<String>(), new RandomStrategy<String>(), 1000); serviceNamesMarshaller = new JsonServiceNamesMarshaller(); serviceInstanceMarshaller = new JsonServiceInstanceMarshaller<String>(context); serviceInstancesMarshaller = new JsonServiceInstancesMarshaller<String>(context); Application application = new DefaultResourceConfig() { @Override public Set<Class<?>> getClasses() { Set<Class<?>> classes = Sets.newHashSet(); classes.add(StringDiscoveryResource.class); return classes; } @Override public Set<Object> getSingletons() { Set<Object> singletons = Sets.newHashSet(); singletons.add(context); singletons.add(serviceNamesMarshaller); singletons.add(serviceInstanceMarshaller); singletons.add(serviceInstancesMarshaller); return singletons; } }; ServletContainer container = new ServletContainer(application); port = InstanceSpec.getRandomPort(); server = new Server(port); Context root = new Context(server, "/", Context.SESSIONS); root.addServlet(new ServletHolder(container), "/*"); server.start(); }
Example #22
Source File: SlackNotificationTestServer.java From tcSlackBuildNotifier with MIT License | 5 votes |
public SlackNotificationTestServer(String host, Integer port) { server = new Server(port); Context root = new Context(server,"/",Context.SESSIONS); root.addServlet(new ServletHolder(new MyHttpServlet(HttpServletResponse.SC_OK)), "/200"); root.addServlet(new ServletHolder(new MyHttpServlet(HttpServletResponse.SC_MOVED_TEMPORARILY)), "/302"); root.addServlet(new ServletHolder(new MyHttpServlet(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)), "/500"); }
Example #23
Source File: HttpServer.java From RDFS with Apache License 2.0 | 5 votes |
/** * Add an internal servlet in the server. * @param name The name of the servlet (can be passed as null) * @param pathSpec The path spec for the servlet * @param clazz The servlet class * @deprecated this is a temporary method */ @Deprecated public void addInternalServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz) { ServletHolder holder = new ServletHolder(clazz); if (name != null) { holder.setName(name); } webAppContext.addServlet(holder, pathSpec); }
Example #24
Source File: RestServer.java From hraven with Apache License 2.0 | 5 votes |
@Override protected void startUp() throws Exception { // setup the jetty config ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.packages", "com.twitter.hraven.rest"); sh.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true"); server = new Server(); Connector connector = new SelectChannelConnector(); connector.setPort(this.port); connector.setHost(address); server.addConnector(connector); // TODO: in the future we may want to provide settings for the min and max threads // Jetty sets the default max thread number to 250, if we don't set it. // QueuedThreadPool threadPool = new QueuedThreadPool(); server.setThreadPool(threadPool); server.setSendServerVersion(false); server.setSendDateHeader(false); server.setStopAtShutdown(true); // set up context Context context = new Context(server, "/", Context.SESSIONS); context.addServlet(sh, "/*"); // start server server.start(); }
Example #25
Source File: HttpServer.java From hadoop-gpu with Apache License 2.0 | 5 votes |
/** * Add an internal servlet in the server. * @param name The name of the servlet (can be passed as null) * @param pathSpec The path spec for the servlet * @param clazz The servlet class * @deprecated this is a temporary method */ @Deprecated public void addInternalServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz) { ServletHolder holder = new ServletHolder(clazz); if (name != null) { holder.setName(name); } webAppContext.addServlet(holder, pathSpec); }
Example #26
Source File: TestObjectPayloadWithJersey.java From curator with Apache License 2.0 | 5 votes |
@BeforeMethod public void setup() throws Exception { context = new ServiceDetailsDiscoveryContext(new MockServiceDiscovery<ServiceDetails>(), new RandomStrategy<ServiceDetails>(), 1000); serviceNamesMarshaller = new JsonServiceNamesMarshaller(); serviceInstanceMarshaller = new JsonServiceInstanceMarshaller<ServiceDetails>(context); serviceInstancesMarshaller = new JsonServiceInstancesMarshaller<ServiceDetails>(context); Application application = new DefaultResourceConfig() { @Override public Set<Class<?>> getClasses() { Set<Class<?>> classes = Sets.newHashSet(); classes.add(ServiceDetailsDiscoveryResource.class); return classes; } @Override public Set<Object> getSingletons() { Set<Object> singletons = Sets.newHashSet(); singletons.add(context); singletons.add(serviceNamesMarshaller); singletons.add(serviceInstanceMarshaller); singletons.add(serviceInstancesMarshaller); return singletons; } }; ServletContainer container = new ServletContainer(application); port = InstanceSpec.getRandomPort(); server = new Server(port); Context root = new Context(server, "/", Context.SESSIONS); root.addServlet(new ServletHolder(container), "/*"); server.start(); }
Example #27
Source File: JettyContainer.java From dubbox with Apache License 2.0 | 5 votes |
public void start() { String serverPort = ConfigUtils.getProperty(JETTY_PORT); int port; if (serverPort == null || serverPort.length() == 0) { port = DEFAULT_JETTY_PORT; } else { port = Integer.parseInt(serverPort); } connector = new SelectChannelConnector(); connector.setPort(port); ServletHandler handler = new ServletHandler(); String resources = ConfigUtils.getProperty(JETTY_DIRECTORY); if (resources != null && resources.length() > 0) { FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT); resourceHolder.setInitParameter("resources", resources); } ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*"); pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES)); pageHolder.setInitOrder(2); Server server = new Server(); server.addConnector(connector); server.addHandler(handler); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e); } }
Example #28
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 #29
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 #30
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); }