本文整理了Java中com.linecorp.armeria.server.Server.defaultHostname()
方法的一些代码示例,展示了Server.defaultHostname()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Server.defaultHostname()
方法的具体详情如下:
包路径:com.linecorp.armeria.server.Server
类名称:Server
方法名:defaultHostname
[英]Returns the hostname of the default VirtualHost, which is the hostname of the machine unless configured explicitly via ServerBuilder#defaultVirtualHost(VirtualHost).
[中]返回默认VirtualHost的主机名,该主机名是机器的主机名,除非通过ServerBuilder#defaultVirtualHost(VirtualHost)明确配置。
代码示例来源:origin: line/armeria
@Override
public void serviceAdded(ServiceConfig cfg) {
if (armeriaServer != null) {
if (armeriaServer != cfg.server()) {
throw new IllegalStateException("cannot be added to more than one server");
} else {
return;
}
}
armeriaServer = cfg.server();
armeriaServer.addListener(configurator);
if (hostname == null) {
hostname = armeriaServer.defaultHostname();
}
}
代码示例来源:origin: line/armeria
@Override
public void serverStarted(Server server) throws Exception {
if (endpoint == null) {
assert server.activePort().isPresent();
endpoint = Endpoint.of(server.defaultHostname(),
server.activePort().get()
.localAddress().getPort());
}
client.start();
final String key = endpoint.host() + '_' + endpoint.port();
final byte[] value = nodeValueCodec.encode(endpoint);
client.create()
.creatingParentsIfNeeded()
.withMode(CreateMode.EPHEMERAL)
.forPath(zNodePath + '/' + key, value);
}
代码示例来源:origin: line/armeria
@Override
public void serviceAdded(ServiceConfig cfg) throws Exception {
if (hostName == null) {
hostName = cfg.server().defaultHostname();
}
if (armeriaServer != null) {
if (armeriaServer != cfg.server()) {
throw new IllegalStateException("cannot be added to more than one server");
} else {
return;
}
}
armeriaServer = cfg.server();
armeriaServer.addListener(configurator);
}
代码示例来源:origin: line/armeria
@Test
public void addressesAndPorts_localhost() throws Exception {
try (CloseableHttpClient hc = HttpClients.createMinimal()) {
final HttpGet request = new HttpGet(server().uri("/jsp/addrs_and_ports.jsp"));
request.setHeader("Host", "localhost:1111");
try (CloseableHttpResponse res = hc.execute(request)) {
assertThat(res.getStatusLine().toString()).isEqualTo("HTTP/1.1 200 OK");
assertThat(res.getFirstHeader(HttpHeaderNames.CONTENT_TYPE.toString()).getValue())
.startsWith("text/html");
final String actualContent = CR_OR_LF.matcher(EntityUtils.toString(res.getEntity()))
.replaceAll("");
assertThat(actualContent).matches(
"<html><body>" +
"<p>RemoteAddr: 127\\.0\\.0\\.1</p>" +
"<p>RemoteHost: 127\\.0\\.0\\.1</p>" +
"<p>RemotePort: [1-9][0-9]+</p>" +
"<p>LocalAddr: (?!null)[^<]+</p>" +
"<p>LocalName: " + server().server().defaultHostname() + "</p>" +
"<p>LocalPort: " + server().httpPort() + "</p>" +
"<p>ServerName: localhost</p>" +
"<p>ServerPort: 1111</p>" +
"</body></html>");
}
}
}
代码示例来源:origin: line/armeria
@Test
public void addressesAndPorts_127001() throws Exception {
try (CloseableHttpClient hc = HttpClients.createMinimal()) {
try (CloseableHttpResponse res = hc.execute(
new HttpGet(server().uri("/jsp/addrs_and_ports.jsp")))) {
assertThat(res.getStatusLine().toString()).isEqualTo("HTTP/1.1 200 OK");
assertThat(res.getFirstHeader(HttpHeaderNames.CONTENT_TYPE.toString()).getValue())
.startsWith("text/html");
final String actualContent = CR_OR_LF.matcher(EntityUtils.toString(res.getEntity()))
.replaceAll("");
assertThat(actualContent).matches(
"<html><body>" +
"<p>RemoteAddr: 127\\.0\\.0\\.1</p>" +
"<p>RemoteHost: 127\\.0\\.0\\.1</p>" +
"<p>RemotePort: [1-9][0-9]+</p>" +
"<p>LocalAddr: (?!null)[^<]+</p>" +
"<p>LocalName: " + server().server().defaultHostname() + "</p>" +
"<p>LocalPort: " + server().httpPort() + "</p>" +
"<p>ServerName: 127\\.0\\.0\\.1</p>" +
"<p>ServerPort: " + server().httpPort() + "</p>" +
"</body></html>");
}
}
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server-shaded
@Override
public Entry get(String path, @Nullable String contentEncoding) {
requireNonNull(path, "path");
return new ByteArrayEntry(path, MediaType.PLAIN_TEXT_UTF_8,
server.defaultHostname().getBytes(StandardCharsets.UTF_8));
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server
@Override
public HttpFile get(String path, Clock clock, @Nullable String contentEncoding) {
requireNonNull(path, "path");
return HttpFileBuilder.of(HttpData.of(StandardCharsets.UTF_8, server.defaultHostname()))
.setHeader(HttpHeaderNames.CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8)
.build();
}
代码示例来源:origin: line/centraldogma
@Override
public HttpFile get(String path, Clock clock, @Nullable String contentEncoding) {
requireNonNull(path, "path");
return HttpFileBuilder.of(HttpData.of(StandardCharsets.UTF_8, server.defaultHostname()))
.setHeader(HttpHeaderNames.CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8)
.build();
}
内容来源于网络,如有侵权,请联系作者删除!