How to create a SOAP message from JSON payload in mule - soap

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.

Related

How to read Gzipped payload in a POST request in SpringBoot

I need to read gzipped json payload in a POST request in my SPringBoot app which accepts json data. How to do that in order to keep the application generic as there may be other clients in future sending data in plain json or other compression formats? I suppose this should be handled by the server itself so is there any way to instruct the embedded Tomcat to unzip the payload?
My SpringBoot application runs on embedded Tomcat 9.0.17.
The controller accepts JSON payload in a POST request.
#RequestMapping(value = "/update/v1", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
public ResponseEntity<String> receiveUpdates(#RequestBody String update) {
We recently changed our content provider and the new one is sending payload in "gzip" format (with header content-encoding=gzip) and without any content-type header. As a result it gives the following error
'error': 'Unsupported Media Type', 'message': "Content type '' not supported"
If I change my consume type to MediaType.ALL_VALUE, my controller starts receiving the request but the payload itself is gzipped. I can handle it in my service layer but that would make it specific to gzipped data.
This problem could be solved by introducing a Filter to handle gzipped payload as mentioned here and here.
But I believe there should be a way to instruct the Tomcat to handle this and serve unzipped data.

Using Apache Camel REST DSL how to return different representation of a ressource depending of the HTTP Accept header

I'm trying to use the Apache Camel REST DSL in order to return a different representation (xml, html, pdf) of a ressource using the HTTP Accept header.
Here is the current state of my code which is always returning the pdf representation either the client is sending Accept: text/html, application/xml or application/pdf.
rest("/bpcg").description("BPCG rest service")
.bindingMode(RestBindingMode.auto)
.get("/{id}").description("Find BPCG by id").outType(String.class)
.produces("application/xml")
.param().name("id").type(path).description("The id of the BPCG to get").dataType("int").endParam()
.to("bean:bpcgService?method=getBPCG(${header.id})")
.produces("text/html")
.param().name("id").type(path).dataType("int").endParam()
.route()
.to("bean:bpcgService?method=getBPCG(${header.id})")
.to("xslt:com/connectivia/cie/spec/xslt/CIE - Business partner companion guide to HTML for Confluence.xsl")
.endRest()
.produces("application/pdf")
.param().name("id").type(path).dataType("int").endParam()
.route().to("bean:bpcgService?method=getBPCG(${header.id})")
.to("xslt:com/connectivia/cie/spec/xslt/CIE - Business partner companion guide to PDF.xsl")
.to("xslt:com/connectivia/cie/spec/xslt/CIE - PDF Style Applier.xsl")
.to("bean:converter?method=ConvertXmlFoToPDF(${body})")
.endRest()

Apache camel REST DSL duplicating content-type

Using the rest dsl of apache camel for some reason, I don't know how, the response of the requests is returning duplicate content-type.
Example of code
rest("/api").consumes("application/json").produces("application/json")
.get("/find").to("bean:beanProcessor?method=find");
But if i put this:
rest("/api").consumes("application/json").produces("application/json")
.get("/find")
.route()
.to("bean:beanProcessor?method=find")
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
endRest();
The content-type response return only one "application/json".
Why this happens?
i - I'm using camel 2.15.5.
ii - I try remove the consumes and produces, but the duplicate contunues.

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()

CXF: Difference between PAYLOAD and MESSAGE data formats

I started working with Apache Camel and CXF.
In the "cxf:cxfEndpoint" configuration, what is the difference between dataFormat = PAYLOAD and dataFormat = MESSAGE?
I thought in both cases a org.apache.camel.component.cxf.CxfPayload is passed into the Camel Exchange, no?
So is MESSAGE simply the body of a PAYLOAD (-> PAYLOAD without Header and Attachment) ?
Yes, you are correct. CXF MESSAGE mode applies no SOAP processing, only body extraction. PAYLOAD mode allows for headers etc.
The official documentation is quite clear in this case, refer to:
http://camel.apache.org/cxf.html#CXF-HowtogetandsetSOAPheadersinPAYLOADmode