本文整理匯總了Java中org.eclipse.jetty.server.Handler類的典型用法代碼示例。如果您正苦於以下問題:Java Handler類的具體用法?Java Handler怎麽用?Java Handler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Handler類屬於org.eclipse.jetty.server包,在下文中一共展示了Handler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initServer
import org.eclipse.jetty.server.Handler; //導入依賴的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: main
import org.eclipse.jetty.server.Handler; //導入依賴的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();
}
示例3: startServer
import org.eclipse.jetty.server.Handler; //導入依賴的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);
}
示例4: start
import org.eclipse.jetty.server.Handler; //導入依賴的package包/類
public void start() throws Exception {
Resource configXml = Resource.newSystemResource(config);
XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
server = (Server) configuration.configure();
// Integer port = getPort();
// if (port != null && port > 0) {
// Connector[] connectors = server.getConnectors();
// for (Connector connector : connectors) {
// connector.setPort(port);
// }
// }
Handler handler = server.getHandler();
if (handler != null && handler instanceof WebAppContext) {
WebAppContext webAppContext = (WebAppContext) handler;
webAppContext.setResourceBase(JettyEmbedServer.class.getResource("/webapp").toString());
}
server.start();
if (logger.isInfoEnabled()) {
logger.info("##Jetty Embed Server is startup!");
}
}
示例5: afterPropertiesSet
import org.eclipse.jetty.server.Handler; //導入依賴的package包/類
public void afterPropertiesSet() throws Exception {
Resource configXml = Resource.newSystemResource(config);
XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
server = (Server) configuration.configure();
Integer port = getPort();
if (port != null && port > 0) {
Connector[] connectors = server.getConnectors();
for (Connector connector : connectors) {
connector.setPort(port);
}
}
Handler handler = server.getHandler();
if (handler != null && handler instanceof ServletContextHandler) {
ServletContextHandler servletHandler = (ServletContextHandler) handler;
servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", htdocsDir);
}
server.start();
if (logger.isInfoEnabled()) {
logger.info("##Jetty Embed Server is startup!");
}
}
示例6: main
import org.eclipse.jetty.server.Handler; //導入依賴的package包/類
public static void main(String args[]) throws Exception {
Resource jetty_xml = Resource.newSystemResource("jetty/jetty.xml");
XmlConfiguration configuration = new XmlConfiguration(jetty_xml.getInputStream());
Server server = (Server) configuration.configure();
int port = 8081;
Connector[] connectors = server.getConnectors();
for (Connector connector : connectors) {
connector.setPort(port);
}
Handler handler = server.getHandler();
if (handler != null && handler instanceof ServletContextHandler) {
ServletContextHandler servletHandler = (ServletContextHandler) handler;
servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", "/tmp/");
}
server.start();
server.join();
}
示例7: prepare
import org.eclipse.jetty.server.Handler; //導入依賴的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);
}
}
示例8: getAllServices
import org.eclipse.jetty.server.Handler; //導入依賴的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;
}
示例9: setSessionHandler
import org.eclipse.jetty.server.Handler; //導入依賴的package包/類
/**
* @param sessionHandler The sessionHandler to set.
*/
public void setSessionHandler(SessionHandler sessionHandler)
{
if (isStarted())
throw new IllegalStateException("STARTED");
Handler next=null;
if (_sessionHandler!=null)
{
next=_sessionHandler.getHandler();
_sessionHandler.setHandler(null);
replaceHandler(_sessionHandler,sessionHandler);
}
_sessionHandler = sessionHandler;
if (next!=null && _sessionHandler.getHandler()==null)
_sessionHandler.setHandler(next);
relinkHandlers();
}
示例10: setSecurityHandler
import org.eclipse.jetty.server.Handler; //導入依賴的package包/類
/**
* @param securityHandler The {@link SecurityHandler} to set on this context.
*/
public void setSecurityHandler(SecurityHandler securityHandler)
{
if (isStarted())
throw new IllegalStateException("STARTED");
Handler next=null;
if (_securityHandler!=null)
{
next=_securityHandler.getHandler();
_securityHandler.setHandler(null);
replaceHandler(_securityHandler,securityHandler);
}
_securityHandler = securityHandler;
if (next!=null && _securityHandler.getHandler()==null)
_securityHandler.setHandler(next);
relinkHandlers();
}
示例11: setGzipHandler
import org.eclipse.jetty.server.Handler; //導入依賴的package包/類
/**
* @param gzipHandler The {@link GzipHandler} to set on this context.
*/
public void setGzipHandler(GzipHandler gzipHandler)
{
if (isStarted())
throw new IllegalStateException("STARTED");
Handler next=null;
if (_gzipHandler!=null)
{
next=_gzipHandler.getHandler();
_gzipHandler.setHandler(null);
replaceHandler(_gzipHandler,gzipHandler);
}
_gzipHandler = gzipHandler;
if (next!=null && _gzipHandler.getHandler()==null)
_gzipHandler.setHandler(next);
relinkHandlers();
}
示例12: setServletHandler
import org.eclipse.jetty.server.Handler; //導入依賴的package包/類
/**
* @param servletHandler The servletHandler to set.
*/
public void setServletHandler(ServletHandler servletHandler)
{
if (isStarted())
throw new IllegalStateException("STARTED");
Handler next=null;
if (_servletHandler!=null)
{
next=_servletHandler.getHandler();
_servletHandler.setHandler(null);
replaceHandler(_servletHandler,servletHandler);
}
_servletHandler = servletHandler;
if (next!=null && _servletHandler.getHandler()==null)
_servletHandler.setHandler(next);
relinkHandlers();
}
示例13: start
import org.eclipse.jetty.server.Handler; //導入依賴的package包/類
public void start() {
try {
// start the server
server.start();
// ensure everything started successfully
for (Handler handler : server.getChildHandlers()) {
// see if the handler is a web app
if (handler instanceof WebAppContext) {
WebAppContext context = (WebAppContext) handler;
// see if this webapp had any exceptions that would
// cause it to be unavailable
if (context.getUnavailableException() != null) {
startUpFailure(context.getUnavailableException());
}
}
}
dumpUrls();
} catch (final Throwable t) {
startUpFailure(t);
}
}
示例14: main
import org.eclipse.jetty.server.Handler; //導入依賴的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: beforeClass
import org.eclipse.jetty.server.Handler; //導入依賴的package包/類
@BeforeClass
public static void beforeClass() throws Exception {
ccowServer = new Server(serverPort);
final CCOWContextListener c = new CCOWContextListener(commonContext, new InlinedContextAgentRepositoryModule());
final MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
ccowServer.addBean(mbContainer);
final ServletContextHandler webSocketServletContextHandler = new ServletContextHandler(ccowServer, "/ws",
ServletContextHandler.SESSIONS);
webSocketServletContextHandler.addEventListener(c);
WebSocketServerContainerInitializer.configureContext(webSocketServletContextHandler);
final ServletContextHandler restServletContextHandler = new ServletContextHandler(ccowServer, "/");
restServletContextHandler.addEventListener(c);
restServletContextHandler.addFilter(AppGuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
final ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[] { webSocketServletContextHandler, restServletContextHandler});
ccowServer.setHandler(contexts);
ccowServer.start();
}