Custom Transform REST for SOAP for REST using Apache Camel

We create a utility that will:

  • Accept JSON through a RESTful service
  • Match it with POJO
  • Convert it to an object that can be used to call the remote SOAP service (JSON is not identical to SOAP-XML, for example, several fields are missing, so we need to display objects instead of automation).
  • Call the SOAP API call and get the result.
  • Convert this result to JSON and send it to the client. (The process is synchronous to avoid complexity initially).

A Plan . We successfully tried Mulesoft Anypoint studio to create the stream. It provides Data Mapping, where we can easily map elements from JSON to a SOAP stub and convert the results to JSON again.

Plan Bed and . Due to licensing restrictions in Plan A, I plan to do this with Camel. I'm new to this, but I can successfully create a POC web application that provides a servlet that accepts JSON. But now I’m stuck because I don’t know how to transform and call remote soap. (WSDL is available).

Estimated flow

Client → (Camel starts here) RESTful service → Convert data → Remote SOAP → Accept the response and convert to JSON → Send back to the client.

Any pointer in the right direction will be helpful.

+4
source share
1 answer

, JSON ↔ SOAP. **freemarker** freemarker. JSON SOAP FTL

<#ftl encoding="utf-8">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:iser="http://example.com/service" xmlns:das="http://example.com/service">
   <soapenv:Header>
      <iser:header>
         <iser:username></iser:username>
         <iser:password></iser:password>
         <iser:agency>${body.customer.name}</iser:agency>
      </iser:header>
   </soapenv:Header>
   <soapenv:Body>
      <iser:readCompositeAddressByAddressNum>
         <iser:arg1 addressNum="${body.customer.addressNum}" buildingCode="0" cityCode="0" districtCode="0" quarterCode="0" streetCode="0" streetTypeCode="0" townshipCode="0" villageCode="0">
         </iser:arg1>
      </iser:readCompositeAddressByAddressNum>
   </soapenv:Body>
</soapenv:Envelope>

inputTransformer.ftl. transfomer ftl (SOAP JSON) ,

from("direct-vm:getCustomerDetail")
.routeId("getCustomerDetail")
..
..
.to("freemarker:inputTransformer.ftl")
.log('{$body}')
.to(<Your SOAP Service>)
..
..
.to("freemarker:outputTransformer.ftl")
.log('${body}')

json .

, .

+1

All Articles