Proxy Pattern

Use Case: Proxy Service transforms and enriches payload before creating record in Salesforce. We have system A where our support agents are working are not in Salesforce(system B). These support agents need to create case in system B . System A can invoke SOAP API’s. We do not want System A to directly make calls to System B. We want mediator to proxy System B. In our case we will use MuleSoft as mediator.

Initiator: System A where support agents are working.
Proxy: MuleSoft is acting as a web service proxy
Partner: Salesforce.

HTTP Listener Connector: Listen for HTTP requests
https://docs.mulesoft.com/mule-user-guide/v/3.9/http-listener-connector

CXF Proxy :To proxy web service and to work on SOAP Body
https://docs.mulesoft.com/mule-user-guide/v/3.9/proxying-web-services-with-cxf

Logger Component: To log payload, messages are logged to the app’s log file
https://docs.mulesoft.com/mule4-user-guide/v/4.1/logger-component-reference

Transform Message: Transform request and response message using DataWeave. Transform message to link related Salesforce account to case using external id of account object.
https://docs.mulesoft.com/mule-user-guide/v/3.9/dataweave

Salesforce Connector: Lets us connect to the Salesforce platform
https://docs.mulesoft.com/mule-user-guide/v/3.9/salesforce-connector

Testing: Used SOAP UI to test proxy service

System B (Salesforce)

MuleSoft Flow configuration file

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:http="http://www.mulesoft.org/schema/mule/http" 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" 
	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.xsd
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/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/sfdc http://www.mulesoft.org/schema/mule/sfdc/current/mule-sfdc.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" basePath="api" doc:name="HTTP Listener Configuration"/>
    <cxf:configuration name="CXF_Configuration" enableMuleSoapHeaders="true" initializeStaticBusInstance="true" doc:name="CXF Configuration"/>
    <sfdc:config name="Salesforce__Basic_Authentication" username="xxxxxxx@xxxx.xxxx" password="xxxxxxx" securityToken="xxxxxxxxxxxxxxx" doc:name="Salesforce: Basic Authentication"/>
    <flow name="spdcproxyFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/case" doc:name="HTTP"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <cxf:proxy-service configuration-ref="CXF_Configuration" namespace="http://service.chc.com/" service="CaseServiceService" payload="body" wsdlLocation="case-api.wsdl" doc:name="CXF"/>
        <mulexml:dom-to-xml-transformer mimeType="text/xml" doc:name="DOM to XML"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <dw:transform-message doc:name="Transform Message" metadata:id="fc51d386-61cb-439e-9009-fd57d25374e4">
            <dw:input-payload mimeType="application/xml"/>
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
%namespace ns0 http://service.chc.com/
---
{
	Account: {
		Customer_Id__c: payload.ns0#createCase.arg0.customerNumber
	},
	ContactId: payload.ns0#createCase.arg0.contact,
	Subject: payload.ns0#createCase.arg0.subject,
	Description: payload.ns0#createCase.arg0.description
}]]></dw:set-payload>
        </dw:transform-message>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <sfdc:create-single config-ref="Salesforce__Basic_Authentication" type="Case" doc:name="Salesforce">
        </sfdc:create-single>
        <set-variable variableName="Id" value="#[message.payload.id]" doc:name="Variable"/>
        <dw:transform-message doc:name="Transform Message" metadata:id="b615499e-6da5-417d-8436-dc8b7a4ebcb0">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 http://service.chc.com/
---
{
	ns0#createCaseResponse: {
		return: {
			id: payload.id,
			success: payload.success as :string
		}
	}
}]]></dw:set-payload>
        </dw:transform-message>
        <sfdc:query config-ref="Salesforce__Basic_Authentication" query="dsql:SELECT CaseNumber,Id FROM Case WHERE id = '#[flowVars.id]' LIMIT 1" doc:name="Salesforce"/>
        <dw:transform-message doc:name="Transform Message" metadata:id="e233a72e-2c00-4094-89b8-acd79bba51e6">
            <dw:input-payload doc:sample="sample_data\list_Case.dwl"/>
            <dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 http://service.chc.com/
---
{
	ns0#createCaseResponse: {
		return: {
			id: payload.Id[0],
			caseNumber: payload.CaseNumber[0]
		}
	}
}]]></dw:set-payload>
        </dw:transform-message>
    </flow>
</mule>