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

The following examples show how to use org.mortbay.jetty.webapp.WebAppContext#setContextPath() . 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 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 5
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 6
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 7
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 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 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 10
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 11
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 12
Source File: HermesClassLoaderMetaServer.java    From hermes with Apache License 2.0 5 votes vote down vote up
@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 13
Source File: HttpServer.java    From tajo with Apache License 2.0 4 votes vote down vote up
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 14
Source File: HttpServer.java    From incubator-tajo with Apache License 2.0 4 votes vote down vote up
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 15
Source File: JettyMain.java    From fraud-detection-tutorial with Apache License 2.0 4 votes vote down vote up
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 16
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 17
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();
	}
 
Example 18
Source File: JettyTest.java    From fraud-detection-tutorial with Apache License 2.0 2 votes vote down vote up
public static void main(String args[]) throws Exception {

    LocalHBaseCluster hbaseCluster = new LocalHBaseCluster();
    Configuration config = hbaseCluster.getConfiguration();
    QueueToHBaseProcess queueHBaseProcess = null;
    try {
      System.out.println("Step 1: Config");

      HBaseService hbaseService = new HBaseService(config);

      System.out.println("Step 2: Service");

      hbaseService.generateTables();

      System.out.println("Step 2.5: Tables");

      populateInitialNodes(hbaseService);

      System.out.println("Step 2.75: Rules");

      //populateRules(hbaseService);

      System.out.println("Step 3: Nodes Populated");

      EventListener listener = new InternalQueueListener();

      System.out.println("Step 4: Listener");

      long sleepBetweenIterations = 5000;
      long maxIterations = 200;
      int updateNodeListEveryNIterations = 100;
      int updateEtcFileEveryNRequest = 7;

      NodeDataSymulator sym = new NodeDataSymulator(listener, hbaseService,
              sleepBetweenIterations, maxIterations,
              updateNodeListEveryNIterations, updateEtcFileEveryNRequest);

      queueHBaseProcess = new QueueToHBaseProcess(hbaseService);

      queueHBaseProcess.start();

      sym.run(10);

      System.out.println("Step 5: Sym");


      System.out.println("Step 6: API Test");

      Server server = new Server(8082);

      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 {
      queueHBaseProcess.stop();

      hbaseCluster.shutDown();


      System.out.println("Step 7: Shut Down");
    }
  }