Java Code Examples for org.mortbay.jetty.webapp.WebAppContext#setWar()

The following examples show how to use org.mortbay.jetty.webapp.WebAppContext#setWar() . 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 hadoop with Apache License 2.0 6 votes vote down vote up
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 2
Source File: HttpServer2.java    From big-c with Apache License 2.0 6 votes vote down vote up
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 3
Source File: HttpServer.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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 4
Source File: HttpServer.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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 5
Source File: HttpServer.java    From tajo with Apache License 2.0 5 votes vote down vote up
/**
 * 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 6
Source File: HttpServer.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
/**
 * 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 7
Source File: WebAppContextHelper.java    From yawp with MIT License 5 votes vote down vote up
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 8
Source File: JettyContainer.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
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 9
Source File: HttpServer.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * 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 10
Source File: HttpServer.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * 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 hadoop-gpu with Apache License 2.0 5 votes vote down vote up
/**
 * 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 12
Source File: HttpServer.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
/**
 * 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 13
Source File: SubsonicDeployer.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
private void deployWebApp() {
    try {
        Server server = new Server();
        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
        connector.setHeaderBufferSize(HEADER_BUFFER_SIZE);
        connector.setHost(getHost());
        connector.setPort(getPort());
        if (isHttpsEnabled()) {
            connector.setConfidentialPort(getHttpsPort());
        }
        server.addConnector(connector);

        if (isHttpsEnabled()) {
            SslSocketConnector sslConnector = new SslSocketConnector();
            sslConnector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
            sslConnector.setHeaderBufferSize(HEADER_BUFFER_SIZE);
            sslConnector.setHost(getHost());
            sslConnector.setPort(getHttpsPort());
            sslConnector.setKeystore(System.getProperty("subsonic.ssl.keystore", getClass().getResource("/subsonic.keystore").toExternalForm()));
            sslConnector.setPassword(System.getProperty("subsonic.ssl.password", "subsonic"));
            server.addConnector(sslConnector);
        }

        WebAppContext context = new WebAppContext();
        context.setTempDirectory(getJettyDirectory());
        context.setContextPath(getContextPath());
        context.setWar(getWar());
        context.setOverrideDescriptor("/web-jetty.xml");

        if (isHttpsEnabled()) {

            // Allow non-https for streaming and cover art (for Chromecast, UPnP, Sonos etc)
            context.getSecurityHandler().setConstraintMappings(new ConstraintMapping[]{
                    createConstraintMapping("/stream", Constraint.DC_NONE),
                    createConstraintMapping("/coverArt.view", Constraint.DC_NONE),
                    createConstraintMapping("/ws/*", Constraint.DC_NONE),
                    createConstraintMapping("/sonos/*", Constraint.DC_NONE),
                    createConstraintMapping("/", Constraint.DC_CONFIDENTIAL)
            });
        }

        server.addHandler(context);
        server.start();

        System.err.println("Subsonic running on: " + getUrl());
        if (isHttpsEnabled()) {
            System.err.println("                and: " + getHttpsUrl());
        }

    } catch (Throwable x) {
        x.printStackTrace();
        exception = x;
    }
}
 
Example 14
Source File: JettyServer.java    From athena-rest with Apache License 2.0 3 votes vote down vote up
protected void doStart() throws Exception {

		server = new Server();

		if (this.minThreads != -1 && this.maxThreads != -1) {
			BoundedThreadPool btp = new BoundedThreadPool();
			server.setThreadPool(btp);
		}

		SelectChannelConnector connector = new SelectChannelConnector();

		// Set some timeout options to make debugging easier.
		connector.setSoLingerTime(-1);
		connector.setPort(port);

		server.setConnectors(new Connector[] { connector });

		WebAppContext wac = new WebAppContext();

		wac.setServer(server);
		wac.setContextPath(contextPath);
		wac.setWar(webappPath);

		server.setHandler(wac);

		log.info("Starting jetty server actually.");
		server.start();
	}