From 7cf18cce1b3577c90ce11dced08bf5bf9de141e9 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Fri, 11 Jul 2014 16:18:29 -0500 Subject: [PATCH] add getScheme() and a useful toString() --- .../cloud/service/UriBasedServiceInfo.java | 146 ++++++++++-------- 1 file changed, 79 insertions(+), 67 deletions(-) diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfo.java index 78828de..fda552c 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfo.java @@ -6,84 +6,96 @@ import org.springframework.cloud.util.UriInfoFactory; /** * Common class for all {@link ServiceInfo}s - * + * * @author Ramnivas Laddad * */ public abstract class UriBasedServiceInfo extends BaseServiceInfo { - private UriInfo uriInfo; + private UriInfo uriInfo; - private static UriInfoFactory uriFactory = new StandardUriInfoFactory(); + private static UriInfoFactory uriFactory = new StandardUriInfoFactory(); - public UriBasedServiceInfo(String id, String scheme, String host, int port, String username, String password, String path) { - super(id); - this.uriInfo = getUriInfoFactory().createUri(scheme, host, port, username, password, path); - this.uriInfo = validateAndCleanUriInfo(uriInfo); - } - - public UriBasedServiceInfo(String id, String uriString) { - super(id); - this.uriInfo = getUriInfoFactory().createUri(uriString); - this.uriInfo = validateAndCleanUriInfo(uriInfo); - } + public UriBasedServiceInfo(String id, String scheme, String host, int port, String username, String password, String path) { + super(id); + this.uriInfo = getUriInfoFactory().createUri(scheme, host, port, username, password, path); + this.uriInfo = validateAndCleanUriInfo(uriInfo); + } - /** - * For URI-based (@link ServiceInfo}s which don't conform to the standard URI - * format, override this method in your own ServiceInfo class to return a - * {@link UriInfoFactory} which will create the appropriate URIs. - * - * @return your special UriInfoFactory - */ - public UriInfoFactory getUriInfoFactory() { - return uriFactory; - } + public UriBasedServiceInfo(String id, String uriString) { + super(id); + this.uriInfo = getUriInfoFactory().createUri(uriString); + this.uriInfo = validateAndCleanUriInfo(uriInfo); + } - @ServiceProperty(category="connection") - public String getUri() { - return uriInfo.getUri().toString(); - } - - @ServiceProperty(category="connection") - public String getUserName() { - return uriInfo.getUserName(); - } - - @ServiceProperty(category="connection") - public String getPassword() { - return uriInfo.getPassword(); - } + /** + * For URI-based (@link ServiceInfo}s which don't conform to the standard URI + * format, override this method in your own ServiceInfo class to return a {@link UriInfoFactory} which will create the + * appropriate URIs. + * + * @return your special UriInfoFactory + */ + public UriInfoFactory getUriInfoFactory() { + return uriFactory; + } - @ServiceProperty(category="connection") - public String getHost() { - return uriInfo.getHost(); - } + @ServiceProperty(category = "connection") + public String getUri() { + return uriInfo.getUri().toString(); + } - @ServiceProperty(category="connection") - public int getPort() { - return uriInfo.getPort(); - } + @ServiceProperty(category = "connection") + public String getUserName() { + return uriInfo.getUserName(); + } - @ServiceProperty(category="connection") - public String getPath() { - return uriInfo.getPath(); - } + @ServiceProperty(category = "connection") + public String getPassword() { + return uriInfo.getPassword(); + } - @ServiceProperty(category="connection") - public String getQuery() { - return uriInfo.getQuery(); - } + @ServiceProperty(category = "connection") + public String getHost() { + return uriInfo.getHost(); + } - /** - * Validate the URI and clean it up by using defaults for any missing information, if possible. - * - * @param uriInfo uri info based on parsed payload - * @return cleaned up uri info - */ - protected UriInfo validateAndCleanUriInfo(UriInfo uriInfo) { - return uriInfo; - } - - protected UriInfo getUriInfo() { - return uriInfo; - } + @ServiceProperty(category = "connection") + public int getPort() { + return uriInfo.getPort(); + } + + @ServiceProperty(category = "connection") + public String getPath() { + return uriInfo.getPath(); + } + + @ServiceProperty(category = "connection") + public String getQuery() { + return uriInfo.getQuery(); + } + + @ServiceProperty(category = "connection") + public String getScheme() { + return uriInfo.getScheme(); + } + + /** + * Validate the URI and clean it up by using defaults for any missing information, if possible. + * + * @param uriInfo + * uri info based on parsed payload + * @return cleaned up uri info + */ + protected UriInfo validateAndCleanUriInfo(UriInfo uriInfo) { + return uriInfo; + } + + protected UriInfo getUriInfo() { + return uriInfo; + } + + @Override + public String toString() { + return getClass().getSimpleName() + "[" + getScheme() + "://" + getUserName() + ":****@" + getHost() + ":" + getPort() + + "/" + getPath() + "]"; + } }