Skip to content

Commit

Permalink
Merge pull request #27891 from cescoffier/stork-filter-handle-unset-h…
Browse files Browse the repository at this point in the history
…ost-and-port

Use default host and port when the service instance does not set them
  • Loading branch information
gsmet authored Sep 13, 2022
2 parents 9de09fa + 66a11c4 commit 136ed6f
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 136ed6f

Please sign in to comment.