|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2012-2020 the original author or authors. |
|
|
|
* Copyright 2012-2022 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
@ -18,6 +18,7 @@ package org.springframework.cloud.client; |
|
|
|
|
|
|
|
|
|
|
|
import java.net.URI; |
|
|
|
import java.net.URI; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
|
|
@ -28,15 +29,20 @@ import java.util.Objects; |
|
|
|
* @author Tim Ysewyn |
|
|
|
* @author Tim Ysewyn |
|
|
|
* @author Charu Covindane |
|
|
|
* @author Charu Covindane |
|
|
|
* @author Neil Powell |
|
|
|
* @author Neil Powell |
|
|
|
|
|
|
|
* @author Olga Maciaszek-Sharma |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class DefaultServiceInstance implements ServiceInstance { |
|
|
|
public class DefaultServiceInstance implements ServiceInstance { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final List<String> secureSchemes = List.of("https", "wss"); |
|
|
|
|
|
|
|
|
|
|
|
private String instanceId; |
|
|
|
private String instanceId; |
|
|
|
|
|
|
|
|
|
|
|
private String serviceId; |
|
|
|
private String serviceId; |
|
|
|
|
|
|
|
|
|
|
|
private String host; |
|
|
|
private String host; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String scheme; |
|
|
|
|
|
|
|
|
|
|
|
private int port; |
|
|
|
private int port; |
|
|
|
|
|
|
|
|
|
|
|
private boolean secure; |
|
|
|
private boolean secure; |
|
|
@ -45,6 +51,7 @@ public class DefaultServiceInstance implements ServiceInstance { |
|
|
|
|
|
|
|
|
|
|
|
private URI uri; |
|
|
|
private URI uri; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param instanceId the id of the instance. |
|
|
|
* @param instanceId the id of the instance. |
|
|
|
* @param serviceId the id of the service. |
|
|
|
* @param serviceId the id of the service. |
|
|
@ -55,12 +62,27 @@ public class DefaultServiceInstance implements ServiceInstance { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public DefaultServiceInstance(String instanceId, String serviceId, String host, int port, boolean secure, |
|
|
|
public DefaultServiceInstance(String instanceId, String serviceId, String host, int port, boolean secure, |
|
|
|
Map<String, String> metadata) { |
|
|
|
Map<String, String> metadata) { |
|
|
|
|
|
|
|
this(instanceId, serviceId, host, port, secure, metadata, secure ? "https" : "http"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @param instanceId the id of the instance. |
|
|
|
|
|
|
|
* @param serviceId the id of the service. |
|
|
|
|
|
|
|
* @param host the host where the service instance can be found. |
|
|
|
|
|
|
|
* @param port the port on which the service is running. |
|
|
|
|
|
|
|
* @param secure indicates whether or not the connection needs to be secure. |
|
|
|
|
|
|
|
* @param metadata a map containing metadata. |
|
|
|
|
|
|
|
* @param scheme the protocol used to connect to the service instance. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public DefaultServiceInstance(String instanceId, String serviceId, String host, int port, boolean secure, |
|
|
|
|
|
|
|
Map<String, String> metadata, String scheme) { |
|
|
|
this.instanceId = instanceId; |
|
|
|
this.instanceId = instanceId; |
|
|
|
this.serviceId = serviceId; |
|
|
|
this.serviceId = serviceId; |
|
|
|
this.host = host; |
|
|
|
this.host = host; |
|
|
|
this.port = port; |
|
|
|
this.port = port; |
|
|
|
this.secure = secure; |
|
|
|
this.secure = secure; |
|
|
|
this.metadata = metadata; |
|
|
|
this.metadata = metadata; |
|
|
|
|
|
|
|
this.scheme = scheme; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -77,6 +99,19 @@ public class DefaultServiceInstance implements ServiceInstance { |
|
|
|
public DefaultServiceInstance() { |
|
|
|
public DefaultServiceInstance() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @param instanceId the id of the instance. |
|
|
|
|
|
|
|
* @param serviceId the id of the service. |
|
|
|
|
|
|
|
* @param host the host where the service instance can be found. |
|
|
|
|
|
|
|
* @param port the port on which the service is running. |
|
|
|
|
|
|
|
* @param secure indicates whether or not the connection needs to be secure. |
|
|
|
|
|
|
|
* @param scheme the protocol used to connect to the service instance. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public DefaultServiceInstance(String instanceId, String serviceId, String host, int port, boolean secure, |
|
|
|
|
|
|
|
String scheme) { |
|
|
|
|
|
|
|
this(instanceId, serviceId, host, port, secure, new LinkedHashMap<>(), scheme); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a URI from the given ServiceInstance's host:port. |
|
|
|
* Creates a URI from the given ServiceInstance's host:port. |
|
|
|
* @param instance the ServiceInstance. |
|
|
|
* @param instance the ServiceInstance. |
|
|
@ -84,7 +119,7 @@ public class DefaultServiceInstance implements ServiceInstance { |
|
|
|
* if port not set. |
|
|
|
* if port not set. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static URI getUri(ServiceInstance instance) { |
|
|
|
public static URI getUri(ServiceInstance instance) { |
|
|
|
String scheme = (instance.isSecure()) ? "https" : "http"; |
|
|
|
String scheme = instance.getScheme(); |
|
|
|
int port = instance.getPort(); |
|
|
|
int port = instance.getPort(); |
|
|
|
if (port <= 0) { |
|
|
|
if (port <= 0) { |
|
|
|
port = (instance.isSecure()) ? 443 : 80; |
|
|
|
port = (instance.isSecure()) ? 443 : 80; |
|
|
@ -148,8 +183,8 @@ public class DefaultServiceInstance implements ServiceInstance { |
|
|
|
this.uri = uri; |
|
|
|
this.uri = uri; |
|
|
|
this.host = this.uri.getHost(); |
|
|
|
this.host = this.uri.getHost(); |
|
|
|
this.port = this.uri.getPort(); |
|
|
|
this.port = this.uri.getPort(); |
|
|
|
String scheme = this.uri.getScheme(); |
|
|
|
scheme = this.uri.getScheme(); |
|
|
|
if ("https".equals(scheme)) { |
|
|
|
if (secureSchemes.contains(scheme)) { |
|
|
|
this.secure = true; |
|
|
|
this.secure = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -179,4 +214,9 @@ public class DefaultServiceInstance implements ServiceInstance { |
|
|
|
return Objects.hash(instanceId, serviceId, host, port, secure, metadata); |
|
|
|
return Objects.hash(instanceId, serviceId, host, port, secure, metadata); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String getScheme() { |
|
|
|
|
|
|
|
return scheme; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|