HowTo – Wrap SOAP web service around a database

November 25 2015

6 comments 0
motif

We recently introduced our blog series, which is designed to present simple use-case tutorials to help you as you evaluate Anypoint Platform. This first blog in Series 1 will show you how to insulate your backend systems like databases by exposing a system API using SOAP over HTTP.  The principle behind this approach is our API led connectivity methodology, which is an evolution of SOA.

For years, most organizations have tightly coupled their front end applications with the backend enterprise systems like ERP and databases. The logic to access and process data from backend systems is baked directly into these front end applications. If there is any change in the backend system, it turns into a very costly exercise to propagate that change to each dependent application.

decoupling_transform

Therefore, there is a need to insulate these enterprise systems and provide an abstraction layer using a system level API. Having a system API decouples the front end consuming applications from interface changes in the backend enterprise systems, exposes information in your business specific semantics and provides flexibility to make changes with less impact. Although some systems like SaaS applications do have vendor provided APIs, having a system API layer still allows the user to abstract the complexity of these vendor APIs. These APIs will be highly reusable for different integrations, will change more infrequently and will be governed by Central IT given the importance of the underlying systems.  As a best practice, we first define the API contract (in this case, for a SOAP interface, so we’ll use a WSDL) before implementing the API. This approach helps to decouple the consumers of the API from the provider to speed development, provide reusability of assets like schemas, security schemes, and transport resources and help with versioning of the APIs.

Pre-requisites:

Steps:

  1. Start Mulesoft Anypoint Studio and point to a new workspace.
  2. Create a new project. File -> New -> Mule Projectpicture2
  3. Give a name to the project and click finish. You will see the mule configuration file where we can now add the Mule flows.
    Here is more information to understand Mule configuration.picture3
  4. Copy the schema and WSDL for loan service in the following directory path of the project, loan_system_api /src/main/resourcesDevBlogSeries1Part1
  5. Add HTTP endpoint to the Mule configuration file. Dropping the HTTP endpoint on the canvas will automatically create a flow (What is a mule flow?). In the HTTP endpoint properties tab below click on connector configuration.picture4
  6. Configure as below and click Ok.picture5
  7. Add value “loan” to the path variable in HTTP property.
    picture6
  8. Add the CXF component to the flow.
    (Here is more detail on the CXF component.)
    picture7
  9. Change the configurations for the CXF component to match the parameter from the WSDL. Add the WSDL location in the advanced tab.
    picture8
    picture9
  10. Add transformer “Dom to XML”.
    (Note: This transformer will convert the org.w3c.dom.Document object to XML message. This way we can apply XPath expressions to extract various values from the incoming message payload.)picture10
  11. To parse the XML, SOAP request message switch to the Configuration XML view and add the following.
    This namespace is obtained from the WSDL (Here are more details on how namespaces are handled in MuleSoft).
    picture11
  12. Add the database connector to look up the table.
    picture12
  13. Configure the database with all the parameters.
  14. Configure the database connector property with the following select query by using the XPath query to extract the input parameter from the request payload.select * from loan where loan_id = #[xpath3("sch:getLoanRequest/sch:loanId")]  picture13                      
  15. Add a logger component. Configure the metadata of the logger component with the schema object of the SOAP response message. This is done to assist with data mapping in the next step.picture14picture15
    picture24
  16. Add the component “Transform Message” in between the database connector and logger (Here is more detail on Transform Message).picture17
  17. To see all the fields click the button to show the scaffold output structure.
    picture18
  18. Map the response from the database connector to the SOAP response message.
    picture21
  19. Right-click the project and choose the run as “Mule Application” option. This will run the project in Anypoint Studio embedded Mule runtime.                                                                                      picture22
  20. Start SOAP UI and create a new project. Add a new WSDL and enter the link as follows: http://localhost:8081/bank/loan?wsdl
    Run the request and check the response.
    picture23

 

We have now successfully created a system API in front of a database, thus decoupling it from the user requesting the data.

To create this system API we have leveraged the following features of the Anypoint Platform:

  • Open standards support i.e. full support for WS* standards and open source services framework like Apache CXF.
  • Drag and drop and configure the CXF components that speed up development.
  • Database Connector: Allows you to connect to almost any relational database.
  • DataSense uses message metadata to facilitate application design.
  • Mule Expression Language (MEL): Lightweight Mule-specific expression language that can be used to access/evaluate the data in the payload.
  • Transformers/DataWeave:  A simple, powerful way to query and transform data using the platform.  

We have seen a growing need for APIs emerging from new business processes, applications, devices, and interfaces. These requirements from several consumers, it becomes necessary to define a lightweight and easy to consume REST API.

In part 2 of this series we will walk through creating a REST API on top of an existing SOAP service.


We'd love to hear your opinion on this post

6 Responses to “HowTo – Wrap SOAP web service around a database”

  1. Cool .

    Agree(1)Disagree(0)Comment
  2. Hi Neerav, im getting this error when i ran the project:
    org.mule.module.launcher.DeploymentInitException: IllegalStateException: The prefix tns is not bound.
    What can i miss?

    Agree(1)Disagree(0)Comment
    • Hi Leonardo,
      Did you download the project from Exchange and then ran it ?
      Are you running it in Studio?

      Neerav

      Agree(0)Disagree(1)Comment
  3. Nice document. I faced few challenges but managed to get it up and running.

    Thanks

    Agree(0)Disagree(0)Comment