Changeset 329f61d
- Timestamp:
- Jun 27, 2008 6:34:17 PM (16 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
- Children:
- 0a47d52
- Parents:
- 4f4b977
- Location:
- fedd
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/fedd.py
r4f4b977 r329f61d 10 10 from M2Crypto import SSL 11 11 from M2Crypto.SSL.SSLServer import SSLServer 12 import xmlrpclib 12 13 13 14 from optparse import OptionParser … … 27 28 self.impl = impl 28 29 29 class fedd_ handler(BaseHTTPRequestHandler):30 class fedd_soap_handler(BaseHTTPRequestHandler): 30 31 server_version = "ZSI/2.0 fedd/0.1 " + BaseHTTPRequestHandler.server_version 31 32 namespace = 'http://www.isi.edu/faber/fedd.wsdl'33 methods = {34 'RequestAccess': 'soap_RequestAccess',35 }36 32 37 33 … … 59 55 """Confirm that this class implements the namespace and SOAP method""" 60 56 root = ps.body_root 61 if root.namespaceURI != fedd_handler.namespace:57 if root.namespaceURI != self.server.impl.soap_namespace: 62 58 self.send_fault(Fault(Fault.Client, 63 59 'Unknown namespace "%s"' % root.namespaceURI)) 64 60 return False 65 if not fedd_handler.methods.has_key(root.localName): 66 self.send_fault(Fault(Fault.Client, 'Unknown operation "%s"' % \67 root.localName))61 62 if getattr(root, 'localName', None) == None: 63 self.send_fault(Fault(Fault.Client, 'No method"')) 68 64 return False 69 65 return True … … 84 80 if not self.check_method(ps): return 85 81 try: 86 # We know this will work because check_method passed above 87 method = getattr(self.server.impl, 88 fedd_handler.methods[ps.body_root.localName]) 89 resp = method(ps, fedid(cert=self.request.get_peer_cert())) 82 resp = self.server.impl.soap_dispatch(ps.body_root.localName, ps, 83 fedid(cert=self.request.get_peer_cert())) 90 84 except Fault, f: 91 85 self.send_fault(f) … … 97 91 self.send_xml(str(sw)) 98 92 93 class fedd_xmlrpc_handler(BaseHTTPRequestHandler): 94 server_version = "ZSI/2.0 fedd/0.1 " + BaseHTTPRequestHandler.server_version 95 96 def send_xml(self, text, code=200): 97 """Send an XML document as reply""" 98 self.send_response(code) 99 self.send_header('Content-type', 'text/xml; charset="utf-8"') 100 self.send_header('Content-Length', str(len(text))) 101 self.end_headers() 102 self.wfile.write(text) 103 self.wfile.flush() 104 105 def do_POST(self): 106 """Treat an HTTP POST request as an XMLRPC service call""" 107 108 resp = None 109 data = None 110 cl = int(self.headers['content-length']) 111 data = self.rfile.read(cl) 112 params, method = xmlrpclib.loads(data) 113 114 try: 115 resp = self.server.impl.xmlrpc_dispatch(method, params, 116 fedid(cert=self.request.get_peer_cert())) 117 data = xmlrpclib.dumps((resp,), methodresponse=True) 118 except Fault, f: 119 xf = xmlrpclib.Fault(f.code, f.string) 120 data = xmlrpclib.dumps(xf, methodresponse=True) 121 resp = None 122 except xmlrpclib.Fault, f: 123 data = xmlrpclib.dumps(f, methodresponse=True) 124 resp = None 125 126 self.send_xml(data) 127 128 99 129 class fedd_opts(OptionParser): 100 130 """Encapsulate option processing in this class, rather than in main""" … … 103 133 version="0.1") 104 134 105 self.set_defaults(host="localhost", port=23235, debug=0) 135 self.set_defaults(host="localhost", port=23235, 136 transport="soap",debug=0) 106 137 107 138 self.add_option("-d", "--debug", action="count", dest="debug", … … 113 144 self.add_option("-p", "--port", action="store", type="int", 114 145 dest="port", help="Port to listen on (default %default)") 146 self.add_option("-x","--transport", action="store", type="choice", 147 choices=("xmlrpc", "soap"), 148 help="Transport for request (xmlrpc|soap) (Default: %default)") 115 149 self.add_option("--trace", action="store_const", dest="tracefile", 116 150 const=sys.stderr, help="Print SOAP exchange to stderr") … … 140 174 raise 141 175 142 s = fedd_server(SOAP_port, fedd_handler, ctx, impl) 176 if opts.transport == "soap": 177 s = fedd_server(SOAP_port, fedd_soap_handler, ctx, impl) 178 elif opts.transport == "xmlrpc": 179 s = fedd_server(SOAP_port, fedd_xmlrpc_handler, ctx, impl) 180 else: 181 s = None 182 143 183 s.serve_forever() -
fedd/fedd_client.py
r4f4b977 r329f61d 8 8 9 9 from M2Crypto import SSL, X509 10 from M2Crypto.m2xmlrpclib import SSL_Transport 10 11 import M2Crypto.httpslib 12 13 from xmlrpclib import ServerProxy, Error, dumps, loads 11 14 from ZSI import SoapWriter 12 15 … … 69 72 70 73 self.set_defaults(url="https://localhost:23235", anonymous=False, 71 serialize_only=False, use_fedid=False, debug=0) 74 serialize_only=False, transport="soap", use_fedid=False, 75 debug=0) 72 76 73 77 self.add_option("-a","--anonymous", action="store_true", … … 108 112 self.add_option("-U", "--username", action="store", dest="user", 109 113 type="string", help="Use this username instead of the uid") 114 self.add_option("-x","--transport", action="store", type="choice", 115 choices=("xmlrpc", "soap"), 116 help="Transport for request (xmlrpc|soap) (Default: %default)") 110 117 self.add_option("--trace", action="store_const", dest="tracefile", 111 118 const=sys.stderr, help="Print SOAP exchange to stderr") … … 230 237 else: raise 231 238 232 loc = feddServiceLocator();233 port = loc.getfeddPortType(opts.url,234 transport=M2Crypto.httpslib.HTTPSConnection,235 transdict={ 'ssl_context' : context },236 tracefile=opts.tracefile)237 238 req = RequestAccessRequestMessage()239 240 239 msg = { 241 240 'allocID': pack_id('test alloc'), … … 268 267 msg['user'] = []; 269 268 270 req.set_element_RequestAccessRequestBody(271 pack_soap(req, "RequestAccessRequestBody", msg))272 273 269 if opts.debug > 1: print >>sys.stderr, msg 274 270 275 if opts.serialize_only: 276 sw = SoapWriter() 277 sw.serialize(req) 278 print str(sw) 279 sys.exit(0) 280 281 try: 282 resp = port.RequestAccess(req) 283 except ZSI.FaultException, e: 284 sys.exit("Fault: %s" % e) 285 286 287 if (resp != None): 288 resp_body = resp.get_element_RequestAccessResponseBody() 289 if ( resp_body != None): 271 if opts.transport == "soap": 272 loc = feddServiceLocator(); 273 port = loc.getfeddPortType(opts.url, 274 transport=M2Crypto.httpslib.HTTPSConnection, 275 transdict={ 'ssl_context' : context }, 276 tracefile=opts.tracefile) 277 278 req = RequestAccessRequestMessage() 279 280 req.set_element_RequestAccessRequestBody( 281 pack_soap(req, "RequestAccessRequestBody", msg)) 282 283 if opts.serialize_only: 284 sw = SoapWriter() 285 sw.serialize(req) 286 print str(sw) 287 sys.exit(0) 288 289 try: 290 resp = port.RequestAccess(req) 291 except ZSI.FaultException, e: 292 sys.exit("Fault: %s" % e) 293 294 295 if (resp != None): 296 resp_body = resp.get_element_RequestAccessResponseBody() 297 if ( resp_body != None): 298 try: 299 resp_dict = unpack_soap(resp_body) 300 if opts.debug > 1: print >>sys.stderr, resp_dict 301 print_response_as_testbed(resp_dict, opts.label) 302 except RuntimeError, e: 303 sys.exit("Bad response. %s" % e.messgae) 304 else: sys.exit("No body in resonpse!?") 305 else: sys.exit("No response?!?") 306 elif opts.transport == "xmlrpc": 307 if opts.serialize_only: 308 ser = dumps((msg,)) 309 sys.exit(0) 310 311 transport = SSL_Transport(context) 312 port = ServerProxy(opts.url, transport=transport) 313 314 try: 315 resp = port.RequestAccess({ 'RequestAccessRequestBody': msg}) 316 resp, method = loads(resp) 317 except Error, e: 318 sys.exit("Fault: %s" % e) 319 320 321 if (resp != None): 290 322 try: 291 resp_dict = unpack_soap(resp_body) 323 print resp 324 resp_dict = resp[0]['RequestAccessResponseBody'] 292 325 if opts.debug > 1: print >>sys.stderr, resp_dict 293 326 print_response_as_testbed(resp_dict, opts.label) 294 327 except RuntimeError, e: 295 328 sys.exit("Bad response. %s" % e.messgae) 296 else: sys.exit("No body in resonpse!?") 297 else: sys.exit("No response?!?") 329 else: sys.exit("No response?!?") -
fedd/fedd_proj.py
r4f4b977 r329f61d 8 8 from M2Crypto.SSL.SSLServer import SSLServer 9 9 import M2Crypto.httpslib 10 import xmlrpclib 10 11 11 12 import re … … 30 31 id_attrs = ("testbed", "cert_file", "trusted_certs", "proxy", 31 32 "proxy_trusted_certs", "cert_pwd") 33 34 # Used by the SOAP caller 35 soap_namespace = 'http://www.isi.edu/faber/fedd.wsdl' 36 soap_methods = { 'RequestAccess': 'soap_RequestAccess' } 37 xmlrpc_methods = { 'RequestAccess': 'xmlrpc_RequestAccess' } 32 38 33 39 class access_project: … … 407 413 return msg 408 414 409 410 def soap_RequestAccess(self, ps, fid):411 req = ps.Parse(RequestAccessRequestMessage.typecode)412 413 414 #if req == None: raise Fault(Fault.Client, "No request??")415 #req = req.get_element_RequestAccessRequestBody()416 # if req == None: raise Fault(Fault.Client, "No request body??")417 418 msg = self.RequestAccess(unpack_soap(req), fedid)419 resp = RequestAccessResponseMessage()420 421 resp.set_element_RequestAccessResponseBody(422 pack_soap(resp, "RequestAccessResponseBody", msg))423 return resp424 425 415 def RequestAccess(self, req, fid): 426 416 … … 466 456 # Proxy the request 467 457 return self.proxy_request(dt, req) 458 459 def soap_RequestAccess(self, ps, fid): 460 req = ps.Parse(RequestAccessRequestMessage.typecode) 461 462 msg = self.RequestAccess(unpack_soap(req), fedid) 463 resp = RequestAccessResponseMessage() 464 465 resp.set_element_RequestAccessResponseBody( 466 pack_soap(resp, "RequestAccessResponseBody", msg)) 467 return resp 468 469 def xmlrpc_RequestAccess(self, params, fid): 470 msg = self.RequestAccess(params[0], fedid) 471 if msg != None: 472 return xmlrpclib.dumps(({ "RequestAccessResponseBody": msg },)) 468 473 469 474 def read_trust(self, trust): … … 634 639 f.close() 635 640 641 def soap_dispatch(self, method, req, fid): 642 if fedd_proj.soap_methods.has_key(method): 643 return getattr(self, fedd_proj.soap_methods[method])(req, fid) 644 else: 645 raise Fault(Fault.Client, "Unknown method: %s" % method) 646 647 def xmlrpc_dispatch(self, method, req, fid): 648 if fedd_proj.xmlrpc_methods.has_key(method): 649 return getattr(self, fedd_proj.xmlrpc_methods[method])(req, fid) 650 else: 651 raise xmlrpclib.Fault(100, "Unknown method: %s" % method) 652 636 653 def new_feddservice(configfile): 637 654 return fedd_proj(configfile)
Note: See TracChangeset
for help on using the changeset viewer.