本文整理汇总了Java中org.eclipse.jetty.server.handler.HandlerCollection类的典型用法代码示例。如果您正苦于以下问题:Java HandlerCollection类的具体用法?Java HandlerCollection怎么用?Java HandlerCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HandlerCollection类属于org.eclipse.jetty.server.handler包,在下文中一共展示了HandlerCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initServer
import org.eclipse.jetty.server.handler.HandlerCollection; //导入依赖的package包/类
private static void initServer(Properties properties) throws Exception {
Integer port = Integer.valueOf(properties.getProperty("server.port"));
String host = properties.getProperty("server.host");
Integer clientId = Integer.valueOf(properties.getProperty("client.id"));
String clientSecret = properties.getProperty("client.secret");
HandlerCollection handlers = new HandlerCollection();
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
resourceHandler.setWelcomeFiles(new String[]{"index.html"});
resourceHandler.setResourceBase(Application.class.getResource("/static").getPath());
VkApiClient vk = new VkApiClient(new HttpTransportClient());
handlers.setHandlers(new Handler[]{resourceHandler, new RequestHandler(vk, clientId, clientSecret, host)});
Server server = new Server(port);
server.setHandler(handlers);
server.start();
server.join();
}
示例2: startServer
import org.eclipse.jetty.server.handler.HandlerCollection; //导入依赖的package包/类
public static void startServer(String[] args) throws Exception {
Server server = new Server(8080);
WebAppContext ctx = new WebAppContext();
ctx.setContextPath("/");
ctx.setWar("src/main/webapp/");
HandlerCollection hc = new HandlerCollection();
hc.setHandlers(new Handler[] {ctx});
server.setHandler(hc);
server.setStopAtShutdown(true);
server.start();
server.join();
// server.removeBean(o);
// server.addBean(o);
}
示例3: 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();
}
示例4: 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;
}
示例5: addWebApplication
import org.eclipse.jetty.server.handler.HandlerCollection; //导入依赖的package包/类
public static Server addWebApplication(final Server jetty, final String webAppContext,
final String warFilePath) {
WebAppContext webapp = new WebAppContext();
webapp.setContextPath(webAppContext);
webapp.setWar(warFilePath);
webapp.setParentLoaderPriority(false);
webapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
File tmpPath = new File(getWebAppBaseDirectory(webAppContext));
tmpPath.mkdirs();
webapp.setTempDirectory(tmpPath);
((HandlerCollection) jetty.getHandler()).addHandler(webapp);
return jetty;
}
示例6: jettyConfigBean
import org.eclipse.jetty.server.handler.HandlerCollection; //导入依赖的package包/类
@Bean
public EmbeddedServletContainerFactory jettyConfigBean() {
DynamicPropertyFactory propertyFactory = DynamicPropertyFactory.getInstance();
String accessLogFilePath = propertyFactory.getStringProperty("server.accessLog.config.file", ACCESS_LOG_FILE_PATH).getValue();
JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory
= new JettyEmbeddedServletContainerFactory();
jettyEmbeddedServletContainerFactory.addServerCustomizers(new org.springframework.boot.context.embedded.jetty.JettyServerCustomizer() {
public void customize(Server server) {
HandlerCollection handlers = new HandlerCollection();
for (Handler handler : server.getHandlers()) {
handlers.addHandler(handler);
}
RequestLogHandler requestLogHandler = new RequestLogHandler();
RequestLogImpl requestLogImpl = new RequestLogImpl();
requestLogImpl.setFileName(accessLogFilePath);
requestLogHandler.setRequestLog(requestLogImpl);
handlers.addHandler(requestLogHandler);
server.setHandler(handlers);
LOGGER.info("Jetty Server Customized. Access Log Configuration File - {}", accessLogFilePath);
}
});
return jettyEmbeddedServletContainerFactory;
}
示例7: 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);
}
}
}
}
示例8: initJetty
import org.eclipse.jetty.server.handler.HandlerCollection; //导入依赖的package包/类
public static Server initJetty(final String bindAddress, final int port,
final LogWriterI18n log) throws Exception {
final Server jettyServer = new Server();
// Add a handler collection here, so that each new context adds itself
// to this collection.
jettyServer.setHandler(new HandlerCollection());
// bind on address and port
setAddressAndPort(jettyServer, bindAddress, port);
if (bindAddress != null && !bindAddress.isEmpty()) {
JettyHelper.bindAddress = bindAddress;
}
JettyHelper.port = port;
return jettyServer;
}
示例9: start
import org.eclipse.jetty.server.handler.HandlerCollection; //导入依赖的package包/类
public void start() throws Exception {
RequestLogHandler requestLogHandler = new RequestLogHandler();
Slf4jRequestLog requestLog = new Slf4jRequestLog();
requestLog.setExtended(true);
requestLog.setLogTimeZone(TimeZone.getDefault().getID());
requestLog.setLogLatency(true);
requestLogHandler.setRequestLog(requestLog);
handlers.add(0, new ContextHandlerCollection());
handlers.add(requestLogHandler);
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
server.setHandler(handlerCollection);
server.start();
log.info("Server started at end point {}", getServiceUri());
}
示例10: start
import org.eclipse.jetty.server.handler.HandlerCollection; //导入依赖的package包/类
public void start() throws PulsarServerException {
log.info("Starting web socket proxy at port {}", conf.getWebServicePort());
try {
RequestLogHandler requestLogHandler = new RequestLogHandler();
Slf4jRequestLog requestLog = new Slf4jRequestLog();
requestLog.setExtended(true);
requestLog.setLogTimeZone(TimeZone.getDefault().getID());
requestLog.setLogLatency(true);
requestLogHandler.setRequestLog(requestLog);
handlers.add(0, new ContextHandlerCollection());
handlers.add(requestLogHandler);
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
server.setHandler(handlerCollection);
server.start();
} catch (Exception e) {
throw new PulsarServerException(e);
}
}
示例11: start
import org.eclipse.jetty.server.handler.HandlerCollection; //导入依赖的package包/类
public void start() throws PulsarServerException {
try {
RequestLogHandler requestLogHandler = new RequestLogHandler();
Slf4jRequestLog requestLog = new Slf4jRequestLog();
requestLog.setExtended(true);
requestLog.setLogTimeZone(TimeZone.getDefault().getID());
requestLog.setLogLatency(true);
requestLogHandler.setRequestLog(requestLog);
handlers.add(0, new ContextHandlerCollection());
handlers.add(requestLogHandler);
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
server.setHandler(handlerCollection);
server.start();
log.info("Web Service started at {}", pulsar.getWebServiceAddress());
} catch (Exception e) {
throw new PulsarServerException(e);
}
}
示例12: wrappedHandlers
import org.eclipse.jetty.server.handler.HandlerCollection; //导入依赖的package包/类
@Test
public void wrappedHandlers() throws Exception {
JettyEmbeddedServletContainerFactory factory = getFactory();
factory.setServerCustomizers(Arrays.asList(new JettyServerCustomizer() {
@Override
public void customize(Server server) {
Handler handler = server.getHandler();
HandlerWrapper wrapper = new HandlerWrapper();
wrapper.setHandler(handler);
HandlerCollection collection = new HandlerCollection();
collection.addHandler(wrapper);
server.setHandler(collection);
}
}));
this.container = factory
.getEmbeddedServletContainer(exampleServletRegistration());
this.container.start();
assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:JettyEmbeddedServletContainerFactoryTests.java
示例13: configure
import org.eclipse.jetty.server.handler.HandlerCollection; //导入依赖的package包/类
@Override
public void configure( final Settings settings )
{
final EngineConfigurator engineConfigurator = new EngineConfigurator();
engineConfigurator.configure( settings );
final ServletConfigurator servletConfigurator = new ServletConfigurator();
servletConfigurator.setEngine( engineConfigurator.getEngine() );
servletConfigurator.setDevSourceDirs( engineConfigurator.getEngine().getDevSourceDirs() );
servletConfigurator.configure( settings );
this.handlers = new HandlerCollection();
this.handlers.addHandler( servletConfigurator.getHandler() );
configureServer( settings.getAsSettings( "server" ) );
}
示例14: main
import org.eclipse.jetty.server.handler.HandlerCollection; //导入依赖的package包/类
public static void main( String[] args )
throws Exception
{
Server server = new Server( 8080 );
WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );
ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );
server.setHandler( handlers );
server.start();
server.join();
}
示例15: Olingo2SampleServer
import org.eclipse.jetty.server.handler.HandlerCollection; //导入依赖的package包/类
/**
*
* @param port
* @param resourcePath
*/
public Olingo2SampleServer(int port, String resourcePath) {
this.port = port;
server = new org.eclipse.jetty.server.Server(port);
WebAppContext webappcontext = new WebAppContext();
String contextPath = null;
try {
contextPath = Olingo2SampleServer.class.getResource(resourcePath).toURI().getPath();
} catch (URISyntaxException e) {
LOG.error("Unable to read the resource at {}", resourcePath, e);
}
webappcontext.setContextPath("/");
webappcontext.setWar(contextPath);
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[] {webappcontext, new DefaultHandler()});
server.setHandler(handlers);
}