Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Public Attributes
echo_python.EchoService.EchoService Class Reference

List of all members.

Public Member Functions

def __init__
def __del__
def infinite
def RegistrationCollector
def GetLocalInformation
def process

Public Attributes

 prefix
 suffix
 ssl_config

Detailed Description

Definition at line 11 of file EchoService.py.


Constructor & Destructor Documentation

Definition at line 13 of file EchoService.py.

00013 
00014     def __init__(self, cfg):
00015         log.msg(arc.INFO, "EchoService (python) constructor called")
00016         # get the response-prefix from the config XML
00017         self.prefix = str(cfg.Get('prefix'))
00018         # get the response-suffix from the config XML
00019         self.suffix = str(cfg.Get('suffix'))
00020         log.msg("EchoService (python) has prefix '%s' and suffix '%s'" % (self.prefix, self.suffix))
00021         self.ssl_config = parse_ssl_config(cfg)
00022         thread_test = str(cfg.Get('ThreadTest'))
00023         if thread_test:
00024             threading.Thread(target = self.infinite, args=[thread_test]).start()
        

Definition at line 25 of file EchoService.py.

00025 
00026     def __del__(self):
00027         log.msg(arc.INFO, "EchoService (python) destructor called")
        

Member Function Documentation

Definition at line 54 of file EchoService.py.

00054 
00055     def GetLocalInformation(self):
00056         ns = arc.NS({'':'http://schemas.ogf.org/glue/2008/05/spec_2.0_d41_r01'})
00057         info = arc.XMLNode(ns,'Domains')
00058         service_node = info.NewChild('AdminDomain').NewChild('Services').NewChild('Service')
00059         service_node.NewChild('Type').Set('org.nordugrid.tests.echo_python')
00060         endpoint_node = service_node.NewChild('Endpoint')
00061         endpoint_node.NewChild('HealthState').Set('ok')
00062         endpoint_node.NewChild('ServingState').Set('production')    
00063         return info

Here is the caller graph for this function:

Definition at line 28 of file EchoService.py.

00028 
00029     def infinite(self, url):
00030         log.msg(arc.INFO, "EchoService (python) thread test starting")
00031         i = 0
00032         while True:
00033             try:
00034                 i += 1
00035                 cfg = arc.MCCConfig()
00036                 s = arc.ClientSOAP(cfg, arc.URL(url))
00037                 ns = arc.NS('echo', echo_ns)
00038                 outpayload = arc.PayloadSOAP(ns)
00039                 outpayload.NewChild('echo:echo').NewChild('echo:say').Set('hi!')
00040                 resp, status = s.process(outpayload)
00041                 log.msg(arc.INFO, "EchoService (python) thread test, iteration", i, status)
00042                 time.sleep(3)
00043             except Exception, e:
00044                 log.msg()                

def echo_python.EchoService.EchoService.process (   self,
  inmsg,
  outmsg 
)

Definition at line 64 of file EchoService.py.

00064 
00065     def process(self, inmsg, outmsg):
00066         log.msg("EchoService (python) 'Process' called")
00067         # time.sleep(10)
00068         # get the payload from the message
00069         inpayload = inmsg.Payload()
00070         log.msg(arc.VERBOSE, 'AuthRequest(inmsg) = ', AuthRequest(inmsg))
00071         log.msg(arc.VERBOSE, 'inmsg.Attributes().getAll() = ', inmsg.Attributes().getAll())
00072         log.msg(arc.INFO, "EchoService (python) got:", inpayload.GetXML())
00073         # the first child of the payload should be the name of the request
00074         request_node = inpayload.Child()
00075         # get the namespace
00076         request_namespace = request_node.Namespace()
00077         log.msg("EchoService (python) request_namespace:",  request_namespace)
00078         if request_namespace != echo_ns:
00079             if request_namespace == wsrf_rp_ns:
00080                 outpayload = arc.PayloadSOAP(arc.NS({'wsrf-rp':wsrf_rp_ns}))
00081                 outpayload.NewChild('wsrf-rp:GetResourcePropertyDocumentResponse').NewChild(self.GetLocalInformation())
00082                 outmsg.Payload(outpayload)
00083                 log.msg("outpayload", outpayload.GetXML())
00084                 return arc.MCC_Status(arc.STATUS_OK)
00085             raise Exception, 'wrong namespace. expected: %s' % echo_ns
00086         # get the name of the request without the namespace prefix
00087         # this is the name of the Body node's first child
00088         request_name = request_node.Name()
00089         # create an answer payload
00090         ns = arc.NS({'echo': echo_ns})
00091         outpayload = arc.PayloadSOAP(ns)
00092         # here we defined that 'echo' prefix will be the namespace prefix of 'http://www.nordugrid.org/schemas/echo'
00093         # get the message
00094         say = str(request_node.Get('say'))
00095         # put it between the response-prefix and the response-suffix
00096         hear = self.prefix + say + self.suffix
00097         if request_name == 'double':
00098             # if the name of the request is 'double'
00099             # we create a new echo message which we send to http://localhost:60000/Echo using the ClientSOAP object
00100             cfg = arc.MCCConfig()
00101             ssl = False
00102             if self.ssl_config:
00103                 cfg.AddCertificate(self.ssl_config.get('cert_file', None))
00104                 cfg.AddPrivateKey(self.ssl_config.get('key_file', None))
00105                 if self.ssl_config.has_key('ca_file'):
00106                     cfg.AddCAFile(self.ssl_config.get('ca_file', None))
00107                 else:
00108                     cfg.AddCADir(self.ssl_config.get('ca_dir', None))
00109                 ssl = True
00110             if ssl:
00111                 url = arc.URL('https://localhost:60000/Echo')
00112                 log.msg('Calling https://localhost:60000/Echo using ClientSOAP')
00113             else:
00114                 url = arc.URL('http://localhost:60000/Echo')
00115                 log.msg('Calling http://localhost:60000/Echo using ClientSOAP')
00116             # creating the ClientSOAP object
00117             s = arc.ClientSOAP(cfg, url)
00118             new_payload = arc.PayloadSOAP(ns)
00119             # creating the message
00120             new_payload.NewChild('echo:echo').NewChild('echo:say').Set(hear)
00121             log.msg('new_payload', new_payload.GetXML())
00122             # sending the message
00123             resp, status = s.process(new_payload)
00124             # get the response
00125             hear = str(resp.Get('echoResponse').Get('hear'))
00126         elif request_name == 'httplib':
00127             # if the name of the request is 'httplib'
00128             # we create a new echo message which we send to http://localhost:60000/echo using python's built-in http client
00129             import httplib
00130             log.msg('Calling http://localhost:60000/Echo using httplib')
00131             # create the connection
00132             h = httplib.HTTPConnection('localhost', 60000)
00133             new_payload = arc.PayloadSOAP(ns)
00134             # create the message
00135             new_payload.NewChild('echo:echo').NewChild('echo:say').Set(hear)
00136             log.msg('new_payload', new_payload.GetXML())
00137             # send the message
00138             h.request('POST', '/Echo', new_payload.GetXML())
00139             r = h.getresponse()
00140             response = r.read()
00141             log.msg(response)
00142             resp = arc.XMLNode(response)
00143             # get the response
00144             hear = str(resp.Child().Get('echoResponse').Get('hear'))
00145         elif request_name == 'wait':
00146             log.msg('Start waiting 10 sec...')
00147             time.sleep(10)
00148             log.msg('Waiting ends.')
00149         # we create a node at '/echo:echoResponse/echo:hear' and put the string in it
00150         outpayload.NewChild('echo:echoResponse').NewChild('echo:hear').Set(hear)
00151         outmsg.Payload(outpayload)
00152         log.msg("outpayload", outpayload.GetXML())
00153         # return with STATUS_OK
00154         return arc.MCC_Status(arc.STATUS_OK)
00155 
00156 # you can easily test this with this shellscript:
00157 """
00158 MESSAGE='<?xml version="1.0"?><soap-env:Envelope xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:star="http://www.nordugrid.org/schemas/echo"><soap-env:Body><star:echo><star:say>HELLO</star:say></star:echo></soap-env:Body></soap-env:Envelope>'
00159 echo Request:
00160 echo $MESSAGE
00161 echo
00162 echo Response:
00163 curl -d "$MESSAGE" http://localhost:60000/Echo
00164 echo
00165 """
00166 #

Here is the call graph for this function:

Definition at line 45 of file EchoService.py.

00045 
00046     def RegistrationCollector(self, doc):
00047         regentry = arc.XMLNode('<RegEntry />')
00048         SrcAdv = regentry.NewChild('SrcAdv')
00049         SrcAdv.NewChild('Type').Set('org.nordugrid.tests.echo_python')
00050 
00051         #Place the document into the doc attribute
00052         doc.Replace(regentry)
00053         return True


Member Data Documentation

Definition at line 16 of file EchoService.py.

Definition at line 20 of file EchoService.py.

Definition at line 18 of file EchoService.py.


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