Before we see MuleSoft specific method of implementation, let us investigate what a web-service is.
Web-Site vs Web-Service:
A web-site is a HTTP transport based communication between a client (technically called browser used by human beings) and the server components. The server components can be of different technology platforms such as .NET, Java or PHP based ones.
A web-service is a HTTP transport based communication between 2 different application systems where manual intervention is completely avoided to bring automation. These are aimed to have 2 different systems exchange data automatically.
What is Contract-first web-service?
A 'contract' is an agreement or format between 2 systems that intends to exchange data. In order to avoid assumptions and later confusions, the schema is identified before hand (before 2 systems start to implement their server side components). A WSDL is a meta-data that comprises of schema, operation and address.
A contract-first approach of designing a web-service is very helpful if both publisher and consumer applications do not have any components developed yet. With the manual construction of WSDL, one can agree the structure of data and different operations involved in the data exchange between them before hand.
Constructing Contract-First web-service using MuleSoft:
Step-1 Create a new project in Anypoint Studio with HTTP inbound:
Create a new Mule Project and introduce a inbound HTTP service by selecting HTTP component into a design canvas section.
Step-2 Import WSDL:
Choose the project, right click and select 'Import' option to get the 'Select' dialog window and select 'File System' and then choose 'Next'. Once you have the next window, choose the WSDL file and select the folder where the WSDL file to be imported. Probably create a folder 'wsdl' under src/main/resources folder to get the WSDL imported.
Step-3 Create CXF object for web-service:
The basic inbound HTTP service will need to be wrapped as a CXF in order to publish the WSDL and bind it to the associated Java class.
Now, drag and drop 'CXF' object into the canvas.
Step-4: Associate the Java Classes into web-service:
Select the 'CXF' object to see the properties window and choose the operation 'JAX-WS service' and click 'Generate from WSDL' against the 'service class' option. Now, in the dialog window, choose the wsdl that is earlier imported and mention the package name where the stub classes are to be created.
Step-5: Now add business logic in Mule Flow:
We are all set to go. Now following the CXF introduce any business logic to process the incoming data in the format specified in WSDL.
Once these steps are completed, you may use any tools like SoapUI to test the functionality.
No comments:
Post a Comment