本文整理汇总了Java中org.eclipse.jetty.server.handler.HandlerList.addHandler方法的典型用法代码示例。如果您正苦于以下问题:Java HandlerList.addHandler方法的具体用法?Java HandlerList.addHandler怎么用?Java HandlerList.addHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.server.handler.HandlerList
的用法示例。
在下文中一共展示了HandlerList.addHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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()));
}
}
示例3: 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);
}
}
示例4: 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;
}
示例5: 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);
}
}
示例6: 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");
}
示例7: run
import org.eclipse.jetty.server.handler.HandlerList; //导入方法依赖的package包/类
public int run() throws Exception {
org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(port);
HandlerList handlerList = new HandlerList();
ServletContextHandler servletContextHandler = new ServletContextHandler();
FilterHolder cof = new FilterHolder(new CrossOriginFilter());
cof.setInitParameter(
CrossOriginFilter.EXPOSED_HEADERS_PARAM,
"Date");
servletContextHandler.addFilter(cof, "/*", EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST));
servletContextHandler.addServlet(new ServletHolder(new SmoothStreamingServlet(dataDir)), "/*");
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setBaseResource(Resource.newClassPathResource("supportfiles"));
handlerList.addHandler(resourceHandler);
handlerList.addHandler(servletContextHandler);
server.setHandler(handlerList);
server.start();
server.dumpStdErr();
server.join();
return 0;
}
示例8: start
import org.eclipse.jetty.server.handler.HandlerList; //导入方法依赖的package包/类
public void start() throws Exception {
server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(port);
server.setConnectors(new Connector[]{connector});
RequestLogHandler requestLogHandler = new RequestLogHandler();
configureRequestLogImpl();
requestLogHandler.setRequestLog(requestLogImpl);
HandlerList handlers = new HandlerList();
handlers.addHandler(requestLogHandler);
handlers.addHandler(getRequestHandler());
server.setHandler(handlers);
server.start();
}
示例9: start
import org.eclipse.jetty.server.handler.HandlerList; //导入方法依赖的package包/类
public void start() {
try {
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(port);
connector.setIdleTimeout(idleTimeout);
server.setConnectors(new Connector[] { connector });
HandlerList handlers = new HandlerList();
handlers.addHandler(handler);
server.setHandler(handlers);
server.start();
server.join();
} catch (Exception e) {
// TODO : log here
System.exit(1);
}
}
示例10: startServer
import org.eclipse.jetty.server.handler.HandlerList; //导入方法依赖的package包/类
public void startServer() throws Exception {
int serverPort = propertiesConfiguration.getInt("server.port.http");
Server server = new Server(serverPort);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setBaseResource(Resource.newClassPathResource("/web"));
ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/api");
servletContextHandler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
initGuiceInjector();
HandlerList handlerList = new HandlerList();
handlerList.addHandler(resourceHandler);
handlerList.addHandler(servletContextHandler);
server.setHandler(handlerList);
server.start();
server.join();
}
示例11: ChaosHttpProxy
import org.eclipse.jetty.server.handler.HandlerList; //导入方法依赖的package包/类
public ChaosHttpProxy(URI endpoint, ChaosConfig config)
throws Exception {
setChaosConfig(config);
Supplier<Failure> supplier = new RandomFailureSupplier(
config.getFailures());
requireNonNull(endpoint);
client = new HttpClient();
server = new Server();
HttpConnectionFactory httpConnectionFactory =
new HttpConnectionFactory();
// TODO: SSL
ServerConnector connector = new ServerConnector(server,
httpConnectionFactory);
connector.setHost(endpoint.getHost());
connector.setPort(endpoint.getPort());
server.addConnector(connector);
this.handler = new ChaosHttpProxyHandler(client, supplier);
HandlerList handlers = new HandlerList();
handlers.addHandler(new ChaosApiHandler(this, handler));
handlers.addHandler(handler);
server.setHandler(handlers);
}
示例12: start
import org.eclipse.jetty.server.handler.HandlerList; //导入方法依赖的package包/类
public static void start(@Nonnull Config config, @Nonnull List<Handler> extraHandlers,
@Nonnull WebSocketCreator creator) throws Exception {
checkNotNull(config);
checkNotNull(creator);
long idleTimeout = config.getTime("webserver.idleTimeout", "10m");
int maxTextMessageSize = config.getInt("webserver.maxTextMessageSize", 1024 * 1024);
HandlerList handlers = new HandlerList();
handlers.addHandler(new WebSocketHandler() {
@Override
public void configure(WebSocketServletFactory factory) {
factory.getPolicy().setIdleTimeout(idleTimeout);
factory.getPolicy().setMaxTextMessageSize(maxTextMessageSize);
factory.setCreator(creator);
}
});
for (Handler handler : extraHandlers) {
handlers.addHandler(handler);
}
Server server = new Server(config.getInt("webserver.port", 8034));
server.setHandler(handlers);
server.start();
}
示例13: build
import org.eclipse.jetty.server.handler.HandlerList; //导入方法依赖的package包/类
/**
* Builds a {@link Server} object from the parameters passed to the
* {@link ServletServerBuilder}.
*
* @return
*/
public Server build() {
// build base server
Server server = this.baseServerBuilder.build();
// build each servlet to be published
HandlerList servletHandlers = new HandlerList();
for (ServletDefinition servletDefinition : this.servletDefinitions) {
// create the servlet request handler
ServletContextHandler servletHandler = createServletHandler(servletDefinition);
// add security handler if security settings were specified
if (servletDefinition.isRequireHttps() || servletDefinition.isRequireBasicAuth()) {
ConstraintSecurityHandler securityHandler = createSecurityHandler(server, servletDefinition);
servletHandler.setSecurityHandler(securityHandler);
}
if (servletDefinition.isSupportCors()) {
addCrossOriginFilter(servletHandler);
}
servletHandlers.addHandler(servletHandler);
}
server.setHandler(servletHandlers);
return server;
}
示例14: start
import org.eclipse.jetty.server.handler.HandlerList; //导入方法依赖的package包/类
/**
* Starts the server.
*/
public void start() {
try {
//Handler setzen
HandlerList handlerList = new HandlerList();
for (Handler handler : handlers)
handlerList.addHandler(handler);
handlerList.addHandler(new DefaultHandler());
server.setHandler(handlerList);
//Server starten
server.start();
String log = "Server started. Listening on port " + port + ".";
System.out.println(log);
log(remark(log));
} catch (Exception ex) {
handle(fatal(ex));
}
}
示例15: main
import org.eclipse.jetty.server.handler.HandlerList; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
Properties p = PropertyUtil.loadProperties("/ws.properties");
System.out.println(JsonUtil.toJsonStr(p));
Server server = new Server(Integer.parseInt(p
.getProperty("webSocketPort")));
try {
HandlerList handlerList = new HandlerList();
/* websocket */
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addServlet(
new ServletHolder(new Jwservlet(p
.getProperty("handlerClass"))), p
.getProperty("webSocketPath"));
/* webapp */
WebAppContext c = new WebAppContext();
c.setContextPath("/w");
c.setDescriptor("../websockets/WebRoot/WEB-INF/web.xml");
c.setResourceBase("../websockets/WebRoot");
handlerList.addHandler(c);
handlerList.addHandler(context);
handlerList.addHandler(new DefaultHandler());
server.setHandler(handlerList);
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}