2799e98f360f13df3b282a4403cec322d194ea20
[jalview.git] / src / jalview / ws / jws2 / JabaWsServerQuery.java
1 /**
2  * 
3  */
4 package jalview.ws.jws2;
5
6 import jalview.bin.Cache;
7
8 import compbio.data.msa.MsaWS;
9 import compbio.ws.client.Jws2Client;
10 import compbio.ws.client.Services;
11
12 /**
13  * @author JimP
14  *
15  */
16 public class JabaWsServerQuery implements Runnable
17 {
18
19   Jws2Discoverer jws2Discoverer=null;
20   String jwsservers=null;
21   boolean quit=false,
22   running=false;
23   /**
24    * @return the running
25    */
26   public  boolean isRunning()
27   {
28     return running;
29   }
30
31   /**
32    * @param quit the quit to set
33    */
34   public void setQuit(boolean quit)
35   {
36     this.quit = quit;
37   }
38
39   public JabaWsServerQuery(Jws2Discoverer jws2Discoverer, String jwsservers)
40   {
41     this.jws2Discoverer = jws2Discoverer;
42     this.jwsservers=jwsservers;
43   }
44
45   /* (non-Javadoc)
46    * @see java.lang.Runnable#run()
47    */
48   @Override
49   public void run()
50   {
51     running=true;
52         try
53     {
54       if (Jws2Client.validURL(jwsservers))
55       {
56         boolean noservices=true;
57         // look for services
58         for (Services srv : Services.values())
59         {
60           if (quit)
61           {
62             running=false;
63             return;
64           }
65           MsaWS service = null;
66           try
67           {
68             service = Jws2Client.connect(jwsservers, srv);
69           } catch (Exception e)
70           {
71             System.err.println("Jws2 Discoverer: Problem on "
72                     + jwsservers + " with service " + srv + ":\n"
73                     + e.getMessage());
74             if (!(e instanceof javax.xml.ws.WebServiceException))
75             {
76               e.printStackTrace();
77             }
78             // For moment, report service as a problem.
79             jws2Discoverer.addInvalidServiceUrl(jwsservers);
80           }
81           ;
82           if (service != null)
83           {
84             noservices=false;
85             jws2Discoverer.addService(jwsservers, srv, service);
86           }
87         }
88         if (noservices)
89         {
90           jws2Discoverer.addUrlwithnoservices(jwsservers);
91         }
92       }
93       else
94       {
95         jws2Discoverer.addInvalidServiceUrl(jwsservers);
96         Cache.log.info("Ignoring invalid Jws2 service url " + jwsservers);
97       }
98     } catch (Exception e)
99     {
100       e.printStackTrace();
101       Cache.log.warn("Exception when discovering Jws2 services.", e);
102       jws2Discoverer.addInvalidServiceUrl(jwsservers);
103     } catch (Error e)
104     {
105       Cache.log.error("Exception when discovering Jws2 services.", e);
106       jws2Discoverer.addInvalidServiceUrl(jwsservers);
107     }
108     running=false;
109   }
110
111 }