Soap Component
-
Upload
sivachandra-mandalapu -
Category
Education
-
view
67 -
download
1
Transcript of Soap Component
SOAP Component
Abstract
The main motto of this PPT is How to use SOAP Component in our applications.
Introduction
The Mule SOAP component is used for publishing, consuming, and proxying of SOAP web services within a Mule flow. Using the SOAP component, you can also enable Web Service Security. Apache CXF is an open source services framework. CXF helps you build services using frontend programming APIs such as JAX-WS and JAX-RS.
Example
ArthematicOperationsa. Additionb. Subtractionc. Multiplication
1. Create .xsd (XML Schema file) file like below:
Source:<?xml version="1.0" encoding="UTF-8"?><schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/ArthematicOperations" xmlns:tns="http://www.example.org/ArthematicOperations" elementFormDefault="qualified">
<element name="AddRequest" type="tns:InputRequestType"></element> <element name="AddResponse" type="tns:OutputResponseType"></element> <element name="SubRequest" type="tns:InputRequestType"></element> <element name="SubResponse" type="tns:OutputResponseType"></element> <element name="MulRequest" type="tns:InputRequestType"></element> <element name="MulResponse" type="tns:OutputResponseType"></element> <complexType name="InputRequestType"> <sequence> <element name="Num1" type="int"></element> <element name="Num2" type="int"></element> </sequence> </complexType> <complexType name="OutputResponseType"> <sequence> <element name="Result" type="int"></element> </sequence> </complexType></schema>
2. Create WSDL file like below:
Source:<?xml version="1.0" encoding="UTF-8" standalone="no"?><wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/ArthematicOperations/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ArthematicOperations" targetNamespace="http://www.example.org/ArthematicOperations/" xmlns:xsd1="http://www.example.org/ArthematicOperations"> <wsdl:types> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:import namespace="http://www.example.org/ArthematicOperations" schemaLocation="ArthematicOperations.xsd"> </xsd:import></xsd:schema></wsdl:types> <wsdl:message name="AdditionRequest"> <wsdl:part element="xsd1:AddRequest" name="AddRequest"/> </wsdl:message> <wsdl:message name="AdditionResponse"> <wsdl:part element="xsd1:AddResponse" name="AddResponse"/> </wsdl:message> <wsdl:message name="SubractionRequest"> <wsdl:part name="SubRequest" element="xsd1:SubRequest"></wsdl:part> </wsdl:message> <wsdl:message name="SubractionResponse"> <wsdl:part name="SubResponse" element="xsd1:SubResponse"></wsdl:part> </wsdl:message> <wsdl:message name="MultiplacationRequest"> <wsdl:part name="MulRequest" element="xsd1:MulRequest"></wsdl:part> </wsdl:message> <wsdl:message name="MultiplacationResponse"> <wsdl:part name="MulResponse" element="xsd1:MulResponse"></wsdl:part> </wsdl:message> <wsdl:portType name="ArthematicOperations"> <wsdl:operation name="Addition"> <wsdl:input message="tns:AdditionRequest"/> <wsdl:output message="tns:AdditionResponse"/> </wsdl:operation>
<wsdl:operation name="Subraction"> <wsdl:input message="tns:SubractionRequest"></wsdl:input> <wsdl:output message="tns:SubractionResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="Multiplacation"> <wsdl:input message="tns:MultiplacationRequest"></wsdl:input> <wsdl:output message="tns:MultiplacationResponse"></wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="ArthematicOperationsSOAP" type="tns:ArthematicOperations"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="Addition"> <soap:operation soapAction="http://www.example.org/ArthematicOperations/Addition"/> <wsdl:input> <soap:body use="literal" parts="AddRequest "/> </wsdl:input> <wsdl:output> <soap:body use="literal" parts="AddResponse "/> </wsdl:output> </wsdl:operation> <wsdl:operation name="Subraction"> <soap:operation soapAction="http://www.example.org/ArthematicOperations/Subraction"/> <wsdl:input> <soap:body use="literal" parts="SubRequest "/> </wsdl:input> <wsdl:output> <soap:body use="literal" parts="SubResponse "/> </wsdl:output> </wsdl:operation>
<wsdl:operation name="Multiplacation"> <soap:operation soapAction="http://www.example.org/ArthematicOperations/Multiplacation"/> <wsdl:input> <soap:body use="literal" parts="MulRequest "/> </wsdl:input> <wsdl:output> <soap:body use="literal" parts="MulResponse "/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="ArthematicOperations"> <wsdl:port binding="tns:ArthematicOperationsSOAP" name="ArthematicOperationsSOAP"> <soap:address location="http://www.example.org/"/> </wsdl:port> </wsdl:service></wsdl:definitions>
3. Convert the above .WSDL to .java files using apache cxf
4. Mule application:
5. Copy the step-3 result into src\main\java folder.6. Add the interface name (will be in step-3 result) in SOAP component.
7. Create interface implement class
package com.impl;
import javax.jws.WebMethod;import javax.jws.WebParam;import javax.jws.WebResult;
import org.example.arthematicoperations.ArthematicOperations;import org.example.arthematicoperations.InputRequestType;import org.example.arthematicoperations.OutputResponseType;
public class ArthematicOperationsImpl implements ArthematicOperations {
@Override@WebResult(name="SubResponse", targetNamespace="http://www.example.org/ArthematicOperations", partName="SubResponse")@WebMethod(operationName="Subraction", action="http://www.example.org/ArthematicOperations/Subraction")public OutputResponseType subraction(@WebParam(partName="SubRequest", name="SubRequest", targetNamespace="http://www.example.org/ArthematicOperations")InputRequestType subRequest) {
OutputResponseType outputResponseType = new OutputResponseType();outputResponseType.setResult(subRequest.getNum1()-subRequest.getNum2());return outputResponseType;
}
@Override@WebResult(name="AddResponse", targetNamespace="http://www.example.org/ArthematicOperations", partName="AddResponse")@WebMethod(operationName="Addition", action="http://www.example.org/ArthematicOperations/Addition")public OutputResponseType addition(@WebParam(partName="AddRequest", name="AddRequest", targetNamespace="http://www.example.org/ArthematicOperations")InputRequestType addRequest) {
OutputResponseType outputResponseType = new OutputResponseType();outputResponseType.setResult(addRequest.getNum1()+addRequest.getNum2());return outputResponseType;
}
@Override@WebResult(name="MulResponse", targetNamespace="http://www.example.org/ArthematicOperations", partName="MulResponse")@WebMethod(operationName="Multiplacation", action="http://www.example.org/ArthematicOperations/Multiplacation")public OutputResponseType multiplacation(@WebParam(partName="MulRequest", name="MulRequest",
targetNamespace="http://www.example.org/ArthematicOperations")InputRequestType mulRequest) {
OutputResponseType outputResponseType = new OutputResponseType();outputResponseType.setResult(mulRequest.getNum1()*mulRequest.getNum2());return outputResponseType;
}}
.mflow<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsdhttp://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsdhttp://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsdhttp://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd"> <flow name="SOAPPOCFlow1" doc:name="SOAPPOCFlow1"> <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8095" doc:name="HTTP"/> <logger message="--Entered into the flow" level="INFO" doc:name="Logger"/> <cxf:jaxws-service serviceClass="org.example.arthematicoperations.ArthematicOperations" doc:name="SOAP"/> <component class="com.impl.ArthematicOperationsImpl" doc:name="ArthematicOperationsImpl"/> </flow></mule>
8. How to test this?a. Open SOAP UI and import the above wsdl
into it.File->New SOAP UI Project-> Fill Project Name and Initial WSDL fields->OK
b. Trigger the methods:1. Addition:
Console:INFO 2015-12-15 15:32:29,311 [main] org.mule.DefaultMuleContext: *********************************************************************** Application: SOAPPOC ** OS encoding: Cp1252, Mule encoding: UTF-8 ** ** Agents Running: ** Clustering Agent ** JMX Agent ***********************************************************************INFO 2015-12-15 15:32:29,313 [main] org.mule.module.launcher.MuleDeploymentService: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Started app 'SOAPPOC' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++INFO 2015-12-15 15:32:44,490 [[SOAPPOC].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: --Entered into the flow
References
https://docs.mulesoft.com/mule-user-guide/v/3.7/publishing-and-consuming-apis-with-mule