You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by jp...@apache.org on 2015/02/06 13:09:41 UTC

cxf git commit: CXF-6242 added some constants for jaxb event handlers to make it simpler to reference them in custom interceptors change to make sure that the original event handler gets the call to handle event first before the local hack code is execut

Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes 2de364d58 -> 835761049


CXF-6242 added some constants for jaxb event handlers to make it simpler to reference them in custom interceptors
change to make sure that the original event handler gets the call to handle event first before the local hack code is executed
added ability to customise marshal and unmarshal exceptions


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/83576104
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/83576104
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/83576104

Branch: refs/heads/2.7.x-fixes
Commit: 835761049b358a9a66603c06ea1363537a8de657
Parents: 2de364d
Author: Jason Pell <jp...@apache.org>
Authored: Fri Feb 6 16:58:06 2015 +1100
Committer: Jason Pell <jp...@apache.org>
Committed: Fri Feb 6 22:35:15 2015 +1100

----------------------------------------------------------------------
 .../org/apache/cxf/jaxb/JAXBDataBinding.java    |  5 ++
 .../apache/cxf/jaxb/MarshallerEventHandler.java | 25 +++++++
 .../cxf/jaxb/UnmarshallerEventHandler.java      | 25 +++++++
 .../org/apache/cxf/jaxb/io/DataReaderImpl.java  | 65 +++++++++++++-----
 .../org/apache/cxf/jaxb/io/DataWriterImpl.java  | 43 +++++++++---
 .../cxf/jaxb/io/MyCustomMarshallerHandler.java  | 72 ++++++++++++++++++++
 .../cxf/jaxb/io/XMLStreamDataReaderTest.java    | 45 +++++++++---
 .../cxf/jaxb/io/XMLStreamDataWriterTest.java    | 61 +++++++++++++----
 8 files changed, 294 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/83576104/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
----------------------------------------------------------------------
diff --git a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
index 95fed9b..14ce43f 100644
--- a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
+++ b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
@@ -99,6 +99,11 @@ import org.apache.cxf.ws.addressing.ObjectFactory;
 public class JAXBDataBinding extends AbstractDataBinding
     implements WrapperCapableDatabinding, InterceptorProvider {
 
+    public static final String READER_VALIDATION_EVENT_HANDLER = "jaxb-reader-validation-event-handler";
+    public static final String VALIDATION_EVENT_HANDLER = "jaxb-validation-event-handler";
+    public static final String SET_VALIDATION_EVENT_HANDLER = "set-jaxb-validation-event-handler";
+    public static final String WRITER_VALIDATION_EVENT_HANDLER = "jaxb-writer-validation-event-handler";
+    
     public static final String SCHEMA_RESOURCE = "SCHEMRESOURCE";
     public static final String MTOM_THRESHOLD = "org.apache.cxf.jaxb.mtomThreshold";
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/83576104/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/MarshallerEventHandler.java
----------------------------------------------------------------------
diff --git a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/MarshallerEventHandler.java b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/MarshallerEventHandler.java
new file mode 100644
index 0000000..91071d6
--- /dev/null
+++ b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/MarshallerEventHandler.java
@@ -0,0 +1,25 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.jaxb;
+
+import javax.xml.bind.MarshalException;
+
+public interface MarshallerEventHandler {
+    void onMarshalComplete() throws MarshalException;
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/83576104/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/UnmarshallerEventHandler.java
----------------------------------------------------------------------
diff --git a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/UnmarshallerEventHandler.java b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/UnmarshallerEventHandler.java
new file mode 100644
index 0000000..f48be5b
--- /dev/null
+++ b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/UnmarshallerEventHandler.java
@@ -0,0 +1,25 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.jaxb;
+
+import javax.xml.bind.UnmarshalException;
+
+public interface UnmarshallerEventHandler {
+    void onUnmarshalComplete() throws UnmarshalException;
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/83576104/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
----------------------------------------------------------------------
diff --git a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
index 31676a3..8674a41 100644
--- a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
+++ b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
@@ -26,6 +26,7 @@ import java.util.logging.Logger;
 
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.PropertyException;
+import javax.xml.bind.UnmarshalException;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.ValidationEvent;
 import javax.xml.bind.ValidationEventHandler;
@@ -38,6 +39,7 @@ import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxb.JAXBDataBase;
 import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.jaxb.JAXBEncoderDecoder;
+import org.apache.cxf.jaxb.UnmarshallerEventHandler;
 import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.service.model.MessagePartInfo;
 
@@ -65,34 +67,38 @@ public class DataReaderImpl<T> extends JAXBDataBase implements DataReader<T> {
         }
         
         public boolean handleEvent(ValidationEvent event) {
-            String msg = event.getMessage();
-            if (msg != null 
-                && msg.contains(":Id") 
-                && (msg.startsWith("cvc-type.3.1.1: ") 
-                    || msg.startsWith("cvc-type.3.2.2: ") 
-                    || msg.startsWith("cvc-complex-type.3.1.1: ")
-                    || msg.startsWith("cvc-complex-type.3.2.2: "))) {
+            // if the original handler has already handled the event, no need for us
+            // to do anything, otherwise if not yet handled, then do this 'hack' 
+            if (origHandler != null && origHandler.handleEvent(event)) {
                 return true;
+            } else {
+                String msg = event.getMessage();
+                return msg != null 
+                    && msg.contains(":Id") 
+                    && (msg.startsWith("cvc-type.3.1.1: ") 
+                        || msg.startsWith("cvc-type.3.2.2: ") 
+                        || msg.startsWith("cvc-complex-type.3.1.1: ")
+                        || msg.startsWith("cvc-complex-type.3.2.2: "));
             }
-            if (origHandler != null) {
-                return origHandler.handleEvent(event);
-            }
-            return false;
         }
     }
+    
     public void setProperty(String prop, Object value) {
         if (prop.equals(JAXBDataBinding.UNWRAP_JAXB_ELEMENT)) {
             unwrapJAXBElement = Boolean.TRUE.equals(value);
         } else if (prop.equals(org.apache.cxf.message.Message.class.getName())) {
             org.apache.cxf.message.Message m = (org.apache.cxf.message.Message)value;
-            veventHandler = (ValidationEventHandler)m.getContextualProperty("jaxb-reader-validation-event-handler");
+            veventHandler = (ValidationEventHandler)m.getContextualProperty(
+                    JAXBDataBinding.READER_VALIDATION_EVENT_HANDLER);
             if (veventHandler == null) {
-                veventHandler = (ValidationEventHandler)m.getContextualProperty("jaxb-validation-event-handler");
+                veventHandler = (ValidationEventHandler)m.getContextualProperty(
+                        JAXBDataBinding.VALIDATION_EVENT_HANDLER);
             }
             if (veventHandler == null) {
                 veventHandler = databinding.getValidationEventHandler();
             }
-            setEventHandler = MessageUtils.getContextualBoolean(m, "set-jaxb-validation-event-handler", true);
+            setEventHandler = MessageUtils.getContextualBoolean(m, 
+                    JAXBDataBinding.SET_VALIDATION_EVENT_HANDLER, true);
             
             Object unwrapProperty = m.get(JAXBDataBinding.UNWRAP_JAXB_ELEMENT);
             if (unwrapProperty == null) {
@@ -103,6 +109,7 @@ public class DataReaderImpl<T> extends JAXBDataBase implements DataReader<T> {
             }
         }
     }
+    
     private Unmarshaller createUnmarshaller() {
         try {
             Unmarshaller um = null;
@@ -148,23 +155,47 @@ public class DataReaderImpl<T> extends JAXBDataBase implements DataReader<T> {
                 // TODO:Cache the JAXBRIContext
                 QName qname = new QName(null, part.getConcreteName().getLocalPart());
 
-                return JAXBEncoderDecoder.unmarshalWithBridge(qname, 
+                Object obj = JAXBEncoderDecoder.unmarshalWithBridge(qname, 
                                                               part.getTypeClass(), 
                                                               anns, 
                                                               databinding.getContextClasses(), 
                                                               reader, 
                                                               getAttachmentUnmarshaller());
+                
+                onCompleteUnmarshalling();
+                
+                return obj;
             }
         }
         
-        return JAXBEncoderDecoder.unmarshall(createUnmarshaller(), reader, part, 
+        Object obj = JAXBEncoderDecoder.unmarshall(createUnmarshaller(), reader, part, 
                                              unwrapJAXBElement);
+        onCompleteUnmarshalling();
+        
+        return obj;
     }
 
     public Object read(QName name, T input, Class<?> type) {
-        return JAXBEncoderDecoder.unmarshall(createUnmarshaller(), input,
+        Object obj = JAXBEncoderDecoder.unmarshall(createUnmarshaller(), input,
                                              name, type, 
                                              unwrapJAXBElement);
+        onCompleteUnmarshalling();
+        
+        return obj;
     }
 
+    private void onCompleteUnmarshalling() {
+        if (setEventHandler && veventHandler instanceof UnmarshallerEventHandler) {
+            try {
+                ((UnmarshallerEventHandler) veventHandler).onUnmarshalComplete();
+            } catch (UnmarshalException e) {
+                if (e.getLinkedException() != null) {
+                    throw new Fault(new Message("UNMARSHAL_ERROR", LOG, 
+                            e.getLinkedException().getMessage()), e);
+                } else {
+                    throw new Fault(new Message("UNMARSHAL_ERROR", LOG, e.getMessage()), e);
+                }
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/83576104/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
----------------------------------------------------------------------
diff --git a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
index 5846994..51a50ec 100644
--- a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
+++ b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
@@ -30,6 +30,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.xml.bind.JAXBException;
+import javax.xml.bind.MarshalException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.PropertyException;
 import javax.xml.bind.ValidationEvent;
@@ -45,6 +46,7 @@ import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxb.JAXBDataBase;
 import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.jaxb.JAXBEncoderDecoder;
+import org.apache.cxf.jaxb.MarshallerEventHandler;
 import org.apache.cxf.jaxb.attachment.JAXBAttachmentMarshaller;
 import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.service.model.MessagePartInfo;
@@ -70,11 +72,13 @@ public class DataWriterImpl<T> extends JAXBDataBase implements DataWriter<T> {
         if (prop.equals(org.apache.cxf.message.Message.class.getName())) {
             org.apache.cxf.message.Message m = (org.apache.cxf.message.Message)value;
             veventHandler = (ValidationEventHandler)m.getContextualProperty(
-                    "jaxb-writer-validation-event-handler");
+                    JAXBDataBinding.WRITER_VALIDATION_EVENT_HANDLER);
+            
             if (veventHandler == null) {
                 veventHandler = databinding.getValidationEventHandler();
             }      
-            setEventHandler = MessageUtils.getContextualBoolean(m, "set-jaxb-validation-event-handler", true);
+            setEventHandler = MessageUtils.getContextualBoolean(m, 
+                    JAXBDataBinding.SET_VALIDATION_EVENT_HANDLER, true);
         }
     }
     
@@ -88,18 +92,19 @@ public class DataWriterImpl<T> extends JAXBDataBase implements DataWriter<T> {
         }
         
         public boolean handleEvent(ValidationEvent event) {
-            String msg = event.getMessage();
-            if (msg.startsWith("cvc-type.3.1.2: ")
-                && msg.contains(marshaller.getLastMTOMElementName().getLocalPart())) {
+            // if the original handler has already handled the event, no need for us
+            // to do anything, otherwise if not yet handled, then do this 'hack'
+            if (origHandler != null && origHandler.handleEvent(event)) {
                 return true;
+            } else {
+                String msg = event.getMessage();
+                return msg.startsWith("cvc-type.3.1.2: ")
+                    && msg.contains(marshaller.getLastMTOMElementName().getLocalPart());
             }
-            if (origHandler != null) {
-                return origHandler.handleEvent(event);
-            }
-            return false;
         }
         
     }
+    
     public Marshaller createMarshaller(Object elValue, MessagePartInfo part) {
         Class<?> cls = null;
         if (part != null) {
@@ -214,11 +219,13 @@ public class DataWriterImpl<T> extends JAXBDataBase implements DataWriter<T> {
                 JAXBEncoderDecoder.marshallException(createMarshaller(obj, part),
                                                      (Exception)obj,
                                                      part, 
-                                                     output);                
+                                                     output);
+                onCompleteMarshalling();
             } else {
                 Annotation[] anns = getJAXBAnnotation(part);
                 if (!honorJaxbAnnotation || anns.length == 0) {
                     JAXBEncoderDecoder.marshall(createMarshaller(obj, part), obj, part, output);
+                    onCompleteMarshalling();
                 } else if (honorJaxbAnnotation && anns.length > 0) {
                     //RpcLit will use the JAXB Bridge to marshall part message when it is 
                     //annotated with @XmlList,@XmlAttachmentRef,@XmlJavaTypeAdapter
@@ -236,6 +243,8 @@ public class DataWriterImpl<T> extends JAXBDataBase implements DataWriter<T> {
         } else if (needToRender(part)) {
             JAXBEncoderDecoder.marshallNullElement(createMarshaller(null, part),
                                                    output, part);
+            
+            onCompleteMarshalling();
         }
     }
 
@@ -284,4 +293,18 @@ public class DataWriterImpl<T> extends JAXBDataBase implements DataWriter<T> {
         return false;
     }
     
+    private void onCompleteMarshalling() {
+        if (setEventHandler && veventHandler instanceof MarshallerEventHandler) {
+            try {
+                ((MarshallerEventHandler) veventHandler).onMarshalComplete();
+            } catch (MarshalException e) {
+                if (e.getLinkedException() != null) {
+                    throw new Fault(new Message("MARSHAL_ERROR", LOG, 
+                            e.getLinkedException().getMessage()), e);
+                } else {
+                    throw new Fault(new Message("MARSHAL_ERROR", LOG, e.getMessage()), e);
+                }
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/83576104/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/MyCustomMarshallerHandler.java
----------------------------------------------------------------------
diff --git a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/MyCustomMarshallerHandler.java b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/MyCustomMarshallerHandler.java
new file mode 100644
index 0000000..c494dfa
--- /dev/null
+++ b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/MyCustomMarshallerHandler.java
@@ -0,0 +1,72 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.jaxb.io;
+
+import javax.xml.bind.MarshalException;
+import javax.xml.bind.UnmarshalException;
+import javax.xml.bind.ValidationEvent;
+import javax.xml.bind.util.ValidationEventCollector;
+
+import org.apache.cxf.jaxb.MarshallerEventHandler;
+import org.apache.cxf.jaxb.UnmarshallerEventHandler;
+
+public class MyCustomMarshallerHandler extends ValidationEventCollector implements 
+        UnmarshallerEventHandler, MarshallerEventHandler {
+    private boolean used;
+    private boolean onMarshalComplete;
+    private boolean onUnmarshalComplete;
+    
+    public boolean getUsed() {
+        return used;
+    }
+    
+    public boolean isOnMarshalComplete() {
+        return onMarshalComplete;
+    }
+
+    public boolean isOnUnmarshalComplete() {
+        return onUnmarshalComplete;
+    }
+
+    public boolean handleEvent(ValidationEvent event) {
+        super.handleEvent(event);
+        
+        used = true;
+        return true;
+    }
+
+    @Override
+    public void onUnmarshalComplete() throws UnmarshalException {
+        this.onUnmarshalComplete = true;
+        
+        if (hasEvents()) {
+            throw new UnmarshalException("My unmarshalling exception");
+        }
+    }
+
+    @Override
+    public void onMarshalComplete() throws MarshalException {
+        this.onMarshalComplete = true;
+        
+        if (hasEvents()) {
+            throw new MarshalException("My marshalling exception");
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cxf/blob/83576104/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataReaderTest.java
----------------------------------------------------------------------
diff --git a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataReaderTest.java b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataReaderTest.java
index b178764..f4d3405 100644
--- a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataReaderTest.java
+++ b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataReaderTest.java
@@ -23,11 +23,13 @@ import java.io.IOException;
 import java.io.InputStream;
 
 import javax.xml.bind.JAXBContext;
+import javax.xml.bind.ValidationEventHandler;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.cxf.databinding.DataReader;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.staxutils.StaxStreamFilter;
@@ -58,6 +60,39 @@ public class XMLStreamDataReaderTest extends Assert {
 
     @Test
     public void testSetProperty() throws Exception {
+        MyCustomHandler handler = new MyCustomHandler();
+        
+        DataReaderImpl<XMLStreamReader> dr = newDataReader(handler);
+        
+        // Should fail if custom handler doesn't skip formatting error
+        Object val = dr.read(reader);
+        assertTrue(val instanceof GreetMe);
+        assertEquals("TestSOAPInputPMessage", ((GreetMe)val).getRequestType());
+
+        assertTrue(handler.getUsed());
+    }
+    
+    @Test
+    public void testSetPropertyWithCustomExceptionHandling() throws Exception {
+        MyCustomMarshallerHandler handler = new MyCustomMarshallerHandler();
+        
+        DataReaderImpl<XMLStreamReader> dr = newDataReader(handler);
+
+        // Should fail if custom handler doesn't skip formatting error
+        try {
+            dr.read(reader);
+            fail("Expected exception");
+        } catch (Fault f) {
+            assertTrue(f.getMessage().contains("My unmarshalling exception"));
+        }
+        
+        // Check handler used
+        assertTrue(handler.getUsed());
+        assertFalse(handler.isOnMarshalComplete());
+        assertTrue(handler.isOnUnmarshalComplete());
+    }
+    
+    private DataReaderImpl<XMLStreamReader> newDataReader(ValidationEventHandler handler) throws Exception {
         JAXBDataBinding db = getDataBinding(GreetMe.class);
     
         reader = getTestReader("../resources/SetPropertyValidationFailureReq.xml");
@@ -68,18 +103,12 @@ public class XMLStreamDataReaderTest extends Assert {
         
         // Build message to set custom event handler
         org.apache.cxf.message.Message message = new org.apache.cxf.message.MessageImpl();
-        message.put("jaxb-validation-event-handler", new MyCustomHandler());
+        message.put(JAXBDataBinding.READER_VALIDATION_EVENT_HANDLER, handler);
         message.put("unwrap.jaxb.element", true);
     
         dr.setProperty("org.apache.cxf.message.Message", message);        
         
-        // Should fail if custom handler doesn't skip formatting error
-        Object val = dr.read(reader);
-        assertTrue(val instanceof GreetMe);
-        assertEquals("TestSOAPInputPMessage", ((GreetMe)val).getRequestType());
-        
-        // Check handler used
-        assertTrue(((MyCustomHandler)dr.veventHandler).getUsed());
+        return dr;
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/cxf/blob/83576104/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataWriterTest.java
----------------------------------------------------------------------
diff --git a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataWriterTest.java b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataWriterTest.java
index 549ac47..3de374d 100644
--- a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataWriterTest.java
+++ b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataWriterTest.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import javax.xml.bind.JAXBContext;
+import javax.xml.bind.ValidationEventHandler;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLOutputFactory;
@@ -33,6 +34,7 @@ import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.staxutils.DepthXMLStreamReader;
@@ -47,7 +49,6 @@ import org.junit.Before;
 import org.junit.Test;
 
 public class XMLStreamDataWriterTest extends Assert {
-
     private ByteArrayOutputStream baos;
     private XMLStreamWriter streamWriter;
     private XMLInputFactory inFactory;
@@ -68,17 +69,9 @@ public class XMLStreamDataWriterTest extends Assert {
     
     @Test
     public void testSetProperty() throws Exception {
-        JAXBDataBinding db = getTestWriterFactory();
-               
-        DataWriterImpl<XMLStreamWriter> dw = (DataWriterImpl<XMLStreamWriter>)db.createWriter(XMLStreamWriter.class);
-        assertNotNull(dw);
-        
-        // Build message to set custom event handler
-        org.apache.cxf.message.Message message = new org.apache.cxf.message.MessageImpl();
-        message.put("jaxb-writer-validation-event-handler", new MyCustomHandler());
-    
-        dw.setProperty("org.apache.cxf.message.Message", message);     
+        MyCustomHandler handler = new MyCustomHandler();
         
+        DataWriterImpl<XMLStreamWriter> dw = newDataWriter(handler);
         // Write Stuff
         TradePriceData val = new TradePriceData();
         val.setTickerSymbol("This is a symbol");
@@ -92,9 +85,53 @@ public class XMLStreamDataWriterTest extends Assert {
         streamWriter.flush();
         
         // Test MyCustomHandler
-        assertTrue(((MyCustomHandler)dw.veventHandler).getUsed());       
+        assertTrue(handler.getUsed());
+    }
+    
+    @Test
+    public void testSetPropertyWithCustomExceptionHandling() throws Exception {
+        MyCustomMarshallerHandler handler = new MyCustomMarshallerHandler();
+        
+        DataWriterImpl<XMLStreamWriter> dw = newDataWriter(handler);
+        // Write Stuff
+        TradePriceData val = new TradePriceData();
+        val.setTickerSymbol("This is a symbol");
+        val.setTickerPrice(1.0f);
+        
+        QName elName = new QName("http://apache.org/hello_world_doc_lit_bare/types", "inout");
+        MessagePartInfo part = new MessagePartInfo(elName, null);
+        part.setElement(true);
+        part.setElementQName(elName);
+        
+        try {
+            dw.write(val, part, streamWriter);
+            streamWriter.flush();
+            fail("Expected exception");
+        } catch (Fault f) {
+            assertTrue(f.getMessage().contains("My marshalling exception"));
+        }
+        
+        // Test MyCustomHandler
+        assertTrue(handler.getUsed());
+        assertTrue(handler.isOnMarshalComplete());
+        assertFalse(handler.isOnUnmarshalComplete());
     }
 
+    private DataWriterImpl<XMLStreamWriter> newDataWriter(ValidationEventHandler handler) throws Exception {
+        JAXBDataBinding db = getTestWriterFactory();
+        
+        DataWriterImpl<XMLStreamWriter> dw = (DataWriterImpl<XMLStreamWriter>)db.createWriter(XMLStreamWriter.class);
+        assertNotNull(dw);
+        
+        // Build message to set custom event handler
+        org.apache.cxf.message.Message message = new org.apache.cxf.message.MessageImpl();
+        message.put(JAXBDataBinding.WRITER_VALIDATION_EVENT_HANDLER, handler);
+    
+        dw.setProperty("org.apache.cxf.message.Message", message);     
+        
+        return dw;
+    }
+    
     @Test
     public void testWriteRPCLit1() throws Exception {
         JAXBDataBinding db = getTestWriterFactory();