本文整理汇总了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();
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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() };
}
示例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();
}
示例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;
}
示例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;
}