Exemplo n.º 1
0
 def GetLocalInformation(self):
     ns = arc.NS(
         {'': 'http://schemas.ogf.org/glue/2008/05/spec_2.0_d41_r01'})
     info = arc.XMLNode(ns, 'Domains')
     service_node = info.NewChild('AdminDomain').NewChild(
         'Services').NewChild('Service')
     service_node.NewChild('Type').Set('org.nordugrid.tests.echo_python')
     endpoint_node = service_node.NewChild('Endpoint')
     endpoint_node.NewChild('HealthState').Set('ok')
     endpoint_node.NewChild('ServingState').Set('production')
     return info
Exemplo n.º 2
0
 def infinite(self, url):
     logger.msg(arc.INFO, "EchoService (python) thread test starting")
     i = 0
     while True:
         try:
             i += 1
             cfg = arc.MCCConfig()
             s = arc.ClientSOAP(cfg, arc.URL(url))
             ns = arc.NS('echo', echo_ns)
             outpayload = arc.PayloadSOAP(ns)
             outpayload.NewChild('echo:echo').NewChild('echo:say').Set(
                 'hi!')
             resp, status = s.process(outpayload)
             logger.msg(
                 arc.INFO,
                 "EchoService (python) thread test, iteration %(iteration)s %(status)s"
                 % {
                     'iteration': i,
                     'status': status
                 })
             time.sleep(3)
         except Exception as e:
             import traceback
             logger.msg(arc.DEBUG, traceback.format_exc())
Exemplo n.º 3
0
 def process(self, inmsg, outmsg):
     logger.msg(arc.DEBUG, "EchoService (python) 'Process' called")
     # time.sleep(10)
     # get the payload from the message
     inpayload = inmsg.Payload()
     logger.msg(
         arc.VERBOSE, 'inmsg.Auth().Export(arc.SecAttr.ARCAuth) = %s' %
         inmsg.Auth().Export(arc.SecAttr.ARCAuth).GetXML())
     logger.msg(
         arc.VERBOSE,
         'inmsg.Attributes().getAll() = %s ' % inmsg.Attributes().getAll())
     logger.msg(arc.INFO,
                "EchoService (python) got: %s " % inpayload.GetXML())
     # the first child of the payload should be the name of the request
     request_node = inpayload.Child()
     # get the namespace
     request_namespace = request_node.Namespace()
     logger.msg(
         arc.DEBUG,
         "EchoService (python) request_namespace: %s" % request_namespace)
     if request_namespace != echo_ns:
         if request_namespace == wsrf_rp_ns:
             outpayload = arc.PayloadSOAP(arc.NS({'wsrf-rp': wsrf_rp_ns}))
             outpayload.NewChild(
                 'wsrf-rp:GetResourcePropertyDocumentResponse').NewChild(
                     self.GetLocalInformation())
             outmsg.Payload(outpayload)
             logger.msg(arc.DEBUG, "outpayload %s" % outpayload.GetXML())
             return arc.MCC_Status(arc.STATUS_OK)
         raise Exception('wrong namespace. expected: %s' % echo_ns)
     # get the name of the request without the namespace prefix
     # this is the name of the Body node's first child
     request_name = request_node.Name()
     # create an answer payload
     ns = arc.NS({'echo': echo_ns})
     outpayload = arc.PayloadSOAP(ns)
     # here we defined that 'echo' prefix will be the namespace prefix of 'http://www.nordugrid.org/schemas/echo'
     # get the message
     say = str(request_node.Get('say'))
     # put it between the response-prefix and the response-suffix
     hear = self.prefix + say + self.suffix
     if request_name == 'double':
         # if the name of the request is 'double'
         # we create a new echo message which we send to http://localhost:60000/Echo using the ClientSOAP object
         cfg = arc.MCCConfig()
         ssl = False
         if self.ssl_config:
             cfg.AddCertificate(self.ssl_config.get('cert_file', None))
             cfg.AddPrivateKey(self.ssl_config.get('key_file', None))
             if 'ca_file' in self.ssl_config:
                 cfg.AddCAFile(self.ssl_config.get('ca_file', None))
             else:
                 cfg.AddCADir(self.ssl_config.get('ca_dir', None))
             ssl = True
         if ssl:
             url = arc.URL('https://localhost:60000/Echo')
             logger.msg(
                 arc.DEBUG,
                 'Calling https://localhost:60000/Echo using ClientSOAP')
         else:
             url = arc.URL('http://localhost:60000/Echo')
             logger.msg(
                 arc.DEBUG,
                 'Calling http://localhost:60000/Echo using ClientSOAP')
         # creating the ClientSOAP object
         s = arc.ClientSOAP(cfg, url)
         new_payload = arc.PayloadSOAP(ns)
         # creating the message
         new_payload.NewChild('echo:echo').NewChild('echo:say').Set(hear)
         logger.msg(arc.DEBUG, 'new_payload %s' % new_payload.GetXML())
         # sending the message
         resp, status = s.process(new_payload)
         # get the response
         hear = str(resp.Get('echoResponse').Get('hear'))
     elif request_name == 'httplib':
         # if the name of the request is 'httplib'
         # we create a new echo message which we send to http://localhost:60000/echo using python's built-in http client
         try:
             import http.client as httplib
         except ImportError:
             import httplib
         logger.msg(arc.DEBUG,
                    'Calling http://localhost:60000/Echo using httplib')
         # create the connection
         h = httplib.HTTPConnection('localhost', 60000)
         new_payload = arc.PayloadSOAP(ns)
         # create the message
         new_payload.NewChild('echo:echo').NewChild('echo:say').Set(hear)
         logger.msg(arc.DEBUG, 'new_payload %s' % new_payload.GetXML())
         # send the message
         h.request('POST', '/Echo', new_payload.GetXML())
         r = h.getresponse()
         response = r.read()
         logger.msg(arc.DEBUG, response)
         resp = arc.XMLNode(response)
         # get the response
         hear = str(resp.Child().Get('echoResponse').Get('hear'))
     elif request_name == 'wait':
         logger.msg(arc.DEBUG, 'Start waiting 10 sec...')
         time.sleep(10)
         logger.msg(arc.DEBUG, 'Waiting ends.')
     # we create a node at '/echo:echoResponse/echo:hear' and put the string in it
     outpayload.NewChild('echo:echoResponse').NewChild('echo:hear').Set(
         hear)
     outmsg.Payload(outpayload)
     logger.msg(arc.DEBUG, "outpayload %s" % outpayload.GetXML())
     # return with STATUS_OK
     return arc.MCC_Status(arc.STATUS_OK)
Exemplo n.º 4
0
#! /usr/bin/env python

from __future__ import print_function

import arc
import sys
root_logger = arc.Logger_getRootLogger()
root_logger.addDestination(arc.LogStream(sys.stdout))
root_logger.setThreshold(arc.ERROR)
if len(sys.argv) < 2:
    print("Usage: echo_client.py URL [message]")
    print(
        "  echo_client gets the credentials from the default user config file")
    sys.exit(-1)
url = arc.URL(sys.argv[1])
try:
    message = sys.argv[2]
except:
    message = 'hi!'
cfg = arc.MCCConfig()
uc = arc.UserConfig('')
uc.ApplyToConfig(cfg)
s = arc.ClientSOAP(cfg, url)
outpayload = arc.PayloadSOAP(
    arc.NS('echo', 'http://www.nordugrid.org/schemas/echo'))
outpayload.NewChild('echo:echo').NewChild('echo:say').Set(message)
resp, status = s.process(outpayload)
print(resp.GetXML(True))
Exemplo n.º 5
0
#!/usr/bin/env python

from __future__ import print_function

import arc
#f = open('soap.xml').read()
#e = arc.SOAPEnvelope(f)
#print e.toBool()
#p = arc.PayloadSOAP(e)
#print p.toBool(), p.Size()
#g = p.Get("echo").Get("say")
#print str(g)
ns = arc.NS()
ns['echo'] = 'urn:echo'
outpayload = arc.PayloadSOAP(ns)
print(type(outpayload))
outpayload.NewChild('echo:echoResponse').NewChild('echo:hear').Set('foo')
# n = outpayload.NewChild('echo:echoResponse')
# print type(n)
outmsg = arc.SOAPMessage()
outmsg.Payload(outpayload)
s = 'a'
ss = outpayload.GetXML()
print(s, ss)
print(str(outmsg))
Exemplo n.º 6
0
import sys
root_logger = arc.Logger_getRootLogger()
root_logger.addDestination(arc.LogStream(sys.stdout))
logger = arc.Logger(root_logger, "Test")

logger.msg(arc.INFO, "Creating a soap client")

cfg = arc.MCCConfig()
# cfg.AddPrivateKey('key.pem')
# cfg.AddCertificate('cert.pem')
# cfg.AddCAFile('ca.pem')

# s = arc.ClientSOAP(cfg, 'localhost', 60000, True, '/Echo')
s = arc.ClientSOAP(cfg, 'localhost', 60000, False, '/Echo')

logger.msg(arc.INFO, "Creating and sending request")
ns = arc.NS({'echo': 'http://www.nordugrid.org/schemas/echo'})
outpayload = arc.PayloadSOAP(ns)
outpayload.NewChild('echo:echo').NewChild('echo:say').Set('HELLO')

resp, status = s.process(outpayload)

if not status:
    logger.msg(arc.ERROR, "SOAP invocation failed")
elif not resp:
    logger.msg(arc.ERROR, "There was no SOAP response")
else:
    print("XML:", resp.GetXML())
    print("Response:", str(resp.Get('echoResponse').Get('hear')))