SOAP request XML elements order (node-soap) - soap

Using node-soap, when making a SOAP call, the XML elements are ordered by the order I write them in the request object (which is not reliable in JavaScript - nor is it maintainable at scale over time).
I've read that in some cases the order of the elements matter and it may require to organize the XML elements in the same order that appear in the WSDL - This appear to be the my case.
Consider this example:
<Request>
<Element2>
<SubElement1>
<SubElement2>
</Element2>
<Element1>
<SubElement3>
<SubElement4>
</Element1>
</Request>
For this WSDL:
<Request>
<Element1>
<SubElement3>
<SubElement4>
</Element1>
<Element2>
<SubElement1>
<SubElement2>
</Element2>
</Request>
For this request I would get an error that <Element1> is missing.
I could not find an option in node-soap to force the elements order by the WSDL.
Am I missing it or is there another way around.

Related

Passing encoded XML content in SOAP envelop request in Java application

I'm developing a Java application where I need to make a web service request using SOAP protocol. In that SOAP envelop request, one of the XML attribute/property called content will hold the XML file itself like below:-
<n1:envelope>
<message>
<id>67872894892424</id>
</message>
<sender agency="GS1" scheme="tGLK">ur.0</sender>
<recipients>
<id agency="GS1" scheme="tGLK">test</id>
</recipients>
<content encoding="XML" extension="A" format="ATTP">
------
----
</content></n1:envelope>
I'm new to it and requires some assistance in clarifying my doubts. I'm using JDK1.8 and Apache CXF. How can I do marshaling/unmarshalling for this particular content attribute? Normal SOAP envelops request is easy to do it but not sure how to pass an encoded XML itself in SOAP request. Is there any reference links? Thanks
Your case is an example of including XML inside XML. Yes, XML could be included inside an SOAP(XML), there are two ways, though both means almost same thing.
Using CDATA encoding
<hello><![CDATA[<El><E2><E3 attr="D1">Text</E3></E2></El>]]></hello>
Converting the XML into text by replacing, < with <, " with &quote; and > with >
<hello><El><E2><E3 attr="D1">Text</E3></E2></El></hello>
To
<hello>>El<>E2<>E3 attr="D1"<Text>/E3<>/E2<>/El<</hello>
Hence, to include the XML inside SOAP, while adding the XML element, you need to follow either approach while marshaling/unmarshaling.

transaction flow with roll back strategy mule

Input:-
<balanceInquiry>
<request>
<amount>
<amount>5.0</amount>
<currency/>
</amount>
</request>
</balanceInquiry>
<balanceInquiry>
<request>
<amount>
<amount>10.0</amount>
<currency/>
</amount>
</request>
</balanceInquiry>
<balanceInquiry>
<request>
<amount>
<amount>57.0</amount>
<currency/>
</amount>
</request>
</balanceInquiry>
I am trying to hit a SOAP webservice using the above input, but the webservice can only accept one balanceInquiry request at once. So I am spliting the request into different balanceInquiry using splitter. but if the status of 1st request is success then I have to go for 2nd and so on. If anyone of them fails then I need to rollback all the previous transaction. there is a attribute which can be "success" or "fail" depending on the request.
So I want to know if there is any component to achieve this in mule? Please suggest.
I believe you should take a look at the foreach documentation. https://docs.mulesoft.com/mule-user-guide/v/3.7/foreach and the exception handling strategy ; https://docs.mulesoft.com/mule-user-guide/v/3.7/error-handling.
If your 3 inquiries are in the same message and that you are using the default exception strategy, it will rollback the previous transactions... assuming you are writing the SOAP responses in a database using a DB connector.
Since I don't know exactly what you wish to do in your transaction, here's another interesting link : https://docs.mulesoft.com/mule-user-guide/v/3.7/rollback-exception-strategy

Order of unbounded elements in xmlschema sequence

I'm currently developing an application that uses webservices (SOAP 1.2). I'm interested in knowing if I can rely on the order of unbounded elements in a xmlschema sequence. Here is my definition of that sequence in the wsdl I'm using.
<xsd:complexType name="IdList">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="id" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
Does that give me any kind of guarantee on the order of the elements? Say this is an excerpt of the associated soap message:
<web:globalRecipientIds>
<!--Zero or more repetitions:-->
<web:id>1</web:id>
<web:id>15</web:id>
<web:id>7</web:id>
</web:globalRecipientIds>
Does that mean that the receiving end will treat it in the order that it appears in the SOAP message? Is this something that depends on the implementation of the receiving end? If it does, I generated the receiving end using wsdl2java from apache axis to generate the java code from the wsdl file. Can you tell me something specific about this?
The order of XML elements is significative - regardless of the schema - e.g.
<web:globalRecipientIds>
<web:id>1</web:id>
<web:id>15</web:id>
<web:id>7</web:id>
</web:globalRecipientIds>
and
<web:globalRecipientIds>
<web:id>15</web:id>
<web:id>1</web:id>
<web:id>7</web:id>
</web:globalRecipientIds>
are two different XML, and XML tools (should) preserve and recognize the order of elements.
Having said that, this does not guarantee that 'the receiving end will treat it in the order that it appears in the SOAP message' - depends on what the receiving end does with the XML. It receives an ordered list of ids, but if (for example) puts those ids in a dictionary or some other hashed structure the order is lost.

How to throw Soap Fault manually in mule

I'm face with a situation where we cannot use schema to validate incoming request (basically schema is there but it accepts any String in request, wsdl designers have their own reasons to do that to accept request from different sources and flexibility). But when the request is received, I validate that the child element of request wrapper is what we expect (using XPath for that). Now if the child element is not what expected, I'd like to throw Soap Fault with Client code and may be include error message that schema validation failed, request doesn't contain valid element.
I'm using Mule 3.3 and doing my XPath validation in <choice> element and I want to throw exception in <otherwise> block.
Is there a way to throw Soap Fault manually in mule flow and
How to add custom fault string. I'm not sure if an outInterceptor will solve the purpose as I'm not using schemaValidation attribute of <cxf:proxyService>.
Here is part of my flow
<http:inbound-endpoint address="${service.address}" exchange-pattern="request-response">
<cxf:proxy-service wsdlLocation="classpath:service.wsdl" namespace="http://company.com/services/service" service="CompanyService" />
</http:inbound-endpoint>
<choice>
<when>.....</when>
<otherwise><!-- Here I want to throw Soap Fault ---></otherwise>
</choice>
<catch-exception-strategy>
<flow-ref name="generateErrorResponse" />
</catch-exception-strategy>
Since you are using a cxf:proxy-service you have complete control on the response. For example, if you add the following in your otherwise block, you'll be able to create whatever SOAP fault you want:
<expression-component><![CDATA[
message.payload = '<soap:Fault xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
+ '<faultcode>A code</faultcode><faultstring>A string</faultstring>'
+ '</soap:Fault>';
]]></expression-component>

Sending and retrieving a constant field

I'm using Filemaker 11 to manage content over Custom Web publishing, with a json xslt sheet to convert the XML to a json format is there any way to add a parameter to the url, and have it come back down without modifying it?
I thought about globals, but from what I can tell if two requests were sent within a short enough amount of time, there could be a race condition, one overwriting the others global..
Parameters are passed to the stylesheet in <xsl:param name="request-query" />, whose structure must be specified in the documentation, but as far as I remember it's
<query action="..."> <-- the form action, i.e. the url -->
<parameter name="...">...</parameter>
</query>
The query namespace is http://www.filemaker.com/xml/query. FileMaker's own idea of passing custom parameters is to name them like token.1, etc., but it's possible to pass just any set of parameters to a XSLT that uses a process action (i.e. doesn't hit the database), sort the parameters out into what goes into the db and what stays, make an inline call, and then process the result and add the saved parameters back.
Note that you also can access the cookies and the headers, if you need. Also note that XSLT API is deprecated and won't be supported in future FileMaker version.