webservice with multiple parameter - axis2

I create a webservice with axis2 like that:
public void setWeather(#WebParam(name = "weather") Weather weather,
#WebParam(name = "city") String city,
#WebParam(name = "country") String country) {
System.out.println("weather:" + weather);
System.out.println("city:" + city);
System.out.println("country:" + country);
this.weather = weather;
}
Then I send a soap message:
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<ns2:setWeather xmlns:ns2="http://service.pojo.sample">
<ns2:weather>
<ns1:forecast xmlns:ns1="http://data.pojo.sample/xsd">rain</ns1:forecast>
<ns1:howMuchRain xmlns:ns1="http://data.pojo.sample/xsd">102.3</ns1:howMuchRain>
<ns1:rain xmlns:ns1="http://data.pojo.sample/xsd">true</ns1:rain>
<ns1:temperature xmlns:ns1="http://data.pojo.sample/xsd">20.3</ns1:temperature>
</ns2:weather>
<ns2:country>china</ns2:country>
</ns2:setWeather>
</soapenv:Body>
</soapenv:Envelope>
And I receive
weather:Weather [temperature=20.3, forecast=rain, rain=true, howMuchRain=102.3]
city:china
country:null
ns2:country node have been assigned null, why this happens?

Related

DataWeave 2 - transform Java ArrayList to XML with array item tags

I have a Java payload in Mule 4.3 which contains an ArrayList:
agentList = {ArrayList}
0 = {SomeClass}
id = "0"
name = "Agent0"
1 = {SomeClass}
id = "1"
name = "Agent1"
I want to transform this to XML as:
<agentList>
<agent>
<id>0</id>
<name>Agent0</name>
</agent>
<agent>
<id>1</id>
<name>Agent1</name>
</agent>
</agentList>
If I do a DataWeave transform output application/xml --- result: payload, I get this XML:
<result>
<agentList>
<id>0</id>
<name>Agent0</name>
</agentList>
<agentList>
<id>1</id>
<name>Agent1</name>
</agentList>
</result>
How can I transform the ArrayList so that I get each item enclosed by agent tags and the entire list as agentList?
%dw 2.0
output application/xml
---
result: {
agentList: payload.*agentList map (value) -> { agent: value }
}

Unable to access the XML tag value using Karate.get() method

Unable to access the XML tag value using Karate.get() method
* def xml1 =
"""
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:QueryUsageBalance xmlns:ns2="http://www.mycompany.com/usage/V1">
<ns2:UsageBalance>
<ns2:LicenseId>12341234</ns2:LicenseId>
</ns2:UsageBalance>
</ns2:QueryUsageBalance>
</S:Body>
</S:Envelope>
"""
* def temp1 = karate.get('$xml1/S:Envelope/S:Body/ns2:QueryUsageBalance/ns2:UsageBalance/ns2:LicenseId')
* def result1 = temp1 ? 'yes' : 'no'
* print temp1
It's printing "no", seems unable to identify the XPATH. Could anyone please let me know what I am doing wrong here ?
I suggest you spend more time reading the docs and examples.
* def temp1 = $xml1/Envelope/Body/QueryUsageBalance/UsageBalance/LicenseId
* match temp1 == '12341234'

I am having trouble to add tags with nsmap for lxml library

I have wrote a function to generate Google Merchant RSS Feed with lxml library
I have the following code which is shortened for single tag:
from lxml import etree
def generate_xml(self):
nsmap = {
"g": "http://base.google.com/ns/1.0",
}
page = etree.Element('rss', nsmap=nsmap)
channel = etree.SubElement(page, 'channel')
channel_title = etree.SubElement(channel, 'title')
channel_title.text = "Test RSS 2.0 data feed template products"
channel_description = etree.SubElement(channel, 'description')
channel_description.text = "test data feed template."
channel_link = etree.SubElement(channel, 'link')
channel_link.text = "https://test-abcd.com"
item = etree.SubElement(channel, "item")
item_id = etree.SubElement(item, "id", nsmap=nsmap)
item_id.text = "123456789"
return etree.tostring(page, xml_declaration=True, encoding="utf-8")
The function returns the following output:
<?xml version='1.0' encoding='utf-8'?>
<rss xmlns:g="http://base.google.com/ns/1.0">
<channel>
<title>Test RSS 2.0 data feed template products</title>
<description>test data feed template.</description>
<link>https://test-abcd.com</link>
<item>
<id>123456789</id>
</item>
</channel>
</rss>
but it should be as the following (<g:id>123456789</g:id>) :
<?xml version='1.0' encoding='utf-8'?>
<rss xmlns:g="http://base.google.com/ns/1.0">
<channel>
<title>Test RSS 2.0 data feed template products</title>
<description>test data feed template.</description>
<link>https://test-abcd.com</link>
<item>
<g:id>123456789</g:id>
</item>
</channel>
</rss>
I have found the solution which is to use etree.QName() to build the qualified name for id:
def generate_xml(self):
nsmap = {
"g": "http://base.google.com/ns/1.0",
}
page = etree.Element('rss', nsmap=nsmap)
channel = etree.SubElement(page, 'channel')
channel_title = etree.SubElement(channel, 'title')
channel_title.text = "Test RSS 2.0 data feed template products"
channel_description = etree.SubElement(channel, 'description')
channel_description.text = "test data feed template."
channel_link = etree.SubElement(channel, 'link')
channel_link.text = "https://test-abcd.com"
item = etree.SubElement(channel, "item")
item_id = etree.SubElement(item, etree.QName(nsmap.get("g"), 'id'))
item_id.text = "123456789"
return etree.tostring(page, xml_declaration=True, encoding="utf-8")

Savon Rails—How to pass multiple parameters?

I have this code:
client = Savon.client(wsdl: wsdl)
response = client.call(:post, message: {
login: {
userName: username,
password: password
},
data: {
parameters: {
key: "firstName",
value: "Joe"
}
})
This works, but I need to send multiple parameters. If I have multiple parameters: {mydata} fields, it doesn't work because a hash must have unique keys...
How do I get Savon to send multiple parameter fields?
I still don't know the proper way, but the message parameter can be an XML string, so I ended up with the following solution:
client = Savon.client(wsdl: wsdl)
response = client.call(:post, message: build_xml)
def build_xml
"
#{login_xml}
<data>
<code>CUSTOMER_DETAILS</code>
" + test_data.map { |h| parameter_xml(h.first, h.last) }.join("") + "
</data>
"
end
def login_xml
"
<login>
<userName>#{#xml_username}</userName>
<password>#{#xml_password}</password>
</login>
"
end
def parameter_xml(key, val)
"
<parameters>
<key>#{key}</key>
<value>#{val}</value>
</parameters>
"
end

Add Soap Headers to XDocument

I am creating an XDocument with the following structure:
Dim xDocHandle As XDocument =
New XDocument(
New XDeclaration("1.0", Nothing, Nothing),
New XElement("Element",
New XElement("Dialogue",
New XElement("Desc", AppDesc),
New XElement("Num", Num),
New XElement("Ref", Ref),
New XElement("ms", Ms),
New XElement("im", Im))
))
To have the following output:
<Element>
<Dialogue>
<Desc>test</Desc>
<Num>1</Num>
<Ref></Ref>
<ms>2411616</ms>
<im></im>
</Dialogue>
</Element>
I want to add the following headers
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns="">
Should I add them as new XDeclaration , new XElement?
Whats the type of the soap headers?
Any help would be appreciated.
<soap:Envelope> and <soap:Body> are clearly elements. You can do something like this to construct XML with soap header :
'create <Element> node :'
Dim element As XElement = New XElement("Element",
New XElement("Dialogue",
New XElement("Desc", AppDesc),
New XElement("Num", Num),
New XElement("Ref", Ref),
New XElement("ms", Ms),
New XElement("im", Im))
)
'create <soap:Envelope> node and add <Element> as child of <soap:Body> :'
Dim soap As XNamespace = "http://www.w3.org/2001/12/soap-envelope"
Dim soapEnvelope As XElement = New XElement(soap + "Envelope",
New XAttribute(XNamespace.Xmlns + "soap", soap.NamespaceName),
New XAttribute(soap + "encodingStyle", "http://www.w3.org/2001/12/soap-encoding"),
New XElement(soap + "Body", element))
'create XDocument and set <soap:Envelope> as content'
Dim xDocHandle As XDocument =
New XDocument(
New XDeclaration("1.0", Nothing, Nothing),
soapEnvelope
)
Output :
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body>
<Element>
<Dialogue>
<Desc>test</Desc>
<Num>1</Num>
<Ref></Ref>
<ms>2411616</ms>
<im></im>
</Dialogue>
</Element>
</soap:Body>
</soap:Envelope>