Java Code Examples for org.mortbay.jetty.servlet.Context#setResourceBase()

The following examples show how to use org.mortbay.jetty.servlet.Context#setResourceBase() . 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: MyriadWebServer.java    From incubator-myriad with Apache License 2.0 6 votes vote down vote up
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 2
Source File: HttpServer.java    From RDFS with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: HttpServer.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
/**
 * 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 4
Source File: HttpServer.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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)) {
      logContext.getInitParams().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 5
Source File: HttpServer2.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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 6
Source File: HttpServer.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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)) {
      logContext.getInitParams().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 7
Source File: HttpServer2.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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 8
Source File: WebServer.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public WebServer(int httpport, DataStore data, MetadataStore metadata) throws IOException, URISyntaxException {
    super(httpport);

    extractWebUI();

    this.data = data;
    this.metadata = metadata;

    // Initialize Velocity template engine
    try {
        Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.Log4JLogChute");
        Velocity.setProperty("runtime.log.logsystem.log4j.logger", "edu.berkeley.xtrace.server.XTraceServer");
        Velocity.setProperty("file.resource.loader.path", webui + "/templates");
        Velocity.setProperty("file.resource.loader.cache", "true");
        Velocity.init();
    } catch (Exception e) {
        LOG.warn("Failed to initialize Velocity", e);
    }

    // Create Jetty server
    Context context = new Context(this, "/");

    // Create a CGI servlet for scripts in webui/cgi-bin
    ServletHolder cgiHolder = new ServletHolder(new CGI());
    cgiHolder.setInitParameter("cgibinResourceBase", webui + "/cgi-bin");

    // Pass any special PATH setting on to the execution environment
    if (System.getenv("PATH") != null)
        cgiHolder.setInitParameter("Path", System.getenv("PATH"));

    context.addServlet(cgiHolder, "*.cgi");
    context.addServlet(cgiHolder, "*.pl");
    context.addServlet(cgiHolder, "*.py");
    context.addServlet(cgiHolder, "*.rb");
    context.addServlet(cgiHolder, "*.tcl");
    context.addServlet(new ServletHolder(new GetReportsServlet()), "/reports/*");
    context.addServlet(new ServletHolder(new TagServlet()), "/tag/*");
    context.addServlet(new ServletHolder(new TitleServlet()), "/title/*");
    context.addServlet(new ServletHolder(new TitleLikeServlet()), "/titleLike/*");

    // JSON APIs for interactive visualization
    context.addServlet(new ServletHolder(new GetJSONReportsServlet()), "/interactive/reports/*");
    context.addServlet(new ServletHolder(new GetOverlappingTasksServlet()), "/interactive/overlapping/*");
    context.addServlet(new ServletHolder(new GetTagsForTaskServlet()), "/interactive/tags/*");
    context.addServlet(new ServletHolder(new GetTasksForTags()), "/interactive/taggedwith/*");

    context.setResourceBase(webui + "/html");
    context.addServlet(new ServletHolder(new IndexServlet()), "/");
}
 
Example 9
Source File: BaseJettyServer.java    From recipes-rss with Apache License 2.0 4 votes vote down vote up
public void start() {

        final int port   = ConfigurationManager.getConfigInstance().getInt(RSSConstants.JETTY_HTTP_PORT, Integer.MIN_VALUE);

        final Context context = new Context(jettyServer, "/", Context.SESSIONS);
        context.setResourceBase(RSSConstants.WEBAPPS_DIR);
        context.setClassLoader(Thread.currentThread().getContextClassLoader());
        context.addServlet(JspServlet.class, "*.jsp");

        // Enable hystrix.stream
        context.addServlet(HystrixMetricsStreamServlet.class, RSSConstants.HYSTRIX_STREAM_PATH);

        final Server server = new Server(port);
        server.setHandler(context);

        try {
            karyonServer.start();
            server.start();
        } catch (Exception exc) {
            throw new RuntimeException("Cannot start karyon server ...", exc);
        }
    }