Loading…
Loading…
Configure per-operation and per-field binary encoding overrides, including modes and data URL MIME types, for API responses in the runtime.
The BinaryHandlingApplyService provides a mechanism for API publishers to apply fine-grained binary content handling overrides for specific API operations. This service allows customization of how binary data from a backend SOAP response is encoded in the final API response, on a per-operation and even per-field basis.
This is necessary when the system-wide default binary handling strategy is not suitable for a particular operation. The runtime uses a resolution chain to determine the encoding for a given field: it first looks for a per-field override, then an operation-level override, and finally falls back to the system default. This service configures the first two links in that chain.
An API publisher invokes this service to modify the configuration of an operation that is part of a service version in a draft state. The service validates the inputs, merges them with existing settings, and persists them to the s2r_operation_mapping table.
The service applies a set of overrides to an operation's active mapping in a single, transactional database update. The core logic resides in the apply method.
flowchart TD
subgraph "apply() Method"
A[Start] --> B{Normalize Inputs};
B --> C{Read Existing Field Overrides};
C --> D{Process New Field Overrides};
D --> E{Validate Operation Mutability};
E --> F{Serialize Merged Field Map};
F --> G{Update Database};
G --> H[Return Result];
end
subgraph "Error Paths"
B -- Invalid Mode/MIME --> I(Throw S2R-VAL-0497);
D -- Invalid XPath --> I;
E -- Version Not Draft --> J(Throw S2R-ADM-0410);
E -- Operation Not Found --> K(Throw S2R-ADM-0404);
F -- Serialization Failure --> I;
G -- No Active Mapping --> K;
endThe process consists of the following steps:
Input Normalization: The operation-level operationOverride mode and dataUrlMimeOverride are normalized. Normalization involves trimming whitespace and, for the mode, converting to lowercase. If a provided mode or MIME type is invalid, the process fails. An empty or null string for either value clears the existing override.
Field Map Retrieval: The service reads the existing response_field_binary_handling JSONB data from the s2r_operation_mapping table for the specified operationId. This represents the current set of per-field overrides.
Field Override Merging: The service iterates through the fieldOverrides list provided in the request.
soapXPath is required for every field override entry.mode is null or blank, the existing override for that soapXPath is removed from the map.mode, it is added to or updated in the map. The mode is validated against a list of supported values. An optional dataUrlMime can be provided and is validated to be a compliant RFC 6838 token.Mutability Validation: The service retrieves metadata for the target operation. It verifies that the operation's parent service version is in a draft state and is not active. Configuration for active or non-draft service versions is immutable, and attempts to modify it will be rejected.
Persistence:
UPDATE statement is executed against the s2r_operation_mapping table. This statement atomically sets the binary_handling_override (operation mode), binary_data_url_mime_override (operation MIME type), and response_field_binary_handling (per-field map) columns for the row matching the operation_id.is_active is true. If no row is updated, it means no active mapping exists for the operation, and an error is thrown.Result: If the transaction is successful, the service returns an ApplyResult object containing the final, applied configuration, including the operation key and the merged map of response field overrides.
The service exposes a single method, apply, to manage binary handling overrides.
apply MethodApplies operation-level and field-level binary handling overrides to an active operation mapping.
| Name | Type | Required | Description |
|---|---|---|---|
operationId | UUID | Yes | The unique identifier for the operation to modify. |
operationOverride | String | No | The binary handling mode to apply to the entire operation. Must be one of the system's valid modes. A null or empty string clears the override. |
dataUrlMimeOverride | String | No | The default MIME type to use for data-url encoding at the operation level. Must be a valid RFC 6838 token. A null or empty string clears the override. |
fieldOverrides | List<FieldEntry> | No | A list of FieldEntry objects for per-field overrides. A null list is permitted and results in no changes to field overrides. |
FieldEntry StructureThe fieldOverrides parameter is a list of FieldEntry objects, each with the following structure:
| Field | Type | Required | Description |
|---|---|---|---|
soapXPath | String | Yes | The XPath expression identifying a field in the SOAP response. |
mode | String | No | The binary handling mode for this specific field. If null or blank, any existing override for this soapXPath is removed. Otherwise, must be one of the system's valid modes. |
dataUrlMime | String | No | The MIME type for data-url encoding for this specific field. Only applicable if mode is set to a data URL mode. Must be a valid RFC 6838 token. |
NOTE
The source does not specify the list of valid modes for the mode parameter. The service will reject invalid values with an error message listing the available options.
The method returns an ApplyResult object upon success.
| Field | Type | Description |
|---|---|---|
operationId | UUID | The ID of the operation that was modified. |
operationKey | String | The key of the operation that was modified. |
operationOverride | String | The applied operation-level handling mode. |
dataUrlMimeOverride | String | The applied operation-level data URL MIME type. |
responseFieldOverrides | Map<String, Object> | The complete, merged map of per-field overrides that was persisted. The keys are soapXPath strings. |
Calls to the apply method may fail with an ApplyValidationException. The exception contains a code and a descriptive message.
| Error Code | Trigger | Meaning and Resolution |
|---|---|---|
S2R-VAL-0497 | A FieldEntry in fieldOverrides has a null or blank soapXPath. | Every field override must be associated with a specific field. Ensure all soapXPath values are non-empty strings. |
S2R-VAL-0497 | The operationOverride or a FieldEntry.mode is not a valid handling mode. | The provided mode is not recognized by the system. The error message will list the valid modes. Correct the value or set it to null to clear the override. |
S2R-VAL-0497 | The dataUrlMimeOverride or a FieldEntry.dataUrlMime is not a valid MIME type. | The value must be a valid RFC 6838 MIME type token (e.g., application/pdf). Correct the value. |
S2R-VAL-0497 | The merged map of field overrides could not be serialized to JSON. | This indicates an internal error during the serialization process. The error message may contain more details from the underlying serializer. |
S2R-ADM-0404 | No s2r_operation record exists for the provided operationId. | The operationId does not correspond to any known operation. Verify the ID is correct. |
S2R-ADM-0404 | No active s2r_operation_mapping record exists for the provided operationId. | The operation exists, but it does not have an active mapping to apply overrides to. This may indicate a configuration issue with the operation itself. |
S2R-ADM-0410 | The operation's service version is not in a draft state or is already active. | Binary handling overrides can only be modified when the parent service version is a mutable draft. You cannot change settings for a version that is locked or active. |