Loading…
Loading…
Explains how the WSDL parser processes WSDL and XSD documents, resolves external references, suggests backend configurations, and handles various SOAP
The WSDL Parser is a component responsible for parsing, analyzing, and interpreting Web Services Definition Language (WSDL) 1.1 documents. It serves as the primary mechanism for onboarding SOAP-based services by extracting the necessary metadata to configure the API platform.
The parser's main function is to take a raw WSDL XML document, either as a string or from a URL, and produce a structured representation of the service contract. This includes:
wsdl:import or xsd:import/include.The parser is called during the API creation process when an API publisher imports a WSDL file. It is designed to be robust, secure, and provide detailed diagnostics to help publishers understand and troubleshoot their WSDL definitions.
The WSDL parsing process involves several distinct stages, from initial XML processing to the final extraction of service metadata. The parser is designed to handle complex WSDLs that are split across multiple files.
flowchart TD
A[API Publisher provides WSDL XML] --> B(WsdlParser);
subgraph "Parser Processing Stages"
direction TD
B --> C[1. Pre-process & Repair];
C --> D[2. Parse to XML Document];
D --> E{Has External Refs?};
E -- Yes --> F[3. Fetch & Merge Refs];
E -- No --> G[4. Analyze & Extract];
F --> G;
G --> H[5. Generate Parsed Document];
end
subgraph "Secure Fetch Mechanism"
F -- "HTTP/HTTPS only" --> I[SSRF Guard];
I --> J[HTTP Client];
J --> K[Backend SOAP Service];
end
H --> L[Output: WsdlParsedDocument];
style F fill:#f9f,stroke:#333,stroke-width:2pxBefore parsing, the WSDL XML undergoes two cleanup steps:
U+FEFF) characters, which can cause parsing failures.WsdlNamespaceRepairSupport component. This fixes many validation errors found in hand-edited or legacy WSDL files.The cleaned XML string is parsed into a standard DOM Document object. The parser uses a security-hardened DocumentBuilderFactory with the following features to prevent common XML-based attacks:
FEATURE_SECURE_PROCESSING is enabled.disallow-doctype-decl is enabled to prevent XML External Entity (XXE) attacks via <!DOCTYPE>.ACCESS_EXTERNAL_DTD and ACCESS_EXTERNAL_SCHEMA are disabled.WSDLs often import other WSDLs or external XML Schemas (XSDs). The parser recursively resolves and merges these external documents.
wsdl:import elements and all <xsd:schema> blocks for xsd:import, xsd:include, and xsd:redefine elements.location or schemaLocation attribute into an absolute URI. Relative paths are resolved against the base URI of the document containing the reference.OperatorUrlGuard, which enforces egress policies to prevent Server-Side Request Forgery (SSRF) attacks. References to blocked or non-HTTP/HTTPS URLs will fail.OperatorUrlGuard follows each redirect hop manually and re-validates the destination URL to prevent redirect-based SSRF attacks.<types> are processed. If it's an XSD, the <schema> element is imported directly into the main WSDL document's <types> section. This creates a single, unified DOM for analysis.With a complete and merged DOM, the parser extracts structural metadata using XPath and direct DOM traversal.
wsdl:binding elements, determining their SOAP version (1.1 or 1.2), transport protocol (e.g., http://schemas.xmlsoap.org/soap/http), and binding style (document or rpc).wsdl:service and wsdl:port elements to discover backend endpoint addresses from soap:address declarations.wsdl:portType/wsdl:operation to serve as the primary unit of extraction.soap:header, soap:headerfault, and wsdl:fault definitions from both the wsdl:binding and wsdl:portType.For each operation, the parser assembles a complete record.
WsdlContractBuilder is used to generate JSON Schemas for the operation's input and output messages. The binding style (rpc vs. document) is a key input to this process, as it determines whether to unwrap the top-level operation element in the SOAP Body.WsdlBackendSuggestionRecord. This record recommends a preferred endpoint URL, SOAP version, and authentication type. It also includes diagnostic notes about the WSDL's structure and capabilities.WsdlParsedDocument object, which contains the list of WsdlOperationRecords and the WsdlBackendSuggestionRecord.The WsdlParser component exposes several public methods for parsing and diagnostics.
| Method | Description |
|---|---|
parse(String wsdlXml) | Parses the given WSDL XML string. External references cannot be resolved without a sourceLocation. |
parse(String wsdlXml, String sourceLocation) | Parses the WSDL XML string, using sourceLocation as the base URI for resolving relative external references (wsdl:import, xsd:import, etc.). |
parseWithResolvedDocuments(String wsdlXml, String sourceLocation, Map<String, String> documentsByUri) | Parses a WSDL using a pre-fetched map of its external dependencies. This method operates entirely offline; any reference not present in the documentsByUri map will cause a failure. It is used for re-parsing previously imported artifacts without depending on the original backend servers being available. |
// Conceptual example of invoking the parser
WsdlParser parser = new WsdlParser(/*...dependencies...*/);
String wsdlContent = "... WSDL XML content ...";
String wsdlUrl = "https://api.example.com/service?wsdl";
try {
// Parse the WSDL, fetching external references relative to wsdlUrl
WsdlParsedDocument parsedDoc = parser.parse(wsdlContent, wsdlUrl);
// Access the extracted operations and backend suggestions
System.out.println("Target Namespace: " + parsedDoc.getTargetNamespace());
System.out.println("Suggested Endpoint: " + parsedDoc.getBackendSuggestion().preferredEndpointUrl());
for (WsdlOperationRecord op : parsedDoc.getOperations()) {
System.out.println("Found operation: " + op.getOperationName());
}
} catch (WsdlParseException e) {
System.err.println("Failed to parse WSDL: " + e.getMessage());
// The root cause is often included for diagnosis
if (e.getCause() != null) {
System.err.println("Cause: " + e.getCause().getMessage());
}
}
These methods help diagnose issues with a WSDL before performing a full import.
| Method | Description |
|---|---|
previewNamespaceRepair(String wsdlXml, Map<String, String> manualMappings) | Previews the result of automatic namespace repair without performing a full parse. It returns a NamespaceRepairPreview object showing the original and repaired XML, along with lists of repaired, unrepaired, and manually applied prefixes. |
previewExternalReferences(String wsdlXml, String sourceLocation) | Scans the WSDL for all external references (wsdl:import, xsd:import, etc.) and attempts to resolve and fetch them, reporting the status of each. This is a powerful tool for diagnosing connectivity issues, authentication problems, or broken links before committing to an import. It returns an ExternalReferencePreview object. |
The previewExternalReferences method returns a detailed report on every external document linked from the WSDL. The report contains a list of ExternalReferenceRecord objects, each with the following fields:
| Field | Type | Description |
|---|---|---|
kind | String | The type of reference, either wsdl_import or schema_reference (for xsd:import, include, or redefine). |
location | String | The raw location string from the location or schemaLocation attribute in the source WSDL/XSD. |
resolvedUri | String | The absolute URI that the location resolved to. This is the URL that was actually fetched. |
baseUri | String | The base URI used to resolve a relative location. |
status | String | The outcome of the fetch attempt: resolved, unresolved (for relative paths with no base URI), or failed. |
detail | String | For failed references, a message explaining the reason for failure (e.g., HTTP 404, connection timed out, blocked by SSRF egress guard). For resolved references, this is "Loaded successfully." |rootElement | String | The tag name of the root element of the fetched document (e.g., wsdl:definitions or xsd:schema). - |
| depth | int | The recursion depth of the reference (0 for top-level, 1 for a reference within a top-level import, etc.). |
| --- | --- | --- |
| fileNameHint | String | A suggested filename for the referenced document, derived from its location URL. |
| suggestedFix | String | An actionable suggestion for how to resolve a failed or unresolved reference, such as downloading the file manually or correcting a URL. |When a WSDL fails to parse, the parser provides detailed error messages and diagnostics to help identify the root cause.
WsdlParseException: This is the primary exception thrown for most parsing failures. The message includes a high-level summary and, crucially, a cause field containing the underlying exception. Always check the cause for specific details, such as HTTP 404 for a missing import or an XML parsing error for malformed content.IllegalArgumentException: Thrown for invalid inputs or conditions detected during parsing. Common causes include:
Root element must be wsdl:definitions: The provided XML is not a valid WSDL document.No wsdl:operation elements found under wsdl:portType: The WSDL is missing the core operation definitions.external reference blocked by SSRF egress guard: An import URL was blocked for security reasons.unsupported schema reference scheme: An import uses a protocol other than http or https.HTTP 401, HTTP 403, HTTP 404: The parser failed to fetch an external reference due to authentication, authorization, or a broken link.IllegalStateException: Thrown by parseWithResolvedDocuments if a required external document is not found in the provided map.The parser embeds diagnostic notes in the WsdlBackendSuggestionRecord to flag potential issues or important characteristics of the WSDL.
WARNING
Unsupported RPC/Encoded Style
If the WSDL uses the retired RPC/encoded style (soap:body use="encoded"), the parser will add a note with the code S2R-ADM-0424. Operations using this style cannot be converted, as the platform does not support the multi-reference object graphs it produces. The service must be republished using a document/literal binding.
Other common notes include:
wsdl:import was found with a namespace but no location. These cannot be fetched automatically and may lead to unresolved types.wsdl:service Elements: A note to alert the API publisher that the WSDL defines multiple services, and they should confirm which one to use.The parser inspects the WSDL for common WS-Security Policy assertions and other markers to suggest a backend authentication type. It looks for keywords inside element names, attributes, and namespaces.
| Suggested Auth Type | Inferred From Markers Like...