diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-11-23 13:51:12 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-11-23 13:51:12 -0500 |
| commit | 3c62b863509131e78c18ed13c6b83e4fc508848f (patch) | |
| tree | cf246e91da283edf704af936b9cef7eb8e09a6f8 /src/main/java/derms/replica/replica1/Client.java | |
| parent | e3b72053e8b04f2df013da0d7d49fe33927461a9 (diff) | |
| download | soen423-3c62b863509131e78c18ed13c6b83e4fc508848f.zip | |
import replica code from assignment
Diffstat (limited to 'src/main/java/derms/replica/replica1/Client.java')
| -rw-r--r-- | src/main/java/derms/replica/replica1/Client.java | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/main/java/derms/replica/replica1/Client.java b/src/main/java/derms/replica/replica1/Client.java new file mode 100644 index 0000000..7ebbb68 --- /dev/null +++ b/src/main/java/derms/replica/replica1/Client.java @@ -0,0 +1,30 @@ +package derms.replica.replica1; + +import javax.xml.namespace.QName; +import javax.xml.ws.Service; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.UnknownHostException; + +public abstract class Client<I, C> { + public static final String namespace = "derms.samanthony.xyz"; + public static final int port = 8080; + + private final Class<I> endpointInterface; + private final QName qname; + + protected Client(Class<I> endpointInterface, Class<C> endpointClass) { + this.endpointInterface = endpointInterface; + this.qname = new QName("http://"+namespace+"/", endpointClass.getSimpleName()+"Service"); + } + + protected I connect(String host) throws MalformedURLException { + URL url = new URL("http://"+host+":"+port+"/"+endpointInterface.getSimpleName()+"?wsdl"); + return Service.create(url, qname).getPort(endpointInterface); + } + + protected I connect(City city) throws UnknownHostException, MalformedURLException { + String host = Hosts.get(city); + return connect(host); + } +} |