cvs co xct/XSoapExt xct/mslib xct/ldmalloc xct/prepbuild xct/xbs xct/build_xsoap xct/.xct_top_marker
cd xct build_xsoap create build_xsoap make
cd <module directory> ../prepbuild/prepbuild refresh (or ../prepbuild/prepbuild create ** in th case the module is create at first time **)\\ cd <platform sepcific directory> (like linux-2.6-x86-gcc-3.3.5---32-dyn-dbg)\\ gmake
cd XSoapExt cd <platform specific directory> #(e.g. linux-2.6-x86-gcc-3.3.5---32-dyn-dbg)Suppose you are under the paltform specific directory,(e.g. linux-2.6-x86-gcc-3.3.5--32-dyn-dbg), then
cd src/pyton gmakeThen _xsoap.so and xsoap.py will be generated, now you can run Python, and load xsoap into Python. You can find couple demo .py files in this directory, some of which also will be introduced in the below section. Running those demo files by Python function execfile.
# create a QName n = QName("www.foo.com","foo") # print a QName print n.toString()
# create an element node e1 = make_Element(QName("www.foo.com","foo")) # create an element node , which has a text node "hello" e2 = make_Element(QName("www.foo.com","foo"), "hello") # create an attribute node, whose name is age and value is 37 a1 = make_Attribute(QName("","age"),"37")
# add attribute node under e1 element e1.append_attribute(a1) # add element2 under e1 element e1.append_child(e2)
Or you can iterate the tree by the interfaces:
# iterate over the all attributres of the element node i = 0 while i < e1.attributes_size() : a3 = e1.attributes(i) print a3.node_name().toString() + "=" + a3.string_value() i += 1 # iterate over the all children elements of the element node print "The children elements are: " i = 0 while i < e1.elements_size() : e3 = e1.elements(i) print e3.node_name().toString() i += 1 # iterate over the all text nodes of the element node print "The textnode elements are: " print e.text() i = 0 while i < e1.textnodes_size() : t3 = e1.textnodes(i) print t3.string_value() i += 1
# assume the content is just a dummy element content = make_Element(name) # create the SOAP body element body = make_Body() # add the content element into SOAP body body.add_element(content) # create the SOAP envelope including the body envelope = make_Envelope(body) # visit the element associated with the envelope, body or header print elementToString(envelope.element())
# Now we create the communication end representing the cliend side. # The end is called DefaultSoapClientEnd, # it needs url of the server port to be the input parameter remoteEnd = DefaultClientEnd("www.foo.com",port,path);Thereafter by calling DefaultClientEnd.send_request(SoapEnvelope), we can send the SOAP envelope of the request message synchronously; The return value of the method call is the SOAP envelope of the response message, which could be SOAP response message or SOAP fault message.
# send the SOAP envelope via the client end # and synchronously wait the response ret = remoteEnd.send_request(envelope); # print the response print elementToString(ret.element())
For example, we are going to build a Math service which will supported two operations: Add and Minus;
class AddOperation(DefaultOperation): # init is necessary though it doesn't do much stuff. # name is the QName representing the SOAP method name def __init__(self, name): DefaultOperation.__init__(self,name) # handle_message is a call_back method, # which will be invoked by the backgroup Soap server thread # input argument is the input Soap envelope # the function shoudl return another envelope to represent the response def handle_message(self,input): # get the input soap message e = input.body().element().elements(0) if e.elements_size() != 2 : # wrong usage, return a SOAP fault return make_FaultEnvelope("argument is not correct") # get the 2 arguments in the message i = int(e.elements(0).text()) j = int(e.elements(1).text()) # create the response envelope content = make_Element(add_responseName,str(i+j)) body = make_Body() body.add_element(content) envelope = make_Envelope(body) return envelope
The AddOperation::handle_message is the call back method (or hook method, or Template pattern in Gof4 book),
which will be invoked by back ground SOAP server thread with the input SOAP request message as the argument.
This method is supposed to return a SOAP envelope as the SOAP response message.
It should be noted that in the AddOperation::init a QName should be given by the user. The QName is known as method name, by which SOAP server can dispatch the request to correct operation.
# Logically, a port is a collection of operations # What the user should do here is telling the port # which operations should belong to it (registering) class MathPort(DefaultPort): def __init__(self,port,path): # create the port at the address(port + path) DefaultPort.__init__(self,port,path) # create a operation instance of SayHiOperation self.op1 = AddOperation(add_name) # register the created operation into the port self.register_op(self.op1) # create a operation instance of SayHiOperation self.op2 = MinusOperation(minus_name) # register the created operation into the port self.register_op(self.op2)Basically, what the MathPort class has done is just creating those operations instances and registering them into the port.
server = MathPort(port,path)
Below code is from test_eventing_sink.py and test_eventing_source.py.
# a user specific event sink # which will listen the time event # and then print the server time contained in the event. class TimeEventSink(ThreadSafeEventSink): def __init__(self, port, path): ThreadSafeEventSink.__init__(self,port, path) # override this method to provide user specific processing of the event def handle_safe_event(self,event): # assume the schema of received event is # <Body><LocalTime>...</></> # event argument is the element of the SOAP message body if event.elements_size() != 1: print "the event format is incorrect" print "The the server time is " + event.elements(0).text()The event argument in the handle_safe_event actually is the element in the body of the received SOAP message. This simple sink just extracts the time data from the message and prints it
# now you can launch the sink s = TimeEventSink(sinkPort, sinkPath)
sub = DefaultSubscription(topic,sourceURI,sinkURI) sub.subscribe();As the code shows, to create the subscription you need to specify the event topic, the location of the event sink and the location of the event source. That means the event sink, event source and the host where the subscription is issued can be different hosts in the networking. ``sub.subscribe()'' will send the subscription request and wait the response from the event source.
# create and launch the event source and subscription manager # in this example, we use a simple all in one implemenation, which # includes the both event source and subscription manager and # and it accepts all subscribing request source = AllInOneEventSource(sourcePort,sourcePath,managerPort,managerPath);To create the object, you need to specify the port and path for both event source service and subscription manager service; Thereafter, you can send the event to the subscriber of the event source by calling source.notify(topic,message), which will send the message to all the subscriber who are interested in the topic. The below code shows in the time eventing demo how to generate an XML element including current time and send it to all subscribers through the event source.
e = make_Element(QName("","LocalTime"), time.asctime()) source.notify(topic,e);
It should be noted that the convenience is at the cost of policy flexibility. Event resource and subscription manager could have user specific management policy, like whether a subscription request is allowed, whether a renew request is allowed as so on. But AllInOneEventSource adopts simplest policies, by which all the requests will be allowed.
This document was generated using the LaTeX2HTML translator Version 2002-2-1 (1.71)
Copyright © 1993, 1994, 1995, 1996,
Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.
The command line arguments were:
latex2html -split 0 -show_section_number python_tutorial.tex -dir /u/welu/work/doc/docs/web/portals/XSoapExt/python_tutorial/
The translation was initiated by Wei Lu on 2005-05-24