diff options
author | mkuppe | 2009-03-08 11:25:22 +0000 |
---|---|---|
committer | mkuppe | 2009-03-08 11:25:22 +0000 |
commit | 23e0ba07772f709720318c417fb8958a19706f40 (patch) | |
tree | 657766fe6d2fc6cfba634879e713ad6303f8631e /framework/bundles/org.eclipse.ecf.discovery | |
parent | 28f5a3cfdee3d090b3eeab2db0f1a3bd455d1e1c (diff) | |
download | org.eclipse.ecf-23e0ba07772f709720318c417fb8958a19706f40.tar.gz org.eclipse.ecf-23e0ba07772f709720318c417fb8958a19706f40.tar.xz org.eclipse.ecf-23e0ba07772f709720318c417fb8958a19706f40.zip |
Check URI more thoroughly
Diffstat (limited to 'framework/bundles/org.eclipse.ecf.discovery')
-rw-r--r-- | framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/ServiceInfo.java | 66 |
1 files changed, 60 insertions, 6 deletions
diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/ServiceInfo.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/ServiceInfo.java index 10f585fbc..b07825af0 100644 --- a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/ServiceInfo.java +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/ServiceInfo.java @@ -46,13 +46,67 @@ public class ServiceInfo implements IServiceInfo, Serializable, public ServiceInfo(URI anURI, IServiceID serviceID, int priority, int weight, IServiceProperties props) { - this.uri = anURI; - Assert.isNotNull(this.uri); - this.serviceID = serviceID; + Assert.isNotNull(anURI); + // Assert.isLegal(anURI.isOpaque(), "Opaque uri is not supported"); + // Assert.isLegal(!anURI.isAbsolute(), + // "Non absolut uri is not supported"); + + // [scheme:][//authority][path][?query][#fragment] + + // Scheme -> Protocol + String scheme = anURI.getScheme(); + if (scheme == null) { + scheme = UNKNOWN_PROTOCOL; + } + + // UserInfo + String userInfo = anURI.getUserInfo(); + if (userInfo == null) { + userInfo = ""; + } else { + userInfo += "@"; + } + + // Host + String host = anURI.getHost(); + Assert.isNotNull(host); + + // Port + int port = anURI.getPort(); + if (port == -1) { + port = 0; + } + + // Path + String path = anURI.getPath(); + if (path == null) { + path = "/"; + } + + // query + String query = anURI.getQuery(); + if (query == null) { + query = ""; + } else { + query = "?" + query; + } + + // fragment + String fragment = anURI.getFragment(); + if (fragment == null) { + fragment = ""; + } else { + fragment = "#" + fragment; + } + + this.uri = URI.create(scheme + "://" + userInfo + host + ":" + port + + path + query + fragment); + Assert.isNotNull(serviceID); - this.priority = priority; + this.serviceID = serviceID; this.weight = weight; - this.properties = (props == null) ? new ServiceProperties() : props; + this.priority = priority; + properties = (props == null) ? new ServiceProperties() : props; } public ServiceInfo(String protocol, String host, int port, @@ -62,7 +116,7 @@ public class ServiceInfo implements IServiceInfo, Serializable, if (host == null) host = InetAddress.getLocalHost().getHostAddress(); uri = new URI((protocol == null) ? UNKNOWN_PROTOCOL : protocol, - null, host, port, null, null, null); + null, host, port, "/", null, null); } catch (URISyntaxException e) { throw new IllegalArgumentException( Messages.ServiceInfo_EXCEPTION_INVALID_HOST_ARG); |