cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r922295 - in /cxf/branches/2.2.x-fixes: ./ api/src/main/java/org/apache/cxf/wsdl/ rt/core/src/main/java/org/apache/cxf/interceptor/ rt/core/src/test/java/org/apache/cxf/wsdl11/
Date Fri, 12 Mar 2010 15:27:31 GMT
Author: dkulp
Date: Fri Mar 12 15:27:30 2010
New Revision: 922295

URL: http://svn.apache.org/viewvc?rev=922295&view=rev
Log:
Merged revisions 922289 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r922289 | dkulp | 2010-03-12 10:16:13 -0500 (Fri, 12 Mar 2010) | 2 lines
  
  [CXF-2708] Add more work to find schemas to create the schema for
  validation
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractInDatabindingInterceptor.java
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java
    cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/wsdl11/WSDLServiceBuilderTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Mar 12 15:27:30 2010
@@ -1 +1 @@
-/cxf/trunk:921955
+/cxf/trunk:921955,922289

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java?rev=922295&r1=922294&r2=922295&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
Fri Mar 12 15:27:30 2010
@@ -67,6 +67,7 @@ import org.w3c.dom.ls.LSResourceResolver
 import org.xml.sax.InputSource;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.WSDLConstants;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
@@ -78,6 +79,7 @@ import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
 import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.resource.ExtendedURIResolver;
+import org.apache.cxf.resource.ResourceManager;
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.staxutils.StaxUtils;
@@ -111,9 +113,11 @@ public final class EndpointReferenceUtil
         private final Map<String, byte[]> schemas;
         private final Set<String> done = new HashSet<String>();
         private final ExtendedURIResolver resolver = new ExtendedURIResolver();
+        private final Bus bus;
         
-        private SchemaLSResourceResolver(Map<String, byte[]> schemas) {
+        private SchemaLSResourceResolver(Map<String, byte[]> schemas, Bus b) {
             this.schemas = schemas;
+            this.bus = b;
         }
         
         public LSInput resolveResource(String type, String namespaceURI, String publicId,
@@ -139,38 +143,71 @@ public final class EndpointReferenceUtil
             if (done.contains(newId + ":" + namespaceURI)) {
                 return null;
             }
+            LSInputImpl impl = null;
+            
             if (schemas.containsKey(newId + ":" + namespaceURI)) {
                 byte[] ds = schemas.remove(newId + ":" + namespaceURI);
-                LSInputImpl impl = new LSInputImpl();
+                impl = new LSInputImpl();
                 impl.setSystemId(newId);
                 impl.setBaseURI(newId);
                 impl.setByteStream(new ByteArrayInputStream(ds));
                 done.add(newId + ":" + namespaceURI);
-                return impl;
             }
-            if (schemas.containsKey(newId + ":null")) {
+            if (impl == null && schemas.containsKey(newId + ":null")) {
                 byte[] ds = schemas.get(newId + ":null");
-                LSInputImpl impl = new LSInputImpl();
+                impl = new LSInputImpl();
                 impl.setSystemId(newId);
                 impl.setBaseURI(newId);
                 impl.setByteStream(new ByteArrayInputStream(ds));
                 done.add(newId + ":" + namespaceURI);
-                return impl;                
             }
-
+            if (impl == null && bus != null) {
+                ResourceManager rm = bus.getExtension(ResourceManager.class);
+                URL url = rm == null ? null : rm.resolveResource(systemId, URL.class);
+                if (url != null) {
+                    newId = url.toString();
+                    if (done.contains(newId + ":" + namespaceURI)) {
+                        return null;
+                    }
+                    if (schemas.containsKey(newId + ":" + namespaceURI)) {
+                        byte[] ds = schemas.remove(newId + ":" + namespaceURI);
+                        impl = new LSInputImpl();
+                        impl.setSystemId(newId);
+                        impl.setBaseURI(newId);
+                        impl.setByteStream(new ByteArrayInputStream(ds));
+                        done.add(newId + ":" + namespaceURI);
+                    }
+                }
+            }
+            if (impl != null) {
+                return impl;
+            }
+            for (Map.Entry<String, byte[]> ent : schemas.entrySet()) {
+                if (ent.getKey().endsWith(systemId + ":" + namespaceURI)) {
+                    schemas.remove(ent.getKey());
+                    impl = new LSInputImpl();
+                    impl.setSystemId(newId);
+                    impl.setBaseURI(newId);
+                    impl.setCharacterStream(
+                        new InputStreamReader(
+                            new ByteArrayInputStream(ent.getValue())));
+                    done.add(newId + ":" + namespaceURI);
+                    return impl;
+                }
+            }
             // handle case where given systemId is null (so that
             // direct key lookup fails) by scanning through map
             // searching for a namespace match
-            //
             for (Map.Entry<String, byte[]> ent : schemas.entrySet()) {
                 if (ent.getKey().endsWith(namespaceURI)) {
                     schemas.remove(ent.getKey());
-                    LSInputImpl impl = new LSInputImpl();
+                    impl = new LSInputImpl();
                     impl.setSystemId(newId);
                     impl.setBaseURI(newId);
                     impl.setCharacterStream(
                         new InputStreamReader(
                             new ByteArrayInputStream(ent.getValue())));
+                    done.add(newId + ":" + namespaceURI);
                     return impl;
                 }
             }
@@ -182,15 +219,14 @@ public final class EndpointReferenceUtil
             if (systemId != null) {
                 InputSource source = resolver.resolve(systemId, baseURI);
                 if (source != null) {
-                    LSInputImpl impl = new LSInputImpl();
+                    impl = new LSInputImpl();
                     impl.setByteStream(source.getByteStream());
                     impl.setSystemId(source.getSystemId());
                     impl.setPublicId(source.getPublicId());
-                    return impl;
                 }
             }
             LOG.warning("Could not resolve Schema for " + systemId);
-            return null;
+            return impl;
         }
     }
 
@@ -605,7 +641,10 @@ public final class EndpointReferenceUtil
     }
     
     
-    private static Schema createSchema(ServiceInfo serviceInfo) {
+    private static Schema createSchema(ServiceInfo serviceInfo, Bus b) {
+        if (b == null) {
+            b = BusFactory.getThreadDefaultBus(false);
+        }
         Schema schema = serviceInfo.getProperty(Schema.class.getName(), Schema.class);
         if (schema == null) {
             SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
@@ -665,17 +704,17 @@ public final class EndpointReferenceUtil
                 } 
 
 
-                factory.setResourceResolver(new SchemaLSResourceResolver(schemaSourcesMap));
+                factory.setResourceResolver(new SchemaLSResourceResolver(schemaSourcesMap,
b));
                 schema = factory.newSchema(schemaSourcesMap2.values()
                                            .toArray(new Source[schemaSourcesMap2.size()]));
                 
                 
             } catch (Exception ex) {
                 // Something not right with the schema from the wsdl.
-                LOG.log(Level.WARNING, "SAXException for newSchema() on ", ex);
+                LOG.log(Level.WARNING, "SAXException for newSchema()", ex);
                 for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) {
                     String s = XMLUtils.toString(schemaInfo.getElement(), 4);
-                    LOG.log(Level.WARNING, "Schema for: " + schemaInfo.getNamespaceURI()
+ "\n" + s);
+                    LOG.log(Level.INFO, "Schema for: " + schemaInfo.getNamespaceURI() + "\n"
+ s);
                 }
             }
             serviceInfo.setProperty(Schema.class.getName(), schema);
@@ -684,13 +723,16 @@ public final class EndpointReferenceUtil
     }
     
     public static Schema getSchema(ServiceInfo serviceInfo) {
+        return getSchema(serviceInfo, null);
+    }
+    public static Schema getSchema(ServiceInfo serviceInfo, Bus b) {
         if (serviceInfo == null) {
             return null;
         }
         Schema schema = serviceInfo.getProperty(Schema.class.getName(), Schema.class);
         if (schema == null && !serviceInfo.hasProperty(Schema.class.getName())) {
             synchronized (serviceInfo) {
-                return createSchema(serviceInfo);
+                return createSchema(serviceInfo, b);
             }
         }
         return schema;

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractInDatabindingInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractInDatabindingInterceptor.java?rev=922295&r1=922294&r2=922295&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractInDatabindingInterceptor.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractInDatabindingInterceptor.java
Fri Mar 12 15:27:30 2010
@@ -31,6 +31,7 @@ import javax.xml.validation.Schema;
 
 import org.w3c.dom.Node;
 
+import org.apache.cxf.Bus;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.databinding.DataBindingValidation2;
 import org.apache.cxf.databinding.DataReader;
@@ -106,7 +107,8 @@ public abstract class AbstractInDatabind
     private void setSchemaInMessage(Service service, Message message, DataReader<?>
reader) {
         if (MessageUtils.getContextualBoolean(message, Message.SCHEMA_VALIDATION_ENABLED,
Boolean.FALSE)) {
             //all serviceInfos have the same schemas
-            Schema schema = EndpointReferenceUtils.getSchema(service.getServiceInfos().get(0));
+            Schema schema = EndpointReferenceUtils.getSchema(service.getServiceInfos().get(0),
+                                                             message.getExchange().get(Bus.class));
             reader.setSchema(schema);
             /* This might be a reader that wants to grab the schema from the
              * service info. 

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java?rev=922295&r1=922294&r2=922295&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java
Fri Mar 12 15:27:30 2010
@@ -29,6 +29,7 @@ import javax.xml.stream.XMLStreamWriter;
 import javax.xml.stream.events.XMLEvent;
 import javax.xml.validation.Schema;
 
+import org.apache.cxf.Bus;
 import org.apache.cxf.databinding.DataWriter;
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Exchange;
@@ -175,7 +176,8 @@ public abstract class AbstractOutDatabin
 
     private void setSchemaOutMessage(Service service, Message message, DataWriter<?>
writer) {
         if (shouldValidate(message)) {
-            Schema schema = EndpointReferenceUtils.getSchema(service.getServiceInfos().get(0));
+            Schema schema = EndpointReferenceUtils.getSchema(service.getServiceInfos().get(0),
+                                                             message.getExchange().get(Bus.class));
             writer.setSchema(schema);
         }
     }

Modified: cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/wsdl11/WSDLServiceBuilderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/wsdl11/WSDLServiceBuilderTest.java?rev=922295&r1=922294&r2=922295&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/wsdl11/WSDLServiceBuilderTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/wsdl11/WSDLServiceBuilderTest.java
Fri Mar 12 15:27:30 2010
@@ -459,7 +459,7 @@ public class WSDLServiceBuilderTest exte
         assertNotNull(serviceInfo.getSchemas());
         Element ele = serviceInfo.getSchemas().iterator().next().getElement();
         assertNotNull(ele);
-        Schema schema = EndpointReferenceUtils.getSchema(serviceInfo);        
+        Schema schema = EndpointReferenceUtils.getSchema(serviceInfo, null);        
         assertNotNull(schema);        
         control.verify();
     }



Mime
View raw message