X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fjws2%2FJabaWsServerQuery.java;h=832a2cb6a8ff83cb562d702c2ba94dac0f6a2785;hb=da53a3eaf1e5c06ff6a2506b7b603086293a887e;hp=f3b8de51371ad1da9629e8cd74c8e50857ac8828;hpb=a8f483d04205bb8273ee311c12968b7e86d205fa;p=jalview.git
diff --git a/src/jalview/ws/jws2/JabaWsServerQuery.java b/src/jalview/ws/jws2/JabaWsServerQuery.java
index f3b8de5..832a2cb 100644
--- a/src/jalview/ws/jws2/JabaWsServerQuery.java
+++ b/src/jalview/ws/jws2/JabaWsServerQuery.java
@@ -6,14 +6,16 @@
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
/**
@@ -25,6 +27,9 @@ import jalview.bin.Cache;
import jalview.ws.jws2.jabaws2.Jws2Instance;
import jalview.ws.jws2.jabaws2.Jws2InstanceFactory;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.HashSet;
import java.util.Set;
@@ -42,7 +47,7 @@ public class JabaWsServerQuery implements Runnable
Jws2Discoverer jws2Discoverer = null;
- String jwsservers = null;
+ String jwsserver = null;
boolean quit = false, running = false;
@@ -63,10 +68,10 @@ public class JabaWsServerQuery implements Runnable
this.quit = quit;
}
- public JabaWsServerQuery(Jws2Discoverer jws2Discoverer, String jwsservers)
+ public JabaWsServerQuery(Jws2Discoverer jws2Discoverer, String server)
{
this.jws2Discoverer = jws2Discoverer;
- this.jwsservers = jwsservers;
+ this.jwsserver = server;
}
Services[] JABAWS1SERVERS = new Services[]
@@ -90,7 +95,9 @@ public class JabaWsServerQuery implements Runnable
running = true;
try
{
- if (Jws2Client.validURL(jwsservers))
+ // TODO this test doesn't seem to attempt a connection - should it?
+ // would save a lot of failed tries with UnknownHostException
+ if (isValidUrl(jwsserver))
{
compbio.data.msa.RegistryWS registry = null;
Set svccategories = null;
@@ -107,7 +114,7 @@ public class JabaWsServerQuery implements Runnable
try
{
// JBPNote: why is RegistryWS in compbio.data.msa ?
- registry = Jws2Client.connectToRegistry(jwsservers);
+ registry = Jws2Client.connectToRegistry(jwsserver);
if (registry != null)
{
// System.err.println("Test Services Output\n"
@@ -117,14 +124,16 @@ public class JabaWsServerQuery implements Runnable
jabasws2 = true;
srv_set = registry.getSupportedServices();
-
+
// dan test
- System.out.println("registry.getSupportedServices: " + srv_set.toString());
-
+ System.out.println("registry.getSupportedServices: "
+ + srv_set.toString());
+
svccategories = registry.getServiceCategories();
-
+
// dan test
-// System.out.println("registry.getServiceCategories: " + svccategories.toString());
+ // System.out.println("registry.getServiceCategories: " +
+ // svccategories.toString());
}
} catch (Exception ex)
@@ -133,13 +142,14 @@ public class JabaWsServerQuery implements Runnable
ex.printStackTrace();
// if that failed, then we are probably working with a JABAWS1 server.
// in that case, look for each service endpoint
- System.err.println("JWS2 Discoverer: " + jwsservers
+ System.err.println("JWS2 Discoverer: " + jwsserver
+ " is a JABAWS1 server. Using hardwired list.");
for (Services srv : JABAWS1SERVERS)
{
srv_set.add(srv);
}
}
+
for (Category cat : categories)
{
for (Services srv : cat.getServices())
@@ -156,18 +166,18 @@ public class JabaWsServerQuery implements Runnable
JABAService service = null;
try
{
- service = Jws2Client.connect(jwsservers, srv);
+ service = Jws2Client.connect(jwsserver, srv);
} catch (Exception e)
{
System.err.println("Jws2 Discoverer: Problem on "
- + jwsservers + " with service " + srv + ":\n"
+ + jwsserver + " with service " + srv + ":\n"
+ e.getMessage());
if (!(e instanceof javax.xml.ws.WebServiceException))
{
e.printStackTrace();
}
// For moment, report service as a problem.
- jws2Discoverer.addInvalidServiceUrl(jwsservers);
+ jws2Discoverer.addInvalidServiceUrl(jwsserver);
}
;
if (service != null)
@@ -179,15 +189,16 @@ public class JabaWsServerQuery implements Runnable
String description = registry.getServiceDescription(srv);
- svc = Jws2InstanceFactory.newJws2Instance(jwsservers, srv.toString(),
- cat.name, description, service);
+ svc = Jws2InstanceFactory.newJws2Instance(jwsserver,
+ srv.toString(), cat.name, description, service);
}
if (svc == null)
{
- svc = Jws2InstanceFactory.newJws2Instance(jwsservers, srv.toString(),
- cat.name, "JABAWS 1 Alignment Service", service);
+ svc = Jws2InstanceFactory.newJws2Instance(jwsserver,
+ srv.toString(), cat.name,
+ "JABAWS 1 Alignment Service", service);
}
- jws2Discoverer.addService(jwsservers, svc);
+ jws2Discoverer.addService(jwsserver, svc);
}
}
@@ -195,25 +206,53 @@ public class JabaWsServerQuery implements Runnable
if (noservices)
{
- jws2Discoverer.addUrlwithnoservices(jwsservers);
+ jws2Discoverer.addUrlwithnoservices(jwsserver);
}
}
else
{
- jws2Discoverer.addInvalidServiceUrl(jwsservers);
- Cache.log.info("Ignoring invalid Jws2 service url " + jwsservers);
+ jws2Discoverer.addInvalidServiceUrl(jwsserver);
+ Cache.log.warn("Ignoring invalid Jws2 service url " + jwsserver);
}
} catch (Exception e)
{
e.printStackTrace();
Cache.log.warn("Exception when discovering Jws2 services.", e);
- jws2Discoverer.addInvalidServiceUrl(jwsservers);
+ jws2Discoverer.addInvalidServiceUrl(jwsserver);
} catch (Error e)
{
Cache.log.error("Exception when discovering Jws2 services.", e);
- jws2Discoverer.addInvalidServiceUrl(jwsservers);
+ jws2Discoverer.addInvalidServiceUrl(jwsserver);
}
running = false;
}
+ /**
+ * Check if the URL is valid and responding.
+ *
+ * @return
+ */
+ private boolean isValidUrl(String server)
+ {
+ // return Jws2Client.validURL(jwsserver); // checks syntax only
+ boolean result = false;
+ if (server != null) {
+ try {
+ URL url = new URL(server);
+ url.openStream().close();
+ result = true;
+ } catch (MalformedURLException e)
+ {
+ System.err.println("Invalid server URL: " + server);
+ result = false;
+ } catch (IOException e)
+ {
+ System.err.println("Error connecting to server: " + server + ": "
+ + e.toString());
+ result = false;
+ }
+ }
+ return result;
+ }
+
}