Loading…
Loading…
Explains the consume data path handler, which transforms inbound SOAP requests into outbound REST calls, validates payloads, and maps REST responses back
The ConsumeSoapHandler is a core runtime component responsible for implementing the "consume" data path. It enables the platform to receive a SOAP request from an API consumer, transform it into a REST request, send it to a configured backend REST service, and then map the REST response back into a SOAP response.
This handler acts as a bridge, allowing API publishers to expose a modern REST-based backend as a traditional SOAP service without modifying the backend. It orchestrates the entire request-response lifecycle for this transformation, including:
POST, GET) and vice-versa.The handler is invoked by the runtime controller, which passes it the inbound request details and the configuration for the matched API route. It returns a structured Result containing the complete SOAP response (or fault) to be sent back to the API consumer.
The ConsumeSoapHandler processes an inbound SOAP request through a multi-step pipeline to produce a corresponding SOAP response. The process involves parsing, validation, a backend REST call, and response generation.
flowchart TD
A[API Consumer] -- SOAP Request --> B[API Gateway: ConsumeSoapHandler];
B --> C{1. Parse SOAP to JSON};
C --> D{2. Validate Request JSON<br/>(Schema & Regex)};
D -- Invalid --> J[Build SOAP Fault];
D -- Valid --> E{3. Prepare REST Request<br/>(URL, Body, Auth)};
E --> F[4. Dispatch REST Call];
subgraph "Backend"
G[REST Service]
end
F -- Direct or via Relay --> G;
G -- REST Response --> H{5. Handle REST Response};
B -- REST Call --> H
H -- Transport/HTTP Error --> J;
H -- Success (2xx) --> I{6. Validate REST Response<br/>(Schema & Regex)};
I -- Invalid --> J;
I -- Valid --> K{7. Build SOAP Response};
J --> L[SOAP Response (Fault)];
K --> M[SOAP Response (Success)];
L --> A;
M --> A;Content Validation: The handler first inspects the Content-Type header of the inbound request. It accepts text/xml (SOAP 1.1), application/soap+xml (SOAP 1.2), application/xml, and multipart/related (for MTOM). Any other content type is rejected with a 415 Unsupported Media Type error (S2R-RUN-0408).
SOAP Version Detection: It determines the SOAP version (1.1 or 1.2) by inspecting the SOAP envelope's XML namespace. This version is used to format the final SOAP response or fault, ensuring the consumer receives a reply in the version it sent.
MTOM Handling: If the request is multipart/related, the handler inlines any attachments referenced by xop:Include elements. It decodes the attachments and embeds them as base64-encoded strings directly into the SOAP body, producing a standard SOAP envelope for the next steps. This process is protected against DoS attacks by enforcing limits on part count and total payload size.
SOAP-to-JSON Parsing: The SOAP body is parsed into a JSON object. This transformation is guided by the request_mapping defined in the operation's route configuration. If the inbound SOAP message is malformed or is itself a SOAP Fault, the process is aborted and a soap:Client fault is generated (S2R-RUN-0409).
Request Payload Validation: Before contacting the backend, the generated JSON payload undergoes two validation steps:
400 Bad Request fault (S2R-VAL-0410).requestFieldValidationRegexes configured, specific fields in the JSON are validated against regular expressions. A mismatch also results in a 400 Bad Request fault (S2R-VAL-0411).Outbound REST Request Preparation:
endpointUrl and the route's restPath.POST, GET) is taken from the route's restMethod.POST/PUT/PATCH requests, the validated JSON becomes the request body. For GET/DELETE requests, the body is empty, and the JSON fields are encoded as URL query string parameters.X-Correlation-Id is also forwarded to the backend to enable distributed tracing.oauth2_client_credentials authentication, the handler fetches a bearer token and adds it to the Authorization header. If mTLS is enabled, the appropriate SSL context is prepared for the call.Backend REST Call: The handler dispatches the REST request.
dispatch_mode=relay is configured, routed through a relay service for backends in private networks.retry_count and retry_backoff_ms settings in the backend profile.REST Response Handling:
S2R-RUN-0424), or circuit breaker trips (S2R-RUN-0529) are mapped to a soap:Server fault.401 Unauthorized and OAuth 2.0 is in use, the handler automatically invalidates the cached token, fetches a new one, and retries the request once.Response Payload Validation: For successful (2xx) REST responses, the JSON response body can be validated against the operation's OpenAPI response schema and response-side field regexes. A validation failure in enforce mode results in a soap:Server fault (S2R-VAL-0430 for schema, S2R-VAL-0431 for regex), preventing a malformed response from reaching the consumer.
JSON-to-SOAP Building: The validated JSON response is transformed back into a SOAP XML payload using the response_mapping from the route configuration. The resulting SOAP envelope is constructed using the same SOAP version as the original request.
Final Result: The handler returns the final SOAP envelope (success or fault) and associated metadata to the controller, which sends the HTTP response to the API consumer.
The primary entry point is the handle method. Several overloads exist for backward compatibility, but the full 7-argument version provides complete control.
handle Methodpublic Result handle(
RouteMetadata route,
BackendTargetMetadata backendTarget,
String inboundSoapBody,
String authorizationHeader,
ConversionModes modes,
UUID correlationId,
String soapVersion
)
Executes the full consume flow.
Parameters:
route: RouteMetadata containing the configuration for the matched API operation, including mappings, validation rules, and timeouts.backendTarget: BackendTargetMetadata defining the target REST backend, including its URL, authentication method, and retry settings.inboundSoapBody: The raw string content of the inbound SOAP request body.authorizationHeader: The Authorization header from the inbound request, if any.modes: A ConversionModes record specifying overrides for data type conversions.correlationId: A UUID for tracing the request through the system. This ID is forwarded to the backend in the X-Correlation-Id header.soapVersion: A string, either "1.1" or "1.2", indicating the SOAP version of the inbound request. This determines the version of the outbound response.Returns: A Result record containing the outcome of the operation.
Result RecordThe handle method returns a Result object that encapsulates the outcome.
| Field | Type | Description |
|---|---|---|
httpStatus | int | The HTTP status code to return to the API consumer (e.g., 200 for success, 415 for bad content type). |
contentType | String | The Content-Type header for the SOAP response (e.g., text/xml; charset=utf-8). |
responseBody | String | The full SOAP response envelope or SOAP Fault as a string. |
resultCode | String | A code indicating the outcome: success, error, or fault. |
errorCode | String | The platform-specific error code (e.g., S2R-RUN-0408) if the operation failed. |
errorMessage | String | A human-readable summary of the error. |
backendLatencyMs | Integer | The latency of the call to the backend REST service in milliseconds. |
soapFaultCode | String | The SOAP fault code (e.g., soap:Client, soap:Server) embedded in the fault response. |
faultClass | String | A classification of the failure type, such as client_error, transport_failure, or backend_4xx. |
validateContentType(HttpServletRequest request): Checks if the request's Content-Type is a supported SOAP type. Returns a Result object for a 415 error if invalid, or null if valid.detectSoapVersion(HttpServletRequest request, String inboundSoapBody): Returns "1.1" or "1.2" based on the SOAP envelope namespace or Content-Type header.isMtomInbound(HttpServletRequest request): Returns true if the request Content-Type is multipart/related.inlineMtomInbound(String rawBody, String contentType): Parses a multipart/related body, inlines attachments as base64, and returns the resulting plain SOAP envelope as a string.The handler's behavior is primarily configured through the RouteMetadata, BackendTargetMetadata, and ConversionModes objects passed to it. The ConversionModes record provides fine-grained control over data type conversions during the SOAP-to-JSON and JSON-to-SOAP transformations.
ConversionModes RecordThis record allows an API publisher to override default conversion behaviors for boolean and null values, both globally and on a per-field basis.
| Field | Type | Description |
|---|---|---|
boolMode | String | The global strategy for handling boolean values. a |
nullRequestMode | String | The strategy for handling nulls when building the SOAP response from the REST response JSON. |
nullResponseMode | String | The strategy for handling nulls when parsing the inbound SOAP request into JSON. |
requestFieldBoolean | Map<String, String> | Per-field overrides for boolean handling when building the SOAP response. The map keys are field paths. |
responseFieldBoolean | Map<String, String> | Per-field overrides for boolean handling when parsing the SOAP request. The map keys are field paths. |
requestFieldNull | Map<String, String> | Per-field overrides for null handling when building the SOAP response. The map keys are field paths. |
responseFieldNull | Map<String, String> | Per-field overrides for null handling when parsing the SOAP request. The map keys are field paths. |
When the ConsumeSoapHandler encounters an issue, it generates a SOAP Fault and returns a specific error code in the Result object. These codes are logged and can be used for diagnostics.
| Error Code | Trigger | Meaning |
|---|---|---|
S2R-RUN-0408 | The inbound request's Content-Type is not text/xml, application/soap+xml, application/xml, or multipart/related. | The API consumer sent a request with an unsupported media type. The response is an HTTP 415. |
S2R-RUN-0409 | The inbound SOAP envelope is malformed, cannot be parsed, or is itself a SOAP Fault. | The API consumer sent an invalid SOAP message. The response is an HTTP 400 with a soap:Client fault. |
S2R-VAL-0410 | The JSON generated from the SOAP request failed validation against the operation's OpenAPI request schema. | The data sent by the API consumer does not conform to the API contract. The response is an HTTP 400 with a soap:Client fault. |
S2R-VAL-0411 | A field in the JSON generated from the SOAP request failed validation against a configured regular expression. | The data sent by the API consumer contains an invalid field format. The response is an HTTP 400 with a ` |