You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Frank Cornelis (JIRA)" <ji...@apache.org> on 2014/11/20 08:31:34 UTC

[jira] [Updated] (CXF-6110) AbstractSTSClient MEX: download XML schema from Location

     [ https://issues.apache.org/jira/browse/CXF-6110?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Frank Cornelis updated CXF-6110:
--------------------------------
    Description: 
For MEX data like:
{code:xml}
  <MetadataSection
    Dialect="http://www.w3.org/2001/XMLSchema"
    Identifier="http://something">
        <Location>https://some/location.xsd</Location>
  </MetadataSection>
{code}
the AbstractSTSClient should probably start downloading when getAny() gives NULL.

I stumbled upon this by implementing a WS-Trust STS with a WSDL that contains schema imports instead of an embedded XML schema.

The next patch adds this feature (quick and dirty).
{code}
--- src/main/java/org/apache/cxf/ws/security/trust/AbstractSTSClient.java.orig	2014-11-19 17:49:37.964705313 +0100
+++ src/main/java/org/apache/cxf/ws/security/trust/AbstractSTSClient.java	2014-11-19 18:19:01.989607217 +0100
@@ -41,6 +41,9 @@
 import javax.wsdl.extensions.ExtensibilityElement;
 import javax.wsdl.extensions.schema.Schema;
 import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.dom.DOMSource;
@@ -48,6 +51,7 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusException;
 import org.apache.cxf.binding.soap.SoapBindingConstants;
@@ -525,6 +529,11 @@
                             bus.getExtension(WSDLManager.class).getDefinition((Element)s.getAny());
                     } else if ("http://www.w3.org/2001/XMLSchema".equals(s.getDialect())) {
                         Element schemaElement = (Element)s.getAny();
+                        if (schemaElement ==  null) {
+                            String schemaLocation = s.getLocation();
+                            LOG.info("XSD schema location: " + schemaLocation);
+                            schemaElement = downloadSchema(schemaLocation);
+                        }
                         QName schemaName = 
                             new QName(schemaElement.getNamespaceURI(), schemaElement.getLocalName());
                         WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
@@ -586,10 +595,20 @@
                     client = new ClientImpl(bus, endpoint);
                 }
             } catch (Exception ex) {
-                throw new TrustException(LOG, "WS_MEX_ERROR", ex);
+                throw new TrustException("WS_MEX_ERROR", LOG, ex);
             }
         }
     }
+
+    private Element downloadSchema(String schemaLocation)
+        throws ParserConfigurationException, SAXException, IOException {
+        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+        documentBuilderFactory.setNamespaceAware(true);
+        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+        Document document = documentBuilder.parse(schemaLocation);
+        return document.getDocumentElement();
+    }
+
     protected String findMEXLocation(EndpointReferenceType ref, boolean useEPRWSAAddrAsMEXLocation) {
         if (ref.getMetadata() != null && ref.getMetadata().getAny() != null) {
             for (Object any : ref.getMetadata().getAny()) {
{code}

  was:
For MEX data like:
{code:xml}
  <MetadataSection
    Dialect="http://www.w3.org/2001/XMLSchema"
    Identifier="http://something">
        <Location>https://some/location.xsd</Location>
  </MetadataSection>
{code}
the AbstractSTSClient should probably start downloading when getAny() gives NULL.
The next patch adds this feature (quick and dirty).
{code}
--- src/main/java/org/apache/cxf/ws/security/trust/AbstractSTSClient.java.orig	2014-11-19 17:49:37.964705313 +0100
+++ src/main/java/org/apache/cxf/ws/security/trust/AbstractSTSClient.java	2014-11-19 18:19:01.989607217 +0100
@@ -41,6 +41,9 @@
 import javax.wsdl.extensions.ExtensibilityElement;
 import javax.wsdl.extensions.schema.Schema;
 import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.dom.DOMSource;
@@ -48,6 +51,7 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusException;
 import org.apache.cxf.binding.soap.SoapBindingConstants;
@@ -525,6 +529,11 @@
                             bus.getExtension(WSDLManager.class).getDefinition((Element)s.getAny());
                     } else if ("http://www.w3.org/2001/XMLSchema".equals(s.getDialect())) {
                         Element schemaElement = (Element)s.getAny();
+                        if (schemaElement ==  null) {
+                            String schemaLocation = s.getLocation();
+                            LOG.info("XSD schema location: " + schemaLocation);
+                            schemaElement = downloadSchema(schemaLocation);
+                        }
                         QName schemaName = 
                             new QName(schemaElement.getNamespaceURI(), schemaElement.getLocalName());
                         WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
@@ -586,10 +595,20 @@
                     client = new ClientImpl(bus, endpoint);
                 }
             } catch (Exception ex) {
-                throw new TrustException(LOG, "WS_MEX_ERROR", ex);
+                throw new TrustException("WS_MEX_ERROR", LOG, ex);
             }
         }
     }
+
+    private Element downloadSchema(String schemaLocation)
+        throws ParserConfigurationException, SAXException, IOException {
+        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+        documentBuilderFactory.setNamespaceAware(true);
+        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+        Document document = documentBuilder.parse(schemaLocation);
+        return document.getDocumentElement();
+    }
+
     protected String findMEXLocation(EndpointReferenceType ref, boolean useEPRWSAAddrAsMEXLocation) {
         if (ref.getMetadata() != null && ref.getMetadata().getAny() != null) {
             for (Object any : ref.getMetadata().getAny()) {
{code}


> AbstractSTSClient MEX: download XML schema from Location
> --------------------------------------------------------
>
>                 Key: CXF-6110
>                 URL: https://issues.apache.org/jira/browse/CXF-6110
>             Project: CXF
>          Issue Type: Improvement
>          Components: STS
>    Affects Versions: 2.7.13
>            Reporter: Frank Cornelis
>
> For MEX data like:
> {code:xml}
>   <MetadataSection
>     Dialect="http://www.w3.org/2001/XMLSchema"
>     Identifier="http://something">
>         <Location>https://some/location.xsd</Location>
>   </MetadataSection>
> {code}
> the AbstractSTSClient should probably start downloading when getAny() gives NULL.
> I stumbled upon this by implementing a WS-Trust STS with a WSDL that contains schema imports instead of an embedded XML schema.
> The next patch adds this feature (quick and dirty).
> {code}
> --- src/main/java/org/apache/cxf/ws/security/trust/AbstractSTSClient.java.orig	2014-11-19 17:49:37.964705313 +0100
> +++ src/main/java/org/apache/cxf/ws/security/trust/AbstractSTSClient.java	2014-11-19 18:19:01.989607217 +0100
> @@ -41,6 +41,9 @@
>  import javax.wsdl.extensions.ExtensibilityElement;
>  import javax.wsdl.extensions.schema.Schema;
>  import javax.xml.namespace.QName;
> +import javax.xml.parsers.DocumentBuilder;
> +import javax.xml.parsers.DocumentBuilderFactory;
> +import javax.xml.parsers.ParserConfigurationException;
>  import javax.xml.stream.XMLStreamException;
>  import javax.xml.stream.XMLStreamWriter;
>  import javax.xml.transform.dom.DOMSource;
> @@ -48,6 +51,7 @@
>  import org.w3c.dom.Document;
>  import org.w3c.dom.Element;
>  import org.w3c.dom.Node;
> +import org.xml.sax.SAXException;
>  import org.apache.cxf.Bus;
>  import org.apache.cxf.BusException;
>  import org.apache.cxf.binding.soap.SoapBindingConstants;
> @@ -525,6 +529,11 @@
>                              bus.getExtension(WSDLManager.class).getDefinition((Element)s.getAny());
>                      } else if ("http://www.w3.org/2001/XMLSchema".equals(s.getDialect())) {
>                          Element schemaElement = (Element)s.getAny();
> +                        if (schemaElement ==  null) {
> +                            String schemaLocation = s.getLocation();
> +                            LOG.info("XSD schema location: " + schemaLocation);
> +                            schemaElement = downloadSchema(schemaLocation);
> +                        }
>                          QName schemaName = 
>                              new QName(schemaElement.getNamespaceURI(), schemaElement.getLocalName());
>                          WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
> @@ -586,10 +595,20 @@
>                      client = new ClientImpl(bus, endpoint);
>                  }
>              } catch (Exception ex) {
> -                throw new TrustException(LOG, "WS_MEX_ERROR", ex);
> +                throw new TrustException("WS_MEX_ERROR", LOG, ex);
>              }
>          }
>      }
> +
> +    private Element downloadSchema(String schemaLocation)
> +        throws ParserConfigurationException, SAXException, IOException {
> +        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
> +        documentBuilderFactory.setNamespaceAware(true);
> +        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
> +        Document document = documentBuilder.parse(schemaLocation);
> +        return document.getDocumentElement();
> +    }
> +
>      protected String findMEXLocation(EndpointReferenceType ref, boolean useEPRWSAAddrAsMEXLocation) {
>          if (ref.getMetadata() != null && ref.getMetadata().getAny() != null) {
>              for (Object any : ref.getMetadata().getAny()) {
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)