Soap Webservice Response validation using citrus framework - citrus-framework

I am trying to validate the payload response came from the server,
soap()
.server(todoServer)
.send()
.payload(new ClassPathResource("templates/getTodoListResponse.xml"));
Is there a way todo a field level validation like below using SoapActionBuilder,
http()
.client(todoClient)
.receive()
.response(HttpStatus.OK)
.validate("/t:todo/t:id", "${todoId}")
.validate("/t:todo/t:title", "${todoName}")
.validate("/t:todo/t:description", "${todoDescription}")
.validate("/t:todo/t:done", "false");

The SoapActionBuilder is also able to use XPath element validation.
soap()
.client(todoClient)
.receive()
.validate("/t:todo/t:id", "${todoId}")
.validate("/t:todo/t:title", "${todoName}")
.validate("/t:todo/t:description", "${todoDescription}")
.validate("/t:todo/t:done", "false");
Notice that the SOAP envelope is automatically handled in the Citrus client. So your XPath expression is able to use the payload root element as root base path for the expression. You can also tell Citrus to not automatically handle the SOAP envelope. Then your XPath expression need to use the SOAP-ENV:Envelope as root element.

Related

How to get ResponseEntity body in spring-integration

I am using xml based configuration - http outbound gateway to trii=gger a rest service, the response is ResponseEntity and I dont know that service details. The output I receive should be put in a JMS Queue.
How can I update the below to extract only the body of response entity and pass to output-channel? If there is a transformer, please give example. Is it possible using config?
<int:chain input-channel="gsInChannel" output-channel="dest-channel">
<int-http:outbound-gateway
url="https://ia-zatie.str13.tst.belst.nu/ia-zaatie/rest/signal/v2"
http-method="POST"
header-mapper="headerMapper"
request-factory="sslFactory"
>
</int-http:outbound-gateway>
</int:chain>
dest-channel is jms:outbound-channel-adapter
boot version 1.4.3 and integration version 4.3.6
Error: org.springframework.messaging.MessageHandlingException: error
occurred in message handler
[org.springframework.integration.jms.JmsSendingMessageHandler#0];
nested exception is
org.springframework.jms.support.converter.MessageConversionException:
Cannot convert object of type
[org.springframework.http.ResponseEntity] to JMS message. Supported
message payloads are: String, byte array, Map, Serializable
object.
I was using HTTP POST method and so not expecting, a response. SoO has not included expected-response-type, which returns the body
<int-http:outbound-gateway
url="https://ia-zatie.str13.tst.belst.nu/ia-zaatie/rest/signal/v2"
http-method="POST"
header-mapper="headerMapper"
request-factory="sslFactory"
expected-response-type="java.lang.String">

How to create a SOAP message from JSON payload in mule

I need to transform the following json payload into a soap message and send the message to a consumer, the consumer edits the data and sends back the soap message.
I haven't done much in soap. I only have REST experience. what steps do I need to take in a process like this?
what is the best approach?
[{"salesOrderId":"00004-5-6","saleName":"House Sale","status":"processing"}, {"salesOrderId":"00001-2-3","saleName":"Car Sale","status":"processing"}]
There are various way to perform this transformation, for example:
PATH - 1
Json To XML (with transformer or string set payload)
Xml To SOAP Request using XSLT, transformer or string set payload.
Send SOAP Request sobre HTTP (POST / Content-type: applicacion/xml / soapAction)
PATH - 2
Json To SOAP Request using Groovy, XSLT or string set payload.
Send SOAP Request sobre HTTP-OUTBOUND (POST / Content-type: applicacion/xml / soapAction)
PATH - 3
Json To SOAP Request Proxy (WSDL To Java).
Send SOAP Request sobre HTTP-OUTBOUND (POST / Content-type: applicacion/xml / soapAction)
The easiest way of doing it is extract the JSON elements from the JSON payload by using <json:json-to-object-transformer/>and store each node value in variables like flow variable in Mule.
Then You can create the SOAP request using XSLT and passing the flow variables value into XSLT as <mulexml:context-property/>
ref:- https://developer.mulesoft.com/docs/display/current/XSLT+Transformer
Once your SOAP XML is created, you can simply post them to your HTTP outbound endpoint pointing to your external web service you need to consume
Try using Mule DataMapper. That helps you to convert a JSON to XML in the more easier way. You can try it in Anypoint Studio of Mule.

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>

SOAPUI Extract data from SOAP Response and use in REST request

I have been looking at the answer to this question:
Pulling details from response to new request SoapUI
which is similar to what I am looking for but I can't get it to work.
I have a small SOAPUI testsuite and I need to extract a value from the response of a SOAP request and then use this value in a subsequent REST request.
The response to my SOAP request is:
<ns0:session xmlns:ns0="http://www.someurl.com/la/la/v1_0">
<token>AQIC5wM2xAAIwMg==#</token>
</ns0:session>
so I need the token to use in my REST request. I know it involves using Property Transfer and some XPath / XQuery but I just can't get it right. At the moment my property transfer window points to Source: SOAP test Property: Response and has data(/session/token/text()) in the text box. In target it has Target: REST testcase Property: newProp and I have Use XQuery checked.
Any help greatly appreciated.
Thanks,
Adrian
I think you just need to declare the namespace ns0 and use it in the XPath. Also, uncheck the XQuery, it is only used when you are using XQuery, not XPath.
Replace your expression with this:
declare namespace ns0='http://www.someurl.com/la/la/v1_0';
/ns0:session/token/text()

Parsing response from the WSDL

I've generated the web service client in eclipse for the OpenCalais WSDL using the "develop" client type. Actually I was following this post so not really going in detail. Now when I get the results this way: new CalaisLocator().getcalaisSoap().enlighten(key, content, requestParams);, I get the String object, containing the response XML. Sure it's possible to parse that XML, but I think there must be some way to do it automatically, e.g. getting the response object in the form of some list whatsoever?
The response from the SOAP interface is already parsed. The englighten() method returns an XML string. When you call it with SOAP, this response is wrapped within even more XML. The SOAP library already parses the outer SOAP XML and returns the result of the enlighten() method, which is also XML.