cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jp...@apache.org
Subject 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
Date Fri, 06 Feb 2015 21:27:16 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 589ee44b9 -> 596988d73


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

Conflicts:
	rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataWriterTest.java


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

Branch: refs/heads/3.0.x-fixes
Commit: 596988d7376970130594e2dbd42f9e354b78b4e6
Parents: 589ee44
Author: Jason Pell <jpell@apache.org>
Authored: Fri Feb 6 16:58:06 2015 +1100
Committer: Jason Pell <jpell@apache.org>
Committed: Sat Feb 7 08:27:07 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    | 69 ++++++++++++++++++-
 8 files changed, 313 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/596988d7/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 38f5cdb..b624d8a 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
@@ -94,6 +94,11 @@ import org.apache.cxf.ws.addressing.ObjectFactory;
 public class JAXBDataBinding extends AbstractInterceptorProvidingDataBinding
     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/596988d7/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/596988d7/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/596988d7/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 b08a8b7..f9deb66 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;
@@ -39,6 +40,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;
 
@@ -66,34 +68,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) {
@@ -104,6 +110,7 @@ public class DataReaderImpl<T> extends JAXBDataBase implements DataReader<T>
{
             }
         }
     }
+    
     private Unmarshaller createUnmarshaller() {
         try {
             Unmarshaller um = null;
@@ -152,23 +159,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/596988d7/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 d45f664..de9e195 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;
@@ -46,6 +47,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;
@@ -71,7 +73,8 @@ 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 = (ValidationEventHandler)m.getContextualProperty(
                     "jaxb-validation-event-handler");
@@ -79,7 +82,8 @@ public class DataWriterImpl<T> extends JAXBDataBase implements DataWriter<T>
{
             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);
         }
     }
     
@@ -93,18 +97,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) {
@@ -222,11 +227,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
@@ -244,6 +251,8 @@ public class DataWriterImpl<T> extends JAXBDataBase implements DataWriter<T>
{
         } else if (needToRender(part)) {
             JAXBEncoderDecoder.marshallNullElement(createMarshaller(null, part),
                                                    output, part);
+            
+            onCompleteMarshalling();
         }
     }
 
@@ -292,4 +301,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/596988d7/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/596988d7/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/596988d7/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 95c6c98..420c843 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;
@@ -48,7 +50,6 @@ import org.junit.Before;
 import org.junit.Test;
 
 public class XMLStreamDataWriterTest extends Assert {
-
     private ByteArrayOutputStream baos;
     private XMLStreamWriter streamWriter;
     private XMLInputFactory inFactory;
@@ -66,7 +67,73 @@ public class XMLStreamDataWriterTest extends Assert {
     public void tearDown() throws Exception {
         baos.close();
     }
+    
+    @Test
+    public void testSetProperty() throws Exception {
+        MyCustomHandler handler = new MyCustomHandler();
+        
+        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);
+        dw.write(val, part, streamWriter);
+        streamWriter.flush();
+        
+        // Test MyCustomHandler
+        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();


Mime
View raw message