comparison WebServiceExtensionsV1.1/WebServiceToolWorkflow_REST_SOAP/WebServiceTool_input_method_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 import warnings
7 with warnings.catch_warnings():
8 warnings.simplefilter("ignore")
9 import warnings
10 import urllib2
11 import platform
12 import os,sys
13 from clientGenerator.creatorEngineComplex import *
14 from clientGenerator.wsdl2path import *
15 from clientGenerator.paramConverter import *
16 from generateClient import *
17 from generateClient1 import *
18
19 '''input : wadl/wsdl/sawadl-url, method name
20 purpose:
21 1. Calls methods from generateClient1.py to generate client description for one-time invocation
22 of the Web service. This client description is added as a xml file under ./clients/
23 2. Calls methods from generateClient.py to generate client description for invocation of Web service
24 in a workflow. This client description is added as a xml file under ./workflowclients/
25 3. Adds the path to the above xml files to Galaxy tool-conf.xml file using call edit_tool_conf.py
26 '''
27
28 servicetype=''
29
30 #read the url passed as an argument
31 url = sys.argv[2]
32 while(url.find('__tilda__')>-1):
33 ulist = url.split('__tilda__')
34 url = '~'.join(ulist)
35
36 #split url passed on '.' character
37 urllist = url.split('/')
38 wsdlname = urllist[len(urllist)-1].split(".")
39 if len(wsdlname)==1:
40 wsdlname =urllist[len(urllist)-1].split('?')
41
42 '''#checks the description document (WSDL/WADL) is for SOAP 1.1 or SOAP 2.0 or REST
43 If the extesnion is wsdl then servicetype is SOAP else If the extension is wadl then servicetype is REST
44 in other conditions(i.e. the file has no extension)
45 '''
46 #u = None
47 #try:
48 # u = urllib2.urlopen(url)
49 #except urllib2.HTTPError, e:
50 # print e.code
51 # print e.msg
52 # print e.headers
53 # print e.fp.read()
54 print 'the url is : ',sys.argv[2]
55 u = urllib2.urlopen(url)
56 descfile = open('temp','w')
57 descfile.write(u.read())
58 descfile.close()
59 readwsdl = open('temp','r')
60 tempstring = 'start'
61
62 #checks the description document (WSDL/WADL) is for SOAP 1.1 or SOAP 2.0 or REST
63 while (tempstring != ''):
64 tempstring = readwsdl.readline()
65 if tempstring.find('<definitions') != -1 or tempstring.find('<wsdl:definitions') != -1:
66 print 'WSDL 1.1 or 1.0'
67 servicetype = 'SOAP'
68 break
69 elif tempstring.find('description') != -1:
70 while tempstring != '':
71 if tempstring.find('<bindings ') != -1:
72 bind = tempstring.split('type')
73 bindLength = len(bind)
74 bindingtype = bind[bindLength-1]
75 print bindingtype
76 break
77 tempstring = readwsdl.readline()
78 if bindingtype.find('http://www.w3.org/ns/wsdl/soap') != -1:
79 servicetype='WSDL2SOAP'
80 print 'SOAP'
81 else:
82 servicetype='WSDL2REST'
83 break
84 elif tempstring.find('<application') != -1:
85 servicetype='REST'
86 break
87
88 readwsdl.close()
89 operations = sys.argv[3].split(',')
90
91 # The webservice is a soap webservice
92 if servicetype == 'SOAP':
93
94 #Create client tool for using web services in workflow
95 for operation in operations:
96 if operation != '':
97 clientGenerator = ClientGenerator(url,operation,sys.argv[4],'SOAP')#webservice,operation,inputl)
98 if clientGenerator.isToolPresent():
99 f = open(sys.argv[4],'a')
100 f.write('The web service workflow tool for service '+url+' and operation '+operation+' was already added to galaxy\n')
101 else:
102 clientGenerator.wsdlClient()
103
104
105 #Create cleint tool for invoking web service stand alone
106 clientGenerator1 = ClientGenerator1(url,operation,sys.argv[4],'SOAP')#webservice,operation,inputl)
107 if clientGenerator1.isToolPresent():
108 f = open(sys.argv[4],'a')
109 f.write('The web service tool for service '+url+' and operation '+operation+' was already added to galaxy\n')
110 else:
111 clientGenerator1.wsdlClient()
112
113
114
115 #Web service is a REST Webservice
116 elif servicetype == 'REST':
117
118 javahome = os.environ.get('JAVA_HOME')
119 galaxyhome=os.environ.get('GALAXY_HOME')
120 classpath= galaxyhome + '/tools/WebServiceToolWorkflow_REST_SOAP/ParserForWADL/bin'
121 jarpath = galaxyhome + '/tools/WebServiceToolWorkflow_REST_SOAP/ParserForWADL/lib/'
122 machine = platform.machine()
123
124 if machine == 'x86_64' :
125 print 'a'
126 startJVM("%s/jre/lib/amd64/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
127 elif machine == 'i686' :
128 startJVM("%s/jre/lib/i386/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
129 print 'b'
130 elif machine == 'sun4u' :
131 startJVM("%s/jre/lib/sparc/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
132 else :
133 print 'c'
134 System.exit("Could not identify machine, please specify path to libjvm.so")
135
136
137
138 for operation in operations:
139 if(operation != ''):
140 clientGenerator = ClientGenerator(url,operation,sys.argv[4],'REST')
141 clientGenerator1 = ClientGenerator1(url,operation,sys.argv[4],'REST')
142 if clientGenerator.isToolPresent():
143 f = open(sys.argv[4],'a')
144 f.write('\nThe web service workflow tool for service '+url+' and operation '+operation+' was already added to galaxy\n')
145 else:
146 clientGenerator.wadlClient()
147 if clientGenerator1.isToolPresent():
148 f = open(sys.argv[4],'a')
149 f.write('\nThe web service tool for service '+url+' and operation '+operation+' was already added to galaxy\n')
150 else:
151 clientGenerator1.wadlClient()
152
153
154 #shutdownJVM()
155