org.mortbay.jetty.servlet.Context Java Examples
The following examples show how to use
org.mortbay.jetty.servlet.Context.
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: HttpServer.java From big-c with Apache License 2.0 | 6 votes |
@Override public void addFilter(String name, String classname, Map<String, String> parameters) { final String[] USER_FACING_URLS = { "*.html", "*.jsp" }; defineFilter(webAppContext, name, classname, parameters, USER_FACING_URLS); LOG.info("Added filter " + name + " (class=" + classname + ") to context " + webAppContext.getDisplayName()); final String[] ALL_URLS = { "/*" }; for (Map.Entry<Context, Boolean> e : defaultContexts.entrySet()) { if (e.getValue()) { Context ctx = e.getKey(); defineFilter(ctx, name, classname, parameters, ALL_URLS); LOG.info("Added filter " + name + " (class=" + classname + ") to context " + ctx.getDisplayName()); } } filterNames.add(name); }
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( 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 #3
Source File: HttpServer.java From hadoop with Apache License 2.0 | 6 votes |
@Override public void addFilter(String name, String classname, Map<String, String> parameters) { final String[] USER_FACING_URLS = { "*.html", "*.jsp" }; defineFilter(webAppContext, name, classname, parameters, USER_FACING_URLS); LOG.info("Added filter " + name + " (class=" + classname + ") to context " + webAppContext.getDisplayName()); final String[] ALL_URLS = { "/*" }; for (Map.Entry<Context, Boolean> e : defaultContexts.entrySet()) { if (e.getValue()) { Context ctx = e.getKey(); defineFilter(ctx, name, classname, parameters, ALL_URLS); LOG.info("Added filter " + name + " (class=" + classname + ") to context " + ctx.getDisplayName()); } } filterNames.add(name); }
Example #4
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 #5
Source File: HttpServer.java From hadoop-gpu with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ public void addFilter(String name, String classname, Map<String, String> parameters) { final String[] USER_FACING_URLS = { "*.html", "*.jsp" }; defineFilter(webAppContext, name, classname, parameters, USER_FACING_URLS); final String[] ALL_URLS = { "/*" }; for (Map.Entry<Context, Boolean> e : defaultContexts.entrySet()) { if (e.getValue()) { Context ctx = e.getKey(); defineFilter(ctx, name, classname, parameters, ALL_URLS); LOG.info("Added filter " + name + " (class=" + classname + ") to context " + ctx.getDisplayName()); } } filterNames.add(name); }
Example #6
Source File: TestHFSTestCase.java From hadoop with Apache License 2.0 | 6 votes |
@Test @TestJetty public void testJetty() throws Exception { Context context = new Context(); context.setContextPath("/"); context.addServlet(MyServlet.class, "/bar"); Server server = TestJettyHelper.getJettyServer(); server.addHandler(context); server.start(); URL url = new URL(TestJettyHelper.getJettyURL(), "/bar"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); assertEquals(reader.readLine(), "foo"); reader.close(); }
Example #7
Source File: HttpServer.java From RDFS with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ public void addFilter(String name, String classname, Map<String, String> parameters) { final String[] USER_FACING_URLS = { "*.html", "*.jsp" }; defineFilter(webAppContext, name, classname, parameters, USER_FACING_URLS); final String[] ALL_URLS = { "/*" }; for (Map.Entry<Context, Boolean> e : defaultContexts.entrySet()) { if (e.getValue()) { Context ctx = e.getKey(); defineFilter(ctx, name, classname, parameters, ALL_URLS); LOG.info("Added filter " + name + " (class=" + classname + ") to context " + ctx.getDisplayName()); } } filterNames.add(name); }
Example #8
Source File: HttpServer.java From hadoop with Apache License 2.0 | 6 votes |
/** * Define a filter for a context and set up default url mappings. */ public void defineFilter(Context ctx, String name, String classname, Map<String,String> parameters, String[] urls) { FilterHolder holder = new FilterHolder(); holder.setName(name); holder.setClassName(classname); holder.setInitParameters(parameters); FilterMapping fmap = new FilterMapping(); fmap.setPathSpecs(urls); fmap.setDispatches(Handler.ALL); fmap.setFilterName(name); ServletHandler handler = ctx.getServletHandler(); handler.addFilter(holder, fmap); }
Example #9
Source File: MyriadWebServer.java From incubator-myriad with Apache License 2.0 | 6 votes |
public void start() throws Exception { this.jetty.addConnector(connector); ServletHandler servletHandler = new ServletHandler(); String filterName = "MyriadGuiceFilter"; FilterHolder holder = new FilterHolder(filter); holder.setName(filterName); FilterMapping filterMapping = new FilterMapping(); filterMapping.setPathSpec("/*"); filterMapping.setDispatches(Handler.ALL); filterMapping.setFilterName(filterName); servletHandler.addFilter(holder, filterMapping); Context context = new Context(); context.setServletHandler(servletHandler); context.addServlet(DefaultServlet.class, "/"); String staticDir = this.getClass().getClassLoader().getResource("webapp/public").toExternalForm(); context.setResourceBase(staticDir); this.jetty.addHandler(context); this.jetty.start(); }
Example #10
Source File: HttpServer2.java From hadoop with Apache License 2.0 | 6 votes |
@Override public void addFilter(String name, String classname, Map<String, String> parameters) { FilterHolder filterHolder = getFilterHolder(name, classname, parameters); final String[] USER_FACING_URLS = { "*.html", "*.jsp" }; FilterMapping fmap = getFilterMapping(name, USER_FACING_URLS); defineFilter(webAppContext, filterHolder, fmap); LOG.info( "Added filter " + name + " (class=" + classname + ") to context " + webAppContext.getDisplayName()); final String[] ALL_URLS = { "/*" }; fmap = getFilterMapping(name, ALL_URLS); for (Map.Entry<Context, Boolean> e : defaultContexts.entrySet()) { if (e.getValue()) { Context ctx = e.getKey(); defineFilter(ctx, filterHolder, fmap); LOG.info("Added filter " + name + " (class=" + classname + ") to context " + ctx.getDisplayName()); } } filterNames.add(name); }
Example #11
Source File: AuthenticatorTestCase.java From registry with Apache License 2.0 | 6 votes |
protected void startTomcat() throws Exception { tomcat = new Tomcat(); File base = new File(System.getProperty("java.io.tmpdir")); org.apache.catalina.Context ctx = tomcat.addContext("/foo", base.getAbsolutePath()); FilterDef fd = new FilterDef(); fd.setFilterClass(TestFilter.class.getName()); fd.setFilterName("TestFilter"); FilterMap fm = new FilterMap(); fm.setFilterName("TestFilter"); fm.addURLPattern("/*"); fm.addServletName("/bar"); ctx.addFilterDef(fd); ctx.addFilterMap(fm); tomcat.addServlet(ctx, "/bar", TestServlet.class.getName()); ctx.addServletMapping("/bar", "/bar"); host = "localhost"; port = getLocalPort(); tomcat.setHostname(host); tomcat.setPort(port); tomcat.start(); }
Example #12
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 #13
Source File: HttpServer2.java From big-c with Apache License 2.0 | 6 votes |
@Override public void addFilter(String name, String classname, Map<String, String> parameters) { FilterHolder filterHolder = getFilterHolder(name, classname, parameters); final String[] USER_FACING_URLS = { "*.html", "*.jsp" }; FilterMapping fmap = getFilterMapping(name, USER_FACING_URLS); defineFilter(webAppContext, filterHolder, fmap); LOG.info( "Added filter " + name + " (class=" + classname + ") to context " + webAppContext.getDisplayName()); final String[] ALL_URLS = { "/*" }; fmap = getFilterMapping(name, ALL_URLS); for (Map.Entry<Context, Boolean> e : defaultContexts.entrySet()) { if (e.getValue()) { Context ctx = e.getKey(); defineFilter(ctx, filterHolder, fmap); LOG.info("Added filter " + name + " (class=" + classname + ") to context " + ctx.getDisplayName()); } } filterNames.add(name); }
Example #14
Source File: TestHFSTestCase.java From big-c with Apache License 2.0 | 6 votes |
@Test @TestJetty public void testJetty() throws Exception { Context context = new Context(); context.setContextPath("/"); context.addServlet(MyServlet.class, "/bar"); Server server = TestJettyHelper.getJettyServer(); server.addHandler(context); server.start(); URL url = new URL(TestJettyHelper.getJettyURL(), "/bar"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); assertEquals(reader.readLine(), "foo"); reader.close(); }
Example #15
Source File: TestHTestCase.java From big-c with Apache License 2.0 | 6 votes |
@Test @TestJetty public void testJetty() throws Exception { Context context = new Context(); context.setContextPath("/"); context.addServlet(MyServlet.class, "/bar"); Server server = TestJettyHelper.getJettyServer(); server.addHandler(context); server.start(); URL url = new URL(TestJettyHelper.getJettyURL(), "/bar"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); assertEquals(reader.readLine(), "foo"); reader.close(); }
Example #16
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 #17
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 #18
Source File: AuthenticatorTestCase.java From hadoop with Apache License 2.0 | 6 votes |
protected void startTomcat() throws Exception { tomcat = new Tomcat(); File base = new File(System.getProperty("java.io.tmpdir")); org.apache.catalina.Context ctx = tomcat.addContext("/foo",base.getAbsolutePath()); FilterDef fd = new FilterDef(); fd.setFilterClass(TestFilter.class.getName()); fd.setFilterName("TestFilter"); FilterMap fm = new FilterMap(); fm.setFilterName("TestFilter"); fm.addURLPattern("/*"); fm.addServletName("/bar"); ctx.addFilterDef(fd); ctx.addFilterMap(fm); tomcat.addServlet(ctx, "/bar", TestServlet.class.getName()); ctx.addServletMapping("/bar", "/bar"); host = "localhost"; port = getLocalPort(); tomcat.setHostname(host); tomcat.setPort(port); tomcat.start(); }
Example #19
Source File: HttpServer.java From hadoop-gpu with Apache License 2.0 | 6 votes |
/** * Add default apps. * @param appDir The application directory * @throws IOException */ protected void addDefaultApps(ContextHandlerCollection parent, final String appDir) throws IOException { // set up the context for "/logs/" if "hadoop.log.dir" property is defined. String logDir = System.getProperty("hadoop.log.dir"); if (logDir != null) { Context logContext = new Context(parent, "/logs"); logContext.setResourceBase(logDir); logContext.addServlet(DefaultServlet.class, "/"); defaultContexts.put(logContext, true); } // set up the context for "/static/*" Context staticContext = new Context(parent, "/static"); staticContext.setResourceBase(appDir + "/static"); staticContext.addServlet(DefaultServlet.class, "/*"); defaultContexts.put(staticContext, true); }
Example #20
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 #21
Source File: HttpServer.java From big-c with Apache License 2.0 | 5 votes |
/** * Add the path spec to the filter path mapping. * @param pathSpec The path spec * @param webAppCtx The WebApplicationContext to add to */ protected void addFilterPathMapping(String pathSpec, Context webAppCtx) { ServletHandler handler = webAppCtx.getServletHandler(); for(String name : filterNames) { FilterMapping fmap = new FilterMapping(); fmap.setPathSpec(pathSpec); fmap.setFilterName(name); fmap.setDispatches(Handler.ALL); handler.addFilterMapping(fmap); } }
Example #22
Source File: AdminResourcesContainer.java From karyon with Apache License 2.0 | 5 votes |
private void applyAdditionalFilters(final Context contextHandler, List<Filter> additionalFilters) { if (additionalFilters != null && !additionalFilters.isEmpty()) { for(Filter f : additionalFilters) { contextHandler.addFilter(new FilterHolder(f), "/*", Handler.DEFAULT); } } }
Example #23
Source File: ServletTestContext.java From oink with Apache License 2.0 | 5 votes |
/** * Creates a servlet test context. * * @param contextPath context path for the servlet, it must be prefixed with "/", * for the default context use "/" */ public ServletTestContext(String contextPath) { if(!contextPath.startsWith("/")) { contextPath = "/" + contextPath; } this.contextPath = contextPath; webServer = new org.mortbay.jetty.Server(); // create context context = new Context(webServer, contextPath); }
Example #24
Source File: HttpServer2.java From big-c with Apache License 2.0 | 5 votes |
/** * Add the path spec to the filter path mapping. * @param pathSpec The path spec * @param webAppCtx The WebApplicationContext to add to */ protected void addFilterPathMapping(String pathSpec, Context webAppCtx) { ServletHandler handler = webAppCtx.getServletHandler(); for(String name : filterNames) { FilterMapping fmap = new FilterMapping(); fmap.setPathSpec(pathSpec); fmap.setFilterName(name); fmap.setDispatches(Handler.ALL); handler.addFilterMapping(fmap); } }
Example #25
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 #26
Source File: HttpServer2.java From big-c with Apache License 2.0 | 5 votes |
/** * Add default apps. * @param appDir The application directory * @throws IOException */ protected void addDefaultApps(ContextHandlerCollection parent, final String appDir, Configuration conf) throws IOException { // set up the context for "/logs/" if "hadoop.log.dir" property is defined. String logDir = System.getProperty("hadoop.log.dir"); if (logDir != null) { Context logContext = new Context(parent, "/logs"); logContext.setResourceBase(logDir); logContext.addServlet(AdminAuthorizedServlet.class, "/*"); if (conf.getBoolean( CommonConfigurationKeys.HADOOP_JETTY_LOGS_SERVE_ALIASES, CommonConfigurationKeys.DEFAULT_HADOOP_JETTY_LOGS_SERVE_ALIASES)) { @SuppressWarnings("unchecked") Map<String, String> params = logContext.getInitParams(); params.put( "org.mortbay.jetty.servlet.Default.aliases", "true"); } logContext.setDisplayName("logs"); setContextAttributes(logContext, conf); addNoCacheFilter(webAppContext); defaultContexts.put(logContext, true); } // set up the context for "/static/*" Context staticContext = new Context(parent, "/static"); staticContext.setResourceBase(appDir + "/static"); staticContext.addServlet(DefaultServlet.class, "/*"); staticContext.setDisplayName("static"); setContextAttributes(staticContext, conf); defaultContexts.put(staticContext, true); }
Example #27
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 #28
Source File: HttpServer2.java From big-c with Apache License 2.0 | 5 votes |
@Override public void addGlobalFilter(String name, String classname, Map<String, String> parameters) { final String[] ALL_URLS = { "/*" }; FilterHolder filterHolder = getFilterHolder(name, classname, parameters); FilterMapping fmap = getFilterMapping(name, ALL_URLS); defineFilter(webAppContext, filterHolder, fmap); for (Context ctx : defaultContexts.keySet()) { defineFilter(ctx, filterHolder, fmap); } LOG.info("Added global filter '" + name + "' (class=" + classname + ")"); }
Example #29
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 #30
Source File: HttpServer2.java From big-c with Apache License 2.0 | 5 votes |
/** * Define a filter for a context and set up default url mappings. */ public static void defineFilter(Context ctx, String name, String classname, Map<String,String> parameters, String[] urls) { FilterHolder filterHolder = getFilterHolder(name, classname, parameters); FilterMapping fmap = getFilterMapping(name, urls); defineFilter(ctx, filterHolder, fmap); }