def test_href(self): # the template. Start at pos 0, some servers complain if # xml tag is not in the first line. a = '''<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:types="http://example.com/encodedTypes" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <tns:myResponse xsi:type="tns:myResponse"> <myResult href="#id1" /> </tns:myResponse> <soapenc:Array id="id1" soapenc:arrayType="tns:MyData[2]"> <Item href="#id2" /> <Item href="#id3" /> </soapenc:Array> <tns:MyData id="id2" xsi:type="tns:MyData"> <Machine xsi:type="xsd:string">somemachine</Machine> <UserName xsi:type="xsd:string">someuser</UserName> </tns:MyData> <tns:MyData id="id3" xsi:type="tns:MyData"> <Machine xsi:type="xsd:string">machine2</Machine> <UserName xsi:type="xsd:string">user2</UserName> </tns:MyData> </soap:Body> </soap:Envelope>''' payload, header = from_soap(a, 'utf8') # quick and dirty test href reconstruction self.assertEquals(len(payload.getchildren()[0].getchildren()), 2)
def __decode_soap_request(self, http_env, http_payload): """ Decode http payload using information in the http header """ # fyi, here's what the parse_header function returns: # >>> import cgi; cgi.parse_header("text/xml; charset=utf-8") # ('text/xml', {'charset': 'utf-8'}) content_type = cgi.parse_header(http_env.get("CONTENT_TYPE")) charset = content_type[1].get('charset', None) if charset is None: charset = 'ascii' http_payload = collapse_swa(content_type, http_payload) # deserialize the body of the message req_payload, req_header = from_soap(http_payload, charset) return req_header, req_payload
def __decode_soap_request(self, http_env, http_payload): """ Decode http payload using information in the http header """ # fyi, here's what the parse_header function returns: # >>> import cgi; cgi.parse_header("text/xml; charset=utf-8") # ('text/xml', {'charset': 'utf-8'}) content_type = cgi.parse_header(http_env.get("CONTENT_TYPE")) charset = content_type[1].get('charset',None) if charset is None: charset = 'ascii' http_payload = collapse_swa(content_type, http_payload) # deserialize the body of the message req_payload, req_header = from_soap(http_payload, charset) return req_header, req_payload
def parseSoapRequest(request): # Test if this is a SOAP request. SOAP 1.1 specifies special # header, SOAP 1.2 special Content-Type soapAction = request.headers["SOAPAction"]; import cgi contentType = cgi.parse_header(request.headers["Content-Type"]); if (not soapAction and contentType[0] != "application/soap+xml"): return # Get body data of request body = request.body.read() # Use soaplib to separate header and payload charset = contentType[1].get('charset',None) if charset is None: charset = 'utf-8' payload, soapheader = from_soap(body, charset) from cocy.soaplib.soap import collapse_swa payload = collapse_swa(contentType, payload) if payload is not None: soapAction = payload.tag return soapAction, soapheader, payload