本文整理汇总了Java中org.mortbay.jetty.Server.setConnectors方法的典型用法代码示例。如果您正苦于以下问题:Java Server.setConnectors方法的具体用法?Java Server.setConnectors怎么用?Java Server.setConnectors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mortbay.jetty.Server
的用法示例。
在下文中一共展示了Server.setConnectors方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
@Override
public void start() {
jettyServer = new Server();
//We can use Contexts etc if we have many urls to handle. For one url,
//specifying a handler directly is the most efficient.
SelectChannelConnector connector = new SelectChannelConnector();
connector.setReuseAddress(true);
connector.setPort(port);
jettyServer.setConnectors(new Connector[] {connector});
jettyServer.setHandler(new HTTPMetricsHandler());
try {
jettyServer.start();
while (!jettyServer.isStarted()) {
Thread.sleep(500);
}
} catch (Exception ex) {
LOG.error("Error starting Jetty. JSON Metrics may not be available.", ex);
}
}
示例2: createJettyServer
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
private Server createJettyServer() {
try {
InetAddress localhost = InetAddress.getByName("localhost");
String host = "localhost";
ServerSocket ss = new ServerSocket(0, 50, localhost);
int port = ss.getLocalPort();
ss.close();
Server server = new Server(0);
if (!ssl) {
server.getConnectors()[0].setHost(host);
server.getConnectors()[0].setPort(port);
} else {
SslSocketConnector c = new SslSocketConnectorSecure();
c.setHost(host);
c.setPort(port);
c.setNeedClientAuth(false);
c.setKeystore(keyStore);
c.setKeystoreType(keyStoreType);
c.setKeyPassword(keyStorePassword);
server.setConnectors(new Connector[] {c});
}
return server;
} catch (Exception ex) {
throw new RuntimeException("Could not stop embedded servlet container, " + ex.getMessage(), ex);
}
}
示例3: createJettyServer
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
private Server createJettyServer() {
try {
InetAddress localhost = InetAddress.getByName("localhost");
String host = "localhost";
ServerSocket ss = new ServerSocket(0, 50, localhost);
int port = ss.getLocalPort();
ss.close();
Server server = new Server(0);
if (!ssl) {
server.getConnectors()[0].setHost(host);
server.getConnectors()[0].setPort(port);
} else {
SslSocketConnector c = new SslSocketConnectorSecure();
c.setHost(host);
c.setPort(port);
c.setNeedClientAuth(false);
c.setKeystore(keyStore);
c.setKeystoreType(keyStoreType);
c.setKeyPassword(keyStorePassword);
server.setConnectors(new Connector[] {c});
}
return server;
} catch (Exception ex) {
throw new RuntimeException("Could not start embedded servlet container, " + ex.getMessage(), ex);
}
}
示例4: createJettyServer
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
private static Server createJettyServer(String keyStore, String password, int inPort) {
try {
boolean ssl = keyStore != null;
String host = "localhost";
Server server = new Server(inPort);
if (!ssl) {
server.getConnectors()[0].setHost(host);
} else {
SslSocketConnector c = new SslSocketConnectorSecure();
c.setHost(host);
c.setNeedClientAuth(false);
c.setKeystore(keyStore);
c.setKeystoreType("jks");
c.setKeyPassword(password);
server.setConnectors(new Connector[]{c});
}
return server;
} catch (Exception ex) {
throw new RuntimeException("Could not start embedded servlet container, "
+ ex.getMessage(), ex);
}
}
示例5: createJettyServer
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
private static Server createJettyServer(String keyStore, String password, int inPort) {
try {
boolean ssl = keyStore != null;
InetAddress localhost = InetAddress.getByName("localhost");
String host = "localhost";
ServerSocket ss = new ServerSocket((inPort < 0) ? 0 : inPort, 50, localhost);
int port = ss.getLocalPort();
ss.close();
Server server = new Server(0);
if (!ssl) {
server.getConnectors()[0].setHost(host);
server.getConnectors()[0].setPort(port);
} else {
SslSocketConnector c = new SslSocketConnectorSecure();
c.setHost(host);
c.setPort(port);
c.setNeedClientAuth(false);
c.setKeystore(keyStore);
c.setKeystoreType("jks");
c.setKeyPassword(password);
server.setConnectors(new Connector[]{c});
}
return server;
} catch (Exception ex) {
throw new RuntimeException("Could not start embedded servlet container, "
+ ex.getMessage(), ex);
}
}
示例6: main
import org.mortbay.jetty.Server; //导入方法依赖的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);
}
}
示例7: main
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception
{
String jetty_home=System.getProperty("jetty.home","../../..");
String jetty_port=System.getProperty("jetty.port", "8080");
String node_name=System.getProperty("node.name", "red");
Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(Integer.parseInt(jetty_port));
server.setConnectors(new Connector[]{connector});
HandlerCollection handlers = new HandlerCollection();
ContextHandlerCollection contexts = new ContextHandlerCollection();
//TODO: find a way to dynamically get the endpoint url
WadiCluster wadiCluster = new WadiCluster("CLUSTER", node_name, "http://localhost:"+jetty_port+"/test");
wadiCluster.doStart();
WadiSessionManager wadiManager = new WadiSessionManager(wadiCluster, 2, 24, 360);
WadiSessionHandler wSessionHandler = new WadiSessionHandler(wadiManager);
WebAppContext wah = new WebAppContext(null, wSessionHandler, null, null);
wah.setContextPath("/test");
wah.setResourceBase(jetty_home+"/webapps/test");
contexts.setHandlers(new Handler[]{wah});
handlers.setHandlers(new Handler[]{contexts,new DefaultHandler()});
server.setHandler(handlers);
HashUserRealm hur = new HashUserRealm();
hur.setName("Test Realm");
hur.setConfig(jetty_home+"/etc/realm.properties");
wah.getSecurityHandler().setUserRealm(hur);
server.start();
server.join();
}
示例8: main
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
/** temp main - just to help testing */
public static void main(String[] args)
throws Exception
{
Server server = new Server();
Connector connector=new GrizzlyConnector();
connector.setPort(8080);
server.setConnectors(new Connector[]{connector});
HandlerCollection handlers = new HandlerCollection();
ContextHandlerCollection contexts = new ContextHandlerCollection();
handlers.setHandlers(new Handler[]{contexts,new DefaultHandler()});
server.setHandler(handlers);
// TODO add javadoc context to contexts
WebAppContext.addWebApplications(server, "../../webapps", "org/mortbay/jetty/webapp/webdefault.xml", true, false);
HashUserRealm userRealm = new HashUserRealm();
userRealm.setName("Test Realm");
userRealm.setConfig("../../etc/realm.properties");
server.setUserRealms(new UserRealm[]{userRealm});
server.start();
server.join();
}
示例9: doStart
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
public static void doStart() throws Exception {
Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(JETTY_SERVER_PORT);
String webDefault = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "**/webdefault.xml";
Resource web = resolver.getResources(webDefault)[0];
String descriptor = web.getFile().getAbsolutePath();
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "**/" + SpiderJetty.class.getName() + ".class";
Resource resource = resolver.getResources(pattern)[0];
String resourcePath = resource.getFile().getAbsolutePath().replaceAll("target.*$", "") + "webapp";
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setDefaultsDescriptor(descriptor);
context.setResourceBase("file:" + resourcePath);
context.setClassLoader(Thread.currentThread().getContextClassLoader());
server.setConnectors(new Connector[]{connector});
server.setHandler(context);
server.setStopAtShutdown(true);
server.setSendServerVersion(false);
server.setSendDateHeader(false);
server.setGracefulShutdown(1000);
try {
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}