cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r695935 - in /cxf/trunk: rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/ rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/ rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/ systests/src/test/java/org/apache/cx...
Date Tue, 16 Sep 2008 15:19:20 GMT
Author: dkulp
Date: Tue Sep 16 08:19:19 2008
New Revision: 695935

URL: http://svn.apache.org/viewvc?rev=695935&view=rev
Log:
[CXF-1194] Ignore the validation errors caused by mtom attachments.
Also add the ability to register your own custom validation handlers

Modified:
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentMarshaller.java
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?rev=695935&r1=695934&r2=695935&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java Tue
Sep 16 08:19:19 2008
@@ -45,6 +45,7 @@
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.SchemaOutputResolver;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.ValidationEventHandler;
 import javax.xml.bind.annotation.XmlElementDecl;
 import javax.xml.stream.XMLEventReader;
 import javax.xml.stream.XMLEventWriter;
@@ -151,7 +152,9 @@
     private Map<String, Object> unmarshallerProperties = Collections.emptyMap();
     private Unmarshaller.Listener unmarshallerListener;
     private Marshaller.Listener marshallerListener;
+    private ValidationEventHandler validationEventHandler;
     
+
     private boolean qualifiedSchemas;
     private Service service;
 
@@ -705,6 +708,15 @@
     public void setMarshallerListener(Marshaller.Listener marshallerListener) {
         this.marshallerListener = marshallerListener;
     }
+    
+    
+    public ValidationEventHandler getValidationEventHandler() {
+        return validationEventHandler;
+    }
+
+    public void setValidationEventHandler(ValidationEventHandler validationEventHandler)
{
+        this.validationEventHandler = validationEventHandler;
+    }
 
     
     public static void clearCaches() {

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentMarshaller.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentMarshaller.java?rev=695935&r1=695934&r2=695935&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentMarshaller.java
(original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentMarshaller.java
Tue Sep 16 08:19:19 2008
@@ -29,6 +29,7 @@
 import javax.activation.DataSource;
 import javax.activation.FileDataSource;
 import javax.xml.bind.attachment.AttachmentMarshaller;
+import javax.xml.namespace.QName;
 
 import org.apache.cxf.attachment.AttachmentImpl;
 import org.apache.cxf.attachment.AttachmentUtil;
@@ -41,6 +42,7 @@
     private int threshold = 5 * 1024;
     private Collection<Attachment> atts;
     private boolean isXop;
+    private QName lastElementName;
 
     public JAXBAttachmentMarshaller(Collection<Attachment> attachments, Integer mtomThreshold)
{
         super();
@@ -50,6 +52,10 @@
         atts = attachments;
         isXop = attachments != null;
     }
+    
+    public QName getLastMTOMElementName() {
+        return lastElementName;
+    }
 
     public String addMtomAttachment(byte[] data, int offset, int length, String mimeType,
String elementNS,
                                     String elementLocalName) {
@@ -77,6 +83,7 @@
         att.setXOP(this.isXop);
         atts.add(att);
 
+        lastElementName = new QName(elementNS, elementLocalName);
         return "cid:" + id;
     }
 
@@ -118,6 +125,7 @@
         AttachmentImpl att = new AttachmentImpl(id, handler);
         att.setXOP(this.isXop);
         atts.add(att);
+        lastElementName = new QName(elementNS, elementLocalName);
 
         return "cid:" + id;
     }

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java?rev=695935&r1=695934&r2=695935&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
(original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
Tue Sep 16 08:19:19 2008
@@ -60,6 +60,9 @@
             if (databinding.getUnmarshallerListener() != null) {
                 um.setListener(databinding.getUnmarshallerListener());
             }
+            if (databinding.getValidationEventHandler() != null) {
+                um.setEventHandler(databinding.getValidationEventHandler());
+            }
             if (databinding.getUnmarshallerProperties() != null) {
                 for (Map.Entry<String, Object> propEntry 
                     : databinding.getUnmarshallerProperties().entrySet()) {

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java?rev=695935&r1=695934&r2=695935&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
(original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
Tue Sep 16 08:19:19 2008
@@ -29,6 +29,9 @@
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.PropertyException;
+import javax.xml.bind.ValidationEvent;
+import javax.xml.bind.ValidationEventHandler;
+import javax.xml.bind.attachment.AttachmentMarshaller;
 import javax.xml.namespace.QName;
 
 import com.sun.xml.bind.api.TypeReference;
@@ -40,6 +43,7 @@
 import org.apache.cxf.jaxb.JAXBDataBase;
 import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.jaxb.JAXBEncoderDecoder;
+import org.apache.cxf.jaxb.attachment.JAXBAttachmentMarshaller;
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 
@@ -56,7 +60,28 @@
     public void write(Object obj, T output) {
         write(obj, null, output);
     }
-    
+    private static class MtomValidationHandler implements ValidationEventHandler {
+        ValidationEventHandler origHandler;
+        JAXBAttachmentMarshaller marshaller;
+        public MtomValidationHandler(ValidationEventHandler v,
+                                     JAXBAttachmentMarshaller m) {
+            origHandler = v;
+            marshaller = m;
+        }
+        
+        public boolean handleEvent(ValidationEvent event) {
+            String msg = event.getMessage();
+            if (msg.startsWith("cvc-type.3.1.2: ")
+                && msg.contains(marshaller.getLastMTOMElementName().getLocalPart()))
{
+                return true;
+            }
+            if (origHandler != null) {
+                return origHandler.handleEvent(event);
+            }
+            return false;
+        }
+        
+    }
     public Marshaller createMarshaller(Object elValue, MessagePartInfo part) {
         Class<?> cls = null;
         if (part != null) {
@@ -79,7 +104,9 @@
             marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
             marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
             marshaller.setListener(databinding.getMarshallerListener());
-            
+            if (databinding.getValidationEventHandler() != null) {
+                marshaller.setEventHandler(databinding.getValidationEventHandler());
+            }
             marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper",
                                    databinding.getNamespacePrefixMapper());
             if (databinding.getMarshallerProperties() != null) {
@@ -94,7 +121,15 @@
             }
             
             marshaller.setSchema(schema);
-            marshaller.setAttachmentMarshaller(getAttachmentMarshaller());
+            AttachmentMarshaller atmarsh = getAttachmentMarshaller();
+            marshaller.setAttachmentMarshaller(atmarsh);
+            
+            if (schema != null
+                && atmarsh instanceof JAXBAttachmentMarshaller) {
+                //we need a special even handler for XOP attachments 
+                marshaller.setEventHandler(new MtomValidationHandler(marshaller.getEventHandler(),
+                                                            (JAXBAttachmentMarshaller)atmarsh));
+            }
         } catch (JAXBException ex) {
             if (ex instanceof javax.xml.bind.MarshalException) {
                 javax.xml.bind.MarshalException marshalEx = (javax.xml.bind.MarshalException)ex;

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java?rev=695935&r1=695934&r2=695935&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
Tue Sep 16 08:19:19 2008
@@ -60,7 +60,7 @@
 
     @BeforeClass
     public static void startServers() throws Exception {
-        assertTrue("server did not launch correctly", launchServer(ServerMisc.class, true));
+        assertTrue("server did not launch correctly", launchServer(ServerMisc.class));
     }
     
     @Test

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java?rev=695935&r1=695934&r2=695935&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java Tue
Sep 16 08:19:19 2008
@@ -102,6 +102,9 @@
                                                                                 fileSize);
             }
             
+            ((BindingProvider)mtomPort).getRequestContext().put("schema-validation-enabled",
+                                                                Boolean.TRUE);
+            
             param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
             Holder<String> name = new Holder<String>("call detail");
             mtomPort.testXop(name, param);



Mime
View raw message