Skip to content

Commit

Permalink
fixes #273 set the right default port number for DirectRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu committed Sep 1, 2018
1 parent c06743e commit 20e04d4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
14 changes: 14 additions & 0 deletions registry/src/main/java/com/networknt/registry/URLImpl.java
@@ -1,6 +1,8 @@
package com.networknt.registry;

import com.networknt.utility.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -12,6 +14,8 @@
* @author Steve Hu
*/
public class URLImpl implements URL {
private static final Logger logger = LoggerFactory.getLogger(URLImpl.class);

private String protocol;

private String host;
Expand Down Expand Up @@ -90,6 +94,16 @@ public static URL valueOf(String url) {
url = url.substring(0, i);
}
if (url.length() > 0) host = url;
if(port == 0) {
// set the default port based on the protocol
if("http".equalsIgnoreCase(protocol)) {
port = 80;
} else if("https".equalsIgnoreCase(protocol)) {
port = 443;
} else {
logger.error("Unknown protocol " + protocol);
}
}
return new URLImpl(protocol, host, port, path, parameters);
}

Expand Down
4 changes: 4 additions & 0 deletions registry/src/test/java/com/networknt/registry/URLTest.java
Expand Up @@ -104,4 +104,8 @@ public void testURL() {
Assert.assertNotNull(newUrl);
}

@Test
public void testDefaultPort() {

}
}
Expand Up @@ -15,7 +15,7 @@
public class DirectRegistryTest {
@Test
public void testDirectRegistry() {
Registry registry = (Registry)SingletonServiceFactory.getBean(Registry.class);
Registry registry = SingletonServiceFactory.getBean(Registry.class);

URL subscribeUrl = URLImpl.valueOf("light://localhost:8080/token");
List<URL> urls = registry.discover(subscribeUrl);
Expand All @@ -24,5 +24,7 @@ public void testDirectRegistry() {
subscribeUrl = URLImpl.valueOf("light://localhost:8080/code");
urls = registry.discover(subscribeUrl);
Assert.assertEquals(2, urls.size());


}
}
1 change: 1 addition & 0 deletions registry/src/test/resources/config/service.yml
Expand Up @@ -10,5 +10,6 @@ singletons:
parameters:
code: http://192.168.1.100:6881,http://192.168.1.101:6881
token: http://192.168.1.100:6882
com.networknt.test-1.0.0: http://localhost,https://localhost
- com.networknt.registry.Registry:
- com.networknt.registry.support.DirectRegistry

0 comments on commit 20e04d4

Please sign in to comment.