org.mortbay.jetty.webapp.WebAppContext Java Examples
The following examples show how to use
org.mortbay.jetty.webapp.WebAppContext.
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: JettyLauncher.java From nextreports-server with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Server server = new Server(); SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(PORT); server.addConnector(connector); server.setStopAtShutdown(true); // the orders of handlers is very important! ContextHandler contextHandler = new ContextHandler(); contextHandler.setContextPath("/reports"); contextHandler.setResourceBase("./reports/"); contextHandler.addHandler(new ResourceHandler()); server.addHandler(contextHandler); server.addHandler(new WebAppContext("webapp", "/nextreports-server")); long t = System.currentTimeMillis(); server.start(); t = System.currentTimeMillis() - t; String version = server.getClass().getPackage().getImplementationVersion(); System.out.println("Started Jetty Server " + version + " on port " + PORT + " in " + t / 1000 + "s"); 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( 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 #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( 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 #5
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 #6
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 #7
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 #8
Source File: HttpServer.java From hadoop-gpu with Apache License 2.0 | 5 votes |
/** * Add a context * @param pathSpec The path spec for the context * @param dir The directory containing the context * @param isFiltered if true, the servlet is added to the filter path mapping * @throws IOException */ protected void addContext(String pathSpec, String dir, boolean isFiltered) throws IOException { if (0 == webServer.getHandlers().length) { throw new RuntimeException("Couldn't find handler"); } WebAppContext webAppCtx = new WebAppContext(); webAppCtx.setContextPath(pathSpec); webAppCtx.setWar(dir); addContext(webAppCtx, true); }
Example #9
Source File: HttpServer.java From tajo with Apache License 2.0 | 5 votes |
/** * Add a context * @param pathSpec The path spec for the context * @param dir The directory containing the context * @param isFiltered if true, the servlet is added to the filter path mapping * @throws IOException */ protected void addContext(String pathSpec, String dir, boolean isFiltered) throws IOException { if (0 == webServer.getHandlers().length) { throw new RuntimeException("Couldn't find handler"); } WebAppContext webAppCtx = new WebAppContext(); webAppCtx.setContextPath(pathSpec); webAppCtx.setWar(dir); addContext(webAppCtx, true); }
Example #10
Source File: HttpServer.java From incubator-tajo with Apache License 2.0 | 5 votes |
/** * Add a context * @param pathSpec The path spec for the context * @param dir The directory containing the context * @param isFiltered if true, the servlet is added to the filter path mapping * @throws IOException */ protected void addContext(String pathSpec, String dir, boolean isFiltered) throws IOException { if (0 == webServer.getHandlers().length) { throw new RuntimeException("Couldn't find handler"); } WebAppContext webAppCtx = new WebAppContext(); webAppCtx.setContextPath(pathSpec); webAppCtx.setWar(dir); addContext(webAppCtx, true); }
Example #11
Source File: HttpServer.java From big-c with Apache License 2.0 | 5 votes |
/** * Add a context * @param pathSpec The path spec for the context * @param dir The directory containing the context * @param isFiltered if true, the servlet is added to the filter path mapping * @throws IOException */ protected void addContext(String pathSpec, String dir, boolean isFiltered) throws IOException { if (0 == webServer.getHandlers().length) { throw new RuntimeException("Couldn't find handler"); } WebAppContext webAppCtx = new WebAppContext(); webAppCtx.setContextPath(pathSpec); webAppCtx.setWar(dir); addContext(webAppCtx, true); }
Example #12
Source File: WebAppContextHelper.java From yawp with MIT License | 5 votes |
public WebAppContext createWebApp() { webapp = createWebAppContext(); webapp.setDefaultsDescriptor(getWebDefaultXml()); configureCustom(); configureClassloader(); configureHotDeploy(); return webapp; }
Example #13
Source File: WebAppContextHelper.java From yawp with MIT License | 5 votes |
protected WebAppContext createWebAppContext() { try { Resource jettyEnv = Resource.newResource(String.format("%s/WEB-INF/jetty-env.xml", mojo.getAppDir())); XmlConfiguration conf = new XmlConfiguration(jettyEnv.getInputStream()); WebAppContext webapp = (WebAppContext) conf.configure(); webapp.setWar(mojo.getAppDir()); System.setProperty("java.naming.factory.url.pkgs", "org.mortbay.naming"); System.setProperty("java.naming.factory.initial", "org.mortbay.naming.InitialContextFactory"); return webapp; } catch (Exception e) { throw new RuntimeException(e); } }
Example #14
Source File: HttpServer.java From hadoop with Apache License 2.0 | 5 votes |
/** * Add a context * @param pathSpec The path spec for the context * @param dir The directory containing the context * @param isFiltered if true, the servlet is added to the filter path mapping * @throws IOException */ protected void addContext(String pathSpec, String dir, boolean isFiltered) throws IOException { if (0 == webServer.getHandlers().length) { throw new RuntimeException("Couldn't find handler"); } WebAppContext webAppCtx = new WebAppContext(); webAppCtx.setContextPath(pathSpec); webAppCtx.setWar(dir); addContext(webAppCtx, true); }
Example #15
Source File: JettyContainer.java From light-task-scheduler with Apache License 2.0 | 5 votes |
public static void main(String[] args) { try { String confPath = args[0]; confPath = confPath.trim(); Properties conf = new Properties(); InputStream is = new FileInputStream(new File(confPath + "/conf/lts-admin.cfg")); conf.load(is); String port = conf.getProperty("port"); if (port == null || port.trim().equals("")) { port = "8081"; } String contextPath = conf.getProperty("contextPath"); if (contextPath == null || contextPath.trim().equals("")) { contextPath = "/"; } Server server = new Server(Integer.parseInt(port)); WebAppContext webapp = new WebAppContext(); webapp.setWar(confPath + "/war/lts-admin.war"); webapp.setContextPath(contextPath); Map<String, String> initParams = new HashMap<String, String>(); initParams.put("lts.admin.config.path", confPath + "/conf"); webapp.setInitParams(initParams); server.setHandler(webapp); server.setStopAtShutdown(true); server.start(); System.out.println("LTS-Admin started. http://" + NetUtils.getLocalHost() + ":" + port + (contextPath == "/" ? "" : contextPath) + "/index.htm"); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
Example #16
Source File: HttpServer.java From RDFS 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); int maxThreads = conf.getInt(HTTP_MAX_THREADS, -1); // If HTTP_MAX_THREADS is not configured, QueueThreadPool() will use the // default value (currently 254). QueuedThreadPool threadPool = maxThreads == -1 ? new QueuedThreadPool() : new QueuedThreadPool(maxThreads); webServer.setThreadPool(threadPool); final String appDir = getWebAppsPath(); ContextHandlerCollection contexts = new ContextHandlerCollection(); webServer.setHandler(contexts); webAppContext = new WebAppContext(); webAppContext.setContextPath("/"); webAppContext.setWar(appDir + "/" + name); webAppContext.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, conf); webServer.addHandler(webAppContext); addDefaultApps(contexts, appDir); addGlobalFilter("safety", QuotingInputFilter.class.getName(), null); final FilterInitializer[] initializers = getFilterInitializers(conf); if (initializers != null) { for(FilterInitializer c : initializers) { c.initFilter(this); } } addDefaultServlets(); }
Example #17
Source File: HermesClassLoaderMetaServer.java From hermes with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") protected void configure(WebAppContext context) throws Exception { File warRoot = getWarRoot(); m_resource = new WebModuleResource(warRoot); context.getInitParams().put("org.mortbay.jetty.servlet.Default.dirAllowed", "false"); context.setContextPath(getContextPath()); context.setDescriptor(new File(warRoot, "WEB-INF/web.xml").getPath()); context.setBaseResource(m_resource); }
Example #18
Source File: HermesClassLoaderMetaServer.java From hermes with Apache License 2.0 | 5 votes |
public void startServer() throws Exception { Server server = new Server(port); WebAppContext context = new ResourceFallbackWebAppContext(); configure(context); ClassLoader parent = new HermesClassLoader(((URLClassLoader) this.getClass().getClassLoader()).getURLs(), "com.ctrip.", "com.dianping.", "org.unidal."); context.setClassLoader(new WebAppClassLoader(parent, context)); context.addServlet(new ServletHolder(new WebModuleServlet(m_resource)), "/"); // find LoadMocksListener with HermesClassLoader Class clazz = parent.loadClass("com.ctrip.hermes.metaserver.fulltest.LoadMocksListener"); Object obj = clazz.newInstance(); Field field = clazz.getDeclaredField("port"); field.setAccessible(true); field.set(obj, port); context.addEventListener((EventListener) obj); server.addHandler(context); try { server.start(); } catch (java.net.BindException e) { log.warn("CustomClassLoaderMetaServer[localhost:{}] start fail, BindException.", port); } postConfigure(context); m_server = server; }
Example #19
Source File: HttpServer.java From RDFS with Apache License 2.0 | 5 votes |
/** * Add a context * @param pathSpec The path spec for the context * @param dir The directory containing the context * @param isFiltered if true, the servlet is added to the filter path mapping * @throws IOException */ protected void addContext(String pathSpec, String dir, boolean isFiltered) throws IOException { if (0 == webServer.getHandlers().length) { throw new RuntimeException("Couldn't find handler"); } WebAppContext webAppCtx = new WebAppContext(); webAppCtx.setContextPath(pathSpec); webAppCtx.setWar(dir); addContext(webAppCtx, true); }
Example #20
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 #21
Source File: WebAppContextHelper.java From yawp with MIT License | 4 votes |
private void restart(WebAppContext webapp) throws Exception { webapp.stop(); configureClassloader(); webapp.start(); }
Example #22
Source File: AppengineWebAppContextHelper.java From yawp with MIT License | 4 votes |
@Override protected WebAppContext createWebAppContext() { return new AppengineWebAppContext(mojo); }
Example #23
Source File: HttpServer.java From incubator-tajo with Apache License 2.0 | 4 votes |
public HttpServer(String name, String bindAddress, int port, boolean findPort, Connector connector, Configuration conf, String[] pathSpecs) throws IOException { this.webServer = new Server(); this.findPort = findPort; if (connector == null) { listenerStartedExternally = false; listener = createBaseListener(conf); listener.setHost(bindAddress); listener.setPort(port); } else { listenerStartedExternally = true; listener = connector; } webServer.addConnector(listener); SessionIdManager sessionIdManager = new HashSessionIdManager(new Random(System.currentTimeMillis())); webServer.setSessionIdManager(sessionIdManager); int maxThreads = conf.getInt("tajo.http.maxthreads", -1); // If HTTP_MAX_THREADS is not configured, QueueThreadPool() will use the // default value (currently 250). QueuedThreadPool threadPool = maxThreads == -1 ? new QueuedThreadPool() : new QueuedThreadPool(maxThreads); webServer.setThreadPool(threadPool); final String appDir = getWebAppsPath(name); ContextHandlerCollection contexts = new ContextHandlerCollection(); webAppContext = new WebAppContext(); webAppContext.setDisplayName(name); webAppContext.setContextPath("/"); webAppContext.setResourceBase(appDir + "/" + name); webAppContext.setDescriptor(appDir + "/" + name + "/WEB-INF/web.xml"); contexts.addHandler(webAppContext); webServer.setHandler(contexts); addDefaultApps(contexts, appDir, conf); }
Example #24
Source File: Jetty6PluginServer.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
/** * @see Jetty6PluginServer#addWebApplication */ public void addWebApplication(WebAppContext webapp) throws Exception { contexts.addHandler(webapp); }
Example #25
Source File: HttpServer.java From tajo with Apache License 2.0 | 4 votes |
public HttpServer(String name, String bindAddress, int port, boolean findPort, Connector connector, Configuration conf, String[] pathSpecs) throws IOException { this.webServer = new Server(); this.findPort = findPort; if (connector == null) { listenerStartedExternally = false; listener = createBaseListener(conf); listener.setHost(bindAddress); listener.setPort(port); } else { listenerStartedExternally = true; listener = connector; } webServer.addConnector(listener); SessionIdManager sessionIdManager = new HashSessionIdManager(new Random(System.currentTimeMillis())); webServer.setSessionIdManager(sessionIdManager); int maxThreads = conf.getInt("tajo.http.maxthreads", -1); // If HTTP_MAX_THREADS is not configured, QueueThreadPool() will use the // default value (currently 250). QueuedThreadPool threadPool = maxThreads == -1 ? new QueuedThreadPool() : new QueuedThreadPool(maxThreads); webServer.setThreadPool(threadPool); final String appDir = getWebAppsPath(name); ContextHandlerCollection contexts = new ContextHandlerCollection(); webAppContext = new WebAppContext(); webAppContext.setDisplayName(name); webAppContext.setContextPath("/"); webAppContext.setResourceBase(appDir + "/" + name); webAppContext.setDescriptor(appDir + "/" + name + "/WEB-INF/web.xml"); contexts.addHandler(webAppContext); webServer.setHandler(contexts); addDefaultApps(contexts, appDir, conf); }
Example #26
Source File: JettyMain.java From fraud-detection-tutorial with Apache License 2.0 | 4 votes |
public static void main(String args[]) throws Exception { if (args.length == 0) { System.out.println("JettyMain {port} {zookeeperQuorum}"); } try { Configuration config = HBaseConfiguration.create(); config.addResource("/etc/hbase/conf/hbase-site.xml"); config.set(HConstants.ZOOKEEPER_QUORUM, args[1]); //config.set(HConstants.ZOOKEEPER_CLIENT_PORT, "2181"); HBaseService hbaseService = new HBaseService(config); Server server = new Server(Integer.parseInt(args[0])); WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/fe"); webapp.setResourceBase("./webapp"); webapp.setWelcomeFiles(new String[]{"index.html"}); Context servletContext = new Context(); servletContext.setContextPath("/be"); servletContext.addServlet(GraphTsvServlet.class, "/graph.tsv"); servletContext.addServlet(FileGetterServlet.class, "/file/*"); servletContext.addServlet(NodeAutoCompleteServlet.class, "/auto/*"); servletContext.addServlet(GraphNodeJsonServlet.class, "/nodeGraph/*"); servletContext.addServlet(NodeHomeDashBoardInfoServlet.class, "/nodeDash/*"); server.setHandlers(new Handler[]{webapp, servletContext}); System.out.println("-"); GraphTsvServlet.setHBaseService(hbaseService); FileGetterServlet.setHBaseService(hbaseService); NodeAutoCompleteServlet.setHBaseService(hbaseService); GraphNodeJsonServlet.setHBaseService(hbaseService); NodeHomeDashBoardInfoServlet.setHBaseService(hbaseService); server.start(); server.join(); } finally { System.out.println("Step 7: Shut Down"); } }
Example #27
Source File: HttpServer.java From big-c with Apache License 2.0 | 4 votes |
public WebAppContext getWebAppContext(){ return this.webAppContext; }
Example #28
Source File: Jetty6PluginServer.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
/** * @see Jetty6PluginServer#addWebApplication */ public void addWebApplication(WebAppContext webapp) throws Exception { contexts.addHandler(webapp); }
Example #29
Source File: Jetty6PluginServer.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
/** * @see Jetty6PluginServer#addWebApplication */ public void addWebApplication(WebAppContext webapp) throws Exception { contexts.addHandler(webapp); }
Example #30
Source File: StartMetaServer.java From hermes with Apache License 2.0 | 4 votes |
@Override protected void postConfigure(WebAppContext context) { context.addFilter(GzipFilter.class, "/*", Handler.ALL); }