本文整理匯總了Java中org.eclipse.jetty.server.Connector.getLocalPort方法的典型用法代碼示例。如果您正苦於以下問題:Java Connector.getLocalPort方法的具體用法?Java Connector.getLocalPort怎麽用?Java Connector.getLocalPort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jetty.server.Connector
的用法示例。
在下文中一共展示了Connector.getLocalPort方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: removeConnector
import org.eclipse.jetty.server.Connector; //導入方法依賴的package包/類
synchronized public void removeConnector(String host, int port) {
Connector[] connectors = server.getConnectors();
if (connectors == null)
return;
for (Connector connector : connectors) {
//Fix getPort()
if (connector.getHost().equals(host) && connector.getLocalPort() == port) {
if (connector.isStarted() || connector.isStarting()) {
try {
connector.stop();
} catch (Exception ex) {
log.severe("Couldn't stop connector: " + connector + " " + ex);
throw new RuntimeException(ex);
}
}
server.removeConnector(connector);
if (connectors.length == 1) {
log.info("No more connectors, stopping Jetty server");
stopIfRunning();
}
break;
}
}
}
示例2: getBaseUrl
import org.eclipse.jetty.server.Connector; //導入方法依賴的package包/類
/**
* Returns a base URL consisting of the protocal, host, and port for a
* Connector in use by the Jetty Server contained in this runner.
*/
public URL getBaseUrl() {
String protocol = null;
try {
Connector[] conns = server.getConnectors();
if (0 == conns.length) {
throw new IllegalStateException("Jetty Server has no Connectors");
}
Connector c = conns[0];
if (c.getLocalPort() < 0) {
throw new IllegalStateException("Jetty Connector is not open: " +
c.getLocalPort());
}
protocol = (c instanceof SslConnector) ? "https" : "http";
return new URL(protocol, c.getHost(), c.getLocalPort(), context);
} catch (MalformedURLException e) {
throw new IllegalStateException
("Java could not make sense of protocol: " + protocol, e);
}
}
示例3: initialize
import org.eclipse.jetty.server.Connector; //導入方法依賴的package包/類
@Before
public void initialize()
throws Exception
{
server = new Server( 0 );
createContext( server, new File( "src/test/" ) );
this.server.start();
Connector connector = this.server.getConnectors()[0];
this.port = connector.getLocalPort();
log.info( "start server on port {}", this.port );
nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
}
示例4: findLocalHttpPort
import org.eclipse.jetty.server.Connector; //導入方法依賴的package包/類
/**
* Finds the port the specified server is listening for HTTP connections on.
*
* @param webServer started web server
* @return HTTP port, or -1 if no HTTP port was found
*/
public static int findLocalHttpPort(Server webServer) {
for (Connector connector : webServer.getConnectors()) {
if (!(connector instanceof SslSocketConnector)) {
return connector.getLocalPort();
}
}
return -1;
}
示例5: findLocalHttpsPort
import org.eclipse.jetty.server.Connector; //導入方法依賴的package包/類
/**
* Finds the port the specified server is listening for HTTPS connections on.
*
* @param webServer started web server
* @return HTTP port, or -1 if no HTTPS port was found
*/
public static int findLocalHttpsPort(Server webServer) {
for (Connector connector : webServer.getConnectors()) {
if (connector instanceof SslSocketConnector) {
return connector.getLocalPort();
}
}
return -1;
}
示例6: setUp
import org.eclipse.jetty.server.Connector; //導入方法依賴的package包/類
/**
* Set up server with handler
*
* @param handler
* @return port
* @throws Exception
*/
public static String setUp(final Handler handler) throws Exception {
server = new Server();
if (handler != null)
server.setHandler(handler);
Connector connector = new SelectChannelConnector();
connector.setPort(0);
server.setConnectors(new Connector[] { connector });
server.start();
proxy = new Server();
Connector proxyConnector = new SelectChannelConnector();
proxyConnector.setPort(0);
proxy.setConnectors(new Connector[] { proxyConnector });
ServletHandler proxyHandler = new ServletHandler();
RequestHandler proxyCountingHandler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
proxyHitCount.incrementAndGet();
String auth = request.getHeader("Proxy-Authorization");
auth = auth.substring(auth.indexOf(' ') + 1);
try {
auth = B64Code.decode(auth, CHARSET_UTF8);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
int colon = auth.indexOf(':');
proxyUser.set(auth.substring(0, colon));
proxyPassword.set(auth.substring(colon + 1));
request.setHandled(false);
}
};
HandlerList handlerList = new HandlerList();
handlerList.addHandler(proxyCountingHandler);
handlerList.addHandler(proxyHandler);
proxy.setHandler(handlerList);
ServletHolder proxyHolder = proxyHandler.addServletWithMapping("org.eclipse.jetty.servlets.ProxyServlet", "/");
proxyHolder.setAsyncSupported(true);
proxy.start();
proxyPort = proxyConnector.getLocalPort();
return "http://localhost:" + connector.getLocalPort();
}
示例7: getPort
import org.eclipse.jetty.server.Connector; //導入方法依賴的package包/類
public int getPort() {
Connector connector = server.getConnectors()[0];
return connector.getLocalPort() <= 0 ? connector.getPort() : connector.getLocalPort();
}