Contact Us 1-800-596-4880

SAP S/4HANA SOAP Cloud - Examples - Mule 4

This example sends an XML request to SAP S/4HANA’s SOAP API and prints the response.

In Anypoint Studio 7, the flow appears as:

sap s4hana soap demo flow

POM File for This Example

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.mycompany</groupId>
	<artifactId>sap-hana-soap-demo</artifactId>
    	<version>1.0.0</version>
    	<packaging>mule-application</packaging>

	<name>sap-hana-soap-demo</name>

    <properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

		<app.runtime>4.2.0</app.runtime>
		<mule.maven.plugin.version>3.2.7</mule.maven.plugin.version>
	</properties>

	<build>
	   <plugins>
	      <plugin>
		 <groupId>org.mule.tools.maven</groupId>
		 <artifactId>mule-maven-plugin</artifactId>
		 <version>${mule.maven.plugin.version}</version>
		 <extensions>true</extensions>
	      </plugin>
	   </plugins>
	</build>

	<dependencies>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-http-connector</artifactId>
            <version>1.5.3</version>
            <classifier>mule-plugin</classifier>
        </dependency>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-sockets-connector</artifactId>
            <version>1.1.5</version>
            <classifier>mule-plugin</classifier>
        </dependency>
        <dependency>
	    <groupId>com.mulesoft.connectors.ea</groupId>
	    <artifactId>mule4-sap-s4hana-soap-cloud-connector</artifactId>
	    <version>1.0.0</version>
	    <classifier>mule-plugin</classifier>
	    </dependency>
	</dependencies>

	<repositories>
          <repository>
            <id>anypoint-exchange</id>
            <name>Anypoint Exchange</name>
            <url>https://maven.anypoint.mulesoft.com/api/v1/maven</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>mulesoft-releases</id>
            <name>MuleSoft Releases Repository</name>
            <url>https://repository.mulesoft.org/releases/</url>
            <layout>default</layout>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>mulesoft-releases</id>
            <name>mulesoft release repository</name>
            <layout>default</layout>
            <url>https://repository.mulesoft.org/releases/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>

XML Code for This Example

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

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	xmlns:s4hana-soap="http://www.mulesoft.org/schema/mule/s4hana-soap"
	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: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/s4hana-soap
	http://www.mulesoft.org/schema/mule/s4hana-soap/current/mule-s4hana-soap.xsd
	http://www.mulesoft.org/schema/mule/ee/core
	http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config">
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>

	<configuration-properties
		doc:name="Configuration properties"
		file="mule-artifact.properties" />

	<s4hana-soap:config
		name="SAP_S4_HANA_Cloud_SOAP_Config"
		doc:name="SAP S4 HANA Cloud SOAP Config" >
		<s4hana-soap:basic-authentication-connection
			baseUrl="${config.serviceBaseUrl}"
			username="${config.username}"
			password="${config.password}" />
	</s4hana-soap:config>
	<flow name="htmlPageFlow" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/"/>
		<parse-template doc:name="Parse Template"  location="form.html"/>
	</flow>
	<flow name="queryFlow"  >
		<http:listener doc:name="Listener"  config-ref="HTTP_Listener_config" path="/query"/>
		<ee:transform doc:name="Transform Message"  >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/xml
ns ns0 http://sap.com/xi/SAPGlobal/Global
---
{
	ns0#CreditManagementAccountByIDQuery: {
		MessageHeader: {
			ID: "@" as String,
			CreationDateTime: now()
		},
		Selection: {
			DebtorPartyInternalID: attributes.queryParams['DebtorPartyInternalID'] as String,
			CreditsegmentInternalID: attributes.queryParams['CreditsegmentInternalID'] as String
		},
		LanguageCode: "ZZZ" as String
	}
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO"
			doc:name="Logger"
			message="Request #[payload]"/>
		<s4hana-soap:invoke
			doc:name="Invoke"
			config-ref="SAP_S4_HANA_Cloud_SOAP_Config"
			service="https://mysap.s4hana.instance.com/sap/bc/srt/wsdl_ext/flv_10002S111AD1/srvc_url/sap/bc/srt/scs_ext/sap/creditmanagementaccountbyidqu1"
			operation="CreditManagementAccountByIDQuery_In">
		</s4hana-soap:invoke>
		<logger level="INFO" doc:name="Logger"  message="Response #[payload]"/>
		<ee:transform doc:name="Transform Message" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/xml
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
	</flow>
</mule>
View on GitHub