Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Fixes error where Netty was not binding properly to a host. #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ public static Channel createServer(final URI baseUri, final ResourceConfig confi
.childHandler(new JerseyServerInitializer(baseUri, sslContext, container));

int port = getPort(baseUri);
String host = getHost(baseUri);

Channel ch = b.bind(port).sync().channel();
Channel ch = b.bind(host, port).sync().channel();

ch.closeFuture().addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
Expand Down Expand Up @@ -176,8 +177,9 @@ public static Channel createHttp2Server(final URI baseUri, final ResourceConfig
.childHandler(new JerseyServerInitializer(baseUri, sslContext, container, true));

int port = getPort(baseUri);
String host = getHost(baseUri);

Channel ch = b.bind(port).sync().channel();
Channel ch = b.bind(host, port).sync().channel();

ch.closeFuture().addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
Expand Down Expand Up @@ -209,4 +211,12 @@ private static int getPort(URI uri) {

return uri.getPort();
}

private static String getHost(URI uri) {
String host = uri.getHost();
if (host == null) {
throw new IllegalArgumentException("URI must contain a host.");
}
return host;
}
}