promptsimpleIntegration Flowadvanced

S4HANA System API

Generate a System API exposing records in SAP S4/HANA

(0 reviews)
0 forks
Nico Balestraby Nico Balestra

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

  1. 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.connectors with ${anypoint.org.id}.
  2. Secure Properties (src/main/resources/config-dev.yaml):

    • Include placeholders: ${secure::s4hana.username}, ${secure::s4hana.password}, ${secure::s4hana.baseUrl}.

================================================================================ PART 2: EXACT COMPONENT, DATAWEAVE & CONTEXT RULES

  1. Multi-Context Logging Rules (HTTP + MCP flow-ref Safety):

    • In flows that are invoked by both HTTP Listeners AND flow-ref (e.g. from MCP tool flows), attributes.queryParams or attributes.method MAY 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")]'
  2. SAP S/4HANA OData Connector (s4hana-odata-impl.xml):

    • Namespace: xmlns:s4hana="http://www.mulesoft.org/schema/mule/s4hana"
    • Operation: <s4hana:query> targeting API_BUSINESS_PARTNER / A_BusinessPartner.
    • Query Parameter Rules (MUST use bracket notation ['$param'] and explicit if/else null-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.
  3. 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/operation ZSALES_ORDER_CREATE.
  4. 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>
      

================================================================================ PART 3: IMPLEMENTATION FLOWS (13 Artifacts Total)

  1. global.xml:

    • Configs for HTTP_Listener_Config, SAP_S4HANA_OData_Config, SAP_S4HANA_SOAP_Config, Secure_Properties_Config, and MCP_Server_Config.
    • Global Error Handler: Global_Error_Handler routing S4HANA:CONNECTIVITY (503), S4HANA:UNAUTHORIZED (401), EXPRESSION (400), and ANY (500) into a canonical JSON error envelope {code, message, correlationId, timestamp}.
  2. 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 Ref Global_Error_Handler.
  3. 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 Ref Global_Error_Handler.
  4. mcp-interface.xml:

    • Implement mcp-get-customer-tool-flow (get_customers) and mcp-create-order-tool-flow (create_sales_order).
    • Delegate via flow-ref to s4hana-odata-get-customers-flow and s4hana-soap-create-order-flow.

================================================================================ PART 4: MUNIT 2.X TEST SUITE & MOCK RESOURCES

  1. 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.
  2. MUnit Suites (src/test/munit/):

    • s4hana-odata-impl-test-suite.xml: Mock s4hana:query with MunitTools::getResourceAsString(). Assert status 200. Test S4HANA:CONNECTIVITY asserting 503 response.
    • s4hana-soap-impl-test-suite.xml: Mock s4hana-soap:invoke. Assert vars.originalPayload preservation and HTTP 201. Test invalid payload asserting SAP connector is never called (count 0) and HTTP 400.
    • mcp-interface-test-suite.xml: Use munit-tools:spy targeting flow-ref to 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

0 people tried this

Sign in to share your experience with this prompt.

Tags

sapsapisystem-apiapi-led

Reviews (0)

Sign in to leave a review.

No reviews yet. Be the first to share your experience!

Comments (0)

Sign in to leave a comment.

No comments yet. Be the first to share your thoughts!