本文整理汇总了Java中org.mortbay.jetty.webapp.WebAppContext.setServer方法的典型用法代码示例。如果您正苦于以下问题:Java WebAppContext.setServer方法的具体用法?Java WebAppContext.setServer怎么用?Java WebAppContext.setServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mortbay.jetty.webapp.WebAppContext
的用法示例。
在下文中一共展示了WebAppContext.setServer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public static void main(String[] args) {
Server server = new Server();
SocketConnector connector = new SocketConnector();
// Set some timeout options to make debugging easier.
connector.setMaxIdleTime(1000 * 60 * 60);
connector.setSoLingerTime(-1);
connector.setPort(9080);
server.setConnectors(new Connector[]{connector});
WebAppContext context = new WebAppContext();
context.setServer(server);
context.setContextPath("/");
ProtectionDomain protectionDomain = Main.class.getProtectionDomain();
URL location = protectionDomain.getCodeSource().getLocation();
context.setWar(location.toExternalForm());
server.addHandler(context);
try {
server.start();
System.in.read();
server.stop();
server.join();
} catch (Exception e) {
e.printStackTrace();
System.exit(100);
}
}
示例2: startServer
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public void startServer() throws NamingException {
LOG.info("Configuring jetty web server ...");
final Server server = new Server();
SocketConnector connector = new SocketConnector();
// Set some timeout options to make debugging easier.
connector.setMaxIdleTime(1000 * 60 * 60);
connector.setSoLingerTime(-1);
connector.setPort(Integer.parseInt(System.getProperty("jetty.port", "8086")));
server.setConnectors(new Connector[]{connector});
WebAppContext demo = new WebAppContext();
demo.setServer(server);
demo.setContextPath("/superfly-demo");
demo.setWar("src/main/webapp");
demo.setConfigurationClasses(new String[] {
"org.mortbay.jetty.webapp.WebInfConfiguration",
"org.mortbay.jetty.plus.webapp.EnvConfiguration",
"org.mortbay.jetty.plus.webapp.Configuration",
"org.mortbay.jetty.webapp.JettyWebXmlConfiguration"
});
server.addHandler(demo);
try {
System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
server.start();
while (System.in.available() == 0) {
Thread.sleep(5000);
}
server.stop();
server.join();
} catch (Exception e) {
e.printStackTrace();
System.exit(100);
}
}
示例3: main
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Server server = new Server();
SocketConnector connector = new SocketConnector();
// Set some timeout options to make debugging easier.
connector.setMaxIdleTime(1000 * 60 * 60);
connector.setSoLingerTime(-1);
connector.setPort(8080);
server.setConnectors(new Connector[] { connector });
WebAppContext bb = new WebAppContext();
bb.setServer(server);
bb.setContextPath("/");
bb.setWar("src/main/webapp");
// START JMX SERVER
// MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
// MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
// server.getContainer().addEventListener(mBeanContainer);
// mBeanContainer.start();
server.addHandler(bb);
try {
System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
server.start();
while (System.in.available() == 0) {
Thread.sleep(5000);
}
server.stop();
server.join();
} catch (Exception e) {
e.printStackTrace();
System.exit(100);
}
}
示例4: start
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public void start(String appName) {
try {
jetty = new Server(8080);
WebAppContext context = new WebAppContext();
context.setContextPath("/" + appName);
context.setWar("src/main/webapp");
context.setServer(jetty);
jetty.addHandler(context);
jetty.start();
jetty.setStopAtShutdown(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: addSecurityFile
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
private void addSecurityFile(HashUserRealm realm, String securityFile, Context root) throws Exception
{
// create a temp Jetty context to parse the security portion of the web.xml file
/*
TODO
This code assumes far too much internal knowledge of Jetty. I don't know
of simple way to parse the web.xml though and don't want to write it myself.
*/
final URL url = new URL("file", null, securityFile);
final WebXmlConfiguration webXmlConfiguration = new WebXmlConfiguration();
WebAppContext context = new WebAppContext();
context.setServer(server);
webXmlConfiguration.setWebAppContext(context);
ContextHandler contextHandler = new ContextHandler("/")
{
@Override
protected void startContext() throws Exception
{
super.startContext();
setServer(server);
webXmlConfiguration.configure(url.toString());
}
};
contextHandler.start();
try
{
SecurityHandler securityHandler = webXmlConfiguration.getWebAppContext().getSecurityHandler();
if ( realm != null )
{
securityHandler.setUserRealm(realm);
}
root.setSecurityHandler(securityHandler);
}
finally
{
contextHandler.stop();
}
}
示例6: startWebApp
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public static void startWebApp() {
Server server = new Server();
SocketConnector connector = new SocketConnector();
connector.setMaxIdleTime(1000 * 60 * 60);
connector.setSoLingerTime(-1);
connector.setPort(3030);
server.setConnectors(new Connector[]{connector});
WebAppContext webAppContext = new WebAppContext();
webAppContext.setServer(server);
String path = "sample/src/main/webapp";
path = findWarPath(path);
System.out.println("path = " + path);
webAppContext.setWar(path);
server.addHandler(webAppContext);
try {
String msg = "http://localhost:3030/";
log("Starting " + msg + " (please wait)...");
server.start();
log("Started " + msg);
System.out.println("PRESS ANY KEY TO STOP");
while (System.in.available() == 0) {
Thread.sleep(5000);
}
log("Stopping the webapp...");
webAppContext.stop();
log("The webapp was stopped.");
server.stop();
server.join();
} catch (Exception e) {
e.printStackTrace();
System.exit(100);
}
}
示例7: createJettyWebContext
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
/**
* Creates the Jetty specific web context for the given OSGi bundle.
*
* @param bundle
* @return
* @throws Exception
*/
private WebAppContext createJettyWebContext(Bundle bundle, String contextPath) throws Exception {
WebAppContext wac = new WebAppContext();
// create a jetty web app context
// the server is being used to generate the temp folder (so we have to set it)
wac.setServer(serverService);
// set the war string since it's used to generate the temp path
wac.setWar(OsgiStringUtils.nullSafeName(bundle));
// same goes for the context path (add leading "/" -> w/o the context will not work)
wac.setContextPath(contextPath);
// no hot deployment (at least not through directly Jetty)
wac.setCopyWebDir(false);
wac.setExtractWAR(true);
//
// 1. resource settings
//
// start with the slow, IO activity
Resource rootResource = getRootResource(bundle, wac);
// wac needs access to the WAR root
// we have to make sure we don't trigger any direct file lookup
// so instead of calling .setWar()
// we set the base resource directly
wac.setBaseResource(rootResource);
// reset the war setting (so that the base resource is used)
wac.setWar(null);
//
// 2. class-loading behaviour
//
// obey the servlet spec class-loading contract
wac.setSystemClasses(systemClasses);
wac.setServerClasses(serverClasses);
// no java 2 loading compliance
wac.setParentLoaderPriority(false);
// create special classloader
wac.setClassLoader(Utils.createWebAppClassLoader(bundle, Server.class));
return wac;
}
示例8: doStart
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
protected void doStart() throws Exception {
server = new Server();
if (this.minThreads != -1 && this.maxThreads != -1) {
BoundedThreadPool btp = new BoundedThreadPool();
server.setThreadPool(btp);
}
SelectChannelConnector connector = new SelectChannelConnector();
// Set some timeout options to make debugging easier.
connector.setSoLingerTime(-1);
connector.setPort(port);
server.setConnectors(new Connector[] { connector });
WebAppContext wac = new WebAppContext();
wac.setServer(server);
wac.setContextPath(contextPath);
wac.setWar(webappPath);
server.setHandler(wac);
log.info("Starting jetty server actually.");
server.start();
}