cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r824497 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/helpers/ common/common/src/main/java/org/apache/cxf/staxutils/ rt/core/src/main/java/org/apache/cxf/databinding/source/ rt/core/src/main/java/org/apache/cxf/interceptor/ rt...
Date Mon, 12 Oct 2009 20:57:35 GMT
Author: dkulp
Date: Mon Oct 12 20:57:34 2009
New Revision: 824497

URL: http://svn.apache.org/viewvc?rev=824497&view=rev
Log:
Add support for schema validation to Provider based endpoints
Add streaming support for Provider based endpoints

Added:
    cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq_invalid.xml 
 (with props)
Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/FragmentStreamReader.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/SourceDataBinding.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java
    cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderServiceFactoryTest.java
    cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSourcePayloadProvider.java
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderRPCClientServerTest.java
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderXMLClientServerTest.java
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/Server.java
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/XMLServer.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java?rev=824497&r1=824496&r2=824497&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java Mon Oct 12
20:57:34 2009
@@ -25,6 +25,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.StringWriter;
 import java.io.Writer;
 import java.util.Collections;
 import java.util.List;
@@ -199,7 +200,7 @@
     }
 
     public static String toString(Source source, Properties props) throws TransformerException,
IOException {
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        StringWriter bos = new StringWriter();
         StreamResult sr = new StreamResult(bos);
         Transformer trans = newTransformer();
         if (props == null) {

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/FragmentStreamReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/FragmentStreamReader.java?rev=824497&r1=824496&r2=824497&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/FragmentStreamReader.java
(original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/FragmentStreamReader.java
Mon Oct 12 20:57:34 2009
@@ -23,7 +23,7 @@
 import javax.xml.stream.XMLStreamReader;
 
 /**
- * Wraps a XMLStreamReader and provides START_DOCUMENT and END_DOCUMENT events.
+ * Wraps a XMLStreamReader and provides optional START_DOCUMENT and END_DOCUMENT events.
  * 
  * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
  */
@@ -32,6 +32,7 @@
     private boolean startElement;
     private boolean middle = true;
     private boolean endDoc;
+    private boolean doDocEvents = true;
 
     private int depth;
     private int current = -1;
@@ -41,6 +42,17 @@
     public FragmentStreamReader(XMLStreamReader reader) {
         super(reader);
     }    
+    public FragmentStreamReader(XMLStreamReader reader, boolean doDocEvents) {
+        super(reader);
+        this.doDocEvents = doDocEvents;
+        if (!doDocEvents) {
+            startDoc = true;
+            
+            depth = getDepth();
+            current = reader.getEventType();
+            startElement = true;
+        }
+    }    
    
     public int getEventType() {
         return current;
@@ -58,7 +70,7 @@
         return reader.hasNext();
     }
     
-    public int next() throws XMLStreamException {
+    public final int next() throws XMLStreamException {
         if (!startDoc) {
             startDoc = true;
             current = START_DOCUMENT;
@@ -82,6 +94,9 @@
 
             if (current == END_ELEMENT && getDepth() < depth) {
                 middle = false;
+                if (!doDocEvents) {
+                    endDoc = true;
+                }
             }
         } else if (!endDoc) {
             // Move past the END_ELEMENT token.

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java?rev=824497&r1=824496&r2=824497&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java Mon Oct
12 20:57:34 2009
@@ -148,6 +148,9 @@
                 default:
                     break;
                 }
+                if (!streamReader.hasNext()) {
+                    return;
+                }
                 streamReader.next();
             }
         } catch (XMLStreamException e) {

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=824497&r1=824496&r2=824497&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Mon Oct
12 20:57:34 2009
@@ -356,6 +356,7 @@
                     throw new XMLStreamException(e);
                 }
             }
+       
         }
         
         XMLStreamReader reader = createXMLStreamReader(source);
@@ -937,6 +938,13 @@
                 if (null != el) {
                     return new W3CDOMStreamReader(el);
                 }
+            } else if ("javax.xml.transform.stax.StAXSource".equals(source.getClass().getName()))
{
+                try {
+                    return (XMLStreamReader)source.getClass()
+                        .getMethod("getXMLStreamReader").invoke(source);
+                } catch (Exception ex) {
+                    //ignore
+                }
             }
             
             XMLInputFactory factory = getXMLInputFactory();

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/SourceDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/SourceDataBinding.java?rev=824497&r1=824496&r2=824497&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/SourceDataBinding.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/SourceDataBinding.java
Mon Oct 12 20:57:34 2009
@@ -32,6 +32,8 @@
  * A simple databinding implementation which reads and writes Source objects.
  */
 public class SourceDataBinding extends org.apache.cxf.databinding.AbstractDataBinding {
+    
+    public static final String PREFERRED_FORMAT = "source-preferred-format";
 
     private XMLStreamDataReader xsrReader;
     private XMLStreamDataWriter xswWriter;

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java?rev=824497&r1=824496&r2=824497&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
Mon Oct 12 20:57:34 2009
@@ -29,22 +29,30 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 
 import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 
-import org.apache.cxf.common.i18n.Message;
+import org.xml.sax.SAXException;
+
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.databinding.DataReader;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Attachment;
+import org.apache.cxf.message.Message;
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.staxutils.DepthXMLStreamReader;
+import org.apache.cxf.staxutils.FragmentStreamReader;
+import org.apache.cxf.staxutils.StaxSource;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.staxutils.W3CDOMStreamReader;
 
@@ -52,31 +60,51 @@
 
 public class XMLStreamDataReader implements DataReader<XMLStreamReader> {
     private static final Logger LOG = LogUtils.getL7dLogger(XMLStreamDataReader.class);
-
+    private Schema schema;
+    private Message message;
+    
     public Object read(MessagePartInfo part, XMLStreamReader input) {
         return read(null, input, part.getTypeClass());
     }
 
     public Object read(final QName name, XMLStreamReader input, Class type) {
-        if (type != null) {
-            if (SAXSource.class.isAssignableFrom(type)) {
+        if (Source.class.equals(type) && message != null) {
+            //generic Source, find the preferred type
+            String s = (String)message.getContextualProperty(SourceDataBinding.PREFERRED_FORMAT);
+            if (StringUtils.isEmpty(s)) {
+                s = "dom";  //for now, should probably be stax
+            }
+            if ("dom".equalsIgnoreCase(s)) {
+                type = DOMSource.class;
+            } else if ("stream".equalsIgnoreCase(s)) {
+                type = StreamSource.class;
+            } else if ("sax".equalsIgnoreCase(s) || "cxf.stax".equalsIgnoreCase(s)) {
+                type = SAXSource.class;
+            } else if ("stax".equals(s)) {
                 try {
-                    return new SAXSource(new InputSource(getInputStream(input)));
-                } catch (IOException e) {
-                    throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
-                } catch (XMLStreamException e) {
-                    throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
+                    type = ClassLoaderUtils.loadClass("javax.xml.transform.stax.StAXSource",
getClass());
+                } catch (ClassNotFoundException e) {
+                    type = SAXSource.class;
                 }
-            } else if (StreamSource.class.isAssignableFrom(type)) {
-                try {
+            } else {
+                type = DOMSource.class;
+            }
+        }
+        try {
+            Element dom = null;
+            if (schema != null) {
+                dom = validate(input);
+                input = StaxUtils.createXMLStreamReader(dom);
+            }
+            if (type != null) {
+                if (SAXSource.class.isAssignableFrom(type)
+                    || StaxSource.class.isAssignableFrom(type)) {
+                    return new StaxSource(resetForStreaming(input));
+                } else if (StreamSource.class.isAssignableFrom(type)) {
                     return new StreamSource(getInputStream(input));
-                } catch (IOException e) {
-                    throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
-                } catch (XMLStreamException e) {
-                    throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
-                }
-            } else if (DataSource.class.isAssignableFrom(type)) {
-                try {
+                } else if (XMLStreamReader.class.isAssignableFrom(type)) {
+                    return resetForStreaming(input);
+                } else if (DataSource.class.isAssignableFrom(type)) {
                     final InputStream ins = getInputStream(input);
                     return new DataSource() {
                         public String getContentType() {
@@ -92,15 +120,71 @@
                             return null;
                         }
                     };
-                } catch (IOException e) {
-                    throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
-                } catch (XMLStreamException e) {
-                    throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
-                }                
+                } else if ("javax.xml.transform.stax.StAXSource".equals(type.getName()))
{
+                    input = resetForStreaming(input);
+                    Object o = createStaxSource(input, type);
+                    if (o != null) {
+                        return o;
+                    }
+                }
             }
+            return dom == null ? read(input) : new DOMSource(dom);
+        } catch (IOException e) {
+            throw new Fault("COULD_NOT_READ_XML_STREAM", LOG, e);
+        } catch (XMLStreamException e) {
+            throw new Fault("COULD_NOT_READ_XML_STREAM", LOG, e);
+        } catch (SAXException e) {
+            throw new Fault("COULD_NOT_READ_XML_STREAM", LOG, e);
         }
-        return read(input);
     }
+    
+    private Object createStaxSource(XMLStreamReader input, Class<?> type) {
+        try {
+            return type.getConstructor(XMLStreamReader.class).newInstance(input);
+        } catch (Exception e) {
+            //ignore
+        }
+        return null;
+    }
+    
+    private XMLStreamReader resetForStreaming(XMLStreamReader input) throws XMLStreamException
{
+        //Need to mark the message as streaming this so input stream
+        //is not closed and additional parts are not read and such
+        if (message != null) {
+            message.removeContent(XMLStreamReader.class);
+            final InputStream ins = message.getContent(InputStream.class);
+            message.removeContent(InputStream.class);
+            
+            input = new FragmentStreamReader(input, false) {
+                boolean closed;
+                public boolean hasNext() throws XMLStreamException {
+                    boolean b = super.hasNext();
+                    if (!b && !closed) {
+                        closed = true;
+                        try {
+                            ins.close();
+                        } catch (IOException e) {
+                            //ignore
+                        }
+                    }
+                    return b;
+                }
+            };
+        }
+        return input;
+    }
+
+    private Element validate(XMLStreamReader input) 
+        throws XMLStreamException, SAXException, IOException {
+        DOMSource ds = read(input);
+        schema.newValidator().validate(ds);
+        Node nd = ds.getNode();
+        if (nd instanceof Document) {
+            return ((Document)nd).getDocumentElement();
+        }
+        return (Element)ds.getNode();
+    }
+
     private InputStream getInputStream(XMLStreamReader input) 
         throws XMLStreamException, IOException {
         
@@ -114,7 +198,7 @@
             out.close();
         }
     }
-    public Object read(XMLStreamReader reader) {
+    public DOMSource read(XMLStreamReader reader) {
         // Use a DOMSource for now, we should really use a StaxSource/SAXSource though for

         // performance reasons
         try {
@@ -124,7 +208,7 @@
             }
             if (reader2 instanceof W3CDOMStreamReader) {
                 W3CDOMStreamReader domreader = (W3CDOMStreamReader)reader2;
-                Object o = new DOMSource(domreader.getCurrentElement());
+                DOMSource o = new DOMSource(domreader.getCurrentElement());
                 domreader.consumeFrame();
                 return o;
             } else {
@@ -132,16 +216,20 @@
                 return new DOMSource(document);
             }
         } catch (XMLStreamException e) {
-            throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
+            throw new Fault("COULD_NOT_READ_XML_STREAM", LOG, e);
         }
     }
     
     public void setSchema(Schema s) {
+        schema = s;
     }
 
     public void setAttachments(Collection<Attachment> attachments) {
     }
 
-    public void setProperty(String prop, Object value) {   
+    public void setProperty(String prop, Object value) {
+        if (Message.class.getName().equals(prop)) {
+            message = (Message)value;
+        }
     }
 }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java?rev=824497&r1=824496&r2=824497&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java
Mon Oct 12 20:57:34 2009
@@ -189,7 +189,10 @@
                     parameters.put(p, o);
                     
                     paramNum++;
-                } while (StaxUtils.toNextElement(xmlReader));
+                    if (message.getContent(XMLStreamReader.class) == null) {
+                        xmlReader = null;
+                    }
+                } while (xmlReader != null && StaxUtils.toNextElement(xmlReader));
     
             }
     

Modified: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderServiceFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderServiceFactoryTest.java?rev=824497&r1=824496&r2=824497&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderServiceFactoryTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderServiceFactoryTest.java
Mon Oct 12 20:57:34 2009
@@ -128,7 +128,7 @@
         JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
         svrFactory.setBus(getBus());
         svrFactory.setServiceFactory(bean);
-        String address = "http://localhost:9000/test";
+        String address = "local://localhost:9000/test";
         svrFactory.setAddress(address);
 
         ServerImpl server = (ServerImpl)svrFactory.create();
@@ -169,7 +169,7 @@
         JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
         svrFactory.setBus(getBus());
         svrFactory.setServiceFactory(bean);
-        String address = "http://localhost:9000/test";
+        String address = "local://localhost:9000/test";
         svrFactory.setAddress(address);
 
         ServerImpl server = (ServerImpl)svrFactory.create();
@@ -214,7 +214,7 @@
         svrFactory.setServiceClass(SourceMessageProvider.class);
         svrFactory.setBus(getBus());
         svrFactory.setServiceBean(new SourceMessageProvider());
-        String address = "http://localhost:9000/test";
+        String address = "local://localhost:9000/test";
         svrFactory.setAddress(address);
 
         svrFactory.create();

Modified: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java?rev=824497&r1=824496&r2=824497&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java
Mon Oct 12 20:57:34 2009
@@ -29,9 +29,9 @@
     @Test
     public void testInvocation() throws Exception {
         EndpointImpl ep = new EndpointImpl(getBus(), new PayloadProvider(), (String) null);
-        ep.publish("http://localhost:9000/Provider");
+        ep.publish("local://localhost:9000/Provider");
         
-        Node response = invoke("http://localhost:9000/Provider",
+        Node response = invoke("local://localhost:9000/Provider",
                                LocalTransportFactory.TRANSPORT_ID, 
                                "/org/apache/cxf/jaxws/sayHi.xml");
 
@@ -45,9 +45,9 @@
     @Test
     public void testCXF1852() throws Exception {
         EndpointImpl ep = new EndpointImpl(getBus(), new PayloadProvider2(), (String) null);
-        ep.publish("http://localhost:9001/Provider2");
+        ep.publish("local://localhost:9001/Provider2");
         
-        Node response = invoke("http://localhost:9001/Provider2",
+        Node response = invoke("local://localhost:9001/Provider2",
                                LocalTransportFactory.TRANSPORT_ID, 
                                "/org/apache/cxf/jaxws/sayHi.xml");
 

Modified: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSourcePayloadProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSourcePayloadProvider.java?rev=824497&r1=824496&r2=824497&view=diff
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSourcePayloadProvider.java
(original)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSourcePayloadProvider.java
Mon Oct 12 20:57:34 2009
@@ -23,16 +23,28 @@
 import java.io.Writer;
 
 import javax.jws.HandlerChain;
+import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Source;
 import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.ws.Provider;
 import javax.xml.ws.ServiceMode;
 import javax.xml.ws.WebServiceProvider;
 
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.staxutils.StaxSource;
+import org.apache.cxf.staxutils.StaxUtils;
+
 //The following wsdl file is used.
 //wsdlLocation = "/trunk/testutils/src/main/resources/wsdl/hello_world_rpc_lit.wsdl"
 @WebServiceProvider(portName = "SoapPortProviderRPCLit3", serviceName = "SOAPServiceProviderRPCLit",
@@ -41,6 +53,7 @@
 @ServiceMode (value = javax.xml.ws.Service.Mode.PAYLOAD)
 @HandlerChain(file = "./handlers_invocation.xml", name = "TestHandlerChain")
 public class HWSourcePayloadProvider implements Provider<Source> {
+    boolean doneStax;
     
     public HWSourcePayloadProvider() {
     
@@ -48,17 +61,12 @@
     
     public Source invoke(Source request) {        
         try {
+            System.out.println(request.getClass().getName());
             String input = getSourceAsString(request);
             System.out.println(input);  
             
             if (input.indexOf("ServerLogicalHandler") >= 0) {
-                StreamSource source = new StreamSource();
-                
-                InputStream greetMeInputStream = getClass()
-                    .getResourceAsStream("resources/GreetMeRpcLiteralRespBody.xml");
-
-                source.setInputStream(greetMeInputStream);
-                return source;               
+                return map(request.getClass());
             }
 
         } catch (Exception e) {
@@ -68,14 +76,51 @@
         return null;
     }
     
+    private Source map(Class<? extends Source> class1) 
+        throws Exception {
+        
+        InputStream greetMeInputStream = getClass()
+            .getResourceAsStream("resources/GreetMeRpcLiteralRespBody.xml");
+        if (DOMSource.class.equals(class1)) {
+            return new DOMSource(XMLUtils.parse(greetMeInputStream));
+        } else if (StaxSource.class.equals(class1)) {
+            if (doneStax) {
+                XMLReader reader = XMLReaderFactory.createXMLReader();
+                return new SAXSource(reader, new InputSource(greetMeInputStream));
+            } else {
+                doneStax = true;
+                return new StaxSource(StaxUtils.createXMLStreamReader(greetMeInputStream));
+            }
+        } else if (StreamSource.class.equals(class1)) {
+            StreamSource source = new StreamSource();
+            source.setInputStream(greetMeInputStream);
+            return source;
+        }
+        //java 6 javax.xml.transform.stax.StAXSource
+        XMLStreamReader reader = StaxUtils.createXMLStreamReader(greetMeInputStream);
+        return class1.getConstructor(XMLStreamReader.class).newInstance(reader);
+    }
+
     public static String getSourceAsString(Source s) throws Exception {
-        Transformer transformer = TransformerFactory.newInstance().newTransformer();
-        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
-        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
-        Writer out = new StringWriter();
-        StreamResult streamResult = new StreamResult();
-        streamResult.setWriter(out);
-        transformer.transform(s, streamResult);
-        return streamResult.getWriter().toString();
+        try {
+            Transformer transformer = TransformerFactory.newInstance().newTransformer();
+            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+            Writer out = new StringWriter();
+            StreamResult streamResult = new StreamResult();
+            streamResult.setWriter(out);
+            transformer.transform(s, streamResult);
+            return streamResult.getWriter().toString();
+            
+        } catch (TransformerException te) {
+            if ("javax.xml.transform.stax.StAXSource".equals(s.getClass().getName())) {
+                //on java6, we will get this class if "stax" is configured
+                //for the preferred type. However, older xalans don't know about it
+                //we'll manually do it
+                XMLStreamReader r = (XMLStreamReader)s.getClass().getMethod("getXMLStreamReader").invoke(s);
+                return XMLUtils.toString(StaxUtils.read(r).getDocumentElement());
+            }
+            throw te;
+        }
     }
 }

Modified: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderRPCClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderRPCClientServerTest.java?rev=824497&r1=824496&r2=824497&view=diff
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderRPCClientServerTest.java
(original)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderRPCClientServerTest.java
Mon Oct 12 20:57:34 2009
@@ -29,6 +29,7 @@
 import javax.xml.soap.SOAPConnectionFactory;
 import javax.xml.soap.SOAPFactory;
 import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.BindingProvider;
 import javax.xml.ws.soap.SOAPFaultException;
 
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -73,10 +74,21 @@
                                  QName portName,
                                  int count,
                                  boolean doFault) throws Exception {
+        doGreeterRPCLit(service, portName, count, doFault, null);
+    }
+    private void doGreeterRPCLit(SOAPServiceRPCLit service,
+                                 QName portName,
+                                 int count,
+                                 boolean doFault,
+                                 String address) throws Exception {
         String response1 = new String("TestGreetMeResponse");
         String response2 = new String("TestSayHiResponse");
         try {
             GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class);
+            if (address != null) {
+                ((BindingProvider)greeter).getRequestContext()
+                    .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
+            }
             for (int idx = 0; idx < count; idx++) {
                 String greeting = greeter.greetMe("Milestone-" + idx);
                 assertNotNull("no response received from service", greeting);
@@ -164,17 +176,23 @@
         SOAPServiceRPCLit service = new SOAPServiceRPCLit(wsdl, serviceName);
         assertNotNull(service);
 
-        
+        String addresses[] = {
+            "http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8",
+            "http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-dom",
+            "http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-sax",
+            "http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-cxfstax",
+            "http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-stax",
+            "http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-stream"
              
+        };
         String response1 = new String("TestGreetMeResponseServerLogicalHandlerServerSOAPHandler");
-        try {
-            GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class);
+        GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class);
+        for (String ad : addresses) {
+            ((BindingProvider)greeter).getRequestContext()
+                .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ad);
             String greeting = greeter.greetMe("Milestone-0");
-            assertNotNull("no response received from service", greeting);
-            assertEquals(response1, greeting);
-        } catch (UndeclaredThrowableException ex) {
-            throw (Exception)ex.getCause();
+            assertNotNull("no response received from service " + ad, greeting);
+            assertEquals("wrong response received from service " + ad, response1, greeting);
         }
-
     }
     
     @Test

Modified: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderXMLClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderXMLClientServerTest.java?rev=824497&r1=824496&r2=824497&view=diff
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderXMLClientServerTest.java
(original)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderXMLClientServerTest.java
Mon Oct 12 20:57:34 2009
@@ -72,6 +72,22 @@
         assertEquals("greetMeResponse", respDoc.getFirstChild().getLocalName());
         assertEquals("TestXMLBindingProviderMessage", respDoc.getFirstChild()
                 .getTextContent());
+        
+        is = getClass().getResourceAsStream(
+            "/messages/XML_GreetMeDocLiteralReq_invalid.xml");
+        doc = XMLUtils.parse(is);
+        reqMsg = new DOMSource(doc);
+        assertNotNull(reqMsg);
+
+        disp = service.createDispatch(portName,
+                                      DOMSource.class, Service.Mode.PAYLOAD);
+        
+        try {
+            result = disp.invoke(reqMsg);
+            fail("should have a schema validation exception of some sort");
+        } catch (Exception ex) {
+            //expected - different validators are throwing different error messages though
+        }
     }
 
 }

Modified: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/Server.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/Server.java?rev=824497&r1=824496&r2=824497&view=diff
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/Server.java (original)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/Server.java Mon
Oct 12 20:57:34 2009
@@ -19,8 +19,12 @@
 
 package org.apache.cxf.systest.provider;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import javax.xml.ws.Endpoint;
 
+import org.apache.cxf.databinding.source.SourceDataBinding;
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
 
 public class Server extends AbstractBusTestServerBase {
@@ -28,7 +32,40 @@
     protected void run() {
         Object implementor = new HWSourcePayloadProvider();
         String address = "http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8";
-        Endpoint.publish(address, implementor);        
+        Endpoint ep = Endpoint.create(implementor);
+        ep.publish(address);
+        
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put(SourceDataBinding.PREFERRED_FORMAT, "dom");
+        address = "http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-dom";
+        ep = Endpoint.create(implementor);
+        ep.setProperties(map);
+        ep.publish(address);
+        
+        map.put(SourceDataBinding.PREFERRED_FORMAT, "sax");
+        address = "http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-sax";
+        ep = Endpoint.create(implementor);
+        ep.setProperties(map);
+        ep.publish(address);
+
+        map.put(SourceDataBinding.PREFERRED_FORMAT, "stax");
+        address = "http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-stax";
+        ep = Endpoint.create(implementor);
+        ep.setProperties(map);
+        ep.publish(address);
+
+        map.put(SourceDataBinding.PREFERRED_FORMAT, "cxf.stax");
+        address = "http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-cxfstax";
+        ep = Endpoint.create(implementor);
+        ep.setProperties(map);
+        ep.publish(address);
+
+        map.put(SourceDataBinding.PREFERRED_FORMAT, "stream");
+        address = "http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-stream";
+        ep = Endpoint.create(implementor);
+        ep.setProperties(map);
+        ep.publish(address);
+
                
         implementor = new HWSoapMessageProvider();
         address = "http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit1";

Modified: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/XMLServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/XMLServer.java?rev=824497&r1=824496&r2=824497&view=diff
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/XMLServer.java
(original)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/XMLServer.java
Mon Oct 12 20:57:34 2009
@@ -19,6 +19,9 @@
 
 package org.apache.cxf.systest.provider;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import javax.xml.ws.Endpoint;
 
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
@@ -28,7 +31,11 @@
     protected void run() {
         Object implementor = new HWDOMSourcePayloadXMLBindingProvider();
         String address = "http://localhost:9022/XMLService/XMLProviderPort";
-        Endpoint.publish(address, implementor);
+        Endpoint ep = Endpoint.create(implementor);
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("schema-validation-enabled", Boolean.TRUE);
+        ep.setProperties(map);
+        ep.publish(address);
     }
 
     public static void main(String[] args) {

Added: cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq_invalid.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq_invalid.xml?rev=824497&view=auto
==============================================================================
--- cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq_invalid.xml (added)
+++ cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq_invalid.xml Mon
Oct 12 20:57:34 2009
@@ -0,0 +1,22 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<ns2:greetMe xmlns="http://www.w3.org/2005/02/addressing/wsdl"
+	xmlns:ns2="http://apache.org/hello_world_xml_http/wrapped/types">
+	<requestType xmlns="">tli</requestType>
+</ns2:greetMe>

Propchange: cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq_invalid.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq_invalid.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/testutils/src/main/resources/messages/XML_GreetMeDocLiteralReq_invalid.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message