S4HANA System API
Generate a System API exposing records in SAP S4/HANA
Prompt
…
Act as a Principal MuleSoft Architect and Test Automation Lead. Generate a complete, production-grade Mule 4 System API named "s4hana-system-api" for SAP S/4HANA integration, targeting Mule Runtime 4.11.2 and Java 17, alongside a comprehensive MUnit 2.x test suite adhering to API-Led Connectivity best practices.
================================================================================ PART 1: MAVEN DEPENDENCIES & PROJECT SETUP
-
pom.xml: Include exact official Exchange connector dependencies with<classifier>mule-plugin</classifier>:- SAP S/4HANA OData Connector:
com.mulesoft.connectors:mule-sap-s4hana-cloud-connector:2.9.4 - SAP S/4HANA SOAP Connector:
com.mulesoft.connectors:mule-sap-s4hana-soap-cloud-connector:2.6.0(MUST include -cloud-) - Anypoint MCP Connector:
com.mulesoft.connectors:mule-mcp-connector:1.6.0 - Secure Configuration Module:
com.mulesoft.modules:mule-secure-configuration-property-module:1.2.6 - MUnit Plugins & Runners:
munit-runner:3.2.0,munit-tools:3.2.0,munit-maven-plugin:3.2.0 - Include XML comments explaining that private Exchange v3 repos replace
com.mulesoft.connectorswith${anypoint.org.id}.
- SAP S/4HANA OData Connector:
-
Secure Properties (
src/main/resources/config-dev.yaml):- Include placeholders:
${secure::s4hana.username},${secure::s4hana.password},${secure::s4hana.baseUrl}.
- Include placeholders:
================================================================================ PART 2: EXACT COMPONENT, DATAWEAVE & CONTEXT RULES
-
Multi-Context Logging Rules (HTTP + MCP
flow-refSafety):- In flows that are invoked by both HTTP Listeners AND
flow-ref(e.g. from MCP tool flows),attributes.queryParamsorattributes.methodMAY BE NULL. - DO NOT execute
write(attributes.queryParams)directly in loggers. Use null-safe expressions:message='#["[ENTRY] flow=s4hana-odata-get-customers-flow | correlationId=" ++ correlationId ++ " | method=" ++ (attributes.method default "INTERNAL") ++ " | path=" ++ (attributes.requestPath default "INTERNAL")]'
- In flows that are invoked by both HTTP Listeners AND
-
SAP S/4HANA OData Connector (
s4hana-odata-impl.xml):- Namespace:
xmlns:s4hana="http://www.mulesoft.org/schema/mule/s4hana" - Operation:
<s4hana:query>targetingAPI_BUSINESS_PARTNER/A_BusinessPartner. - Query Parameter Rules (MUST use bracket notation
['$param']and explicitif/elsenull-guards to avoid IDE scope false-positives and coercion crashes):top="#[if (attributes.queryParams['$top'] != null) (attributes.queryParams['$top'] as Number) else 100]"(Default 100 prevents unbounded SAP queries)skip="#[if (attributes.queryParams['$skip'] != null) (attributes.queryParams['$skip'] as Number) else 0]"filter="#[attributes.queryParams['$filter']]"select="#[attributes.queryParams['$select'] default '*']"orderBy="#[attributes.queryParams['$orderby']]"
- Error Namespace:
S4HANA:CONNECTIVITY,S4HANA:UNAUTHORIZED.
- Namespace:
-
SAP S/4HANA SOAP Connector (
s4hana-soap-impl.xml):- Namespace:
xmlns:s4hana-soap="http://www.mulesoft.org/schema/mule/s4hana-soap" - Operation:
<s4hana-soap:invoke>targeting service/operationZSALES_ORDER_CREATE.
- Namespace:
-
Anypoint MCP Server & Listener (
mcp-interface.xml):- Server Config:
<mcp:streamable-http-server-connection listenerConfig="HTTP_Listener_Config" mcpEndpointPath="/mcp"/>. - Tool Listener Syntax (
<mcp:tool-listener>): MUST use child elements (NOT XML attributes) for description, parameters-schema, and responses:<mcp:tool-listener config-ref="MCP_Server_Config" name="get_customers" doc:name="MCP Tool: get_customers" doc:id="mcp-tool-listener-get-customers"> <mcp:description>Retrieve SAP S/4HANA Business Partners...</mcp:description> <mcp:parameters-schema><![CDATA[{ "type": "object", ... }]]></mcp:parameters-schema> <mcp:responses> <mcp:text-tool-response-content text="#[output application/json --- payload]"/> </mcp:responses> </mcp:tool-listener>
- Server Config:
================================================================================ PART 3: IMPLEMENTATION FLOWS (13 Artifacts Total)
-
global.xml:- Configs for
HTTP_Listener_Config,SAP_S4HANA_OData_Config,SAP_S4HANA_SOAP_Config,Secure_Properties_Config, andMCP_Server_Config. - Global Error Handler:
Global_Error_HandlerroutingS4HANA:CONNECTIVITY(503),S4HANA:UNAUTHORIZED(401),EXPRESSION(400), andANY(500) into a canonical JSON error envelope{code, message, correlationId, timestamp}.
- Configs for
-
s4hana-odata-impl.xml(GET /api/v1/customers):- HTTP Listener -> Context-Safe ENTRY Logger ->
s4hana:query(with guarded DW bracket query params) -> DataWeave (to canonical JSON) -> EXIT Logger -> Error Handler RefGlobal_Error_Handler.
- HTTP Listener -> Context-Safe ENTRY Logger ->
-
s4hana-soap-impl.xml(POST /api/v1/orders):- HTTP Listener -> Set Variable (
vars.originalPayload) -> Context-Safe ENTRY Logger -> DataWeave Validation (dw::Runtime::fail) -> DataWeave (JSON to SOAP XML) ->s4hana-soap:invoke-> DataWeave (SOAP XML to JSON) -> Set HTTP status 201 -> EXIT Logger -> Error Handler RefGlobal_Error_Handler.
- HTTP Listener -> Set Variable (
-
mcp-interface.xml:- Implement
mcp-get-customer-tool-flow(get_customers) andmcp-create-order-tool-flow(create_sales_order). - Delegate via
flow-reftos4hana-odata-get-customers-flowands4hana-soap-create-order-flow.
- Implement
================================================================================ PART 4: MUNIT 2.X TEST SUITE & MOCK RESOURCES
-
Mock Resources (
src/test/resources/mock_data/):mock-odata-customers-response.json,mock-soap-create-order-response.xml,mock-create-order-request.json,mock-create-order-invalid-request.json.
-
MUnit Suites (
src/test/munit/):s4hana-odata-impl-test-suite.xml: Mocks4hana:querywithMunitTools::getResourceAsString(). Assert status 200. TestS4HANA:CONNECTIVITYasserting 503 response.s4hana-soap-impl-test-suite.xml: Mocks4hana-soap:invoke. Assertvars.originalPayloadpreservation and HTTP 201. Test invalid payload asserting SAP connector is never called (count 0) and HTTP 400.mcp-interface-test-suite.xml: Usemunit-tools:spytargetingflow-refto verify parameter pass-through.
Output complete, syntactically correct XML files, DataWeave scripts, configuration files, and MUnit suites for all 13 artifacts.
….. Ignore below dotted line
Fix — Reload the VS Code window (one-time action)
Press ⌘ Shift P → type Developer: Reload Window → Enter
mvn clean package -DskipTests -Denv=dev -Denc.key=changeme32charkey0000000000000000
Maven dependency:resolve
Community Results
Sign in to share your experience with this prompt.
