comparison WebServiceExtensionsV1.1/WebServiceToolWorkflow_REST_SOAP/getMethods_m.py @ 0:049760c677de default tip

Galaxy WSExtensions added successfully
author uga-galaxy-group
date Tue, 05 Jul 2011 19:34:18 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:049760c677de
1 '''
2 @author Chaitanya Guttula
3 @see LICENSE (MIT style license file).
4 '''
5
6
7 # Author = Chaitanya Guttula
8
9 import warnings
10
11 with warnings.catch_warnings():
12 warnings.simplefilter("ignore")
13
14 import platform
15 import commands
16 import ZSI
17 import os
18 from clientGenerator.creatorEngineComplex import *
19 from clientGenerator.wsdl2path import *
20 from jpype._jpackage import JPackage
21 from jpype import *
22 import sys
23
24 class Document(object):
25
26 '''
27 Method to get all the operations from the WSDL file and write it to Galaxy output datasets
28 '''
29
30 def getWSDLMethods(self, url , outputFileUrl):
31 wLoad=wsdlLoader()
32 a= str(url).split('/')
33 wsdlnamelist = a[len(a)-1].split(".")
34 if len(wsdlnamelist)==1:
35 wsdlnamelist=a[len(a)-1].split('?')
36 print wsdlnamelist
37
38 foldername=wsdlnamelist[0]
39
40 galaxyhome=os.environ.get('GALAXY_HOME')
41 path =galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator/'+foldername
42 os.chdir(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator/')
43
44 #creates the client stubs
45 clientfile=wLoad.wsdlUrl2path(str(url),foldername)
46
47 #Gets the list of operations
48 test=ClientCreator()
49 operations=test.path2Ops(str(clientfile)).keys()
50
51 #COnvert ~ to __tilda__
52 if(url.find('~')>-1):
53 ulist = url.split('~')
54 url = '__tilda__'.join(ulist)
55
56
57 #Print all the operations and web service info to the Galaxy output dataset
58 outputfile=open(outputFileUrl,'w')
59 count=0
60 outputfile.seek(0,0)
61 for k in operations:
62 count=count+1
63 if(count==1):
64 outputfile.write(k+'\t'+clientfile+'\t'+url+'\n')
65 else:
66 outputfile.write(k+'\n')
67
68 #invoked to get REST methods described in a WSDL 2.0 document. Steps are similar to getWADLMethods except the library to parse WSDL 2.0 is used.
69 def getWSDLRESTMethods(self, wsdlUrl, outputFileUrl ):
70 javahome = os.environ.get('JAVA_HOME')
71 galaxyhome=os.environ.get('GALAXY_HOME')
72 classpath= galaxyhome + '/tools/WebServiceToolWorkflow_REST_SOAP/WodenWSDLParser/bin'
73 jarpath = galaxyhome + '/tools/WebServiceToolWorkflow_REST_SOAP/WodenWSDLParser/lib/'
74 machine = platform.machine()
75
76 #start JVM depending on the machine. The location of libjvm.so is assumed to be standard.
77 #you can replace lines 81 to 88, with startJVM("LOCATION OF YOUR LIBJVM.SO","-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
78 if machine == 'x86_64' :
79 startJVM("%s/jre/lib/amd64/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
80 elif machine == 'i686' :
81 startJVM("%s/jre/lib/i386/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
82 elif machine == 'sun4u' :
83 startJVM("%s/jre/lib/sparc/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
84 else :
85 System.exit("Could not identify machine, please specify path to libjvm.so")
86
87 pkg=JPackage('lsdis')
88
89 outputfile=open(outputFileUrl,'w')
90 outputfile.seek(0,0)
91 length=(len(sys.argv))
92
93 urls = []
94 methods = []
95
96 if(wsdlUrl.find('__tilda__')>-1):
97 ulist = wsdlUrl.split('__tilda__')
98 urlToPass = '~'.join(ulist)
99
100 WSDLParserDriver=pkg.WSDLParserDriver
101 wPD=WSDLParserDriver()
102 wPD.parse(urlToPass)
103 urls = wPD.getUrl()
104 methods = wPD.getCompleteMethodList()
105
106 i=0
107 for url in urls:
108 outputfile.write(wsdlUrl+"\t")
109 outputfile.write(str(methods[i].getName().getLocalPart())+"\t")
110 outputfile.write(str(url)+"\n")
111 i=i+1
112
113
114
115 '''
116 Invoked to get methods described in a WADL document
117 '''
118 def getWADLMethods(self, wadlUrl, outputFileUrl ):
119
120 #get environment variables JAVA_HOME and GALAXY_HOME
121 javahome = os.environ.get('JAVA_HOME')
122 galaxyhome=os.environ.get('GALAXY_HOME')
123
124 #classpath, jarpath are variables pointing to the java libraries required to parse a WADL document
125 classpath= galaxyhome + '/tools/WebServiceToolWorkflow_REST_SOAP/ParserForWADL/bin'
126 jarpath = galaxyhome + '/tools/WebServiceToolWorkflow_REST_SOAP/ParserForWADL/lib/'
127
128 #start JVM depending on the machine. The location of libjvm.so is assumed to be standard.
129 #you can replace lines 28 to 35, with startJVM("LOCATION OF YOUR LIBJVM.SO","-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
130 machine = platform.machine()
131 if machine == 'x86_64' :
132 startJVM("%s/jre/lib/amd64/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
133 elif machine == 'i686' :
134 startJVM("%s/jre/lib/i386/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
135 elif machine == 'sun4u' :
136 startJVM("%s/jre/lib/sparc/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
137 else :
138 System.exit("Could not identify machine, please specify path to libjvm.so")
139
140 #tell JPYPE that the package name is lsdis
141 pkg=JPackage('lsdis')
142
143 urlToPass=java.net.URL(wadlUrl)
144
145 #convert __tilda__ to ~
146 if(wadlUrl.find('__tilda__')>-1):
147 ulist = wadlUrl.split('__tilda__')
148 urlToPass = java.net.URL('~'.join(ulist))
149
150
151 outputfile=open(outputFileUrl,'w')
152 outputfile.seek(0,0)
153
154 urls = []
155 methods = []
156
157 #using JPYPE call appropriate Java classes and methods to parse the WADL document and get a list of methods defined in it
158 WADLParserDriver=pkg.WADLParserDriver
159 wPD=WADLParserDriver()
160 wPD.parse(urlToPass)
161 urls = wPD.getUrl()
162 methods = wPD.getCompleteMethodList()
163
164 #write the url of the WADL and the list of methods to the output in a tabular format, for the Step 2 tool to read from.
165 i=0
166 for url in urls:
167 outputfile.write(str(url)+"\t")
168 outputfile.write(str(methods[i].getId())+"\t")
169 outputfile.write(wadlUrl+"\n")
170 i=i+1
171
172
173
174 # invoked to get methods described in a SAWADL document
175 def getSAWADLMethods(self, sawadlUrl, outputFileUrl ):
176 javahome = os.environ.get('JAVA_HOME')
177 galaxyhome=os.environ.get('GALAXY_HOME')
178 classpath= galaxyhome + '/tools/restclientSAWADL/lib/SAWADLParser/bin'
179 machine = platform.machine()
180
181 #start JVM depending on the machine. The location of libjvm.so is assumed to be standard.
182 #you can replace lines 126 to 133, with startJVM("LOCATION OF YOUR LIBJVM.SO","-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
183 if machine == 'x86_64' :
184 startJVM("%s/jre/lib/amd64/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath)
185 elif machine == 'i686' :
186 startJVM("%s/jre/lib/i386/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath)
187 elif machine == 'sun4u' :
188 startJVM("%s/jre/lib/sparc/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath)
189 else :
190 System.exit("Could not identify machine, please specify path to libjvm.so")
191
192 pkg=JPackage('edu.uga.cs.lsdis.meteors.wadls')
193
194
195 # Open the output file for galaxy
196 outputfile=open(outputFileUrl,'w')
197 outputfile.seek(0,0)
198
199 if(sawadlUrl.find('__tilda__')>-1):
200 ulist = sawadlUrl.split('__tilda__')
201 urlToPass = '~'.join(ulist)
202
203 urls = []
204 methods = []
205
206 #invoke the parser and get the method list
207 SAWADLParserDriver=pkg.SAWADLParserDriver
208 sawPD=SAWADLParserDriver()
209 sawPD.parse(urlToPass)
210 urls = sawPD.getUrl()
211 methods = sawPD.getCompleteMethodList()
212
213 #Print the methods and service information to the
214 i=0
215 for url in urls:
216 outputfile.write(sawadlUrl+"\t")
217 outputfile.write(str(methods[i].getName())+"\t")
218 outputfile.write(str(url)+"\n")
219 i=i+1
220