Skip to content

Commit

Permalink
Use default host and port when the service instance does not set them
Browse files Browse the repository at this point in the history
  • Loading branch information
cescoffier authored and Alasdair Preston committed Sep 14, 2022
1 parent 7cb775e commit af22e7c
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public void filter(ResteasyReactiveClientRequestContext requestContext) {
try {
serviceInstance = Stork.getInstance()
.getService(serviceName)
.selectInstanceAndRecordStart(measureTime);
.selectInstanceAndRecordStart(measureTime)
.log();
} catch (Throwable e) {
log.error("Error selecting service instance for serviceName: " + serviceName, e);
requestContext.resume(e);
Expand All @@ -46,8 +47,18 @@ public void filter(ResteasyReactiveClientRequestContext requestContext) {
boolean isHttps = instance.isSecure() || "storks".equals(uri.getScheme());
String scheme = isHttps ? "https" : "http";
try {
// In the case the service instance does not set the host and/or port
String host = instance.getHost() == null ? "localhost" : instance.getHost();
int port = instance.getPort();
if (instance.getPort() == 0) {
if (isHttps) {
port = 433;
} else {
port = 80;
}
}
URI newUri = new URI(scheme,
uri.getUserInfo(), instance.getHost(), instance.getPort(),
uri.getUserInfo(), host, port,
uri.getPath(), uri.getQuery(), uri.getFragment());
requestContext.setUri(newUri);
if (measureTime && instance.gatherStatistics()) {
Expand Down

0 comments on commit af22e7c

Please sign in to comment.