DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • The Hidden Engineering Cost of XML in Enterprise Development Workflows
  • How to Convert XLS to XLSX in Java
  • Thread-Safety Pitfalls in XML Processing
  • Loading XML into MongoDB

Trending

  • S3 Vectors: How to Build a RAG Without a Vector Database
  • Introduction to Tactical DDD With Java: Steps to Build Semantic Code
  • Lambda-Driven API Design: Building Composable Node.js Endpoints With Functional Primitives
  • Ujorm3: A New Lightweight ORM for JavaBeans and Records
  1. DZone
  2. Coding
  3. Languages
  4. Mule4 — SoapKit Router. Validation of XML Against XSD

Mule4 — SoapKit Router. Validation of XML Against XSD

SoapKit router is a new addition from Mulesoft. The SoapKit router is for SOAP communication, which uses the WSDL file for endpoint definitions.

By 
Ankur Bhuyan user avatar
Ankur Bhuyan
·
Dec. 09, 20 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
13.1K Views

Join the DZone community and get the full member experience.

Join For Free

SoapKit router is a new addition from Mulesoft. The SoapKit router is for SOAP communication, which uses the WSDL file for endpoint definitions.

Create a Soap-Based Project in Mule 4

Step 1: Create a project

project settings

Step 2: Add the .wsdl file under src\main\resources\api\personService.WSDL location and right-click on the WSDL file and go to Mule -> Generate Flows from WSDL to generate flows based on the WSDL definitions.

generate flows

Step 3: Before generating flow, it will confirm for Service, Port, and destination file (where the flow will generate).

generate flows

Step 4: Before start implementing the flow, add a .xsd file under src\main\resources\xsd\personService.XSD location.

soap-sample

Step 5: Add flow to validate input soap message against XSD schema.

error handling

Step 6: Deploy the API and call the endpoint as like below. For valid payload, it will respond based on your implementation. 

request 1

Step 7: For invalid input content, it will throw an error like this. Error payload will depend on its implementation.

request 1

Step 8: Code snippet. Here is the code repository for this, or you can find it below.

XML
 




x
95


 
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<mule xmlns:xml-module="http://www.mulesoft.org/schema/mule/xml-module" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit-soap="http://www.mulesoft.org/schema/mule/apikit-soap" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/apikit-soap http://www.mulesoft.org/schema/mule/apikit-soap/current/mule-apikit-soap.xsd http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
3
http://www.mulesoft.org/schema/mule/xml-module http://www.mulesoft.org/schema/mule/xml-module/current/mule-xml-module.xsd">
4
    
5
    <flow name="soapkit-https-listener-router">
6
        <http:listener config-ref="api-httpListenerConfig" path="/PersonServiceImplService/PersonServiceImplPort" outputMimeType="application/xml" allowedMethods="POST">
7
            <http:response statusCode="#[vars.httpStatus default 200]">
8
                <http:headers><![CDATA[#[(vars.outboundHeaders default {}) ++
9
                    {'x-correlation-id': correlationId}]
10
                ]]></http:headers>
11
            </http:response>
12
            <http:error-response statusCode="#[vars.httpStatus default 500]">
13
                <http:body><![CDATA[#[payload]]]></http:body>
14
                <http:headers><![CDATA[#[(vars.outboundHeaders default {}) ++
15
                    {'x-correlation-id': correlationId}]
16
                ]]></http:headers>
17
            </http:error-response>
18
        </http:listener>
19
        <apikit-soap:router doc:name="SOAP Kit Router" doc:id="6c1f2c12-5b5c-4e02-bf26-60b1b4939755"
20
            config-ref="soap-config" outputMimeType="application/xml">
21
            <ee:repeatable-file-store-stream bufferUnit="MB" />
22
            <apikit-soap:message ><![CDATA[#[%dw 2.0
23
output application/xml
24
---
25
payload]]]></apikit-soap:message>
26
            <apikit-soap:attributes><![CDATA[#[%dw 2.0
27
output application/java
28
---
29
{
30
    headers: attributes.headers,
31
    method: attributes.method,
32
    queryString: attributes.queryString
33
}]]]></apikit-soap:attributes>
34
        </apikit-soap:router>
35
        <error-handler >
36
            <on-error-propagate enableNotifications="true" logException="true" doc:name="On Error Propagate" doc:id="fcbf42b2-819d-4971-a9be-810f537c2095" type="XML-MODULE:SCHEMA_NOT_HONOURED">
37
                <ee:transform doc:name="prepare Error Resaponse Message" doc:id="0c54d276-aaff-4286-9673-99680355f2f1" >
38
                    <ee:message >
39
                        <ee:set-payload ><![CDATA[%dw 2.0
40
output application/xml
41
ns soapenv http://schemas.xmlsoap.org/soap/envelope/
42
---
43
soapenv#Envelope : {
44
    soapenv#Body : {
45
        TYPE : error.errorType.identifier,
46
        MESSAGE : error.description
47
    }
48
}]]></ee:set-payload>
49
                    </ee:message>
50
                </ee:transform>
51
            
52
</on-error-propagate>
53
        </error-handler>
54
    </flow>
55
    
56
    
57
    <flow name="requestedPersonInfo:\soap-config">
58
        <flow-ref doc:name="validate-schema" name="validate-schema" doc:id="4760d834-fb49-4cbe-bc52-08a5b5b1fd52" /> 
59
        <ee:transform  doc:name="Prepare Response Message" doc:id="e85fceed-6d73-411d-bcd9-82ed62ca13d4">
60
            <ee:message>
61
                <ee:set-payload><![CDATA[%dw 2.0
62
output application/xml
63
ns ank http://ankuran.online/
64
---
65
ank#requestedPersonInfoResponse: {
66
    return:{
67
        id: uuid(),
68
        message: "Hello " ++ payload.body.requestedPersonInfo.arg0.firstName ++ " " ++ payload.body.requestedPersonInfo.arg0.middleName ++ " " ++ payload.body.requestedPersonInfo.arg0.lastName ++ ", your datails are saved successfully."
69
    }
70
}
71
]]></ee:set-payload>
72
            </ee:message>
73
        </ee:transform>
74
    </flow>
75
    <sub-flow name="validate-schema" doc:id="6acf23a0-1117-49ea-b5ee-bb11897466f6" >
76
        <ee:transform doc:name="prepare input Message" doc:id="6ef6ff7e-fe7e-4387-b18c-213b6c6b5752">
77
         <ee:message>
78
                <ee:set-payload><![CDATA[payload
79
]]></ee:set-payload>
80
            </ee:message>
81
            <ee:variables >
82
                <ee:set-variable variableName="requestedBody" ><![CDATA[%dw 2.0
83
output application/xml
84
---
85
payload.body]]></ee:set-variable>
86
            </ee:variables>
87
        
88
</ee:transform>
89
        <logger level="INFO" doc:name="Input Message" doc:id="61810594-b3ac-45f7-859e-81ddc3aef01b" message="Input Message : #[vars.requestedBody]"/>
90
        <xml-module:validate-schema doc:name="Validate schema" doc:id="06ae8cf9-4cdb-4f54-8215-b91411253fc3" config-ref="XML_Config" schemas="xsd\personService.xsd">
91
            <xml-module:content ><![CDATA[#[vars.requestedBody]]]></xml-module:content>
92
        </xml-module:validate-schema>
93
</sub-flow>
94
</mule>
95

          



XML

Opinions expressed by DZone contributors are their own.

Related

  • The Hidden Engineering Cost of XML in Enterprise Development Workflows
  • How to Convert XLS to XLSX in Java
  • Thread-Safety Pitfalls in XML Processing
  • Loading XML into MongoDB

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook