当前位置: 首页>>代码示例>>Java>>正文


Java ResourceHandler类代码示例

本文整理汇总了Java中org.mortbay.jetty.handler.ResourceHandler的典型用法代码示例。如果您正苦于以下问题:Java ResourceHandler类的具体用法?Java ResourceHandler怎么用?Java ResourceHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ResourceHandler类属于org.mortbay.jetty.handler包,在下文中一共展示了ResourceHandler类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.mortbay.jetty.handler.ResourceHandler; //导入依赖的package包/类
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();
}
 
开发者ID:nextreports,项目名称:nextreports-server,代码行数:26,代码来源:JettyLauncher.java

示例2: main

import org.mortbay.jetty.handler.ResourceHandler; //导入依赖的package包/类
/**
 * Sets up and runs server.
 * @param args
 */
public static void main(String[] args)
{
    final Server server = new Server();

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8080);
    server.addConnector(connector);

    Context htmlContext = new Context(server, "/", Context.SESSIONS);

    ResourceHandler htmlHandler = new ResourceHandler();
    htmlHandler.setResourceBase("web");
    htmlContext.setHandler(htmlHandler);

    Context servletContext = new Context(server, "/", Context.SESSIONS);

    GenericWebApplicationContext springContext = new GenericWebApplicationContext();
    springContext.setParent(new ClassPathXmlApplicationContext("org/getahead/dwrdemo/cli/spring.xml"));
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, springContext);

    ServletHolder holder = new ServletHolder(new DwrSpringServlet());
    holder.setInitParameter("pollAndCometEnabled", "true");
    holder.setInitParameter("debug", "true");
    servletContext.addServlet(holder, "/dwr/*");

    try
    {
        JettyShutdown.addShutdownHook(server);
        server.start();
        server.join();
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:41,代码来源:JettySpringLauncher.java

示例3: main

import org.mortbay.jetty.handler.ResourceHandler; //导入依赖的package包/类
/**
 * Sets up and runs server.
 * @param args
 */
public static void main(String[] args)
{
    Server server = new Server();

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8080);
    server.addConnector(connector);

    Context htmlContext = new Context(server, "/", Context.SESSIONS);
    ResourceHandler htmlHandler = new ResourceHandler();
    htmlHandler.setResourceBase("web");
    htmlContext.setHandler(htmlHandler);

    Context servletContext = new Context(server, "/", Context.SESSIONS);
    ServletHolder holder = new ServletHolder(new DwrServlet());
    holder.setInitParameter("activeReverseAjaxEnabled", "true");
    holder.setInitParameter("debug", "true");
    servletContext.addServlet(holder, "/dwr/*");
    servletContext.setResourceBase("web");

    try
    {
        JettyShutdown.addShutdownHook(server);
        server.start();
        server.join();
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:36,代码来源:JettyLauncher.java

示例4: getServer

import org.mortbay.jetty.handler.ResourceHandler; //导入依赖的package包/类
/**
 * Creates a new JettyServer with one static root context
 * 
 * @param port
 *          port to listen to
 * @param staticContent
 *          folder where static content lives
 * @throws UnknownHostException
 */
public static Server getServer(int port, String staticContent)
    throws UnknownHostException {
  Server webServer = new org.mortbay.jetty.Server();
  SocketConnector listener = new SocketConnector();
  listener.setPort(port);
  listener.setHost("127.0.0.1");
  webServer.addConnector(listener);
  ContextHandler staticContext = new ContextHandler();
  staticContext.setContextPath("/");
  staticContext.setResourceBase(staticContent);
  staticContext.addHandler(new ResourceHandler());
  webServer.addHandler(staticContext);
  return webServer;
}
 
开发者ID:jorcox,项目名称:GeoCrawler,代码行数:24,代码来源:CrawlDBTestUtil.java

示例5: newFileHandler

import org.mortbay.jetty.handler.ResourceHandler; //导入依赖的package包/类
public static ResourceHandler newFileHandler(String baseDir) {
    if (StringUtils.isBlank(baseDir)) {
        baseDir = ".";
    }
    ResourceHandler fileHandler = new ResourceHandler();

    fileHandler.setResourceBase(baseDir);
    return fileHandler;
}
 
开发者ID:niuxuetao,项目名称:paxml,代码行数:10,代码来源:FileServer.java

示例6: getServer

import org.mortbay.jetty.handler.ResourceHandler; //导入依赖的package包/类
/**
 * Creates a new JettyServer with one static root context
 * 
 * @param port port to listen to
 * @param staticContent folder where static content lives
 * @throws UnknownHostException 
 */
public static Server getServer(int port, String staticContent) throws UnknownHostException{
  Server webServer = new org.mortbay.jetty.Server();
  SocketConnector listener = new SocketConnector();
  listener.setPort(port);
  listener.setHost("127.0.0.1");
  webServer.addConnector(listener);
  ContextHandler staticContext = new ContextHandler();
  staticContext.setContextPath("/");
  staticContext.setResourceBase(staticContent);
  staticContext.addHandler(new ResourceHandler());
  webServer.addHandler(staticContext);
  return webServer;
}
 
开发者ID:yahoo,项目名称:anthelion,代码行数:21,代码来源:CrawlDBTestUtil.java

示例7: setupLocalServer

import org.mortbay.jetty.handler.ResourceHandler; //导入依赖的package包/类
@Before
public void setupLocalServer() throws Exception {

    // Set up a local Jetty HTTP server
    Server server = new Server();
    server.addConnector(new SocketConnector());
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase("src/test/resources/server");
    server.addHandler(resourceHandler);
    server.start();

    // The server will have a random port assigned, so capture that
    localPort = server.getConnectors()[0].getLocalPort();
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:15,代码来源:LocalServerWebDriverContainerTest.java

示例8: startHttpServerWithDocRoot

import org.mortbay.jetty.handler.ResourceHandler; //导入依赖的package包/类
public static int startHttpServerWithDocRoot(String root)
        throws Exception {
    if (SERVER != null) {
        SERVER.stop();
        SERVER = null;
    }
    SERVER = new Server(0);
    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase(root);
    SERVER.setHandler(resource_handler);
    SERVER.start();
    PORT = SERVER.getConnectors()[0].getLocalPort();
    return PORT;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:15,代码来源:Support_Jetty.java

示例9: createJettyServer

import org.mortbay.jetty.handler.ResourceHandler; //导入依赖的package包/类
protected Server createJettyServer(Site site){
    Server server = new Server();
    //FIXME
    server.setStopAtShutdown(true);

    Connector defaultConnector = createConnector(null, port);
    server.setConnectors( new Connector[] { defaultConnector } );

    String root = site.getRoot();
    String resourceBase = site.getDestination().getPath();
    getLog().info("Server resource base: " + resourceBase);

    if("".equals(root)){
        ResourceHandler resourceHandler = new ResourceHandler();
        //resourceHandler.setDirectoriesListed(true);
        resourceHandler.setWelcomeFiles(new String[]{"index.html"});

        resourceHandler.setResourceBase(resourceBase/*site.getDestination().getPath()*/);

        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[] { resourceHandler, new DefaultHandler()});
        server.setHandler(handlers);
        //server.setHandlers(new Handler[]{handlers, logHandler});
        //getLog().info( "Startisng preview server on http://localhost:" + port + "/" );
    } else {
        getLog().info("Using " + ContextHandler.class.getName());
        ContextHandler contextHandler = new ContextHandler();
        contextHandler.setContextPath(root);
        contextHandler.setHandler(new ResourceHandler());
        contextHandler.setResourceBase(resourceBase/*site.getDestination().getPath()*/);
        //server.setHandler(contextHandler);
        server.setHandlers(new Handler[]{contextHandler, new DefaultHandler()});
        //server.setHandlers(new Handler[]{contextHandler, logHandler});
        //log.info( "Starting preview server on http://localhost:" + port + root );
    }
    return server;
}
 
开发者ID:opoo,项目名称:opoopress,代码行数:38,代码来源:AbstractServerMojo.java

示例10: makeHandlers

import org.mortbay.jetty.handler.ResourceHandler; //导入依赖的package包/类
/**
 * Make the handlers for the HTTP server to test against
 * @return the handlers
 * @throws IOException if the handlers could not be created
 */
protected Handler[] makeHandlers() throws IOException {
    //serve resources from temporary folder
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setBaseResource(Resource.newResource(
            folder.getRoot().getAbsolutePath()));
    return new Handler[] { resourceHandler, new DefaultHandler() };
}
 
开发者ID:michel-kraemer,项目名称:gradle-download-task,代码行数:13,代码来源:TestBase.java

示例11: start

import org.mortbay.jetty.handler.ResourceHandler; //导入依赖的package包/类
public void start() throws Exception {
  // static files
  final ResourceHandler staticHandler = new ResourceHandler();
  staticHandler.setResourceBase("html");

  Handler handler = new AbstractHandler() {
    @Override
    public void handle(String target, HttpServletRequest request,
                       HttpServletResponse response, int dispatch) {
      try{
        // timeunit
        int timeunit = 1000;   // second, divide millionsecond / 1000
        String timeunitLabel = "second";
        if (request.getParameter("u")!= null &&
                request.getParameter("u").equalsIgnoreCase("m")) {
          timeunit = 1000 * 60;
          timeunitLabel = "minute";
        }

        // http request
        if (target.equals("/")) {
          printPageIndex(request, response);
        } else if (target.equals("/simulate")) {
          printPageSimulate(request, response, timeunit, timeunitLabel);
        } else if (target.equals("/track")) {
          printPageTrack(request, response, timeunit, timeunitLabel);
        } else
          // js/css request
          if (target.startsWith("/js") || target.startsWith("/css")) {
            response.setCharacterEncoding("utf-8");
            staticHandler.handle(target, request, response, dispatch);
          } else
            // json request
            if (target.equals("/simulateMetrics")) {
              printJsonMetrics(request, response);
            } else if (target.equals("/trackMetrics")) {
              printJsonTrack(request, response);
            }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  };

  server = new Server(port);
  server.setHandler(handler);

  server.start();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:50,代码来源:SLSWebApp.java

示例12: getResourceHandler

import org.mortbay.jetty.handler.ResourceHandler; //导入依赖的package包/类
private static ResourceHandler getResourceHandler(String resourceBase) {
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase(resourceBase);
    resourceHandler.setCacheControl("max-age=0, no-cache, no-store, must-revalidate");
    return resourceHandler;
}
 
开发者ID:code-orchestra,项目名称:colt-core,代码行数:7,代码来源:CodeOrchestraResourcesHttpServer.java

示例13: createServer

import org.mortbay.jetty.handler.ResourceHandler; //导入依赖的package包/类
/**
 * Starts the server for end-to-end tests.
 */
private Server createServer(int port) throws Exception {
  Server newServer = new Server(port);

  // Attach the test resources in /endtoend as static content for the test
  ResourceHandler resources = new ResourceHandler();
  URL resource = EndToEndTest.class.getResource("/endtoend");
  resources.setBaseResource(Resource.newResource(resource));
  newServer.addHandler(resources);

  Context context = new Context(newServer, "/", Context.SESSIONS);
  context.addEventListener(new GuiceServletContextListener());

  Map<String, String> initParams = Maps.newHashMap();
  String modules = Joiner.on(":")
      .join(SampleModule.class.getName(), DefaultGuiceModule.class.getName(),
          PropertiesModule.class.getName(), OAuthModule.class.getName());

  initParams.put(GuiceServletContextListener.MODULES_ATTRIBUTE, modules);
  context.setInitParams(initParams);

  // Attach the gadget rendering servlet
  ServletHolder gadgetServletHolder = new ServletHolder(new GadgetRenderingServlet());
  context.addServlet(gadgetServletHolder, GADGET_BASE);

  // Attach DataServiceServlet, wrapped in a proxy to fake errors
  ServletHolder restServletHolder = new ServletHolder(new ForceErrorServlet(
      new DataServiceServlet()));
  restServletHolder.setInitParameter("handlers", "org.apache.shindig.social.handlers");
  context.addServlet(restServletHolder, REST_BASE);
  context.addFilter(AuthenticationServletFilter.class, REST_BASE, 0);

  // Attach JsonRpcServlet, wrapped in a proxy to fake errors
  ServletHolder rpcServletHolder = new ServletHolder(new ForceErrorServlet(
      new JsonRpcServlet()));
  rpcServletHolder.setInitParameter("handlers", "org.apache.shindig.social.handlers");
  context.addServlet(rpcServletHolder, JSON_RPC_BASE);
  context.addFilter(AuthenticationServletFilter.class, JSON_RPC_BASE, 0);

  // Attach the ConcatProxyServlet - needed for rewritten JS
  ServletHolder concatHolder = new ServletHolder(new ConcatProxyServlet());
  context.addServlet(concatHolder, CONCAT_BASE);

  // Attach the JsServlet - needed for rewritten JS
  ServletHolder jsHolder = new ServletHolder(new JsServlet());
  context.addServlet(jsHolder, JS_BASE);

  // Attach MakeRequestServlet
  ServletHolder makeRequestHolder = new ServletHolder(new MakeRequestServlet());
  context.addServlet(makeRequestHolder, MAKE_REQUEST_BASE);
  
  // Attach an EchoServlet, used to test proxied rendering
  ServletHolder echoHolder = new ServletHolder(new EchoServlet());
  context.addServlet(echoHolder, "/echo");
  
  return newServer;
}
 
开发者ID:inevo,项目名称:shindig-1.1-BETA5-incubating,代码行数:60,代码来源:EndToEndServer.java


注:本文中的org.mortbay.jetty.handler.ResourceHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。