本文整理汇总了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();
}