Skip to content

Commit 9ebce5a

Browse files
authored
WsdlValidator: new WSDL Parser (#2863)
* Add WSDL parsing utilities and schema validation tests - Introduced comprehensive WSDL parsing utilities (`Definitions`, `Binding`, `Service`, etc.). - Added schema parsing components with support for `Include` and `Import`. - Implemented tests for schema validation, WSDL definitions, services, bindings, and operations. - Enhanced SOAP version detection through `WSDLSOAPVersionExtractor`. - Refactored `AuthorizationService` and `ResolverMap` for improved URI handling. * Remove unused WSDLSOAPVersionExtractor and clean up redundant WSDL parser fields - Deleted `WSDLSOAPVersionExtractor` as it is no longer in use. - Replaced redundant mutable fields in WSDL parser classes with `final` fields to ensure immutability. - Simplified WSDL parser constructors by removing unused context (`ctx`) parameters. - Enhanced code readability by improving method references and streamlining operations. - Updated comments and removed obsolete code for cleaner structure. * Enhance WSDL parser with support for cyclic imports, schema inclusion, and improved validation tests - Added cyclic import handling for WSDL and XSD files, ensuring robust schema parsing in complex configurations. - Enhanced `Schema` class to include logic for merging elements from included schemas. - Streamlined `WSDLParserContext` to track and prevent duplicate resource loading. - Improved schema validation test coverage with new test cases for cyclic and imported elements. - Minor refactorings in WSDL and schema-related classes for better readability and maintainability. * Refactor WSDL parser code for immutability and readability - Replaced mutable fields with `final` to ensure immutability in `WSDLParserContext` and related classes. - Simplified test method `getDefinitions` by removing intermediate variable. - Removed redundant null check on the `type` attribute in `Binding`. - Enhanced code clarity in `PortType` by finalizing the `operations` list. * Refactor WSDL parser and URI utility for improved normalization, binding, and message handling - Added robust path normalization in `URIUtil`, covering relative paths, absolute paths, and various URI schemes. - Enhanced `WSDLParser` to track and validate immutable definitions, bindings, and messages. - Introduced support for handling empty schema locations and improved error handling in cyclic imports. - Updated tests to cover added functionality, ensuring reliable parsing and normalization across platforms. * Add embedded WSDL example and enhance parser robustness for URI normalization and schema imports - Included `embedded.wsdl` as a test resource for integration scenarios. - Improved `URIUtil` logic to handle query strings, fragments, and scheme-relative URIs during normalization. - Enhanced WSDL parser to handle embedded schemas and validate imports with improved error handling. - Updated tests to ensure accurate parsing and normalization in new and existing edge cases. * Improve WSDL parser and URI utility - Streamlined XML schema declarations in `embedded.wsdl`. - Enhanced `URIUtil` to simplify Windows drive path normalization. - Refactored WSDL parser for better error handling, schema imports, and embedded schema handling. - Modernized code by replacing specific types with `var` where applicable. - Improved `URIUtilTest` to cover Windows drive-relative paths and other edge cases. * Add copyright headers, logging improvements, and update SOAP namespace handling - Added Apache 2.0 license headers to all modified files. - Enhanced SOAP analysis with additional debug logging in `SOAPUtil`. - Updated XPath expressions in YAML configuration to use explicit SOAP namespace references (`s11`). - Refactored several test files for consistency and improved readability. * Add copyright headers, logging improvements, and update SOAP namespace handling - Added Apache 2.0 license headers to all modified files. - Enhanced SOAP analysis with additional debug logging in `SOAPUtil`. - Updated XPath expressions in YAML configuration to use explicit SOAP namespace references (`s11`). - Refactored several test files for consistency and improved readability. * Remove unused fields and redundant logic in `WSDLInterceptor` - Deleted unused `registryWSDLRegisterURL` field and associated methods. - Removed redundant `HttpClient` logic. - Simplified `rewrite` method. - Streamlined imports and improved code readability. * Remove redundant WSDL utility methods, tests, and dependencies - Removed unused methods and fields in `WSDLUtil`, `WSDLInterceptor`, and related classes for improved maintainability. - Deleted `WSDLUtilTest` and redundant SOAP operations tests. - Replaced specific types with `var` for modernized code. - Removed dependency on `soa-model-core` and updated `pom.xml` with refined dependencies for Groovy modules. - Simplified WSDL example handling by removing unused logic and streamlining `embedded.wsdl`. * Remove `WSDLUtil` class and refactor related utilities - Deleted `WSDLUtil` and its unused methods for maintainability. - Replaced redundant logic in WSDL parser classes with utility methods. - Streamlined SOAP wsdl-related exemplars and refactored embedded schema handling. - Simplified field initializations and usage of `var` across classes. - Updated documentation to reflect these changes. * Add WSDL fault handling and improve parser robustness - Added new WSDL file (`calculator-fault.wsdl`) with fault definition for testing. - Updated WSDL parser to support fault direction (`FAULT`) in operations handling. - Enhanced `Relocator` and related classes by removing unnecessary fields and imports for better readability. - Added unit test to validate fault handling in operations. * Refactor WSDL parser: streamline imports, enhance schema handling, and simplify logic * Remove unused fields and simplify logic in WSDL parser classes - Deleted redundant `referencingSchema` field in `AbstractIncludeImport`. - Removed `hasLocalName` method from `WSDLElement`. - Simplified lambda usage in `Operation` for better readability. * Refactor WSDL parser: simplify attribute handling, improve SOAP version and style detection, and add unit tests - Replaced direct field assignments with `getAttribute` for cleaner attribute handling in `BindingOperation` and `Address`. - Added `BindingStyle` class to improve SOAP version and style handling logic. - Streamlined `Node` processing in `Binding` and `WSDLElement`. - Introduced helper methods for SOAP namespace and element checks. - Added new unit tests (`WSDLParserUtilTest`) for utility methods and `rpcStyle` test case for style detection. * Simplify `Binding` class by removing unused fields and refining `PortType` and `SOAPVersion` handling logic * Refactor WSDL parser classes for improved readability and maintainability - Simplified object initialization and attribute handling across WSDL parser classes. - Removed redundant fields (`Type`, `Service`, `PortType`, etc.) and unified child node processing logic. - Introduced `instantiateChildren()` and related helper methods for cleaner element instantiation. - Enhanced `Binding`, `Operation`, `Message`, and related classes: reduced complexity by eliminating unnecessary lists and utility methods. - Added `ProtocolOperation` class to handle SOAP operation attributes (e.g., `soapAction`). - Updated and added unit tests to validate changes. * Refactor WSDL parser: simplify field initialization, streamline list handling, and enhance readability - Replaced `get(0)` with `getFirst()` for better semantics in child node initialization. - Made `imports` and `includes` lists final in `Schema` for immutability. - Simplified stream operations with method references in `Definitions`. - Removed unused `addSoapVersion` method and redundant test logic. * Refactor WSDL parser: simplify attribute handling, enhance fault handling, and optimize child element processing - Replaced direct field usage with `getAttribute` for cleaner logic (`getName()` in `WSDLElement` and `BindingOperation`). - Simplified and unified child node processing with `instantiateChildren()` and `instantiateChild()` methods across classes. - Added `Fault` handling for operations and updated `WebServiceExplorerInterceptor` to include fault details in table rendering. - Refactored `Operation` to improve input/output/fault message handling with streamlined classes (`Input`, `Output`, `Fault`). - Introduced `Types` class for better encapsulation of WSDL element processing. - Updated unit tests to validate refactored fault handling and schema updates. * Improve WSDL parser exception handling and test assertions - Replaced `findFirst().get()` with `orElseThrow()` for safer binding retrieval in `Port`. - Simplified `Definitions` parsing logic by removing unused method parameters and refactoring lambda expressions. - Updated unit test assertions for better accuracy (`assertNull` replaced with `assertEquals`). * Fix: include fault details in WebServiceExplorer table rendering - Added missing `td()` element to ensure proper rendering of fault details in the web service explorer table. * Refactor WSDL parser: migrate to `record` for `WSDLParserContext`, simplify methods, and enhance exception handling - Replaced `WSDLParserContext` class with a `record` for better immutability and readability. - Updated method calls to use record getters (e.g., `ctx.definitions()` instead of `ctx.getDefinitions()`). - Enhanced exception messages in `WSDLElement` and `Binding` for better debugging. - Simplified stream and lambda usage across parser classes. - Added unit test for abstract WSDL service validation (`SOAPProxyTest`). * Add SOAP 1.2 WSDL file and corresponding tests for enhanced schema validation - Introduced `hello-soap12.wsdl` in test resources, implementing a SOAP 1.2 example schema for validation purposes. - Added test cases in `WSDLParserTest` to verify the parsing and validation of SOAP 1.2 bindings (`HelloService`). - Created `WSDLIncludeImportTest` to test schema include/import scenarios, including cyclic and embedded cases. - Improved `RelativePathRewriter` in `WSDLPublisherInterceptor` by refining file existence checks and path resolution. - Minor formatting fixes and refinements in existing code and tests. * Refactor schema validation and WSDL parser components - Updated `WSDLMessageElementExtractor` to improve RPC element name handling, ensuring correct direction logic for `INPUT` and `OUTPUT`. - Fixed a formatting issue in `SchemaElement` constructor for better readability. - Simplified lambda usage in `getElementNames` method of `WSDLIncludeImportTest`. - Made `resource` field in `RelativePathRewriter` final for immutability. * Refactor schema validation and WSDL components - Split `getPossibleElements` logic in `WSDLMessageElementExtractor` into separate methods for RPC and document styles for better clarity. - Simplified attribute relocation in `Relocator` by removing redundant `shouldProcess` method and streamlining logic. - Fixed test assertions in `WSDLIncludeImportTest` for correcting import validation (`get(1)` usage). - Updated `WSDLPublisherInterceptor` to improve path * Refactor and enhance URI handling and WSDL/XML components - Added `normalize` method in `URIUtil` for standardizing paths and URIs. - Synchronized `resolveToNumber` method in `WSDLPublisherInterceptor` for thread safety. - Replaced hardcoded schema namespace with constants in `WSDLSchemaExtractor`. - Removed redundant imports and refactored commentary in multiple classes for clarity. - Added `XMLNS_NS` constant to `Constants`. * Refactor URI normalization: rename method for clarity, enhance exception handling, and update references in tests and implementations
1 parent dcc5a04 commit 9ebce5a

File tree

85 files changed

+3332
-1249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3332
-1249
lines changed

annot/src/main/java/com/predic8/membrane/annot/Constants.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.predic8.membrane.annot;
1616

17+
import javax.xml.*;
1718
import javax.xml.namespace.*;
1819
import java.io.*;
1920
import java.util.*;
@@ -61,6 +62,10 @@ public class Constants {
6162

6263
public static final String HTTP_VERSION_11 = "1.1";
6364

65+
public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/";
66+
67+
public static final String WSDL11_NS = "http://schemas.xmlsoap.org/wsdl/";
68+
6469
public static final String WSDL_SOAP11_NS = "http://schemas.xmlsoap.org/wsdl/soap/";
6570
public static final String WSDL_SOAP12_NS = "http://schemas.xmlsoap.org/wsdl/soap12/";
6671
public static final String WSDL_HTTP_NS = "http://schemas.xmlsoap.org/wsdl/http/";
@@ -85,7 +90,7 @@ public enum SoapVersion { SOAP11, SOAP12, SOAP20, UNKNOWN }
8590

8691

8792
/**
88-
* Used for {@link Request}-to-XML and XML-to-{@link Response} conversions.
93+
* Used for Request-to-XML and XML-to-Response conversions.
8994
* See {@link REST2SOAPInterceptor}.
9095
*/
9196
public static final String HTTP_NS = "http://membrane-soa.org/schemas/http/v1/";

core/pom.xml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
15-
--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
15+
-->
16+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
1618

1719
<modelVersion>4.0.0</modelVersion>
1820
<artifactId>service-proxy-core</artifactId>
@@ -89,20 +91,6 @@
8991
<groupId>com.googlecode.jatl</groupId>
9092
<artifactId>jatl</artifactId>
9193
</dependency>
92-
<dependency>
93-
<groupId>com.predic8</groupId>
94-
<artifactId>soa-model-core</artifactId>
95-
<exclusions>
96-
<exclusion>
97-
<groupId>org.apache.httpcomponents</groupId>
98-
<artifactId>httpclient</artifactId>
99-
</exclusion>
100-
<exclusion>
101-
<groupId>org.slf4j</groupId>
102-
<artifactId>jcl-over-slf4j</artifactId>
103-
</exclusion>
104-
</exclusions>
105-
</dependency>
10694
<dependency>
10795
<groupId>commons-fileupload</groupId>
10896
<artifactId>commons-fileupload</artifactId>
@@ -230,6 +218,10 @@
230218
<groupId>org.apache.groovy</groupId>
231219
<artifactId>groovy-templates</artifactId>
232220
</dependency>
221+
<dependency>
222+
<groupId>org.apache.groovy</groupId>
223+
<artifactId>groovy-json</artifactId>
224+
</dependency>
233225

234226
<!-- ntlm support-->
235227
<dependency>
@@ -349,7 +341,7 @@
349341
<version>5.19.1</version>
350342
<scope>test</scope>
351343
</dependency>
352-
<dependency>
344+
<dependency>
353345
<groupId>io.rest-assured</groupId>
354346
<artifactId>rest-assured</artifactId>
355347
<scope>test</scope>
@@ -486,7 +478,8 @@
486478
<configuration>
487479
<target>
488480
<copy todir="../docs">
489-
<fileset dir="${project.build.directory}/classes/com/predic8/membrane/core/config/spring">
481+
<fileset
482+
dir="${project.build.directory}/classes/com/predic8/membrane/core/config/spring">
490483
<include name="router-conf.xsd"/>
491484
</fileset>
492485
</copy>

core/src/main/java/com/predic8/membrane/core/interceptor/RelocatingInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected String getLocationHost(Exchange exc) {
8282
if (host != null)
8383
return host;
8484

85-
String locHost = exc.getOriginalHostHeaderHost();
85+
var locHost = exc.getOriginalHostHeaderHost();
8686

8787
log.debug("host {}",locHost);
8888

core/src/main/java/com/predic8/membrane/core/interceptor/WSDLInterceptor.java

Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
import com.predic8.membrane.annot.*;
1818
import com.predic8.membrane.core.exchange.*;
19-
import com.predic8.membrane.core.http.*;
20-
import com.predic8.membrane.core.transport.http.*;
2119
import com.predic8.membrane.core.util.*;
2220
import com.predic8.membrane.core.ws.relocator.*;
2321
import org.jetbrains.annotations.*;
@@ -28,11 +26,8 @@
2826
import java.net.*;
2927

3028
import static com.predic8.membrane.annot.Constants.*;
31-
import static com.predic8.membrane.core.http.Header.*;
32-
import static com.predic8.membrane.core.http.Request.*;
3329
import static com.predic8.membrane.core.interceptor.Interceptor.Flow.Set.*;
3430
import static com.predic8.membrane.core.util.soap.WSDLUtil.*;
35-
import static java.nio.charset.StandardCharsets.*;
3631

3732
/**
3833
* @description <p>The <i>wsdlRewriter</i> rewrites endpoint addresses of services and XML Schema locations in WSDL documents.</p>
@@ -47,9 +42,7 @@ public class WSDLInterceptor extends RelocatingInterceptor {
4742
public static final QName XSD_INCLUDE_QNAME = new QName(XSD_NS, "include");
4843
public static final String LOCATION = "location";
4944

50-
private String registryWSDLRegisterURL;
5145
private boolean rewriteEndpoint = true;
52-
private HttpClient hc;
5346

5447
/**
5548
* Path of the service location to rewrite
@@ -64,7 +57,6 @@ public WSDLInterceptor() {
6457
@Override
6558
public void init() {
6659
super.init();
67-
hc = router.getHttpClientFactory().createClient(null);
6860

6961
if (path != null)
7062
setPathRewriterOnWSDLInterceptor(path);
@@ -94,12 +86,9 @@ public void setPathRewriterOnWSDLInterceptor(String keypath) {
9486
protected void rewrite(Exchange exc) throws Exception {
9587
log.debug("Changing endpoint address in WSDL");
9688

97-
ByteArrayOutputStream stream = new ByteArrayOutputStream();
98-
Relocator relocator = getRelocator(exc, stream);
89+
var stream = new ByteArrayOutputStream();
90+
var relocator = getRelocator(exc, stream);
9991
relocator.relocate(exc.getResponse().getBodyAsStream());
100-
if (relocator.isWsdlFound()) {
101-
registerWSDL(exc);
102-
}
10392
exc.getResponse().setBodyContent(stream.toByteArray());
10493

10594
// Preserve existing Content-Type if present; otherwise set a sane default including charset.
@@ -109,7 +98,7 @@ protected void rewrite(Exchange exc) throws Exception {
10998
}
11099

111100
private @NotNull Relocator getRelocator(Exchange exc, OutputStream stream) throws Exception {
112-
Relocator relocator = createRelocator(exc, stream);
101+
var relocator = createRelocator(exc, stream);
113102

114103
if (rewriteEndpoint) {
115104
relocator.getRelocatingAttributes().put(WSDL11_ADDRESS_SOAP11, LOCATION);
@@ -128,71 +117,6 @@ protected void rewrite(Exchange exc) throws Exception {
128117
getLocationPort(exc), exc.getHandler().getContextPath(exc), pathRewriter);
129118
}
130119

131-
private void registerWSDL(Exchange exc) {
132-
if (registryWSDLRegisterURL == null)
133-
return;
134-
135-
StringBuilder buf = new StringBuilder(2000);
136-
buf.append(registryWSDLRegisterURL);
137-
buf.append("?wsdl=");
138-
139-
buf.append(URLDecoder.decode(getWSDLURL(exc), US_ASCII));
140-
141-
callRegistry(buf.toString());
142-
143-
log.debug(buf.toString());
144-
}
145-
146-
private void callRegistry(String uri) {
147-
try {
148-
var exchange = createExchange(uri);
149-
hc.call(exchange);
150-
Response res = exchange.getResponse();
151-
if (res.getStatusCode() != 200)
152-
log.warn("{}", res);
153-
} catch (Exception e) {
154-
log.error("", e);
155-
}
156-
}
157-
158-
private Exchange createExchange(String uri) throws MalformedURLException, URISyntaxException {
159-
return get(getCompletePath(new URL(uri))).header(HOST, getHost(uri)).buildExchange();
160-
161-
}
162-
163-
private static String getHost(String uri) throws MalformedURLException {
164-
return new URL(uri).getHost();
165-
}
166-
167-
private String getCompletePath(URL url) {
168-
if (url.getQuery() == null)
169-
return url.getPath();
170-
return url.getPath() + "?" + url.getQuery();
171-
}
172-
173-
private String getWSDLURL(Exchange exc) {
174-
StringBuilder buf = new StringBuilder();
175-
buf.append(getLocationProtocol());
176-
buf.append("://");
177-
buf.append(getLocationHost(exc));
178-
if (getLocationPort(exc) != 80) {
179-
buf.append(":");
180-
buf.append(getLocationPort(exc));
181-
}
182-
buf.append("/");
183-
buf.append(exc.getRequest().getUri());
184-
return buf.toString();
185-
}
186-
187-
@MCAttribute
188-
public void setRegistryWSDLRegisterURL(String registryWSDLRegisterURL) {
189-
this.registryWSDLRegisterURL = registryWSDLRegisterURL;
190-
}
191-
192-
public String getRegistryWSDLRegisterURL() {
193-
return registryWSDLRegisterURL;
194-
}
195-
196120
@Override
197121
public String getShortDescription() {
198122
return "Rewrites SOAP endpoint addresses and XML Schema locations in WSDL and XSD documents.";

core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/AuthorizationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ private String createClientToken(FlowContext flowContext) {
318318
}
319319

320320
public InputStream resolve(ResolverMap rm, String baseLocation, String url) throws Exception {
321-
url = ResolverMap.combine(baseLocation, url);
321+
url = ResolverMap.combine( baseLocation, url);
322322
// ask the internal httpClient (might be proxied/authenticated), if HTTP
323323
if (url.startsWith("http")) {
324324
var exc = get(url).buildExchange();

0 commit comments

Comments
 (0)