0

I am building an application that exposes a Rest API and on the backend communicates and orchestrates multiple SOAP services to build the responses to the REST API. I have been reading about Canonical Data Models and how they can help me loosely couple these backend SOAP services.

Should I be using a canonical Data Model between my Rest API and the backend services?

At the moment the backend SOAP responses are unmarshalled to Java objects using JAXB. I then use scripts to map the jaxb objects to the a map that represents the structure I want to return as JSON and simply convert the Map to Json via my Rest API.

So SOAP -> jaxb Java Object -> Java Map(representing JSON) -> Json

Should I add another step in here for a Canonical Model?

So SOAP -> jaxb Java Object -> CANONICAL MODEL not representing SOAP or JSON structure -> Java Map(representing JSON) -> Json

Is this a good fit for a CDM? Or does adding this extra level redundant?

jon lee
  • 887
  • 1
  • 15
  • 32

2 Answers2

0

I think you're talking about having a facade between you and the services rather than a CDM. You would map the jaxb generated objects into internal objects, perform application logic on these, and then map these to the objects representing your JSON interface. The jaxb-internal mapping will decouple your application from the interfaces you are consuming. The internal-to-json mapping will decouple the interface you expose to your consumers from your internal objects.

Whether this is worth it or not depends on the complexity of your environment, what the cost & likelihood of change is. For instance it might be acceptable to be tightly coupled to services which share and expose a mature and versioned canonical model. It's a very different risk profile if you are consuming a set of ad-hoc or third party interfaces.

justAnotherUser
  • 181
  • 1
  • 6
0

As far as I know canonical data model means a common data model that represents all possible message formats and/or protocols. For an example, in Mule MuelMessage is a canonical data model because every message we sent, Mule creates the MuleMessage which represents your message irrespective of the protocol we use. So creating such a canonical data model is a bit difficult, in general

Coming to your case, I don't know how complex your SOAP objects are. If they are too complex, i.e., having multi-levels, then it would be a difficult job. My suggestion is, instead of having a canonical data model, why can't your write your own custom transformer (see if you can use a built in transformer) which parses and transforms your SOAP message to the corresponding JSON response. You can have a common transformer interface but with multiple implementations do perform parsing and transforming, depends on your SOAP message.

Hope this helped.

Ram Bavireddi
  • 1,139
  • 1
  • 19
  • 43