I’m going to provide an overview on how to build a simple contract-first web-service and JAX-WS client that consumes the web-service with Mule Studio.
The sample below is going to build the following:
- Build SOAP/ HTTP web service using Mule & CXF that is CRUD web service to create, retrieve, update and delete an order and returns the order id. This exercise implements only the create operation for this service.
- Build the Order Receiver Service
- Receives the order information from HTTP Inbound Endpoint.
- Invokes CRUDOrder web service to create the order
- Returns the order id to Portal
Building the CXF web-service
Following are steps needed to build a CXF based web-service using Mule
- Create a Mule project
- Import WSDL into the project
- Configure the HTTP inbound endpoint
- Configure the SOAP component.
- Create the service implementation.
- Final Service configuration.
- Test the Service
Create a Mule Project
- Click File → New → Mule Project
- Enter a project name as below
- Enter the flow name called service-cxf-wsdlfirst
- Then click Finish to complete the project creation.
Import WSDL into the project
- Select File→ Import
- Select General → File System
- Select the File and in the “Into Folder” – “src/main/resources” and click Finish
Configure the HTTP inbound endpoint
- Drag and drop HTTP Inbound EndPoint
- Double-click the HTTP endpoint and configure the HTTP address of the service
- Click Advanced TAB to configure the address to the required WSDL end point. If the address field is configured then remove the http host, port & application field.
<http:inbound-endpoint exchange-pattern=”request-response” address=”http://localhost:8882/OrderSvcs” doc:name=”HTTP”/>
Configure the SOAP component
- Drag and Drop a soap component
- Double click the SOAP component to configure the SOAP end point, and select Operation = JAX-WS Service
- Generate the WSDL to Java Classes
- Click Import
- Select the WSDL location from current project and package name for all the JAVA classes.
Tips: Ensure the WSDL name is full path including the WSDL extension
- Mule Studio automatically generates all the java classes once you import the WSDL.
After the classes are generated, ensure the Service Class Name field would point to actual Service Interface Definition not the Implementation Class and click “OK”.
Create the service implementation class
- Select package the Select → New Class
- Enter the class name & select “Add” to select the Interface Definition
- Define all the business logic in this class.
Final Mule Flow configuration
- Drag and Drop a Java Component
- Double-Click the Java Component to configure the implementation class that was created in the above “Service Implementation” section.
- Run the Service
- Go to webpage and type – http://localhost:8882/OrderSvcs?wsdl. Ensure you can see the complete WSDL including all operations