Skip to content

Commit 2ad6883

Browse files
committed
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`.
1 parent 4582fde commit 2ad6883

File tree

6 files changed

+28
-21
lines changed

6 files changed

+28
-21
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
package com.predic8.membrane.annot;
1616

17-
import com.sun.net.httpserver.*;
18-
17+
import javax.xml.*;
1918
import javax.xml.namespace.*;
2019
import java.io.*;
2120
import java.util.*;
@@ -63,6 +62,8 @@ public class Constants {
6362

6463
public static final String HTTP_VERSION_11 = "1.1";
6564

65+
public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/";
66+
6667
public static final String WSDL11_NS = "http://schemas.xmlsoap.org/wsdl/";
6768

6869
public static final String WSDL_SOAP11_NS = "http://schemas.xmlsoap.org/wsdl/soap/";
@@ -89,7 +90,7 @@ public enum SoapVersion { SOAP11, SOAP12, SOAP20, UNKNOWN }
8990

9091

9192
/**
92-
* Used for {@link Request}-to-XML and XML-to-{@link Response} conversions.
93+
* Used for Request-to-XML and XML-to-Response conversions.
9394
* See {@link REST2SOAPInterceptor}.
9495
*/
9596
public static final String HTTP_NS = "http://membrane-soa.org/schemas/http/v1/";

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.predic8.membrane.core.transport.http.*;
2828
import com.predic8.membrane.core.transport.http.client.*;
2929
import com.predic8.membrane.core.transport.ssl.*;
30-
import com.predic8.membrane.core.util.*;
3130
import jakarta.mail.internet.*;
3231
import org.jose4j.jwt.*;
3332
import org.jose4j.lang.*;

core/src/main/java/com/predic8/membrane/core/interceptor/schemavalidation/WSDLSchemaExtractor.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.predic8.membrane.core.interceptor.schemavalidation;
1616

17+
import com.predic8.membrane.annot.*;
1718
import org.w3c.dom.*;
1819
import org.xml.sax.*;
1920

@@ -24,20 +25,19 @@
2425
import java.io.*;
2526
import java.util.*;
2627

28+
import static com.predic8.membrane.annot.Constants.XMLNS_NS;
29+
import static com.predic8.membrane.annot.Constants.XSD_NS;
2730
import static javax.xml.XMLConstants.*;
2831

2932
public final class WSDLSchemaExtractor {
3033

31-
private static final String XML_SCHEMA_NS = "http://www.w3.org/2001/XMLSchema"; // TODO
32-
private static final String XMLNS_NS = XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
33-
3434
private WSDLSchemaExtractor() {
3535
}
3636

3737
public static List<Document> getSchemas(Element wsdl) {
3838
try {
3939
var result = new ArrayList<Document>();
40-
var schemas = wsdl.getElementsByTagNameNS(XML_SCHEMA_NS, "schema");
40+
var schemas = wsdl.getElementsByTagNameNS(XSD_NS, "schema");
4141
for (int i = 0; i < schemas.getLength(); i++) {
4242
result.add(extractSchema((Element) schemas.item(i),
4343
getNamespaceDeclarations(wsdl)));
@@ -62,7 +62,6 @@ private static List<Attr> getNamespaceDeclarations(Element element) {
6262

6363
private static Document extractSchema(Element originalSchema, List<Attr> definitionNamespaces) throws Exception {
6464
var fac = DocumentBuilderFactory.newInstance();
65-
// fac.setFeature(FEATURE_SECURE_PROCESSING, true);
6665
fac.setNamespaceAware(true);
6766
var builder = fac.newDocumentBuilder();
6867

core/src/main/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptor.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,16 @@ public String rewrite(String path) {
100100
}
101101

102102
private @NotNull String resolveToNumber(String path) {
103-
if (pathsReverse.containsKey(path)) {
104-
return pathsReverse.get(path).toString();
103+
synchronized (paths) {
104+
if (pathsReverse.containsKey(path)) {
105+
return pathsReverse.get(path).toString();
106+
}
107+
int n = paths.size() + 1;
108+
paths.put(n, path);
109+
pathsReverse.put(path, n);
110+
documentsToProcess.add(path);
111+
return Integer.toString(n);
105112
}
106-
int n = paths.size() + 1;
107-
paths.put(n, path);
108-
pathsReverse.put(path, n);
109-
documentsToProcess.add(path);
110-
return Integer.toString(n);
111-
112113
}
113114
}
114115

core/src/main/java/com/predic8/membrane/core/interceptor/soap/WebServiceExplorerInterceptor.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,7 @@ protected void createContent() {
133133

134134
for (com.predic8.membrane.core.util.wsdl.parser.PortType pt : ports.stream().map(Port::getBinding).map(Binding::getPortType).toList()) {
135135
h2().text("Port Type: " + pt.getName()).end();
136-
// Documentation d = pt.getDocumentation(); @TODO
137-
// if (d != null) {
138-
// p().text("Documentation: " + d).end();
139-
// }
136+
// @TODO show pt.getDocumentation() wsdl:documentation here when it is implemented
140137
}
141138

142139
var binding = port.getBinding();

core/src/main/java/com/predic8/membrane/core/util/URIUtil.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ public static String normalizeSingleDot(String uri) {
139139
return sb.toString();
140140
}
141141

142+
/**
143+
* Normalizes the given path or URI. This method handles various formats of paths,
144+
* including filesystem paths, URIs, and paths with potential Windows drive letters.
145+
* The normalization involves resolving relative components, such as "." or "..",
146+
* and ensuring the path conforms to a standardized format.
147+
*
148+
* @param location the path or URI string to normalize. It must not be null or empty.
149+
* @return the normalized path or URI as a string.
150+
* @throws IllegalArgumentException if the input location is null or empty.
151+
*/
142152
public static String normalize(String location) {
143153
if (location == null || location.isEmpty())
144154
throw new IllegalArgumentException("location must not be null or empty");

0 commit comments

Comments
 (0)