本文整理汇总了Java中org.eclipse.jetty.server.ServerConnector.getLocalPort方法的典型用法代码示例。如果您正苦于以下问题:Java ServerConnector.getLocalPort方法的具体用法?Java ServerConnector.getLocalPort怎么用?Java ServerConnector.getLocalPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.server.ServerConnector
的用法示例。
在下文中一共展示了ServerConnector.getLocalPort方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractTableRowForDefaultServer
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
private static List<ApplicationUrlsGenerator> extractTableRowForDefaultServer(Environment environment, ServerConnector connector) {
String protocol = connector.getDefaultProtocol();
int port = connector.getLocalPort();
if ("admin".equals(connector.getName())) {
String adminContextPath = environment.getAdminContext().getContextPath();
return ImmutableList.of(
new ApplicationUrlsGenerator(ADMIN_URL_TYPE, isHttps(protocol), port, adminContextPath),
new ApplicationUrlsGenerator(HEALTHCHECK_URL_TYPE, isHttps(protocol), port, adminContextPath)
);
}
return ImmutableList.of(
new ApplicationUrlsGenerator(APPLICATION_URL_TYPE, isHttps(protocol), port, environment.getApplicationContext().getContextPath())
);
}
示例2: JettyHttpTestServer
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
public JettyHttpTestServer(String host, int port){
this.host = host;
this.port = port;
server = new Server();
ServerConnector http = new ServerConnector(server);
http.setHost(host);
http.setPort(port);
http.setIdleTimeout(30000);
server.addConnector(http);
server.setHandler(new RequestHandler());
try {
server.start();
} catch (Exception e) {
e.printStackTrace();
}
this.port = http.getLocalPort();
}
示例3: createRpcServerMetadata
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
private RpcMetadataResponse createRpcServerMetadata(ServerConnector connector) throws
UnknownHostException {
String host = connector.getHost();
if (null == host) {
// "null" means binding to all interfaces, we need to pick one so the client gets a real
// address and not "0.0.0.0" or similar.
host = InetAddress.getLocalHost().getHostName();
}
final int port = connector.getLocalPort();
return new RpcMetadataResponse(
String.format(Locale.ROOT, "%s:%d", host, port));
}
示例4: setUp
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
registry = spy(new MetricRegistry());
client = new HttpClient();
server = new Server();
when(registry.getNanos()).thenAnswer(i -> now += 123456789);
ServerConnector connector = new ServerConnector(server);
InstrumentedHandler handler = new InstrumentedHandler(registry);
handler.setHandler(new HelloWorldHandler());
server.addConnector(connector);
server.setHandler(handler);
server.start();
client.start();
url = "http://localhost:" + connector.getLocalPort();
}
示例5: setupServer
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
@BeforeClass
public static void setupServer() throws Exception {
// start a local HTTP proxy using Jetty server
server = new Server();
/*
final SSLContextParameters contextParameters = new SSLContextParameters();
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setSslContext(contextParameters.createSSLContext());
ServerConnector connector = new ServerConnector(server, sslContextFactory);
*/
ServerConnector connector = new ServerConnector(server);
connector.setHost(HTTP_PROXY_HOST);
server.addConnector(connector);
final String authenticationString = "Basic "
+ B64Code.encode(HTTP_PROXY_USER_NAME + ":" + HTTP_PROXY_PASSWORD, StringUtil.__ISO_8859_1);
ConnectHandler connectHandler = new ConnectHandler() {
@Override
protected boolean handleAuthentication(HttpServletRequest request, HttpServletResponse response, String address) {
// validate proxy-authentication header
final String header = request.getHeader(PROXY_AUTHORIZATION.toString());
if (!authenticationString.equals(header)) {
LOG.warn("Missing header " + PROXY_AUTHORIZATION);
// ask for authentication header
response.setHeader(PROXY_AUTHENTICATE.toString(), String.format("Basic realm=\"%s\"", HTTP_PROXY_REALM));
return false;
}
LOG.info("Request contains required header " + PROXY_AUTHORIZATION);
return true;
}
};
server.setHandler(connectHandler);
LOG.info("Starting proxy server...");
server.start();
httpProxyPort = connector.getLocalPort();
LOG.info("Started proxy server on port {}", httpProxyPort);
}