Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
arcom.client.Client Class Reference
Inheritance diagram for arcom.client.Client:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def reset
def call
def call_raw

Public Attributes

 ns
 urls
 https
 print_xml
 xmlnode_class
 ssl_config
 cfg
 get_trusted_dns_method
 connection_cache
 semapool

Static Public Attributes

 NS_class = arc.NS

Private Member Functions

def _fawlty

Detailed Description

Base Client class for sending SOAP messages to services 

Definition at line 10 of file client.py.


Constructor & Destructor Documentation

def arcom.client.Client.__init__ (   self,
  url,
  ns,
  print_xml = False,
  xmlnode_class = arc.XMLNode,
  ssl_config = {} 
)
The constructor of the Client class.

Client(url, ns, print_xml = false)

url is the URL of the service, it could be a list of multiple URLs
ns contains the namespaces we want to use with each message
print_xml is for debugging, prints all the SOAP messages to the screen

Definition at line 15 of file client.py.

00015 
00016     def __init__(self, url, ns, print_xml = False, xmlnode_class = arc.XMLNode, ssl_config = {}):
00017         """ The constructor of the Client class.
00018         
00019         Client(url, ns, print_xml = false)
00020         
00021         url is the URL of the service, it could be a list of multiple URLs
00022         ns contains the namespaces we want to use with each message
00023         print_xml is for debugging, prints all the SOAP messages to the screen
00024         """
00025         self.ns = ns
00026         if type(url) == list:
00027             urls = url
00028         else:
00029             urls = [url]
00030         self.urls = [arc.URL(url) for url in urls]
00031         self.https = 'https' in [url.Protocol() for url in self.urls]
00032         self.print_xml = print_xml
00033         self.xmlnode_class = xmlnode_class
00034         self.ssl_config = {}
00035         self.cfg = arc.MCCConfig()
00036         self.get_trusted_dns_method = ssl_config.get('get_trusted_dns_method', None)
00037         self.connection_cache = {}
00038         # semaphores to limit number of concurent writes
00039         self.semapool = threading.BoundedSemaphore(128)
00040         if self.https:
00041             self.ssl_config = ssl_config
00042             if ssl_config.has_key('proxy_file'):
00043                 self.cfg.AddProxy(self.ssl_config['proxy_file'])
00044             else:
00045                 try:
00046                     self.cfg.AddCertificate(self.ssl_config['cert_file'])
00047                     self.cfg.AddPrivateKey(self.ssl_config['key_file'])
00048                 except:
00049                     raise Exception, 'no key file or cert file found!'
00050             if ssl_config.has_key('ca_file'):
00051                 self.cfg.AddCAFile(self.ssl_config['ca_file'])
00052             elif ssl_config.has_key('ca_dir'):
00053                 self.cfg.AddCADir(self.ssl_config['ca_dir'])
00054             else:
00055                 raise Exception, 'no CA file or CA dir found!'
                

Member Function Documentation

def arcom.client.Client._fawlty (   self,
  message,
  status 
) [private]

Definition at line 92 of file client.py.

00092 
00093     def _fawlty(self, message, status):
00094         if not status.isOk():
00095             return 'ERROR: %s' % status
00096         if message.IsFault():
00097             return 'ERROR: %s' % message.Fault().Reason()
00098         return False

Here is the caller graph for this function:

def arcom.client.Client.call (   self,
  tree,
  return_tree_only = False 
)
Create a SOAP message from an XMLTree and send it to the service.

call(tree, return_tree_only = False)

tree is an XMLTree object containing the content of the request
return_tree_only indicates that we only need to put the response into an XMLTree

Definition at line 60 of file client.py.

00060 
00061     def call(self, tree, return_tree_only = False):
00062         """ Create a SOAP message from an XMLTree and send it to the service.
00063         
00064         call(tree, return_tree_only = False)
00065         
00066         tree is an XMLTree object containing the content of the request
00067         return_tree_only indicates that we only need to put the response into an XMLTree
00068         """
00069         # create a new PayloadSOAP object with the given namespace
00070         out = arc.PayloadSOAP(self.ns)
00071         # add the content of the XMLTree to the XMLNode of the SOAP object
00072         tree.add_to_node(out)
00073         if self.print_xml:
00074             msg = out.GetXML()
00075             print 'Request:'
00076             print XMLTree(out).pretty_xml(indent = '    ', prefix = '        #   ')
00077             print
00078         # call the service and get back the response, and the HTTP status
00079         resp = self.call_raw(out)
00080         if self.print_xml:
00081             print 'Response:'
00082             try:
00083                 print XMLTree(from_string = resp).pretty_xml(indent = '    ', prefix = '        #   ')
00084             except:
00085                 print resp
00086             print
00087         if return_tree_only:
00088             # wrap the response into an XMLTree and return only the tree
00089             return XMLTree(from_string = resp, forget_namespace = True).get_trees('///')[0]
00090         else:
00091             return resp

Here is the call graph for this function:

Here is the caller graph for this function:

def arcom.client.Client.call_raw (   self,
  outpayload 
)
Send a POST request with the SOAP XML message.

call_raw(outpayload)

outpayload is an XMLNode with the SOAP message

Definition at line 99 of file client.py.

00099 
00100     def call_raw(self, outpayload):
00101         """ Send a POST request with the SOAP XML message.
00102         
00103         call_raw(outpayload)
00104         
00105         outpayload is an XMLNode with the SOAP message
00106         """
00107         tid = thread.get_ident()
00108         s = self.connection_cache.get(tid, None)
00109         if s:
00110             try:
00111                 resp, status = s.process(outpayload)
00112                 if not self._fawlty(resp, status):
00113                     return resp.GetXML()
00114             except:
00115                 pass
00116             self.connection_cache[tid] = None
00117         if len(self.urls) == 0:
00118             log.msg(arc.WARNING, 'No URLs to connect to (in %s)' % str(self.__class__.__name__))
00119             raise Exception, 'No URLs to connect'
00120         random.shuffle(self.urls)
00121         #print "available URLs", [url.fullstr() for url in self.urls]
00122         for url in self.urls:
00123             #print "trying URL", url.fullstr()
00124             try:
00125                 s = arc.ClientSOAP(self.cfg, url)
00126                 if self.get_trusted_dns_method:
00127                     dnlist = self.get_trusted_dns_method()
00128                     if dnlist:
00129                         dnlistconf = arc.DNListHandlerConfig(dnlist, 'outgoing')
00130                         # _s points to the superclass, but not the object, so it needs the object as first argument
00131                         s._s._s.AddSecHandler(s, dnlistconf, arc.TLSSec)
00132                 resp, status = s.process(outpayload)
00133                 fawlty = self._fawlty(resp, status)
00134                 if fawlty:
00135                     raise Exception, fawlty
00136                 resp = resp.GetXML()
00137                 self.connection_cache[tid] = s
00138                 return resp
00139             except:
00140                 log.msg(arc.WARNING, "ERROR connecting to", url.fullstr())
00141                 pass
00142         log.msg(arc.ERROR, "ERROR connecting to all of these:", ', '.join([url.fullstr() for url in self.urls]))
00143         raise

Here is the call graph for this function:

Here is the caller graph for this function:

def arcom.client.Client.reset (   self)

Definition at line 56 of file client.py.

00056 
00057     def reset(self):
00058         tid = thread.get_ident()
00059         self.connection_cache[tid] = None


Member Data Documentation

Definition at line 34 of file client.py.

Definition at line 36 of file client.py.

Definition at line 35 of file client.py.

Definition at line 30 of file client.py.

Definition at line 24 of file client.py.

Definition at line 13 of file client.py.

Definition at line 31 of file client.py.

Definition at line 38 of file client.py.

Definition at line 33 of file client.py.

Definition at line 29 of file client.py.

Definition at line 32 of file client.py.


The documentation for this class was generated from the following file: