0
|
1 '''
|
|
2 @author Chaitanya Guttula, Sumedha Ganjoo
|
|
3 @see LICENSE (MIT style license file).
|
|
4 '''
|
|
5
|
|
6 import warnings
|
|
7 with warnings.catch_warnings():
|
|
8 warnings.simplefilter("ignore")
|
|
9 import sys
|
|
10 import os
|
|
11 import urllib
|
|
12
|
|
13 """
|
|
14
|
|
15 This script takes the values of the input parameters of the
|
|
16 web service from the user and invokes the web service.
|
|
17 The URL to the WSDL is the command line argument
|
|
18
|
|
19 """
|
|
20 servicetype = sys.argv[2]
|
|
21 if servicetype=='SOAP':
|
|
22 with warnings.catch_warnings():
|
|
23 warnings.simplefilter("ignore")
|
|
24 galaxyhome=os.environ.get('GALAXY_HOME')
|
|
25 sys.path.append(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator/')
|
|
26 os.chdir(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator/')
|
|
27 from creatorEngineComplex import *
|
|
28 from wsdl2path import *
|
|
29 from paramConverter import *
|
|
30 from ZSI.writer import SoapWriter
|
|
31 from msHandler import *
|
|
32
|
|
33 webservice = str(sys.argv[3])
|
|
34 operation = str(sys.argv[4])
|
|
35 resultfile=open(sys.argv[1],'w')
|
|
36 length=len(sys.argv)
|
|
37 inputdict={}
|
|
38 i=5
|
|
39 test=ClientCreator()
|
|
40 while(i>=5 and i<(length-1)):
|
|
41 key=sys.argv[i]
|
|
42 print 'key is : ',key
|
|
43 #if(sys.argv[i+1]=='ZSI.TC.String'):
|
|
44 val=sys.argv[i+1]
|
|
45 while(val.find('__at__')>-1):
|
|
46 vlist = val.split('__at__')
|
|
47 val = '@'.join(vlist)
|
|
48 while(val.find('__sq__')>-1):
|
|
49 vlist = val.split('__sq__')
|
|
50 val = ''.join(vlist)
|
|
51 while(val.find('__gt__')>-1):
|
|
52 vlist = val.split('__gt__')
|
|
53 val = '>'.join(vlist)
|
|
54 while(val.find('***')>-1):
|
|
55 vlist = val.split('***')
|
|
56 val = '\n'.join(vlist)
|
|
57 while(val.find('**')>-1):
|
|
58 vlist = val.split('**')
|
|
59 val = ' '.join(vlist)
|
|
60 #if(val.find(',')>-1):
|
|
61 # print 'found ,'
|
|
62 # vlist = val.split(',')
|
|
63 # val = '\',\''.join(vlist)
|
|
64
|
|
65
|
|
66 #if(val.find('__sq__')>-1):
|
|
67 # j=i+4
|
|
68 # val=val.lstrip('__sq__')
|
|
69 # while(str(sys.argv[j]).find('__sq__')==-1):
|
|
70 # val=val+' '+sys.argv[j]
|
|
71 # j=j+1
|
|
72 #val=val+' '+(str(sys.argv[j]).rstrip('__sq__'))
|
|
73 #i=j-3
|
|
74
|
|
75 #elif((sys.argv[i+1]=='ZSI.TC.Integer')or (sys.argv[i+1]=='ZSI.TCnumbers.Iint')):
|
|
76 # val=int(sys.argv[i+1])
|
|
77 #elif(sys.argv[i+1]=='ZSI.TC.Decimal'):
|
|
78 # val=float(sys.argv[i+1])
|
|
79 #elif(sys.argv[i+2]=='Yes'):
|
|
80 # valFile=open(sys.argv[i+3],'r')
|
|
81 # val=valFile.read()
|
|
82 #else:
|
|
83 # val=sys.argv[i+1]
|
|
84 if(val != "0"):
|
|
85 inputdict[key]= val
|
|
86 #resultfile.write('value is :'+ val+'\n')
|
|
87
|
|
88 i=i+2
|
|
89 if len(inputdict) == 0:
|
|
90 inputdic = {}
|
|
91 else:
|
|
92 inputdic = flat2nestedDict(inputdict)
|
|
93 print 'The operation is : ',operation #added
|
|
94 result=test.invokeOp(operation,webservice,inputdic)
|
|
95
|
|
96 mshandler = MessageHandler()
|
|
97 resultDict={}
|
|
98 resultDict=mshandler.flatten(result) #mshandler.msParser(responseInstance)
|
|
99 flat = nested2flatDict(resultDict)
|
|
100
|
|
101 result=flat
|
|
102
|
|
103
|
|
104 #resultfile.write(result)
|
|
105
|
|
106 # Writing the output to the o/p file when the result is parsed
|
|
107 #keys = result.keys()
|
|
108
|
|
109 #for key in keys:
|
|
110 # resultfile.write(str(key)+'\t')
|
|
111
|
|
112 #resultfile.write('\n')
|
|
113
|
|
114 #for key in keys:
|
|
115 # if type(result[key])==list:
|
|
116 # for i in result[r]:
|
|
117 # resultfile.write(str(i)+'\t')
|
|
118 # print str(i)
|
|
119 # else:
|
|
120 # resultfile.write(str(result[key])+'\t')
|
|
121 for r in result:
|
|
122 if type(result[r])==list:
|
|
123 for i in result[r]:
|
|
124 resultfile.write(str(i)+'\n')
|
|
125 print str(i)
|
|
126 else:
|
|
127 resultfile.write(str(result[r])+'\n')
|
|
128
|
|
129 #Writes the result without parsinf in the XML format it gets.
|
|
130 #sw = SoapWriter(header=False, envelope=False);
|
|
131 #res = test.opname2outputClassOb(operation,webservice)
|
|
132 #res_tc = getattr(res,'typecode')
|
|
133 #ofwhat = res_tc.ofwhat;
|
|
134 #for tc in ofwhat :
|
|
135 # sw.serialize(getattr(result, tc.aname), tc);
|
|
136 # doc = sw.dom.getDocument();
|
|
137 # fp = open(sys.argv[1], 'w');
|
|
138 # try :
|
|
139 # doc.writexml(fp, '\t', '', '\n');
|
|
140 # finally :
|
|
141 # fp.close();
|
|
142
|
|
143
|
|
144 elif servicetype == 'REST':
|
|
145 resUrl = sys.argv[3]
|
|
146
|
|
147 outputFile = open(sys.argv[1],'w')
|
|
148 if(resUrl.find('__tilda__')>-1):
|
|
149 ulist = resUrl.split('__tilda__')
|
|
150 resUrl = '~'.join(ulist)
|
|
151
|
|
152 paramdict={}
|
|
153 length=(len(sys.argv))
|
|
154
|
|
155 print 'in rest',sys.argv
|
|
156 #print s
|
|
157 i=4
|
|
158 print i
|
|
159
|
|
160 while( i>=4 and i<(length-1)):
|
|
161
|
|
162 key=sys.argv[i]
|
|
163 val=sys.argv[i+1]
|
|
164 print 'key : ',key
|
|
165 print 'value : ',val
|
|
166 while(val.find('**')>-1):
|
|
167 vlist = val.split('**')
|
|
168 print '---->',val
|
|
169 val = ' '.join(vlist)
|
|
170 print 'v : ',val
|
|
171 paramdict[key]=val
|
|
172 i=i+2
|
|
173
|
|
174 print paramdict
|
|
175
|
|
176 params = urllib.urlencode(paramdict)
|
|
177 data = urllib.urlopen(resUrl, params).read()
|
|
178 outputFile.write(data)
|
|
179
|
|
180 #
|
|
181 #if __name__ == "__main__":
|
|
182 # main();
|
|
183
|