本文整理匯總了Java中org.mortbay.jetty.Connector.setPort方法的典型用法代碼示例。如果您正苦於以下問題:Java Connector.setPort方法的具體用法?Java Connector.setPort怎麽用?Java Connector.setPort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.mortbay.jetty.Connector
的用法示例。
在下文中一共展示了Connector.setPort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startup
import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
public void startup() {
if (adminPort > 0) {
Connector httpConnector = new SelectChannelConnector();
httpConnector.setHost(adminHost);
httpConnector.setPort(adminPort);
adminServer.addConnector(httpConnector);
}
if (adminServer.getConnectors() == null
|| adminServer.getConnectors().length == 0) {
adminServer = null;
log.warn("Admin console not started due to configuration error.");
return;
}
adminServer
.setHandlers(new Handler[] { contexts, new DefaultHandler() });
try {
adminServer.start();
httpStarted = true;
log.debug("Admin console started.");
} catch (Exception e) {
log.error("Could not start admin conosle server", e);
}
}
示例2: putUpJettyServer
import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
private void putUpJettyServer() throws IOException {
if (!conf.getBoolean("hbase.master.infoserver.redirect", true)) {
return;
}
int infoPort = conf.getInt("hbase.master.info.port.orig",
HConstants.DEFAULT_MASTER_INFOPORT);
// -1 is for disabling info server, so no redirecting
if (infoPort < 0 || infoServer == null) {
return;
}
RedirectServlet.regionServerInfoPort = infoServer.getPort();
masterJettyServer = new org.mortbay.jetty.Server();
Connector connector = new SelectChannelConnector();
connector.setHost(conf.get("hbase.master.info.bindAddress", "0.0.0.0"));
connector.setPort(infoPort);
masterJettyServer.addConnector(connector);
masterJettyServer.setStopAtShutdown(true);
Context context = new Context(masterJettyServer, "/", Context.NO_SESSIONS);
context.addServlet(RedirectServlet.class, "/*");
try {
masterJettyServer.start();
} catch (Exception e) {
throw new IOException("Failed to start redirecting jetty server", e);
}
}
示例3: openListeners
import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
/**
* Open the main listener for the server
* @throws Exception
*/
void openListeners() throws Exception {
for (Connector listener : listeners) {
if (listener.getLocalPort() != -1) {
// This listener is either started externally or has been bound
continue;
}
int port = listener.getPort();
while (true) {
// jetty has a bug where you can't reopen a listener that previously
// failed to open w/o issuing a close first, even if the port is changed
try {
listener.close();
listener.open();
LOG.info("Jetty bound to port " + listener.getLocalPort());
break;
} catch (BindException ex) {
if (port == 0 || !findPort) {
BindException be = new BindException("Port in use: "
+ listener.getHost() + ":" + listener.getPort());
be.initCause(ex);
throw be;
}
}
// try the next port number
listener.setPort(++port);
Thread.sleep(100);
}
}
}
示例4: openListeners
import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
/**
* Open the main listener for the server
* @throws Exception
*/
void openListeners() throws Exception {
for (ListenerInfo li : listeners) {
Connector listener = li.listener;
if (!li.isManaged || li.listener.getLocalPort() != -1) {
// This listener is either started externally or has been bound
continue;
}
int port = listener.getPort();
while (true) {
// jetty has a bug where you can't reopen a listener that previously
// failed to open w/o issuing a close first, even if the port is changed
try {
listener.close();
listener.open();
LOG.info("Jetty bound to port " + listener.getLocalPort());
break;
} catch (BindException ex) {
if (port == 0 || !findPort) {
BindException be = new BindException("Port in use: "
+ listener.getHost() + ":" + listener.getPort());
be.initCause(ex);
throw be;
}
}
// try the next port number
listener.setPort(++port);
Thread.sleep(100);
}
}
}
示例5: putUpJettyServer
import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
private int putUpJettyServer() throws IOException {
if (!conf.getBoolean("hbase.master.infoserver.redirect", true)) {
return -1;
}
int infoPort = conf.getInt("hbase.master.info.port.orig",
HConstants.DEFAULT_MASTER_INFOPORT);
// -1 is for disabling info server, so no redirecting
if (infoPort < 0 || infoServer == null) {
return -1;
}
String addr = conf.get("hbase.master.info.bindAddress", "0.0.0.0");
if (!Addressing.isLocalAddress(InetAddress.getByName(addr))) {
String msg =
"Failed to start redirecting jetty server. Address " + addr
+ " does not belong to this host. Correct configuration parameter: "
+ "hbase.master.info.bindAddress";
LOG.error(msg);
throw new IOException(msg);
}
RedirectServlet.regionServerInfoPort = infoServer.getPort();
if(RedirectServlet.regionServerInfoPort == infoPort) {
return infoPort;
}
masterJettyServer = new org.mortbay.jetty.Server();
Connector connector = new SelectChannelConnector();
connector.setHost(addr);
connector.setPort(infoPort);
masterJettyServer.addConnector(connector);
masterJettyServer.setStopAtShutdown(true);
Context context = new Context(masterJettyServer, "/", Context.NO_SESSIONS);
context.addServlet(RedirectServlet.class, "/*");
try {
masterJettyServer.start();
} catch (Exception e) {
throw new IOException("Failed to start redirecting jetty server", e);
}
return connector.getLocalPort();
}
示例6: main
import org.mortbay.jetty.Connector; //導入方法依賴的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();
}
示例7: jettyServer
import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
@BeforeClass
public static void jettyServer() throws Exception {
server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(PORT);
server.setConnectors(new Connector[] { connector });
ConstraintMapping cm = new ConstraintMapping();
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { ROLE_NAME });
constraint.setAuthenticate(true);
cm.setConstraint(constraint);
cm.setPathSpec("/*");
sh = new SecurityHandler();
userRealm = new HashUserRealm(REALM);
userRealm.put(USERNAME, PASSWORD);
userRealm.addUserToRole(USERNAME, ROLE_NAME);
sh.setUserRealm(userRealm);
sh.setConstraintMappings(new ConstraintMapping[] { cm });
WebAppContext webappcontext = new WebAppContext();
webappcontext.setContextPath("/");
URL htmlRoot = HTTPAuthenticatorIT.class.getResource(HTML);
assertNotNull("Could not find " + HTML, htmlRoot);
webappcontext.setWar(htmlRoot.toExternalForm());
webappcontext.addHandler(sh);
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[] { webappcontext,
new DefaultHandler() });
server.setHandler(handlers);
server.start();
}
示例8: putUpJettyServer
import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
private int putUpJettyServer() throws IOException {
if (!conf.getBoolean("hbase.master.infoserver.redirect", true)) {
return -1;
}
int infoPort = conf.getInt("hbase.master.info.port.orig",
HConstants.DEFAULT_MASTER_INFOPORT);
// -1 is for disabling info server, so no redirecting
if (infoPort < 0 || infoServer == null) {
return -1;
}
String addr = conf.get("hbase.master.info.bindAddress", "0.0.0.0");
if (!Addressing.isLocalAddress(InetAddress.getByName(addr))) {
String msg =
"Failed to start redirecting jetty server. Address " + addr
+ " does not belong to this host. Correct configuration parameter: "
+ "hbase.master.info.bindAddress";
LOG.error(msg);
throw new IOException(msg);
}
RedirectServlet.regionServerInfoPort = infoServer.getPort();
masterJettyServer = new org.mortbay.jetty.Server();
Connector connector = new SelectChannelConnector();
connector.setHost(addr);
connector.setPort(infoPort);
masterJettyServer.addConnector(connector);
masterJettyServer.setStopAtShutdown(true);
Context context = new Context(masterJettyServer, "/", Context.NO_SESSIONS);
context.addServlet(RedirectServlet.class, "/*");
try {
masterJettyServer.start();
} catch (Exception e) {
throw new IOException("Failed to start redirecting jetty server", e);
}
return connector.getLocalPort();
}
示例9: build
import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
public HttpServer2 build() throws IOException {
Preconditions.checkNotNull(name, "name is not set");
Preconditions.checkState(!endpoints.isEmpty(), "No endpoints specified");
if (hostName == null) {
hostName = endpoints.get(0).getHost();
}
if (this.conf == null) {
conf = new Configuration();
}
HttpServer2 server = new HttpServer2(this);
if (this.securityEnabled) {
server.initSpnego(conf, hostName, usernameConfKey, keytabConfKey);
}
for (URI ep : endpoints) {
final Connector listener;
String scheme = ep.getScheme();
if ("http".equals(scheme)) {
listener = HttpServer2.createDefaultChannelConnector();
} else if ("https".equals(scheme)) {
listener = createHttpsChannelConnector();
} else {
throw new HadoopIllegalArgumentException(
"unknown scheme for endpoint:" + ep);
}
listener.setHost(ep.getHost());
listener.setPort(ep.getPort() == -1 ? 0 : ep.getPort());
server.addListener(listener);
}
server.loadListeners();
return server;
}
示例10: startServer
import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
/**
* Starts Jetty.
*
* @param host the host to bound.
* @param port the port to bound.
* @param contextPath the context path to bound.
*/
private static void startServer(final String host, final int port, final String contextPath) {
final Logger log = LoggerFactory.getLogger(JaptProxyServer.class);
log.info("Starting Japt-Proxy {} on host {} port {} using context path '{}'",
Util.VERSION, StringUtils.defaultIfEmpty(host, "*"), port, contextPath);
// Spring startup
final ClassPathXmlApplicationContext classPathXmlApplicationContext =
new ClassPathXmlApplicationContext("master.xml", "standalone.xml");
classPathXmlApplicationContext.registerShutdownHook();
// Jetty startup
final Server server = new Server();
final Connector connector = new BlockingChannelConnector();
if (!StringUtils.isBlank(host)) {
connector.setHost(host);
}
connector.setPort(port);
server.setConnectors(new Connector[]{connector});
server.setStopAtShutdown(true);
final Context root = new Context(server, contextPath);
final JaptProxyServlet japtProxyServlet =
classPathXmlApplicationContext
.getBean("japtProxyServlet", JaptProxyServlet.class);
root.addServlet(new ServletHolder(japtProxyServlet), "/*");
try {
server.start();
} catch (final Exception e) {
// shame on Jetty's exception handling
throw new IllegalStateException("Couldn't start HTTP engine", e);
}
}
示例11: startup
import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
/**
* Starts the Jetty server instance.
*/
public void startup() {
if (adminPort > 0) {
Connector httpConnector = new SelectChannelConnector();
httpConnector.setHost(adminHost);
httpConnector.setPort(adminPort);
adminServer.addConnector(httpConnector);
}
if (adminServer.getConnectors() == null
|| adminServer.getConnectors().length == 0) {
adminServer = null;
log.warn("Admin console not started due to configuration error.");
return;
}
adminServer
.setHandlers(new Handler[] { contexts, new DefaultHandler() });
try {
adminServer.start();
httpStarted = true;
log.debug("Admin console started.");
} catch (Exception e) {
log.error("Could not start admin conosle server", e);
}
}
示例12: startup
import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
public void startup() {
// Create connector for http traffic if it's enabled.
if (adminPort > 0) {
Connector httpConnector = new SelectChannelConnector();
httpConnector.setHost(adminHost);
httpConnector.setPort(adminPort);
adminServer.addConnector(httpConnector);
}
// Make sure that at least one connector was registered.
if (adminServer.getConnectors() == null
|| adminServer.getConnectors().length == 0) {
adminServer = null;
log.warn("Admin console not started due to configuration error.");
return;
}
adminServer
.setHandlers(new Handler[] { contexts, new DefaultHandler() });
try {
adminServer.start();
httpStarted = true;
log.debug("Admin Console started.");
} catch (Exception e) {
log.error("Could not start admin conosle server", e);
}
}
示例13: main
import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
Server server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(8080);
server.setConnectors(new Connector[] {connector});
WebAppContext webapp = new WebAppContext("./root", "/example");
server.addHandler(webapp);
server.start();
server.join();
}
示例14: tryPort
import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
private Server tryPort(final int portNumber) throws Exception {
Server srv = new Server();
final Connector connector = new SocketConnector();
connector.setHost(addressProvider.getLocalAddress());
connector.setPort(portNumber);
srv.addConnector(connector);
try {
srv.start();
LOG.log(Level.INFO, "Jetty Server started with port: {0}", portNumber);
} catch (final BindException ex) {
srv = null;
LOG.log(Level.FINEST, "Cannot use port: {0}. Will try another", portNumber);
}
return srv;
}
示例15: main
import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
Server server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(8080);
server.setConnectors(new Connector[] { connector });
WebAppContext webapp = new WebAppContext("./root", "/example");
server.addHandler(webapp);
server.start();
server.join();
}