本文整理匯總了Java中org.eclipse.jetty.server.handler.HandlerList類的典型用法代碼示例。如果您正苦於以下問題:Java HandlerList類的具體用法?Java HandlerList怎麽用?Java HandlerList使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HandlerList類屬於org.eclipse.jetty.server.handler包,在下文中一共展示了HandlerList類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(PUBLIC_HTML);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
//page reloaded by the timer
context.addServlet(TimerServlet.class, "/timer");
//part of a page reloaded by the timer
context.addServlet(AjaxTimerServlet.class, "/server-time");
//long-polling waits till a message
context.addServlet(new ServletHolder(new MessengerServlet()), "/messenger");
//web chat
context.addServlet(WebSocketChatServlet.class, "/chat");
Server server = new Server(PORT);
server.setHandler(new HandlerList(resourceHandler, context));
server.start();
server.join();
}
示例2: startWebSocket
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
/**
* start server
*
* @param port
* @param path
* @param handlerClass
*/
public static void startWebSocket(int port, String path, String handlerClass) {
try {
Server server = new Server(port);
HandlerList handlerList = new HandlerList();
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addServlet(new ServletHolder(new Jwservlet(handlerClass)),
path);
handlerList.addHandler(context);
handlerList.addHandler(new DefaultHandler());
server.setHandler(handlerList);
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
LogUtil.LOG("start websocket server error:" + e.getMessage(),
LogLev.ERROR, WebSocketServer.class);
System.exit(1);
}
}
示例3: main
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(PUBLIC_HTML);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.addServlet(new ServletHolder(new LoginServlet("anonymous")), "/login");
context.addServlet(AdminServlet.class, "/admin");
context.addServlet(TimerServlet.class, "/timer");
Server server = new Server(PORT);
server.setHandler(new HandlerList(resourceHandler, context));
server.start();
server.join();
}
示例4: start
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
private void start() throws Exception {
resourcesExample();
ResourceHandler resourceHandler = new ResourceHandler();
Resource resource = Resource.newClassPathResource(PUBLIC_HTML);
resourceHandler.setBaseResource(resource);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.addServlet(new ServletHolder(new TimerServlet()), "/timer");
Server server = new Server(PORT);
server.setHandler(new HandlerList(resourceHandler, context));
server.start();
server.join();
}
示例5: main
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
// Create a basic Jetty server object that will listen on port 8080
Server server = new Server(8080);
// Create the ResourceHandler. It is the object that will actually
// handle the request for a given file. It is a Jetty Handler object
// so it is suitable for chaining with other handlers as you will see
// in other examples
ResourceHandler resource_handler = new ResourceHandler();
// Configure the ResourceHandler. Setting the resource base indicates
// where the files should be served out of
resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[]{ "index.html" });
resource_handler.setResourceBase("src/main/webapp/");
// Add the ResourceHandler to the server
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
server.setHandler(handlers);
// Start server
server.start();
server.join();
}
示例6: prepare
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public void prepare() {
try {
Tools.verifyLocalPort("DBServer ", port());
server = new Server();
DefaultHandler webHandler = new DefaultHandler();
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]{getResourceHandler(),
getUIWSHandler(), webHandler});
ServerConnector connector = new ServerConnector(server);
connector.setPort(port());
server.setConnectors(new Connector[]{connector});
server.setHandler(handlers);
LOG.log(Level.INFO, "DB Server on : http://{0}:{1}",
new Object[]{Tools.IP(), port() + ""});
} catch (Exception ex) {
LOG.log(Level.SEVERE, ex.getMessage(), ex);
}
}
示例7: getAllServices
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
private HandlerList getAllServices() throws Exception{
// File server & Context Handler for root, also setting the index.html
// to be the "welcome file", i.e, autolink on root addresses.
ContextHandler rootContext = new ContextHandler();
rootContext.setContextPath("/*");
rootContext.setHandler(getResourceHandlers());
// Possible servlet lists, for all servlets or custom services you want to access later.
// Warning, it might become a little bit nested if you add to many classes.
ServletHandler questionHandler = new ServletHandler();
questionHandler.addServletWithMapping(QuestionHandler.class, "/question");
// Add the ResourceHandler to the server.
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] {
rootContext ,
questionHandler,
});
return handlers;
}
示例8: startServer
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
private void startServer() {
HttpAPIConfig cfg = getSettings();
server = new Server(cfg.getPort());
HandlerList lst = new HandlerList();
LinkController ctr = new JDLinkController(LinkCollector.getInstance());
if(cfg.getUsePassword() && cfg.getPassword() != null && !cfg.getPassword().equals("")) {
lst.addHandler(new AuthorizationHandler(cfg.getPassword()));
}
lst.addHandler(new AjaxHandler(cfg.getAllowGet()));
if(cfg.getAllowGet()) {
lst.addHandler(new JDServerGETHandler(ctr));
}
lst.addHandler(new JDServerPOSTHandler(ctr));
server.setHandler(lst);
try {
server.start();
}
catch(Exception e) {
logger.log(new LogRecord(Level.SEVERE, e.getMessage()));
}
}
示例9: main
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public static void main(String[] args) {
int port = 8297;
HandlerList lst = new HandlerList();
String password = null;//"pass";
Server server = new Server(port);
JDServerPOSTHandler hnd;
LinkController ctr = new SampleLinkController();
if(password != null) {
lst.addHandler(new AuthorizationHandler(password));
}
lst.addHandler(new AjaxHandler(true));
lst.addHandler(new JDServerGETHandler(ctr));
lst.addHandler(new JDServerPOSTHandler(ctr));
server.setHandler(lst);
try {
server.start();
server.join();
}
catch(Exception e) {
System.out.println(e);
}
}
示例10: getHandlerList
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
protected Handler getHandlerList(List<String> hostList) {
// jettyServer.getWebappService().addHandler(new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/"));
// jettyServer.getWebappService().addHandler(new HostResourceHandler("ftrade.leopard.io", "/data/src/ftrade_html/"));
if (hostList.contains("fshop.leopard.io")) {
if (false) {
return new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/");
}
HandlerList handlerList = new HandlerList();
handlerList.addHandler(new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/"));
handlerList.addHandler(new HostResourceHandler("ftrade.leopard.io", "/data/src/ftrade_html/"));
try {
handlerList.start();
}
catch (Exception e) {
e.printStackTrace();
}
return handlerList;
}
return null;
}
示例11: start
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public void start() {
try {
final ServerConnector httpConnector = new ServerConnector(server);
httpConnector.setHost(root.host);
httpConnector.setPort(root.port);
httpConnector.setIdleTimeout(config.getInt("web.idle-timeout"));
server.addConnector(httpConnector);
final HandlerList handlers = new HandlerList();
handlers.addHandler(inContext("/static", newResourcesHandler()));
handlers.addHandler(inContext("/", new RootHandler(version, routes)));
server.setHandler(handlers);
server.start();
log.info("Web Server started on http://" + root.host + ":" + root.port);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
throw new RuntimeException(ex);
}
}
示例12: setUpGlobal
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
@BeforeClass
@Override
public void setUpGlobal() throws Exception {
port1 = findFreePort();
port2 = findFreePort();
server = newJettyHttpServer(port1);
addHttpConnector(server, port2);
HandlerList list = new HandlerList();
list.addHandler(new AbstractHandler() {
@Override
public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
if (request.getLocalPort() == port2) {
httpServletResponse.sendRedirect(getTargetUrl());
}
}
});
list.addHandler(getWebSocketHandler());
server.setHandler(list);
server.start();
logger.info("Local HTTP server started successfully");
}
示例13: start
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
/**
* Start the file server (blocking).
*
* @throws Exception If server cannot start
*/
public final void start() throws Exception {
LOGGER.info("Starting web interface at http://localhost:8000");
Server server = new Server(8000);
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[]{"index.html"});
resource_handler.setResourceBase("../website");
HandlerList handlers = new HandlerList();
handlers.setHandlers(
new Handler[]{
resource_handler,
new DefaultHandler()});
server.setHandler(handlers);
server.start();
}
示例14: run
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public void run(int port) throws Exception {
Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
server.addConnector(connector);
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[] { "index.html" });
resource_handler.setResourceBase("./performance/site/");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resource_handler,
new DefaultHandler() });
server.setHandler(handlers);
server.start();
System.out.println("Started performance file server at port: " + port);
server.join();
}
示例15: main
import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
AccountService accountService = new AccountService();
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.addServlet(new ServletHolder(new SingUpServlet(accountService)), "/signup");
context.addServlet(new ServletHolder(new SignInServlet(accountService)), "/signin");
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setResourceBase("public_html");
HandlerList handlers = new HandlerList();
final Handler[] handler = {resource_handler, context};
handlers.setHandlers(handler);
Server server = new Server(8080);
server.setHandler(handlers);
server.start();
System.out.println("Server started");
server.join();
}