update author list in license for (JAL-826)
[jalview.git] / src / jalview / ws / jws2 / JabaWsServerQuery.java
1 /*******************************************************************************
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
4  *
5  * This file is part of Jalview.
6  *
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  *******************************************************************************/
18 /**
19  * 
20  */
21 package jalview.ws.jws2;
22
23 import jalview.bin.Cache;
24
25 import compbio.data.msa.MsaWS;
26 import compbio.ws.client.Jws2Client;
27 import compbio.ws.client.Services;
28
29 /**
30  * @author JimP
31  *
32  */
33 public class JabaWsServerQuery implements Runnable
34 {
35
36   Jws2Discoverer jws2Discoverer=null;
37   String jwsservers=null;
38   boolean quit=false,
39   running=false;
40   /**
41    * @return the running
42    */
43   public  boolean isRunning()
44   {
45     return running;
46   }
47
48   /**
49    * @param quit the quit to set
50    */
51   public void setQuit(boolean quit)
52   {
53     this.quit = quit;
54   }
55
56   public JabaWsServerQuery(Jws2Discoverer jws2Discoverer, String jwsservers)
57   {
58     this.jws2Discoverer = jws2Discoverer;
59     this.jwsservers=jwsservers;
60   }
61
62   /* (non-Javadoc)
63    * @see java.lang.Runnable#run()
64    */
65   @Override
66   public void run()
67   {
68     running=true;
69         try
70     {
71       if (Jws2Client.validURL(jwsservers))
72       {
73         boolean noservices=true;
74         // look for services
75         for (Services srv : Services.values())
76         {
77           if (quit)
78           {
79             running=false;
80             return;
81           }
82           MsaWS service = null;
83           try
84           {
85             service = Jws2Client.connect(jwsservers, srv);
86           } catch (Exception e)
87           {
88             System.err.println("Jws2 Discoverer: Problem on "
89                     + jwsservers + " with service " + srv + ":\n"
90                     + e.getMessage());
91             if (!(e instanceof javax.xml.ws.WebServiceException))
92             {
93               e.printStackTrace();
94             }
95             // For moment, report service as a problem.
96             jws2Discoverer.addInvalidServiceUrl(jwsservers);
97           }
98           ;
99           if (service != null)
100           {
101             noservices=false;
102             jws2Discoverer.addService(jwsservers, srv, service);
103           }
104         }
105         if (noservices)
106         {
107           jws2Discoverer.addUrlwithnoservices(jwsservers);
108         }
109       }
110       else
111       {
112         jws2Discoverer.addInvalidServiceUrl(jwsservers);
113         Cache.log.info("Ignoring invalid Jws2 service url " + jwsservers);
114       }
115     } catch (Exception e)
116     {
117       e.printStackTrace();
118       Cache.log.warn("Exception when discovering Jws2 services.", e);
119       jws2Discoverer.addInvalidServiceUrl(jwsservers);
120     } catch (Error e)
121     {
122       Cache.log.error("Exception when discovering Jws2 services.", e);
123       jws2Discoverer.addInvalidServiceUrl(jwsservers);
124     }
125     running=false;
126   }
127
128 }