Author: alessio.soldano(a)jboss.com
Date: 2012-12-05 09:38:28 -0500 (Wed, 05 Dec 2012)
New Revision: 17050
Modified:
common/trunk/src/main/java/org/jboss/ws/common/deployment/SOAPAddressWSDLParser.java
Log:
[JBWS-3571] Extending SOAPAddressWSDLParser to process wsdl imports
Modified:
common/trunk/src/main/java/org/jboss/ws/common/deployment/SOAPAddressWSDLParser.java
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/common/deployment/SOAPAddressWSDLParser.java 2012-12-05
10:04:05 UTC (rev 17049)
+++
common/trunk/src/main/java/org/jboss/ws/common/deployment/SOAPAddressWSDLParser.java 2012-12-05
14:38:28 UTC (rev 17050)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -30,9 +30,12 @@
import java.io.IOException;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
@@ -49,6 +52,7 @@
public final class SOAPAddressWSDLParser
{
public static final String SOAP_OVER_JMS_NS =
"http://www.w3.org/2010/soapjms/";
+ public static final String SOAP_HTTP_NS =
"http://schemas.xmlsoap.org/soap/http";
private static final String WSDL_NS = "http://schemas.xmlsoap.org/wsdl/";
private static final String SOAP_NS =
"http://schemas.xmlsoap.org/wsdl/soap/";
private static final String SOAP12_NS =
"http://schemas.xmlsoap.org/wsdl/soap12/";
@@ -56,6 +60,7 @@
private static final String SERVICE = "service";
private static final String PORT = "port";
private static final String BINDING = "binding";
+ private static final String IMPORT = "import";
private static final String TRANSPORT = "transport";
private static final String ADDRESS = "address";
private static final String LOCATION = "location";
@@ -66,12 +71,22 @@
public SOAPAddressWSDLParser(URL wsdlUrl)
{
- this.metadata = getMetaData(wsdlUrl);
+ this.metadata = new WSDLMetaData();
+ parse(this.metadata, wsdlUrl);
+ Map<String, Boolean> map = this.metadata.getImports();
+ while (!map.isEmpty() && map.containsValue(false)) {
+ Set<String> imports = new HashSet<String>(map.keySet());
+ for (String i : imports) {
+ if (!map.get(i)) {
+ parse(this.metadata, i);
+ map.put(i, true);
+ }
+ }
+ }
}
- public String filterSoapAddress(QName serviceName, QName portName, String
transportNamespace)
+ public String filterSoapAddress(QName serviceName, QName portName, String[]
transportNamespaces)
{
- //get the soap:address of the required service/port if the corresponding binding
uses SOAP over JMS transport
WSDLServiceMetaData smd = metadata.getServices().get(serviceName);
if (smd != null)
{
@@ -79,23 +94,46 @@
if (pmd != null)
{
WSDLBindingMetaData bmd = metadata.getBindings().get(pmd.getBindingName());
- if (bmd != null &&
transportNamespace.equals(bmd.getSoapTransport()))
+ if (bmd != null)
{
- return pmd.getSoapAddress();
+ for (String txNs : transportNamespaces)
+ {
+ if (txNs.equals(bmd.getSoapTransport()))
+ {
+ return pmd.getSoapAddress();
+ }
+ }
}
}
}
return null;
}
- protected static WSDLMetaData getMetaData(URL wsdlUrl)
+ public String filterSoapAddress(QName serviceName, QName portName, String
transportNamespace)
{
+ return filterSoapAddress(serviceName, portName, new String[]{transportNamespace});
+ }
+
+ protected static void parse(WSDLMetaData metadata, String wsdlUrl)
+ {
+ try
+ {
+ parse(metadata, new URL(wsdlUrl));
+ }
+ catch (MalformedURLException e)
+ {
+ throw MESSAGES.failedToRead(wsdlUrl, e.getMessage(), e);
+ }
+ }
+
+ protected static void parse(WSDLMetaData metadata, URL wsdlUrl)
+ {
InputStream is = null;
try
{
is = wsdlUrl.openStream();
XMLStreamReader xmlr = StAXUtils.createXMLStreamReader(is);
- return getMetaData(xmlr, wsdlUrl);
+ parse(metadata, xmlr, wsdlUrl);
}
catch (Exception e)
{
@@ -111,7 +149,7 @@
}
}
- private static WSDLMetaData getMetaData(XMLStreamReader reader, URL wsdlUrl) throws
XMLStreamException
+ private static void parse(WSDLMetaData metadata, XMLStreamReader reader, URL wsdlUrl)
throws XMLStreamException
{
int iterate;
try
@@ -123,7 +161,6 @@
// skip non-tag elements
iterate = reader.nextTag();
}
- WSDLMetaData metadata = new WSDLMetaData();
switch (iterate)
{
case END_ELEMENT : {
@@ -143,7 +180,6 @@
}
}
}
- return metadata;
}
private static void parseDefinitions(XMLStreamReader reader, WSDLMetaData metadata,
String targetNS, URL wsdlUrl) throws XMLStreamException
@@ -172,6 +208,14 @@
bmd.setName(name);
metadata.getBindings().put(bmd.getName(), bmd);
}
+ else if (match(reader, WSDL_NS, IMPORT)) {
+ final String location = reader.getAttributeValue(null, LOCATION);
+ final String url = wsdlUrl.toString();
+ final String newUrl = url.substring(0, url.lastIndexOf("/") +
(location.startsWith("/") ? 0 : 1)) + location;
+ if (!metadata.getImports().containsKey(newUrl)) {
+ metadata.getImports().put(newUrl, false);
+ }
+ }
continue;
}
}
@@ -267,6 +311,7 @@
{
private Map<QName, WSDLServiceMetaData> services = new HashMap<QName,
SOAPAddressWSDLParser.WSDLServiceMetaData>();
private Map<QName, WSDLBindingMetaData> bindings = new HashMap<QName,
SOAPAddressWSDLParser.WSDLBindingMetaData>();
+ private Map<String, Boolean> imports = new HashMap<String, Boolean>();
//<url, processed>
public Map<QName, WSDLServiceMetaData> getServices()
{
@@ -276,6 +321,11 @@
{
return bindings;
}
+
+ public Map<String, Boolean> getImports()
+ {
+ return imports;
+ }
}
private static class WSDLServiceMetaData