How to pass CDATA flag into JSON ZEEP SOAP XML request - json

I am trying to pass CDATA flag to a SOAP request using the Python library Zeep, but Zeep ignores the field(s) with CDATA and so the search is too broad and the returned data is much larger than I want. Unfortunately sub-selecting the dataframe with pandas later on is not an option, otherwise all would be well.
The request is a query against an SQL server DB, and I can retrieve the data with SOAP UI with the following:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsc="some_domain.com">
<soapenv:Header/>
<soapenv:Body>
<wsc:search>
<arg0>
<userName>user</userName>
<password>pass</password>
<criteria>
<some_name>
<field_one>CS</field_one>
<date_field>>2019-04-22</date_field>
<![CDATA[<timestamp_field>>2019-04-22 00:00:00.000</timestamp_field>]]>
</some_name>
</criteria>
<maxRows>5</maxRows>
</arg0>
</wsc:search>
</soapenv:Body>
</soapenv:Envelope>
For some reason a date field works fine, but the timestamp requires the use of CDATA, otherwise I get an error. Hence my SO question; how do I achieve the same with Zeep? I think this means that I have to pass CDATA flag into a JSON.
I have looked through SO, GitHub and Zeep documentation, but nowhere can I find an example of passing CDATA into Zeep, or passing CDATA flags into a JSON, which is then used to create the SOAP XML request.
Is passing CDATA into a JSON even possible? Perhaps someone knows how to pass the exact xml envelope I showed above into Zeep (taking into account that the above does not have the WSDL URI that defines the service)?
Here is a full example script
An example WSDL schema
And... XML request and response
Basically I set up the service , form a JSON for the request creation, and pass it under arg0.
from zeep import Client
import zeep
from zeep.transports import Transport
searchTerm = 'ns0:metaWsSearchRequest'
wsdl_url = 'some_url'
XML_viewname = 'SOMENAME'
transport = Transport(timeout=600)
zeep_client = Client(wsdl=wsdl_url, transport=transport)
# I am looking for the correct way to structure this JSON request if I have to pass CDATA
find_criteria_filled = {
'userName': user,
'password': pwd,
'sessionId': None,
'criteria': {
'SOMENAME': {
'<![CDATA[some_column_name3]]>': '2019-04-22 00:00:00.000',
'some_column_name1': 'CS'
}
},
'maxRows': '1'
}
response = zeep_client.service.search(arg0=find_criteria_filled)
The request ends up omitting some_column_name3, and so the search is incorrect. Instead of showing one records for the 22nd, it returns the first record for the search on 'some_column_name1': 'CS', which happens to have the date 2019-04-25.
I tried these combinations without luck:
'': '2019-04-22 00:00:00.000'
'![CDATA[some_column_name3]]': '2019-04-22 00:00:00.000'
'some_column_name3': ''
Any help would be really appreciated. Thank you.

Related

send XML data to server from JS and get XML parameter

In Javascript I can send XML string to JSP server (XmlAction.jsp):
Javascript Code:
var xmlDocument = "<?xml version="1.0" encoding='ISO-8859-1'?>
<Customer>
.......
</Customer>
"
var httpRequest;
httpRequest = new XMLHttpRequest();
httpRequest.open('POST', "http://example.com/XmlAction.jsp", false);
httpRequest.send(xmlDocument);
My question: How can I get XML data in JSP Page XmlAction.jsp ?
Can you give me some java code.
Thank all ^^
Call request.getInputStream() to get a stream of the submitted XML body, and pass it to whatever XML parser you plan to use (eg. for DOM an implementation of DocumentBuilder.parse(stream), which you might get from javax.xml.parsers.DocumentBuilderFactory).
Having a non-web-form (application/x-www-form-urlencoded, multipart/form-data) POST body is slightly unusual for Servlet/JSP but should work okay. Just make sure nothing is calling methods like getParameter() which expect web form input, and will get confused if you've already read the input stream.
[aside: do you really mean ISO-8859-1? If you send Unicode characters in a body with XMLHttpRequest.send(), they will be encoded as UTF-8, which won't match your XML declaration.]

Melissa Data XML Request not giving latitude and longitude in response

I have an application that uses WebObjects to send an XML request to Melissa in order to get location data given an address. The response accurately provides things like the delivery point code and delivery point check digit. The request is sent like so, using the request XML for the value of s:
NSData requestContent = new NSData(s.toString().getBytes());
WORequest request = new WORequest("GET", "/xml.asp", "HTTP/1.1", null, requestContent, null);
WOHTTPConnection httpConnection = new WOHTTPConnection("xml.melissadata.com", 80);
httpConnection.setReceiveTimeout(1000 * 10); // wait only 10 seconds
// for response
if (httpConnection.sendRequest(request)) {
As an example, I can send the following XML request to look up the address 3510 Marvin Rd NE, Olympia, WA:
<?xml version="1.0" ?>
<RecordSet>
<CustomerID>[some ID]</CustomerID>
<Record><Company/>
<Address>3510 Marvin Rd NE</Address>
<Address2/>
<City>Lacey</City>
<State>WA</State>
<Zip/>
<Plus4/>
<Latitude/>
<Longitude/>
<CarrierRoute/>
<DeliveryPointCode/>
<DeliveryPointCheckDigit/>
<AddressTypeCode/>
</Record>
<ErrorString/>
</RecordSet>
...and I get the following XML response from Melissa:
<Company></Company>
<Address>3510 Marvin Rd NE</Address>
<Address2></Address2>
<City>Lacey</City>
<State>WA</State>
<Zip>98516</Zip>
<Plus4>1423</Plus4>
<Latitude/>
<Longitude/>
<CarrierRoute>C082</CarrierRoute>
<DeliveryPointCode>10</DeliveryPointCode>
<DeliveryPointCheckDigit>0</DeliveryPointCheckDigit>
<AddressTypeCode>S</AddressTypeCode>
It seems to get all of the correct location information that I'm interested in except for Latitude and Longitude. In the tutorials I've looked at for Melissa XML requests, everything seems to be formatted the same way I have it, and in this Melissa example app, I'm able to get correct latitude and longitude data using the same test address. I've also tried putting in dummy values for latitude and longitude with the request, but these end up being unchanged. How can I format my request so that the response will give me latitude and longitude?
As it turned out, the problem had to do with the subscription to Melissa. It was solved by upgrading the subscription so that it would be possible to get latitude and longitude from XML queries.

Inserting xml node values from reading a file in soap ui

I have a requirement where there is an xml in my file system and I have to read tag values from that xml and populate in my soap request. I have totally no idea how do I do this.
I wrote a groovy script to read file:
File file = new File("C:/Users/Desktop/abc.txt")
fileContent = file.getText()
Now I want to read tag values from my source xml and populate in my soap request xml tags.
My sample xml is
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<soapenv:Header/>
<soapenv:Body>
<dto:dto>
<mon:abc>
<mon:HDR>
<mon:MESSAGE_ID>abcd</mon:MESSAGE_ID>
<mon:MSG_TIMESTAMP>2015-10-12T11:24:35-06:00</mon:MSG_TIMESTAMP>
</mon:HDR>
</mon:abc>
</dto:dto>
</soapenv:Body>
</soapenv:Envelope>
I have to read message_id from my sample xml into my soap request message id. Can someone guide how can i do this?
Here is the groovy script to extract the Message ID from the given file
Note that the sample you have provide does not have the proper data, missing namespaces.
import com.eviware.soapui.support.XmlHolder
//change the file path here
def xml = new File('/absolute/file/path').text
def holder = new XmlHolder(xml)
def messageId = holder.getNodeValue('//*:MESSAGE_ID')
assert messageId, "Message Id is empty or null"
log.info "MessageId is : ${messageId}"
If you need the messageId to be used in other steps of the same test case, please store it in a test case level property using below additional statement:
context.testCase.setPropertyValue('MESSAGE_ID', messageId)
Later you can use in other steps (except groovy) as ${#TestCase#MESSAGE_ID}
Use it in another groovy script of same test case as context.expand('${#TestCase#MESSAGE_ID}')

How to extract SOAP response using pysimplesoap?

I am new on using pysimplesoap. I am succeed using pysimplesoap to generate a soap request to a SOAP server, and the soap server is responded correctly, however, I do not know how to extract the information returned.
This is my code on pysimplesoap for the request
> from pysimplesoap.client import SoapClient
> client = SoapClient(location="http://192.168.206.111:8998/axis2/services/SecurityService", action="", namespace="http://www.labtest.com/Security", ns="ns3")
> response = client.call("login", ("ns3:loginName", "administrator"), ("ns3:password", "admin"))
The SOAP response is in below format.
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<n:loginResponse
xmlns:n="http://www.labtest.com/Security"
xmlns:n0="http://www.labtest.com/Types">
<n:errorCode>
<n0:hasError>
false
</n0:hasError>
<n0:status>
STATUS_SUCCESS
</n0:status>
</n:errorCode>
<n:authorizationToken>
<n0:token>
6430303938366138316265646532313138623866353235343030346130653330
</n0:token>
<n0:securityPrivileges>
<n0:values>
<n0:securityAttribute>
SUPER_USER_ACCESS
</n0:securityAttribute>
<n0:accessRights>
<n0:values>
FULL_CONTROL
</n0:values>
</n0:accessRights>
</n0:values>
</n0:securityPrivileges>
</n:authorizationToken>
</n:loginResponse>
</soapenv:Body>
</soapenv:Envelope>
I tried to use the print response or print (response), but nothing show up.
The response object is a pysimplesoap.client.SimpleXMLElement.
Behind the hood, a print(response) will call its __str__() method, the choice have been made, for pysimplesoap that `__str__() returns the text content of the node (if any), if your node contains no text content, like :
<MySoapResponse>
<child tag attr="value />
</MySoapResponse>
… then, __str__() will return nothing, and so do printing.
Alternatively, you may want to
navigate the XML tree of your answer by using SimpleXMLElement methods :
children() to grab childrens list
tag['attr'] (dict notation) to access attributes of an XML tag
tag.get_name() to get a tag name ;
inspect the full answer as a string (including Soap headers) as string calling repr(response), but it's more for debugging purposes.
See also the basic client documentation online.

Can I create a soap request with multiple elements of the same type?

I'm having a problem with my soap request. This is the code that creates the request:
[OperationContract()]
[return: MessageParameter(Name = "Dealer")]
List<Dealer> GetDealer(String AccountNumber);
This is the request that is generated:
<tem:GetDealer>
<!--Optional:-->
<tem:AccountNumber>?</tem:AccountNumber>
</tem:GetDealer>
but I need to be able to request multiple AccountNumbers.
Does someone know how to do this without creating a list for AccountNumber because then I'll get an extra element in AccountNumber.
So the request must be like this:
<DealerRequest>
<AccountNumber>1</AccountNumber>
<AccountNumber>2</AccountNumber>
<AccountNumber>3</AccountNumber>
</DealerRequest>

Resources