Add ServiceInstance.getUri and implement in DefaultServiceInstance
fixes gh-12
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.client;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -32,4 +34,17 @@ public class DefaultServiceInstance implements ServiceInstance {
|
||||
|
||||
private final int port;
|
||||
|
||||
private final boolean secure;
|
||||
|
||||
@Override
|
||||
public URI getUri() {
|
||||
return getUri(this);
|
||||
}
|
||||
|
||||
public static URI getUri(ServiceInstance instance) {
|
||||
String scheme = (instance.isSecure()) ? "https" : "http";
|
||||
String uri = String.format("%s://%s:%s", scheme, instance.getHost(),
|
||||
instance.getPort());
|
||||
return URI.create(uri);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.client;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -26,4 +28,9 @@ public interface ServiceInstance {
|
||||
public String getHost();
|
||||
|
||||
public int getPort();
|
||||
|
||||
public boolean isSecure();
|
||||
|
||||
public URI getUri();
|
||||
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class NoopDiscoveryClientAutoConfiguration implements
|
||||
}
|
||||
int port = findPort();
|
||||
this.serviceInstance = new DefaultServiceInstance(this.environment.getProperty(
|
||||
"spring.application.name", "application"), host, port);
|
||||
"spring.application.name", "application"), host, port, false);
|
||||
}
|
||||
|
||||
private int findPort() {
|
||||
|
||||
Reference in New Issue
Block a user