View Javadoc

1   /*
2    * $Id: RestfulGWES.java 1537 2011-07-27 15:34:04Z hoheisel $
3    *
4    * Copyright 2008 Fraunhofer Gesellschaft, Munich, Germany,
5    * for its Fraunhofer Institute for Computer Architecture and Software Technology (FIRST), Berlin, Germany
6    * All rights reserved.
7    *
8    * See http://www.first.fraunhofer.de and http://www.gridworkflow.org/gwes for more details.
9    */
10  
11  package net.kwfgrid.gwes.restfulclient;
12  
13  import net.kwfgrid.gworkflowdl.structure.WorkflowFormatException;
14  import net.kwfgrid.gwes.exception.StateTransitionException;
15  import net.kwfgrid.gwes.exception.NoSuchWorkflowException;
16  import net.kwfgrid.gwes.exception.DatabaseException;
17  import net.kwfgrid.gwes.Constants;
18  import net.kwfgrid.gwes.util.StringUtils;
19  import net.kwfgrid.gwes.util.HTMLFilter;
20  
21  import java.rmi.RemoteException;
22  import java.util.*;
23  import java.util.regex.Pattern;
24  
25  import org.apache.log4j.Logger;
26  
27  /**
28   * @author Andreas Hoheisel
29   *         (<a href="http://www.andreas-hoheisel.de">www.andreas-hoheisel.de</a>)
30   * @version $Id: RestfulGWES.java 1537 2011-07-27 15:34:04Z hoheisel $
31   */
32  public class RestfulGWES extends RestfulClient implements net.kwfgrid.gwes.GWES  {
33  
34      final static Logger logger = Logger.getLogger(RestfulGWES.class);
35  
36      /**
37       * Key is gwesServiceUrl, value is RestfulGWES.
38       */
39      private static Hashtable<String,RestfulGWES> instances = new Hashtable<String,RestfulGWES>();
40  
41      public static final String STRING_SLASH= "/";
42      public static final String STRING_L="<";
43      public static final String STRING_G=">";
44      public static final String STRING_LSLASH="</";
45      public static final String METHOD_INITIATE = "initiate";
46      public static final String METHOD_START = "start";
47      public static final String METHOD_SUSPEND = "suspend";
48      public static final String METHOD_RESUME = "resume";
49      public static final String METHOD_ABORT = "abort";
50      public static final String METHOD_RESTART = "restart";
51      public static final String METHOD_GETWORKFLOWDESCRIPTION = "getWorkflowDescription";
52      public static final String METHOD_SETWORKFLOWDESCRIPTION = "setWorkflowDescription";
53      public static final String METHOD_GETSTATUS = "getStatus";
54      public static final String METHOD_WAITFORSTATUSCHANGEFROM = "waitForStatusChangeFrom";
55      public static final String METHOD_WAITFORSTATUSCHANGETOCOMPLETEDORTERMINATED = "waitForStatusChangeToCompletedOrTerminated";
56      public static final String METHOD_GETWORKFLOWIDS = "getWorkflowIDs";
57      public static final String METHOD_GETWORKFLOWSTATUSARRAY = "getWorkflowStatusArray";
58      public static final String METHOD_STORE = "store";
59      public static final String METHOD_RESTORE = "restore";
60      public static final String METHOD_GETDATA = "getData";
61      public static final String METHOD_SETDESCRIPTION = "setDescription";
62      public static final String METHOD_GETDESCRIPTION = "getDescription";
63      public static final String METHOD_SETPROPERTY = "setProperty";
64      public static final String METHOD_GETPROPERTY = "getProperty";
65      public static final String METHOD_GETPROPERTIES = "getProperties";
66      public static final String METHOD_GETCHECKPOINTS = "getCheckpoints";
67      public static final String METHOD_REMOVE = "remove";
68      public static final String METHOD_GETACTIVITYSTATUSARRAY = "getActivityStatusArray";
69      public static final String METHOD_GETAVAILABLERESOURCES = "getAvailableResources";
70      public static final String METHOD_GETRESOURCEDESCRIPTION_= "getResourceDescription";
71      public static final String ATTRIBUTE_NS = " xmlns=\"http://gwes.kwfgrid.net\"";
72      public static final String ELEMENT_WORKFLOWDESCRIPTION = "workflowDescription";
73      public static final String ELEMENT_USERID = "userID";
74      public static final String ELEMENT_WORKFLOWID = "workflowID";
75      public static final String ELEMENT_DESCRIPTION = "description";
76      public static final String ELEMENT_NAME = "name";
77      public static final String ELEMENT_VALUE = "value";
78      public static final String PARAM_LEVEL="?level=";
79      public static final String PARAM_WORKFLOWID = "?workflowID=";
80      public static final String PARAM_OFCLASS = "?ofClass=";
81      public static final String PARAM_RESOURCEURI = "?resourceUri=";
82      public static final String _PARAM_LEVEL="&level=";
83      public static final String _PARAM_OLDSTATUS = "&oldStatus=";
84      public static final String _PARAM_PLACEID = "&placeID=";
85      public static final String _PARAM_NAME = "&name=";
86      public static final String _PARAM_USERID = "&userID=";
87  
88      protected static final Pattern PATTERN_COLLECTION_NOT_FOUND = Pattern.compile("(?s).*collection .*/.* not found.*", Pattern.DOTALL);
89      protected static final Pattern PATTERN_WORKFLOW_NOT_AVAILABLE = Pattern.compile("(?s).*Workflow.*is not available.*", Pattern.DOTALL);
90      protected static final Pattern PATTERN_WORKFLOW_NOT_AVAILABLE2 = Pattern.compile("(?s).*net.kwfgrid.gwes.exception.NoSuchWorkflowException.*", Pattern.DOTALL);
91      protected static final Pattern PATTERN_PLACE_WORKFLOW_NOT_AVAILABLE = Pattern.compile("(?s).*Place '.*' within Workflow '.*' is not available!.*", Pattern.DOTALL);
92  
93      /**
94       * GWES service URL with ending "/", e.g., http://localhost:8080/gwes/service/GWES/
95       */
96      protected String gwesServiceUrl;
97  
98      /**
99       * Create new or return existing RestfulGWES instance to GWES with service URL as specified by system property.
100      * @see net.kwfgrid.gwes.Constants#PROP_SYSTEM_GWES_SERVICE_BASE_URL_INTERNAL
101      * @return
102      * @throws Exception
103      */
104     public synchronized static RestfulGWES getInstance() throws Exception {
105         String gwesServiceUrl = System.getProperty(Constants.PROP_SYSTEM_GWES_SERVICE_BASE_URL_INTERNAL) + "/services/GWES";
106         if (gwesServiceUrl.equals("null/services/GWES")) {
107             throw new Exception("The GWES client has not been configured correctly. Please set the property "
108                     + Constants.PROP_SYSTEM_GWES_SERVICE_BASE_URL_INTERNAL + " in the file gwes.properties or as system property");
109         }
110 
111         return getInstance(gwesServiceUrl);
112     }
113 
114     /**
115      * Create new or return existing RestfulGWES instance to GWES with service URL as specified by paramter gwesServiceUrl.
116      * @return
117      * @throws Exception
118      */
119     public synchronized static RestfulGWES getInstance(String gwesServiceUrl) throws Exception {
120         RestfulGWES _instance = instances.get(gwesServiceUrl);
121         if (_instance == null) {
122             _instance = new RestfulGWES(gwesServiceUrl);
123             instances.put(gwesServiceUrl,_instance);
124         }
125         return _instance;
126     }
127 
128     /**
129      * Private constructor for internal use only.
130      * Use getInstance() methods instead.
131      * @param gwesServiceUrl
132      * @throws Exception
133      */
134     protected RestfulGWES(String gwesServiceUrl) throws Exception {
135         this.gwesServiceUrl = gwesServiceUrl.endsWith(STRING_SLASH) ? gwesServiceUrl : gwesServiceUrl + STRING_SLASH;
136         logger.info("connected to " + gwesServiceUrl);
137     }
138 
139     protected String[] localExceptionHttpGET(String workflowID, StringBuffer urlBuf) throws NoSuchWorkflowException, RemoteException {
140         String[] ret;
141         try {
142             ret = httpGET(urlBuf.toString());
143         } catch (RemoteException e) {
144             if (PATTERN_COLLECTION_NOT_FOUND.matcher(e.getMessage()).matches()) {
145                 throw new NoSuchWorkflowException("Workflow with ID '"+workflowID+"' is not available in memory or database!",e);
146             } else if (PATTERN_WORKFLOW_NOT_AVAILABLE.matcher(e.getMessage()).matches()) {
147                 throw new NoSuchWorkflowException("Workflow with ID '"+workflowID+"' is not available in memory!",e);
148             } else if (PATTERN_PLACE_WORKFLOW_NOT_AVAILABLE.matcher(e.getMessage()).matches()) {
149                 throw new NoSuchWorkflowException("Place within Workflow '"+workflowID+"' is not available!",e);
150             } else throw e;
151         }
152         return ret;
153     }
154 
155     protected String[][] localExceptionHttpGETArray(String workflowID, StringBuffer urlBuf) throws NoSuchWorkflowException, RemoteException {
156         String[][] ret;
157         try {
158             ret = httpGETArray(urlBuf.toString());
159         } catch (RemoteException e) {
160             if (PATTERN_COLLECTION_NOT_FOUND.matcher(e.getMessage()).matches()) {
161                 throw new NoSuchWorkflowException("Workflow with ID '"+workflowID+"' is not available in memory or database!",e);
162             } else if (PATTERN_WORKFLOW_NOT_AVAILABLE2.matcher(e.getMessage()).matches()) {
163                 throw new NoSuchWorkflowException("Workflow with ID '"+workflowID+"' is not available in memory or database!",e);
164             } else if (PATTERN_WORKFLOW_NOT_AVAILABLE.matcher(e.getMessage()).matches()) {
165                 throw new NoSuchWorkflowException("Workflow with ID '"+workflowID+"' is not available in memory!",e);
166             } else if (PATTERN_PLACE_WORKFLOW_NOT_AVAILABLE.matcher(e.getMessage()).matches()) {
167                 throw new NoSuchWorkflowException("Place within Workflow '"+workflowID+"' is not available!",e);
168             } else throw e;
169         }
170         return ret;
171     }
172 
173     protected String[] localExceptionHttpPUT(String workflowID, StringBuffer urlBuf, StringBuffer payload) throws NoSuchWorkflowException, RemoteException {
174         String[] ret;
175         try {
176             ret = httpPUT(urlBuf.toString(), payload.toString());
177         } catch (RemoteException e) {
178             if (PATTERN_COLLECTION_NOT_FOUND.matcher(e.getMessage()).matches()) {
179                 throw new NoSuchWorkflowException("Workflow with ID '"+workflowID+"' is not available in memory or database!",e);
180             } else if (PATTERN_WORKFLOW_NOT_AVAILABLE2.matcher(e.getMessage()).matches()) {
181                 throw new NoSuchWorkflowException("Workflow with ID '"+workflowID+"' is not available in memory or database!",e);
182             } else if (PATTERN_WORKFLOW_NOT_AVAILABLE.matcher(e.getMessage()).matches()) {
183                 throw new NoSuchWorkflowException("Workflow with ID '"+workflowID+"' is not available in memory!",e);
184             } else if (PATTERN_PLACE_WORKFLOW_NOT_AVAILABLE.matcher(e.getMessage()).matches()) {
185                 throw new NoSuchWorkflowException("Place within Workflow '"+workflowID+"' is not available!",e);
186             } else throw e;
187         }
188         return ret;
189     }
190 
191     protected String[] localExceptionHttpDELETE(String workflowID, StringBuffer urlBuf) throws NoSuchWorkflowException, RemoteException {
192         String[] ret;
193         try {
194             ret = httpDELETE(urlBuf.toString());
195         } catch (RemoteException e) {
196             if (PATTERN_COLLECTION_NOT_FOUND.matcher(e.getMessage()).matches()) {
197                 throw new NoSuchWorkflowException("Workflow with ID '"+workflowID+"' is not available in memory or database!",e);
198             } else if (PATTERN_WORKFLOW_NOT_AVAILABLE2.matcher(e.getMessage()).matches()) {
199                 throw new NoSuchWorkflowException("Workflow with ID '"+workflowID+"' is not available in memory or database!",e);
200             } else if (PATTERN_WORKFLOW_NOT_AVAILABLE.matcher(e.getMessage()).matches()) {
201                 throw new NoSuchWorkflowException("Workflow with ID '"+workflowID+"' is not available in memory!",e);
202             } else if (PATTERN_PLACE_WORKFLOW_NOT_AVAILABLE.matcher(e.getMessage()).matches()) {
203                 throw new NoSuchWorkflowException("Place within Workflow '"+workflowID+"' is not available!",e);
204             } else throw e;
205         }
206         return ret;
207     }
208 
209 
210     /*======================================================================
211       public Methods of interface GWES
212      =======================================================================*/
213 
214     public String initiate(String gworkflowdl, String userID) throws WorkflowFormatException, StateTransitionException, RemoteException {
215         // ToDo: throw WorkflowFormatException
216         // ToDo: throw StateTransitionException
217         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
218         urlBuf.append(METHOD_INITIATE);
219         StringBuffer payload = new StringBuffer();
220         // <initiate xmlns="http://gwes.kwfgrid.net">
221         payload.append(STRING_L).append(METHOD_INITIATE).append(ATTRIBUTE_NS).append(STRING_G);
222         StringUtils.addXmlToStringBuffer(payload,ELEMENT_WORKFLOWDESCRIPTION, HTMLFilter.filter(gworkflowdl));
223         StringUtils.addXmlToStringBuffer(payload,ELEMENT_USERID, HTMLFilter.filter(userID));
224         // </initiate>
225         payload.append(STRING_LSLASH).append(METHOD_INITIATE).append(STRING_G);
226         // PUT
227         String[] ret = httpPUT(urlBuf.toString(), payload.toString());
228         if (ret != null && ret.length > 0) {
229             return ret[0];
230         } else {
231             throw new RemoteException("GWES did not return a workflowID for HTTP PUT "+urlBuf.toString());
232         }
233     }
234 
235     public void start(String workflowID, String userID) throws NoSuchWorkflowException, StateTransitionException, RemoteException {
236         // ToDo: throw StateTransitionException
237         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
238         urlBuf.append(METHOD_START).append(PARAM_WORKFLOWID).append(workflowID);
239         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
240         localExceptionHttpGET(workflowID,urlBuf);
241     }
242 
243     public void suspend(String workflowID, String userID) throws NoSuchWorkflowException, StateTransitionException, RemoteException {
244         // ToDo: throw StateTransitionException
245         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
246         urlBuf.append(METHOD_SUSPEND).append(PARAM_WORKFLOWID).append(workflowID);
247         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
248         localExceptionHttpGET(workflowID,urlBuf);
249     }
250 
251     public void resume(String workflowID, String userID) throws NoSuchWorkflowException, StateTransitionException, RemoteException {
252         // ToDo: throw StateTransitionException
253         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
254         urlBuf.append(METHOD_RESUME).append(PARAM_WORKFLOWID).append(workflowID);
255         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
256         localExceptionHttpGET(workflowID,urlBuf);
257     }
258 
259     public void abort(String workflowID, String userID) throws NoSuchWorkflowException, StateTransitionException, RemoteException {
260         // ToDo: throw StateTransitionException
261         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
262         urlBuf.append(METHOD_ABORT).append(PARAM_WORKFLOWID).append(workflowID);
263         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
264         localExceptionHttpGET(workflowID,urlBuf);
265     }
266 
267     public String restart(String workflowID, String userID) throws NoSuchWorkflowException, WorkflowFormatException, DatabaseException, StateTransitionException, RemoteException {
268         // ToDo: throw StateTransitionException
269         /// ToDo: throw WorkflowFormatException
270         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
271         urlBuf.append(METHOD_RESTART);
272         StringBuffer payload = new StringBuffer();
273         // <restart xmlns="http://gwes.kwfgrid.net">
274         payload.append(STRING_L).append(METHOD_RESTART).append(ATTRIBUTE_NS).append(STRING_G);
275         StringUtils.addXmlToStringBuffer(payload,ELEMENT_WORKFLOWID, workflowID);
276         StringUtils.addXmlToStringBuffer(payload,ELEMENT_USERID, HTMLFilter.filter(userID));
277         // </restart>
278         payload.append(STRING_LSLASH).append(METHOD_RESTART).append(STRING_G);
279 
280         // PUT
281         String[] ret = localExceptionHttpPUT(workflowID, urlBuf, payload);
282         if (ret != null && ret.length > 0) {
283             return ret[0];
284         } else {
285             throw new RemoteException("GWES did not return a result for HTTP PUT "+urlBuf.toString());
286         }
287     }
288 
289     public String getWorkflowDescription(String workflowID, String userID) throws NoSuchWorkflowException, RemoteException, DatabaseException {
290         // ToDo: throw DatabaseException
291         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
292         urlBuf.append(METHOD_GETWORKFLOWDESCRIPTION).append(PARAM_WORKFLOWID).append(workflowID);
293         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
294         // GET
295         String[] ret;
296         ret = localExceptionHttpGET(workflowID, urlBuf);
297 
298         if (ret != null && ret.length > 0) {
299             return ret[0];
300         } else {
301             throw new RemoteException("GWES did not return a result for HTTP GET "+urlBuf.toString());
302         }
303     }
304 
305     public void setWorkflowDescription(String workflowID, String gworkflowdl, String userID) throws NoSuchWorkflowException, StateTransitionException, WorkflowFormatException, RemoteException {
306         // ToDo: throw StateTransitionException
307         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
308         urlBuf.append(METHOD_SETWORKFLOWDESCRIPTION);
309         StringBuffer payload = new StringBuffer();
310         // <setWorkflowDescription xmlns="http://gwes.kwfgrid.net">
311         payload.append(STRING_L).append(METHOD_SETWORKFLOWDESCRIPTION).append(ATTRIBUTE_NS).append(STRING_G);
312         StringUtils.addXmlToStringBuffer(payload,ELEMENT_WORKFLOWID, workflowID);
313         StringUtils.addXmlToStringBuffer(payload,ELEMENT_WORKFLOWDESCRIPTION, HTMLFilter.filter(gworkflowdl));
314         StringUtils.addXmlToStringBuffer(payload,ELEMENT_USERID, HTMLFilter.filter(userID));
315         // </setWorkflowDescription>
316         payload.append(STRING_LSLASH).append(METHOD_SETWORKFLOWDESCRIPTION).append(STRING_G);
317         localExceptionHttpPUT(workflowID, urlBuf, payload);
318     }
319 
320     public int getStatus(String workflowID, String userID) throws NoSuchWorkflowException, RemoteException, DatabaseException {
321         // ToDo: throw DatabaseException
322         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
323         urlBuf.append(METHOD_GETSTATUS).append(PARAM_WORKFLOWID).append(workflowID);
324         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
325         // GET
326         String[] ret = localExceptionHttpGET(workflowID,urlBuf);
327         if (ret != null && ret.length > 0) {
328             return Integer.parseInt(ret[0]);
329         } else {
330             throw new RemoteException("GWES did not return a result for HTTP GET "+urlBuf.toString());
331         }
332     }
333 
334     public int waitForStatusChangeFrom(String workflowID, int oldStatus, String userID) throws NoSuchWorkflowException, RemoteException, InterruptedException {
335         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
336         urlBuf.append(METHOD_WAITFORSTATUSCHANGEFROM);
337         urlBuf.append(PARAM_WORKFLOWID).append(workflowID);
338         urlBuf.append(_PARAM_OLDSTATUS).append(oldStatus);
339         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
340         // GET
341         String[] ret = localExceptionHttpGET(workflowID,urlBuf);
342         if (ret != null && ret.length > 0) {
343             return Integer.parseInt(ret[0]);
344         } else {
345             throw new RemoteException("GWES did not return a result for HTTP GET "+urlBuf.toString());
346         }
347     }
348 
349     public int waitForStatusChangeToCompletedOrTerminated(String workflowID, String userID) throws NoSuchWorkflowException, RemoteException, InterruptedException {
350         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
351         urlBuf.append(METHOD_WAITFORSTATUSCHANGETOCOMPLETEDORTERMINATED);
352         urlBuf.append(PARAM_WORKFLOWID).append(workflowID);
353         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
354         // GET
355         String[] ret = localExceptionHttpGET(workflowID,urlBuf);
356         if (ret != null && ret.length > 0) {
357             return Integer.parseInt(ret[0]);
358         } else {
359             throw new RemoteException("GWES did not return a result for HTTP GET "+urlBuf.toString());
360         }
361     }
362 
363     public String[] getWorkflowIDs(int level, String userID) throws DatabaseException, RemoteException {
364         /// ToDo: throw DatabaseException
365         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
366         urlBuf.append(METHOD_GETWORKFLOWIDS).append(PARAM_LEVEL).append(level);
367         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
368         // GET
369         return httpGET(urlBuf.toString());
370     }
371 
372     public String[][] getWorkflowStatusArray(int level, String userID) throws DatabaseException, RemoteException {
373         /// ToDo: throw DatabaseException
374         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
375         urlBuf.append(METHOD_GETWORKFLOWSTATUSARRAY).append(PARAM_LEVEL).append(level);
376         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
377         // GET
378         return httpGETArray(urlBuf.toString());
379     }
380 
381     public String store(String workflowID, String userID) throws NoSuchWorkflowException, DatabaseException, RemoteException {
382         /// ToDo: throw DatabaseException
383         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
384         urlBuf.append(METHOD_STORE).append(PARAM_WORKFLOWID).append(workflowID);
385         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
386         // GET
387         String[] ret = localExceptionHttpGET(workflowID,urlBuf);
388         if (ret != null && ret.length > 0) {
389             return ret[0];
390         } else {
391             throw new RemoteException("GWES did not return a result for HTTP GET "+urlBuf.toString());
392         }
393     }
394 
395     public String restore(String workflowID, String userID) throws NoSuchWorkflowException, WorkflowFormatException, DatabaseException, StateTransitionException, RemoteException {
396         /// ToDo: throw WorkflowFormatException
397         /// ToDo: throw DatabaseException
398         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
399         urlBuf.append(METHOD_RESTORE);
400         StringBuffer payload = new StringBuffer();
401         // <restore xmlns="http://gwes.kwfgrid.net">
402         payload.append(STRING_L).append(METHOD_RESTORE).append(ATTRIBUTE_NS).append(STRING_G);
403         StringUtils.addXmlToStringBuffer(payload,ELEMENT_WORKFLOWID, workflowID);
404         StringUtils.addXmlToStringBuffer(payload,ELEMENT_USERID, HTMLFilter.filter(userID));
405         // </restore>
406         payload.append(STRING_LSLASH).append(METHOD_RESTORE).append(STRING_G);
407         // PUT
408         String[] ret = localExceptionHttpPUT(workflowID, urlBuf, payload);
409         if (ret != null && ret.length > 0) {
410             return ret[0];
411         } else {
412             throw new RemoteException("GWES did not return a result for HTTP PUT "+urlBuf.toString());
413         }
414     }
415 
416     public String[] getData(String workflowID, String placeID, String userID) throws NoSuchWorkflowException, RemoteException, DatabaseException {
417         /// ToDo: throw DatabaseException
418         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
419         urlBuf.append(METHOD_GETDATA);
420         urlBuf.append(PARAM_WORKFLOWID).append(workflowID);
421         urlBuf.append(_PARAM_PLACEID).append(placeID);
422         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
423         // GET
424         return localExceptionHttpGET(workflowID,urlBuf);
425     }
426 
427     public void setDescription(String workflowID, String description, String userID) throws NoSuchWorkflowException, RemoteException, DatabaseException {
428         /// ToDo: throw DatabaseException
429         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
430         urlBuf.append(METHOD_SETDESCRIPTION);
431         StringBuffer payload = new StringBuffer();
432         // <setDescription xmlns="http://gwes.kwfgrid.net">
433         payload.append(STRING_L).append(METHOD_SETDESCRIPTION).append(ATTRIBUTE_NS).append(STRING_G);
434         StringUtils.addXmlToStringBuffer(payload,ELEMENT_WORKFLOWID, workflowID);
435         StringUtils.addXmlToStringBuffer(payload,ELEMENT_DESCRIPTION, HTMLFilter.filter(description));
436         StringUtils.addXmlToStringBuffer(payload,ELEMENT_USERID, HTMLFilter.filter(userID));
437         // </setDescription>
438         payload.append(STRING_LSLASH).append(METHOD_SETDESCRIPTION).append(STRING_G);
439         // PUT
440         localExceptionHttpPUT(workflowID, urlBuf, payload);
441     }
442 
443     public String getDescription(String workflowID, String userID) throws NoSuchWorkflowException, RemoteException, DatabaseException {
444         /// ToDo: throw DatabaseException
445         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
446         urlBuf.append(METHOD_GETDESCRIPTION);
447         urlBuf.append(PARAM_WORKFLOWID).append(workflowID);
448         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
449         // GET
450         String[] ret = localExceptionHttpGET(workflowID, urlBuf);
451         if (ret != null && ret.length > 0) {
452             return ret[0];
453         } else {
454             throw new RemoteException("GWES did not return a result for HTTP GET "+urlBuf.toString());
455         }
456     }
457 
458     public void setProperty(String workflowID, String name, String value, String userID) throws NoSuchWorkflowException, RemoteException, DatabaseException {
459         /// ToDo: throw DatabaseException
460         // PUT
461         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
462         urlBuf.append(METHOD_SETPROPERTY);
463         StringBuffer payload = new StringBuffer();
464         // <setProperty xmlns="http://gwes.kwfgrid.net">
465         payload.append(STRING_L).append(METHOD_SETPROPERTY).append(ATTRIBUTE_NS).append(STRING_G);
466         StringUtils.addXmlToStringBuffer(payload,ELEMENT_WORKFLOWID, workflowID);
467         StringUtils.addXmlToStringBuffer(payload,ELEMENT_NAME, HTMLFilter.filter(name));
468         StringUtils.addXmlToStringBuffer(payload,ELEMENT_VALUE, HTMLFilter.filter(value));
469         StringUtils.addXmlToStringBuffer(payload,ELEMENT_USERID, HTMLFilter.filter(userID));
470         // </setProperty>
471         payload.append(STRING_LSLASH).append(METHOD_SETPROPERTY).append(STRING_G);
472         localExceptionHttpPUT(workflowID, urlBuf, payload);
473     }
474 
475     public String getProperty(String workflowID, String name, String userID) throws NoSuchWorkflowException, RemoteException, DatabaseException {
476         /// ToDo: throw DatabaseException
477         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
478         urlBuf.append(METHOD_GETPROPERTY);
479         urlBuf.append(PARAM_WORKFLOWID).append(workflowID);
480         urlBuf.append(_PARAM_NAME).append(name);
481         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
482         // GET
483         String[] ret = localExceptionHttpGET(workflowID, urlBuf);
484         if (ret != null && ret.length > 0) {
485             return ret[0];
486         } else {
487             throw new RemoteException("GWES did not return a result for HTTP GET "+urlBuf.toString());
488         }
489     }
490 
491     public String[][] getProperties(String workflowID, String userID) throws NoSuchWorkflowException, RemoteException, DatabaseException {
492         /// ToDo: throw DatabaseException
493         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
494         urlBuf.append(METHOD_GETPROPERTIES);
495         urlBuf.append(PARAM_WORKFLOWID).append(workflowID);
496         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
497         // GET
498         return localExceptionHttpGETArray(workflowID, urlBuf);
499     }
500 
501     public String[] getCheckpoints(String workflowID, String userID) throws NoSuchWorkflowException, RemoteException, DatabaseException {
502         /// ToDo: throw DatabaseException
503         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
504         urlBuf.append(METHOD_GETCHECKPOINTS);
505         urlBuf.append(PARAM_WORKFLOWID).append(workflowID);
506         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
507         // GET
508         return localExceptionHttpGET(workflowID, urlBuf);
509     }
510 
511     public void remove(String workflowID, int level, String userID) throws NoSuchWorkflowException, DatabaseException, RemoteException {
512         /// ToDo: throw DatabaseException
513         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
514         urlBuf.append(METHOD_REMOVE);
515         urlBuf.append(PARAM_WORKFLOWID).append(workflowID);
516         urlBuf.append(_PARAM_LEVEL).append(level);
517         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
518         // DELETE
519         localExceptionHttpDELETE(workflowID, urlBuf);
520     }
521 
522     public String[][] getActivityStatusArray(String workflowID, String userID) throws NoSuchWorkflowException, RemoteException {
523         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
524         urlBuf.append(METHOD_GETACTIVITYSTATUSARRAY).append(PARAM_WORKFLOWID).append(workflowID);
525         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
526         // GET
527         return localExceptionHttpGETArray(workflowID, urlBuf);
528     }
529 
530     public String[] getAvailableResources(String ofClass, String userID) throws DatabaseException, RemoteException {
531         /// ToDo: throw DatabaseException
532         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
533         urlBuf.append(METHOD_GETAVAILABLERESOURCES);
534         urlBuf.append(PARAM_OFCLASS).append(ofClass);
535         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
536         // GET
537         return httpGET(urlBuf.toString());
538     }
539 
540     public String getResourceDescription(String resourceUri, String userID) throws DatabaseException, RemoteException {
541         /// ToDo: throw DatabaseException
542         StringBuffer urlBuf = new StringBuffer(gwesServiceUrl);
543         urlBuf.append(METHOD_GETRESOURCEDESCRIPTION_);
544         urlBuf.append(PARAM_RESOURCEURI).append(HTMLFilter.filter(resourceUri));
545         urlBuf.append(_PARAM_USERID).append(HTMLFilter.filter(userID));
546         // GET
547         String[] ret = httpGET(urlBuf.toString());
548         if (ret != null && ret.length > 0) {
549             return ret[0];
550         } else {
551             throw new RemoteException("GWES did not return a result for HTTP GET "+urlBuf.toString());
552         }
553     }
554 }