3 # Sapan Bhatia <sapanb@cs.princeton.edu>
5 # Generates a WSDL for geniwrapper
7 # - Invalid for the following reasons
8 # - The types are python types, not WSDL types
13 import xml.dom.minidom
18 from geni.util.auth import Auth
19 from geni.util.parameter import Parameter,Mixed,python_type,xmlrpc_type
30 def param_type(param):
32 # if isinstance(param, Mixed) and len(param):
33 # subtypes = [param_type(subparam) for subparam in param]
34 # return " or ".join(subtypes)
35 # elif isinstance(param, (list, tuple, set)) and len(param):
36 # return "array of " + " or ".join([param_type(subparam) for subparam in param])
38 # return xmlrpc_type(python_type(param))
39 return "some type - todo"
42 def add_wsdl_ports_and_bindings (wsdl):
43 for method in apistub.methods:
44 # Skip system. methods
45 if "system." in method:
48 function = apistub.callable(method) # Commented documentation
49 #lines = ["// " + line.strip() for line in function.__doc__.strip().split("\n")]
50 #print "\n".join(lines)
54 in_el = wsdl.firstChild.appendChild(wsdl.createElement("wsdl:message"))
55 in_el.setAttribute("name", method + "_in")
57 for service_name in function.interfaces:
58 if (services.has_key(service_name)):
59 if (not method in services[service_name]):
60 services[service_name].append(method)
62 services[service_name]=[method]
66 if (function.accepts):
67 (min_args, max_args, defaults) = function.args()
68 for (argname,argtype) in zip(max_args,function.accepts):
69 arg_part = in_el.appendChild(wsdl.createElement("wsdl:part"))
70 arg_part.setAttribute("name", argname)
71 arg_part.setAttribute("type", param_type(argtype))
74 return_type = function.returns
75 out_el = wsdl.firstChild.appendChild(wsdl.createElement("wsdl:message"))
76 out_el.setAttribute("name", method + "_out")
77 ret_part = out_el.appendChild(wsdl.createElement("wsdl:part"))
78 ret_part.setAttribute("name", "returnvalue")
79 ret_part.setAttribute("type", param_type(return_type))
81 # Port connecting arguments with return type
83 port_el = wsdl.firstChild.appendChild(wsdl.createElement("wsdl:portType"))
84 port_el.setAttribute("name", method + "_port")
86 op_el = port_el.appendChild(wsdl.createElement("wsdl:operation"))
87 op_el.setAttribute("name", method)
88 op_el.appendChild(wsdl.createElement("wsdl:input")).setAttribute("message","tns:" + method + "_in")
89 op_el.appendChild(wsdl.createElement("wsdl:output")).setAttribute("message","tns:" + method + "_out")
93 bind_el = wsdl.firstChild.appendChild(wsdl.createElement("wsdl:binding"))
94 bind_el.setAttribute("name", method + "_binding")
95 bind_el.setAttribute("type", "tns:" + method + "_port")
97 soap_bind = bind_el.appendChild(wsdl.createElement("soap:binding"))
98 soap_bind.setAttribute("style", "rpc")
99 soap_bind.setAttribute("transport","http://schemas.xmlsoap.org/soap/http")
102 wsdl_op = bind_el.appendChild(wsdl.createElement("wsdl:operation"))
103 wsdl_op.setAttribute("name", method)
104 wsdl_op.appendChild(wsdl.createElement("soap:operation")).setAttribute("soapAction",
108 wsdl_input = wsdl_op.appendChild(wsdl.createElement("wsdl:input"))
109 input_soap_body = wsdl_input.appendChild(wsdl.createElement("soap:body"))
110 input_soap_body.setAttribute("use", "encoded")
111 input_soap_body.setAttribute("namespace", "urn:" + method)
112 input_soap_body.setAttribute("encodingStyle","http://schemas.xmlsoap.org/soap/encoding/")
115 wsdl_output = wsdl_op.appendChild(wsdl.createElement("wsdl:output"))
116 output_soap_body = wsdl_output.appendChild(wsdl.createElement("soap:body"))
117 output_soap_body.setAttribute("use", "encoded")
118 output_soap_body.setAttribute("namespace", "urn:" + method)
119 output_soap_body.setAttribute("encodingStyle","http://schemas.xmlsoap.org/soap/encoding/")
122 def add_wsdl_service(wsdl):
123 for service in services.keys():
124 service_el = wsdl.firstChild.appendChild(wsdl.createElement("wsdl:service"))
125 service_el.setAttribute("name", service)
127 for method in services[service]:
129 servport_el = service_el.appendChild(wsdl.createElement("wsdl:port"))
130 servport_el.setAttribute("name", name + "_port")
131 servport_el.setAttribute("binding", "tns:" + name + "_binding")
133 soapaddress = servport_el.appendChild(wsdl.createElement("soap:address"))
134 soapaddress.setAttribute("location", "%s/%s" % (globals.plc_ns,service))
137 def get_wsdl_definitions():
138 wsdl_text_header = """
140 name="auto_generated"
142 xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
144 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
145 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>""" % (globals.plc_ns,globals.plc_ns)
147 wsdl = xml.dom.minidom.parseString(wsdl_text_header)
154 wsdl = get_wsdl_definitions()
155 add_wsdl_ports_and_bindings(wsdl)
156 add_wsdl_service(wsdl)
159 xml.dom.ext.PrettyPrint(wsdl)