diff --git a/build.gradle b/build.gradle
index 739e7201..5420dd66 100644
--- a/build.gradle
+++ b/build.gradle
@@ -13,7 +13,7 @@ repositories {
}
dependencies {
- api("org.openmicroscopy:omero-blitz:5.5.3")
+ api("org.openmicroscopy:omero-blitz:5.5.4")
implementation("commons-beanutils:commons-beanutils:1.9.3")
implementation("com.zeroc:icegrid:3.6.4")
diff --git a/src/main/java/omero/gateway/Connector.java b/src/main/java/omero/gateway/Connector.java
index f34df984..4cb37703 100644
--- a/src/main/java/omero/gateway/Connector.java
+++ b/src/main/java/omero/gateway/Connector.java
@@ -23,7 +23,6 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -966,7 +965,7 @@ public Connector call() throws Exception {
session = prx.createSessionWithTimeouts(p, 0, timeout);
// Create the userSession
omero.client client = new omero.client(context
- .getServerInformation().getHostname(), context
+ .getServerInformation().getHost(), context
.getServerInformation().getPort());
ServiceFactoryPrx userSession = client.createSession(session
.getUuid().getValue(), session.getUuid().getValue());
diff --git a/src/main/java/omero/gateway/Gateway.java b/src/main/java/omero/gateway/Gateway.java
index d489ec79..cf936895 100644
--- a/src/main/java/omero/gateway/Gateway.java
+++ b/src/main/java/omero/gateway/Gateway.java
@@ -303,7 +303,7 @@ public ExperimenterData connect(LoginCredentials c)
throw new DSOutOfServiceException(e.getMessage(), e);
} catch (DNSException e) {
throw new DSOutOfServiceException("Can't resolve hostname "
- + c.getServer().getHostname(), e);
+ + c.getServer().getHost(), e);
}
}
@@ -1063,10 +1063,10 @@ private SessionWrapper createSession(LoginCredentials c)
} else {
username = c.getUser().getUsername();
if (c.getServer().getPort() > 0)
- secureClient = new client(c.getServer().getHostname(), c
+ secureClient = new client(c.getServer().getHost(), c
.getServer().getPort());
else
- secureClient = new client(c.getServer().getHostname());
+ secureClient = new client(c.getServer().getHost());
}
secureClient.setAgent(c.getApplicationName());
ServiceFactoryPrx entryEncrypted = null;
@@ -1702,7 +1702,7 @@ private Connector createConnector(SecurityContext ctx, boolean permitNull)
args.toArray(new String[args.size()]));
prx = client.createSession();
} else {
- client = new client(login.getServer().getHostname(),
+ client = new client(login.getServer().getHost(),
login.getServer().getPort());
prx = client.createSession(login.getUser().getUsername(), login
.getUser().getPassword());
diff --git a/src/main/java/omero/gateway/LoginCredentials.java b/src/main/java/omero/gateway/LoginCredentials.java
index e18378c7..1db3b229 100644
--- a/src/main/java/omero/gateway/LoginCredentials.java
+++ b/src/main/java/omero/gateway/LoginCredentials.java
@@ -20,7 +20,9 @@
*/
package omero.gateway;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import omero.IllegalArgumentException;
@@ -63,6 +65,16 @@ public class LoginCredentials {
/** Whether to check the client-server versions */
private boolean checkVersion = true;
+ /** Default websocket ports (this might be moved into omero.constants
+ * in future) **/
+ private enum DefaultPort {
+ WS(80), WSS(443);
+ private final int port;
+ DefaultPort(int port) {
+ this.port = port;
+ }
+ }
+
/**
* Creates a new instance
*/
@@ -96,10 +108,10 @@ public LoginCredentials(String[] args) {
* @param password
* The password
* @param host
- * The server hostname
+ * The server hostname or websocket URL
*/
public LoginCredentials(String username, String password, String host) {
- this(username, password, host, omero.constants.GLACIER2PORT.value);
+ this(username, password, host, -1);
}
/**
@@ -111,7 +123,7 @@ public LoginCredentials(String username, String password, String host) {
* @param password
* The password
* @param host
- * The server hostname
+ * The server hostname or websocket URL
* @param port
* The server port
*/
@@ -120,8 +132,23 @@ public LoginCredentials(String username, String password, String host,
this();
user.setUsername(username);
user.setPassword(password);
- server.setHostname(host);
- server.setPort(port);
+ server.setHost(host);
+ if (port >= 0) {
+ server.setPort(port);
+ }
+ else if (server.getPort() < 0) {
+ // set default ports
+ if (!server.isURL()) {
+ server.setPort(omero.constants.GLACIER2PORT.value);
+ }
+ else if (server.getPort() < 0) {
+ try {
+ server.setPort(DefaultPort.valueOf(server.getProtocol().toUpperCase()).port);
+ } catch (IllegalArgumentException e) {
+ // neither ws nor wss
+ }
+ }
+ }
}
/**
diff --git a/src/main/java/omero/gateway/ServerInformation.java b/src/main/java/omero/gateway/ServerInformation.java
index a8fd17bf..1e1cd6ec 100644
--- a/src/main/java/omero/gateway/ServerInformation.java
+++ b/src/main/java/omero/gateway/ServerInformation.java
@@ -20,8 +20,11 @@
*/
package omero.gateway;
+import java.net.URI;
+import java.net.URISyntaxException;
+
/**
- * Holds hostname and port of an OMERO server
+ * Holds the network connection information of an OMERO server
*
* @author Dominik Lindner d.lindner@dundee.ac.uk
@@ -30,49 +33,131 @@
public class ServerInformation {
- /** The hostname */
- private String hostname;
-
- /** The port */
- private int port;
+ /** The URI */
+ private URI uri;
/**
* Creates an empty instance
*/
public ServerInformation() {
+ try {
+ this.uri = new URI(null, null, null,
+ -1, null, null, null);
+ } catch (URISyntaxException e) {
+ }
+ }
+ /**
+ * Creates a new instance
+ *
+ * @param hostname
+ * The hostname or websocket URL
+ */
+ public ServerInformation(String hostname) {
+ this(hostname, -1);
}
/**
* Creates a new instance
*
* @param hostname
- * The hostname
+ * The hostname or websocket URL
* @param port
* The port
*/
public ServerInformation(String hostname, int port) {
- super();
- this.hostname = hostname;
- this.port = port;
+ try {
+ if (hostname.contains(":/")) {
+ // this is already a URI like wss://example.org
+ this.uri = new URI(hostname);
+ if (port >= 0 && this.uri.getPort() < 0) {
+ this.uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(),
+ port, uri.getPath(), uri.getQuery(), uri.getFragment());
+ }
+ }
+ else {
+ if (port < 0 && hostname.contains(":")) {
+ try {
+ String[] parts = hostname.split(":");
+ port = Integer.parseInt(parts[parts.length-1]);
+ hostname = parts[parts.length-2];
+ } catch (Exception e) {}
+ }
+ this.uri = new URI(null,null, hostname,
+ port, null, null, null);
+ }
+ } catch (URISyntaxException e) {
+ }
+ }
+
+ /**
+ * Get the host information as required by the omero.client.
+ * In case a websocket URL was specified the full
+ * URL will be returned. If only a host name was
+ * specified only the host name will be returned.
+ * @return See above.
+ */
+ public String getHost() {
+ if (this.uri.isAbsolute())
+ return this.uri.toString();
+ return this.uri.getHost();
}
/**
- * Return the hostname.
+ * Set the hostname or websocket URL
+ *
+ * @param host
+ * See above
+ */
+ public void setHost(String host) {
+ try {
+ if (host.contains(":/")) {
+ // this is already a URI like wss://example.org
+ int port = this.uri.getPort();
+ this.uri = new URI(host);
+ if (port >= 0 && this.uri.getPort() < 0) {
+ this.uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(),
+ port, uri.getPath(), uri.getQuery(), uri.getFragment());
+ }
+ }
+ else {
+ int port = uri.getPort();
+ if (port < 0 && host.contains(":")) {
+ try {
+ String[] parts = host.split(":");
+ port = Integer.parseInt(parts[parts.length-1]);
+ host = parts[parts.length-2];
+ } catch (Exception e) {}
+ }
+ this.uri = new URI(uri.getScheme(), uri.getUserInfo(), host,
+ port, uri.getPath(), uri.getQuery(), uri.getFragment());
+ }
+ } catch (URISyntaxException e) {
+ }
+ }
+
+ /**
+ * Return the hostname. Even if a websocket URL
+ * was specified only the hostname part will
+ * be returned by this method. Use {@link #getHost()}
+ * to get the full websocket URL.
+ *
* @return The hostname
*/
public String getHostname() {
- return hostname;
+ return uri.getHost();
}
/**
- * Set the hostname
+ * @deprecated Renamed to {@link #setHost(String)}
+ *
+ * Set the hostname or websocket URL
*
* @param hostname
* See above
*/
public void setHostname(String hostname) {
- this.hostname = hostname;
+ setHost(hostname);
}
/**
@@ -80,7 +165,7 @@ public void setHostname(String hostname) {
* @return The port
*/
public int getPort() {
- return port;
+ return uri.getPort();
}
/**
@@ -90,43 +175,35 @@ public int getPort() {
* See above
*/
public void setPort(int port) {
- this.port = port;
+ try {
+ this.uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(),
+ port, uri.getPath(), uri.getQuery(), uri.getFragment());
+ } catch (URISyntaxException e) {
+ }
}
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result
- + ((hostname == null) ? 0 : hostname.hashCode());
- result = prime * result + port;
- return result;
+ /**
+ * Returns true
if a websocket
+ * URL was specified.
+ * @return See above.
+ */
+ public boolean isURL() {
+ return this.uri.isAbsolute();
}
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ServerInformation other = (ServerInformation) obj;
- if (hostname == null) {
- if (other.hostname != null)
- return false;
- } else if (!hostname.equals(other.hostname))
- return false;
- if (port != other.port)
- return false;
- return true;
+ /**
+ * Returns the protocol (lower case) if a websocket URL was specified
+ * (empty String otherwise).
+ * @return See above.
+ */
+ public String getProtocol() {
+ if (isURL())
+ return this.uri.getScheme().toLowerCase();
+ return "";
}
@Override
public String toString() {
- return "ServerInformation [hostname=" + hostname + ", port=" + port
- + "]";
+ return "ServerInformation [uri=" + uri.toString() + "]";
}
-
-
}