本文整理匯總了Java中org.eclipse.jetty.server.Server.getHandler方法的典型用法代碼示例。如果您正苦於以下問題:Java Server.getHandler方法的具體用法?Java Server.getHandler怎麽用?Java Server.getHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jetty.server.Server
的用法示例。
在下文中一共展示了Server.getHandler方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: start
import org.eclipse.jetty.server.Server; //導入方法依賴的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!");
}
}
示例2: afterPropertiesSet
import org.eclipse.jetty.server.Server; //導入方法依賴的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!");
}
}
示例3: main
import org.eclipse.jetty.server.Server; //導入方法依賴的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();
}
示例4: reloadContext
import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
/**
* 快速重新啟動Application
* @see 通常用Main函數啟動JettyServer後,若改動項目的代碼,那就需要停止再啟動Jetty
* @see 雖免去了Tomcat重新打包幾十兆的消耗,但比起PHP完全不用重啟來說還是慢,特別是關閉,啟動一個新的JVM,消耗不小
* @see 所以我們可以在Main()中捕捉到回車後調用此函數,即可重新載入應用(包括Spring配置文件)
* @param server 當前運行的JettyServer實例
* @param classPath 當前運行的Web應用的classpath
*/
@SuppressWarnings("unused")
private static /*synchronized*/ void reloadContext(Server server, String classPath) throws Exception{
WebAppContext context = (WebAppContext)server.getHandler();
System.out.println("Application reloading..開始");
context.stop();
WebAppClassLoader classLoader = new WebAppClassLoader(context);
classLoader.addClassPath(classPath);
context.setClassLoader(classLoader);
//根據給定的配置文件初始化日誌配置(否則應用重載後日誌輸出組件就會失效)
Log4jConfigurer.initLogging(classPath + "/log4j.properties");
context.start();
System.out.println("Application reloading..完畢");
}
示例5: getTestContainerFactory
import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
final TestContainerFactory testContainerFactory = super.getTestContainerFactory();
return new TestContainerFactory() {
@Override
public TestContainer create(URI baseUri, DeploymentContext deploymentContext) {
TestContainer container = testContainerFactory.create(baseUri, deploymentContext);
try {
Field field = container.getClass().getDeclaredField("server");
field.setAccessible(true);
Server server = (Server) field.get(container);
Handler handler = server.getHandler();
SecurityHandler securityHandler = identityManager.getSecurityHandler();
if (securityHandler.getHandler() == null) {
securityHandler.setHandler(handler);
}
server.setHandler(securityHandler);
}
catch (Exception e) {
throw new IllegalStateException(e);
}
return container;
}
};
}