18
Mulesoft | Soap Service - Ujjawal Kant Exposing a Mule Soap Service (Xml Only) from an Abstract WSDL

Mulesoft Soap Service

Embed Size (px)

Citation preview

Page 1: Mulesoft Soap Service

Mulesoft | Soap Service

- Ujjawal Kant

Exposing a Mule Soap Service (Xml Only) from an Abstract WSDL

Page 2: Mulesoft Soap Service

In this slide we will focus on exposing a soap web service using Mule.If we have the concrete WSDL handy, its just a simple configuration that is required and you can jump to Slide X (Step 2) in this case.

We will divide our approach into two steps:• Step 1 - Create a concrete WSDL from the Schema definitions and

abstract WSDL.• Step 2 - It will focus on using the concrete WSDL created in Step 1 and

expose the service eventually.

Page 3: Mulesoft Soap Service

Step 1• We need to first have the Schema definitions and Abstract WSDL in place.• Lets create a new mule project named calculator and place xsd resource under src/main/resources/schemas• Please find the code snippet for calculator.xsd and calculator.wsdl in the next

slides. (We should be aware of creating our xsd and wsdl resources using eclipse)

Page 4: Mulesoft Soap Service

calculator.xsd<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

xmlns="http://www.mule.com/schemas/calculator"

targetNamespace="http://www.mule.com/schemas/calculator"

elementFormDefault="qualified"

attributeFormDefault="unqualified">

<xs:element name="Calculator">

<xs:complexType>

<xs:sequence>

<xs:element name="Numbers">

<xs:complexType>

<xs:sequence>

<xs:element name="Number1"

type="xs:decimal" /> <xs:element name="Number2"

type="xs:decimal" />

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="Result">

<xs:complexType>

<xs:sequence>

<xs:element name="Value" type="xs:decimal"/>

<xs:element name="Status" type="xs:string" minOccurs="0"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="Fault">

<xs:complexType>

<xs:sequence>

<xs:element name="Code" type="xs:string"/> <xs:element name="Message" type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

Page 5: Mulesoft Soap Service

calculator.wsdl<?xml version="1.0" encoding="UTF-8"?>

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://www.mule.com/schemas/calculator" xmlns:tns="http://www.mule.com/calculator/v0.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.mule.com/calculator/v0.1">

<import namespace="http://www.mule.com/schemas../schemas/calculator" location="Calculator.xsd"/>

<message name="AddInput"> <part element="ns:Calculator" name="part1"/>

</message>

<message name="AddOutput">

<part element="ns:Result" name="part1"/>

</message> <message name="SubInput">

<part element="ns:Calculator" name="part1"/>

</message>

<message name="SubOutput">

<part element="ns:Result" name="part1"/>

</message>

<message name="MulInput">

<part element="ns:Calculator" name="part1"/>

</message>

<message name="MulOutput">

<part element="ns:Result" name="part1"/>

</message>

<message name="DivInput">

<part element="ns:Calculator" name="part1"/>

</message>

<message name="DivOutput">

<part element="ns:Result" name="part1"/>

</message>

<message name="Fault">

<part name="part1" element="ns:Fault"/>

</message> <portType name="CalculatorPort">

<operation name="Add">

<input message="tns:AddInput"/>

<output message="tns:AddOutput"/>

<fault name="fault1" message="tns:Fault"/>

</operation>

<operation name="Sub">

<input message="tns:SubInput"/>

<output message="tns:SubOutput"/>

<fault name="fault1" message="tns:Fault"/>

</operation>

<operation name="Mul">

<input message="tns:MulInput"/>

<output message="tns:MulOutput"/>

<fault name="fault1" message="tns:Fault"/>

</operation> <operation name="Div">

<input message="tns:DivInput"/>

<output message="tns:DivOutput"/>

<fault name="fault1" message="tns:Fault"/>

</operation>

</portType>

</definitions>

Page 6: Mulesoft Soap Service

Mule flow for Step 1:• Lets create our Mule Flow for Step 1. This will involve having a Http Connector followed by CXF

component.• Configure the Http Connector first, having the Base Uri with the soap address we want to keep in our

concrete wsdl.

• Next drag and drop CXF Soap activity ; Below is the flow so far. Select JAX-WS service from the Operation drop down available in CXF component.

Page 7: Mulesoft Soap Service

calculatorFlow….• Refer to the below snap shot to generate the related java files using the abstract wsdl, in the CSF

soap component.

Page 8: Mulesoft Soap Service

calculatorFlow….• Once the necessary java files are generated in calculatorservcie package, we would get a folder

structure as shown below :

• Once the java files are intact, drop the Java Component after the CXF component.

Page 9: Mulesoft Soap Service

calculatorFlow….• We need to add the ServiceImplementation class file for this Java component. Under the Class Name

tab, Click Add and give a name to the ServiceImplementation java file (CalculatorServiceImpl in our case) as well as select the package and the Interface name.

• Also browse the Interface which was generated in Slide 8, Browse CalculatorPort.java

Page 10: Mulesoft Soap Service

calculatorFlow….• Below is our flow from Step 1 .You can notice the error visible in the previous slide has disappeared

now

• Run the mule flow, once it is deployed, use the below url over IE/ (any browser) to retrieve the concrete wsdl. Save the concrete wsdl. Do modifications to the soap action of the operations as required. We will use the same soap actions in the choice block of our mule flow to discriminate the operations.

• http://localhost:8899/Calculator?wsdl [Port Used in Http connector was 8899 and /Calculator was the base uri]

• We would receive the full concrete wsdl as a response on our browser. We just need to tweak the wsdl to add soap actions in the operations.

Page 11: Mulesoft Soap Service

calculatorFlow….

Page 12: Mulesoft Soap Service

calculatorFlow….• Below is the modified concrete wsdl with the highlighted additions:

Page 13: Mulesoft Soap Service

Step 2• Once we have the concrete wsdl ready. Place the concrete wsdl under src/main/wsdl location

in your mule project

• We will create a new mule flow “calculatorServiceFlow”. Drag and drop Http and CXF components and select Proxy Service from the Operations drop down in CXF Soap activity

Page 14: Mulesoft Soap Service

calculatorServiceFlow….• CXF Activity Configurations:• Get the values of Port, Namespace, Service from the concrete wsdl

• An important : Add wsdlLocation=“CalculatorConcrete.wsdl” in the cxf component xml tag, as shown below:

• <cxf:proxy-service configuration-ref="CXF_Configuration" port="CalculatorPortPort" namespace="http://www.mule.com/calculator/v0.1" service="CalculatorPortService" payload="body" wsdlLocation="CalculatorConcrete.wsdl" doc:name="CXF"/>

Page 15: Mulesoft Soap Service

calculatorServiceFlow….• Add a logger post the CXF to print the SOAP Action

• Once you run the flow; you can see the SOAP Action printed as:

Page 16: Mulesoft Soap Service

calculatorServiceFlow….• Add a choice to differentiate the operations and its individual implementation:

Page 17: Mulesoft Soap Service

calculatorServiceFlow….• Finally run and deploy you service and test it for its execution:

• Hope this helps!!