本文整理汇总了Java中org.eclipse.jetty.server.handler.HandlerCollection.addHandler方法的典型用法代码示例。如果您正苦于以下问题:Java HandlerCollection.addHandler方法的具体用法?Java HandlerCollection.addHandler怎么用?Java HandlerCollection.addHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.server.handler.HandlerCollection
的用法示例。
在下文中一共展示了HandlerCollection.addHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startInJvmProxy
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
/**
* To test that the CF client is able to go through a proxy, we point the CC client to a broken url that can only be resolved by going
* through an inJVM proxy which rewrites the URI. This method starts this inJvm proxy.
*
* @throws Exception
*/
private static void startInJvmProxy() throws Exception {
inJvmProxyPort = getNextAvailablePort(8080);
inJvmProxyServer = new Server(new InetSocketAddress("127.0.0.1", inJvmProxyPort)); // forcing use of loopback
// that will be used both for Httpclient proxy and SocketDestHelper
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMinThreads(1);
inJvmProxyServer.setThreadPool(threadPool);
HandlerCollection handlers = new HandlerCollection();
inJvmProxyServer.setHandler(handlers);
ServletHandler servletHandler = new ServletHandler();
handlers.addHandler(servletHandler);
nbInJvmProxyRcvReqs = new AtomicInteger();
ChainedProxyServlet chainedProxyServlet = new ChainedProxyServlet(httpProxyConfiguration, nbInJvmProxyRcvReqs);
servletHandler.addServletWithMapping(new ServletHolder(chainedProxyServlet), "/*");
// Setup proxy handler to handle CONNECT methods
ConnectHandler proxyHandler;
proxyHandler = new ChainedProxyConnectHandler(httpProxyConfiguration, nbInJvmProxyRcvReqs);
handlers.addHandler(proxyHandler);
inJvmProxyServer.start();
}
示例2: serverWithStatisticsCollection
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
/**
* @param registry Prometheus CollectorRegistry to register the default exporters.
* @param httpPort The port the Server runs on.
* @return a Jetty Server with Prometheus' default exporters registered.
*/
public static Server serverWithStatisticsCollection(CollectorRegistry registry, int httpPort) {
Server server = new Server(httpPort);
new StandardExports().register(registry);
new MemoryPoolsExports().register(registry);
new GarbageCollectorExports().register(registry);
new ThreadExports().register(registry);
new ClassLoadingExports().register(registry);
new VersionInfoExports().register(registry);
HandlerCollection handlers = new HandlerCollection();
StatisticsHandler statisticsHandler = new StatisticsHandler();
statisticsHandler.setServer(server);
handlers.addHandler(statisticsHandler);
new JettyStatisticsCollector(statisticsHandler).register();
server.setHandler(handlers);
return server;
}
示例3: addJettyHandlers
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
protected void addJettyHandlers(Server server, List<Handler> handlers) {
if (handlers != null && !handlers.isEmpty()) {
for (Handler handler : handlers) {
if (handler instanceof HandlerWrapper) {
// avoid setting the security handler more than once
if (!handler.equals(server.getHandler())) {
((HandlerWrapper) handler).setHandler(server.getHandler());
server.setHandler(handler);
}
} else {
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.addHandler(server.getHandler());
handlerCollection.addHandler(handler);
server.setHandler(handlerCollection);
}
}
}
}
示例4: addJettyHandlers
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
protected void addJettyHandlers(Server server, List<Handler> handlers) {
if (handlers != null && !handlers.isEmpty()) {
for (Handler handler : handlers) {
if (handler instanceof HandlerWrapper) {
// avoid setting the security handler more than once
if (!handler.equals(server.getHandler())) {
((HandlerWrapper) handler).setHandler(server.getHandler());
server.setHandler(handler);
}
} else {
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.addHandler(server.getHandler());
handlerCollection.addHandler(handler);
server.setHandler(handlerCollection);
}
}
}
}
示例5: createContext
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
protected ServletContextHandler createContext(Server server, Connector connector, List<Handler> handlers) throws Exception {
ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
server.addConnector(connector);
if (handlers != null && !handlers.isEmpty()) {
for (Handler handler : handlers) {
if (handler instanceof HandlerWrapper) {
((HandlerWrapper) handler).setHandler(server.getHandler());
server.setHandler(handler);
} else {
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.addHandler(server.getHandler());
handlerCollection.addHandler(handler);
server.setHandler(handlerCollection);
}
}
}
return context;
}
示例6: initJettyServer
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
private Server initJettyServer(ComponentRepository repo) {
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(getPort());
connector.setConfidentialPort(getSecurePort());
connector.setRequestHeaderSize(16384);
Server jettyServer = new Server();
jettyServer.setConnectors(new Connector[] {connector});
ContextHandlerCollection contexts = new ContextHandlerCollection();
HandlerCollection handlers = new HandlerCollection();
handlers.addHandler(contexts);
addHandlers(repo, jettyServer, contexts);
jettyServer.setHandler(handlers);
jettyServer.setStopAtShutdown(true);
jettyServer.setGracefulShutdown(2000);
jettyServer.setSendDateHeader(true);
jettyServer.setSendServerVersion(true);
ComponentInfo info = new ComponentInfo(Server.class, "jetty");
repo.registerComponent(info, jettyServer);
repo.registerLifecycle(new ServerLifecycle(jettyServer));
return jettyServer;
}
示例7: startServer
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
@BeforeClass
public void startServer() throws Exception {
int port = 49152 + RandomUtils.nextInt(65535 - 49152);
String serverUrl = "http://localhost:" + port + "/jax";
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
_jettyServer = new Server();
_jettyServer.setConnectors(new Connector[]{connector});
ContextHandlerCollection contexts = new ContextHandlerCollection();
HandlerCollection handlers = new HandlerCollection();
handlers.addHandler(contexts);
WebAppContext ogWebAppContext = new WebAppContext("RemoteViewRunnerTest", "/");
org.springframework.core.io.Resource resource = new ClassPathResource("web-engine");
ogWebAppContext.setBaseResource(Resource.newResource(resource.getFile()));
DataViewRunnerResource viewRunnerResource = new DataViewRunnerResource(new TestViewRunner());
ComponentRepository repo = new ComponentRepository(ComponentLogger.Console.VERBOSE);
repo.getRestComponents().publishResource(viewRunnerResource);
repo.getRestComponents().publishHelper(new FudgeObjectBinaryConsumer());
repo.getRestComponents().publishHelper(new FudgeObjectBinaryProducer());
ogWebAppContext.setEventListeners(new EventListener[]{new ComponentRepositoryServletContextListener(repo)});
handlers.addHandler(ogWebAppContext);
_jettyServer.setHandler(handlers);
_jettyServer.start();
_remoteViewRunner = new RemoteViewRunner(URI.create(serverUrl));
}
示例8: servletInit
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
/**
* Add all the servlets to the server
* including resource handler serving static files
*/
private void servletInit() {
mainLog.info("Initializing servlets");
HandlerCollection handlers = new HandlerCollection();
Iterable<Handler> servletHandler = Iterables.transform(Configuration.getInstance().getServlets(),
new Function<ServletConfig, Handler>() {
@Override
public Handler apply(ServletConfig servletConfig) {
return buildServletHandler(servletConfig);
}
});
servletHandler.forEach((handler) -> {
handlers.addHandler(handler);
});
handlers.addHandler(buildResourceHandler());
server.setHandler(handlers);
}
示例9: main
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Server server = new Server(15000);
HandlerCollection hc = new HandlerCollection();
ResourceHandler rh = new ResourceHandler();
rh.setBaseResource(Resource.newClassPathResource("/com/frinika/web/content/"));
rh.setDirectoriesListed(true);
hc.addHandler(rh);
server.setHandler(hc);
server.start();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
initAndShowGUI();
}
});
}
示例10: main
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
// add web applications
HandlerCollection handlers = new HandlerCollection();
Preconditions.checkArgument(args != null && args.length > 0, "Missing args: web project. Please pass a list of web projects, e.g.: JettyServer helloworld");
for (String arg : args) {
Iterator<String> it = Splitter.on(":").split(arg).iterator();
String domain = it.next();
String projectName = it.hasNext() ? it.next() : domain;
WebAppContext webappContext = createContext(domain, projectName);
handlers.addHandler(webappContext);
}
server.setHandler(handlers);
// enable web 3.0 annotations
Configuration.ClassList classList = Configuration.ClassList.setServerDefault(server);
classList.addBefore(JettyWebXmlConfiguration.class.getName(), AnnotationConfiguration.class.getName());
server.start();
server.join();
}
示例11: startInJvmProxy
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
/**
* To test that the CF client is able to go through a proxy, we point the CC client to a broken url
* that can only be resolved by going through an inJVM proxy which rewrites the URI.
* This method starts this inJvm proxy.
* @throws Exception
*/
private static void startInJvmProxy() throws Exception {
inJvmProxyPort = getNextAvailablePort(8080);
inJvmProxyServer = new Server(new InetSocketAddress("127.0.0.1", inJvmProxyPort)); //forcing use of loopback that will be used both for Httpclient proxy and SocketDestHelper
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMinThreads(1);
inJvmProxyServer.setThreadPool(threadPool);
HandlerCollection handlers = new HandlerCollection();
inJvmProxyServer.setHandler(handlers);
ServletHandler servletHandler = new ServletHandler();
handlers.addHandler(servletHandler);
nbInJvmProxyRcvReqs = new AtomicInteger();
// ChainedProxyServlet chainedProxyServlet = new ChainedProxyServlet(httpProxyConfiguration, nbInJvmProxyRcvReqs);
// servletHandler.addServletWithMapping(new ServletHolder(chainedProxyServlet), "/*");
// Setup proxy handler to handle CONNECT methods
ConnectHandler proxyHandler;
// proxyHandler = new ChainedProxyConnectHandler(httpProxyConfiguration, nbInJvmProxyRcvReqs);
// handlers.addHandler(proxyHandler);
inJvmProxyServer.start();
}
示例12: configure
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
@Override
public void configure() throws Exception {
server.addEventListener(mbeans());
server.addConnector(plainConnector());
server.addConnector(sslConnector());
HandlerCollection handlers = new HandlerCollection();
handlers.addHandler(welcomeFileHandler());
createWebAppContext();
addResourceHandler(handlers, webAppContext);
handlers.addHandler(webAppContext);
JettyCustomErrorPageHandler errorHandler = new JettyCustomErrorPageHandler();
webAppContext.setErrorHandler(errorHandler);
server.addBean(errorHandler);
server.setHandler(handlers);
performCustomConfiguration();
server.setStopAtShutdown(true);
}
示例13: configureJetty
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
protected Server configureJetty(War war) throws IOException {
System.setProperty("org.eclipse.jetty.xml.XmlParser.NotValidating", "true");
final Server server = createServer();
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.addHandler(configureExternal(server, war));
if (this.configuration.getHttpConfiguration().hasAdminPort()) {
handlerCollection.addHandler(configureInternal(server));
}
if (this.configuration.isRequestLoggingEnabled()) {
RequestLoggingFactory requestLoggingFactory = new RequestLoggingFactory(this.configuration);
handlerCollection.addHandler(requestLoggingFactory.configure());
}
server.setHandler(handlerCollection);
if (this.configuration.isJmxEnabled()) {
JmxServer jmxServer = new JmxServer(this.configuration.getJmxConfiguration());
jmxServer.start();
}
return server;
}
示例14: createWebsocketHandler
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
private void createWebsocketHandler(final HandlerCollection handlerCollection) {
// https://github.com/jetty-project/embedded-jetty-websocket-examples/blob/master/javax.websocket-example/src/main/java/org/eclipse/jetty/demo/EventServer.java
try {
final Set<Class<?>> managedClasses = collectAnnotated(WEBSOCKET_MANAGED_CLASSES);
final ServletContextHandler context = initContext("/websockets", managedClasses);
handlerCollection.addHandler(context);
final ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(context);
managedClasses.forEach(c -> registerEndpoint(wscontainer, c));
} catch (final ServletException e) {
throw new TestEEfiException("Failed to initialize websockets", e);
}
}
示例15: createJerseyHandler
import org.eclipse.jetty.server.handler.HandlerCollection; //导入方法依赖的package包/类
private ServletContextHandler createJerseyHandler(final HandlerCollection handlerCollection) {
// http://nikgrozev.com/2014/10/16/rest-with-embedded-jetty-and-jersey-in-a-single-jar-step-by-step/
final Set<Class<?>> managedClasses = collectAnnotated(JAX_RS_MANAGED_CLASSES);
final ServletContextHandler context = initContext("/rest", managedClasses);
handlerCollection.addHandler(context);
final ResourceConfig config = initConfig(managedClasses);
annotationScanner.scanFor(ApplicationPath.class).forEach(appClass -> {
final String path = appClass.getAnnotation(ApplicationPath.class).value();
final String pathSpec = (path.startsWith("/") ? "" : "/") + path + "/*";
LOG.debug("Mapping rest application {} to {}", appClass.getName(), pathSpec);
context.addServlet(new ServletHolder(new JerseyServlet(config)), pathSpec);
});
return context;
}