本文整理了Java中com.sun.net.httpserver.HttpServer.getAddress()
方法的一些代码示例,展示了HttpServer.getAddress()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpServer.getAddress()
方法的具体详情如下:
包路径:com.sun.net.httpserver.HttpServer
类名称:HttpServer
方法名:getAddress
[英]returns the address this server is listening on
[中]返回此服务器正在侦听的地址
代码示例来源:origin: jersey/jersey
@Override
public InetSocketAddress getAddress() {
return delegate.getAddress();
}
};
代码示例来源:origin: Netflix/eureka
public int getServerPort() {
return httpServer.getAddress().getPort();
}
代码示例来源:origin: 4thline/cling
synchronized public int getPort() {
return server.getAddress().getPort();
}
代码示例来源:origin: jersey/jersey
@Override
public void start() {
if (started.compareAndSet(false, true)) {
LOGGER.log(Level.FINE, "Starting JdkHttpServerTestContainer...");
server.start();
if (baseUri.getPort() == 0) {
baseUri = UriBuilder.fromUri(baseUri)
.port(server.getAddress().getPort())
.build();
LOGGER.log(Level.INFO, "Started JdkHttpServerTestContainer at the base URI " + baseUri);
}
} else {
LOGGER.log(Level.WARNING, "Ignoring start request - JdkHttpServerTestContainer is already started.");
}
}
代码示例来源:origin: apache/ignite
/**
* Returns base server url in the form <i>protocol://serverHostName:serverPort</i>.
*
* @return Base server url.
*/
public String getBaseUrl() {
return proto + "://" + httpSrv.getAddress().getHostName() + ":" + httpSrv.getAddress().getPort();
}
代码示例来源:origin: 4thline/cling
synchronized public void init(InetAddress bindAddress, Router router) throws InitializationException {
try {
InetSocketAddress socketAddress = new InetSocketAddress(bindAddress, configuration.getListenPort());
server = HttpServer.create(socketAddress, configuration.getTcpConnectionBacklog());
server.createContext("/", new RequestHttpHandler(router));
log.info("Created server (for receiving TCP streams) on: " + server.getAddress());
} catch (Exception ex) {
throw new InitializationException("Could not initialize " + getClass().getSimpleName() + ": " + ex.toString(), ex);
}
}
代码示例来源:origin: googleapis/google-cloud-java
private LocalResourceManagerHelper() {
try {
server = HttpServer.create(new InetSocketAddress(0), 0);
port = server.getAddress().getPort();
server.createContext(CONTEXT, new RequestHandler());
server.createContext(OPERATION_CONTEXT, new OperationRequestHandler());
} catch (IOException e) {
throw new RuntimeException("Could not bind the mock Resource Manager server.", e);
}
}
代码示例来源:origin: apache/incubator-pinot
private void start(String path, HttpHandler handler)
throws IOException {
httpServer = HttpServer.create(socket, 0);
httpServer.createContext(path, handler);
new Thread(new Runnable() {
@Override
public void run() {
httpServer.start();
}
}).start();
endpoint = "localhost:" + httpServer.getAddress().getPort();
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* If we have a separate liveness port, start a server on a separate thread pool whose only
* job is to watch for when the CoreNLP server becomes ready.
* This will also immediately signal liveness.
*
* @param live The boolean to track when CoreNLP has initialized and the server is ready
* to serve requests.
*/
private void livenessServer(AtomicBoolean live) {
if (this.serverPort != this.statusPort) {
try {
// Create the server
if (this.ssl) {
server = addSSLContext(HttpsServer.create(new InetSocketAddress(statusPort), 0)); // 0 is the default 'backlog'
} else {
server = HttpServer.create(new InetSocketAddress(statusPort), 0); // 0 is the default 'backlog'
}
// Add the two status endpoints
withAuth(server.createContext("/live", new LiveHandler()), Optional.empty());
withAuth(server.createContext("/ready", new ReadyHandler(live)), Optional.empty());
// Start the server
server.start();
// Server started
log("Liveness server started at " + server.getAddress());
} catch (IOException e) {
err("Could not start liveness server. This will probably result in very bad things happening soon.", e);
}
}
}
代码示例来源:origin: testcontainers/testcontainers-java
@SneakyThrows
protected void assertResponse(GenericContainer container) {
try {
container.start();
String response = container.execInContainer("wget", "-O", "-", "http://host.testcontainers.internal:" + server.getAddress().getPort()).getStdout();
assertEquals("received response", "Hello World!", response);
} finally {
container.stop();
}
}
}
代码示例来源:origin: testcontainers/testcontainers-java
@BeforeClass
public static void setUpClass() throws Exception {
server = HttpServer.create(new InetSocketAddress(0), 0);
server.createContext("/", exchange -> {
byte[] content = "Hello World!".getBytes();
exchange.sendResponseHeaders(200, content.length);
try (OutputStream responseBody = exchange.getResponseBody()) {
responseBody.write(content);
responseBody.flush();
}
});
server.start();
Testcontainers.exposeHostPorts(server.getAddress().getPort());
}
代码示例来源:origin: testcontainers/testcontainers-java
@BeforeClass
public static void setUp() throws Exception {
server = HttpServer.create(new InetSocketAddress(0), 0);
server.createContext("/", exchange -> {
byte[] content = "Hello World!".getBytes();
exchange.sendResponseHeaders(200, content.length);
try (OutputStream responseBody = exchange.getResponseBody()) {
responseBody.write(content);
responseBody.flush();
}
});
server.start();
localServerPort = server.getAddress().getPort();
// exposePort {
Testcontainers.exposeHostPorts(localServerPort);
// }
}
代码示例来源:origin: stanfordnlp/CoreNLP
server.start();
live.set(true);
log("StanfordCoreNLPServer listening at " + server.getAddress());
} catch (IOException e) {
e.printStackTrace();
代码示例来源:origin: prometheus/client_java
/**
* Gets the port number.
*/
public int getPort() {
return server.getAddress().getPort();
}
}
代码示例来源:origin: kingthy/TVRemoteIME
synchronized public int getPort() {
return server.getAddress().getPort();
}
代码示例来源:origin: resteasy/Resteasy
@Override
public void start()
{
if (httpServer == null)
{
try
{
httpServer = HttpServer.create(new InetSocketAddress(configuredPort), 10);
runtimePort = httpServer.getAddress().getPort();
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
context.bind(httpServer);
httpServer.start();
}
代码示例来源:origin: kingthy/TVRemoteIME
synchronized public void init(InetAddress bindAddress, Router router) throws InitializationException {
try {
InetSocketAddress socketAddress = new InetSocketAddress(bindAddress, configuration.getListenPort());
server = HttpServer.create(socketAddress, configuration.getTcpConnectionBacklog());
server.createContext("/", new RequestHttpHandler(router));
log.info("Created server (for receiving TCP streams) on: " + server.getAddress());
} catch (Exception ex) {
throw new InitializationException("Could not initialize " + getClass().getSimpleName() + ": " + ex.toString(), ex);
}
}
代码示例来源:origin: rhuss/jolokia
private String detectAgentUrl(HttpServer pServer, JolokiaServerConfig pConfig, String pContextPath) {
serverAddress= pServer.getAddress();
InetAddress realAddress;
int port;
if (serverAddress != null) {
realAddress = serverAddress.getAddress();
if (realAddress.isAnyLocalAddress()) {
try {
realAddress = NetworkUtil.getLocalAddress();
} catch (IOException e) {
try {
realAddress = InetAddress.getLocalHost();
} catch (UnknownHostException e1) {
// Ok, ok. We take the original one
realAddress = serverAddress.getAddress();
}
}
}
port = serverAddress.getPort();
} else {
realAddress = pConfig.getAddress();
port = pConfig.getPort();
}
return String.format("%s://%s:%d%s",
pConfig.getProtocol(),realAddress.getHostAddress(),port, pContextPath);
}
代码示例来源:origin: biezhi/learn-java8
public static void main(String[] args) {
try {
HttpServer hs = HttpServer.create(new InetSocketAddress(8080), 0);
hs.createContext("/", new MyHandler());
hs.createContext("/java", new MyHandler());
hs.setExecutor(null);
hs.start();
System.out.println("---begin---");
System.out.println("Listening on " + hs.getAddress());
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
代码示例来源:origin: jshiell/checkstyle-idea
@Before
public void startHttpServer() throws IOException {
httpServer = HttpServer.create(new InetSocketAddress(0), 0);
httpServer.createContext("/", new TestHandler());
httpServer.setExecutor(null);
httpServer.start();
serverPort = httpServer.getAddress().getPort();
}
内容来源于网络,如有侵权,请联系作者删除!