cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5648] Updating JAXBProvider to check SchemaValidation type
Date Fri, 04 Apr 2014 15:51:05 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 45e361cc8 -> 621622e3b


[CXF-5648] Updating JAXBProvider to check SchemaValidation type


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

Branch: refs/heads/master
Commit: 621622e3bc47cced4bcd887cdc5d2372460571fe
Parents: 45e361c
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri Apr 4 16:50:40 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri Apr 4 16:50:40 2014 +0100

----------------------------------------------------------------------
 .../jaxrs/provider/AbstractJAXBProvider.java    | 29 ++++++++++++++------
 1 file changed, 21 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/621622e3/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
index e446e45..5603ddf 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
@@ -136,7 +136,8 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
     
     private Class<?>[] extraClass;
     
-    private boolean validateOutput;
+    private boolean validateInputIfPossible = true;
+    private boolean validateOutputIfPossible;
     private boolean validateBeforeWrite;
     private ValidationEventHandler eventHandler;
     private Unmarshaller.Listener unmarshallerListener;
@@ -213,9 +214,10 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
         }
         if (cris != null) {
             List<String> schemaLocs = new LinkedList<String>();
+            SchemaValidation sv = null;
             for (ClassResourceInfo cri : cris) {
-                SchemaValidation sv = cri.getServiceClass().getAnnotation(SchemaValidation.class);
-                if (sv != null && sv.schemas() != null) {
+                sv = cri.getServiceClass().getAnnotation(SchemaValidation.class);
+                if (sv != null && sv.schemas() != null && sv.type() != SchemaValidation.SchemaValidationType.NONE)
{
                     for (String s : sv.schemas()) {
                         String theSchema = s;
                         if (!theSchema.startsWith("classpath:")) {
@@ -227,6 +229,15 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
             }
             if (!schemaLocs.isEmpty()) {
                 this.setSchemaLocations(schemaLocs);
+                if (cris.size() == 0 && schema != null) {
+                    SchemaValidation.SchemaValidationType type = sv.type();
+                    if (type == SchemaValidation.SchemaValidationType.OUT) {
+                        validateInputIfPossible = false;
+                        validateOutputIfPossible = true;
+                    } else if (type == SchemaValidation.SchemaValidationType.BOTH) {
+                        validateOutputIfPossible = true;
+                    }
+                }
             }
         }
     }
@@ -593,9 +604,11 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
         JAXBContext context = isCollection ? getCollectionContext(cls) 
                                            : getJAXBContext(cls, genericType);
         Unmarshaller unmarshaller = context.createUnmarshaller();
-        Schema theSchema = getSchema(cls);
-        if (theSchema != null) {
-            unmarshaller.setSchema(theSchema);
+        if (validateInputIfPossible) {
+            Schema theSchema = getSchema(cls);
+            if (theSchema != null) {
+                unmarshaller.setSchema(theSchema);
+            }
         }
         if (eventHandler != null) {
             unmarshaller.setEventHandler(eventHandler);
@@ -631,7 +644,7 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
     
     protected void validateObjectIfNeeded(Marshaller marshaller, Class<?> cls, Object
obj) 
         throws JAXBException {
-        if (validateOutput) {
+        if (validateOutputIfPossible) {
             Schema theSchema = getSchema(cls);
             if (theSchema != null) {
                 marshaller.setEventHandler(eventHandler);
@@ -822,7 +835,7 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
     }
 
     public void setValidateOutput(boolean validateOutput) {
-        this.validateOutput = validateOutput;
+        this.validateOutputIfPossible = validateOutput;
     }
 
     public void setDepthProperties(DocumentDepthProperties depthProperties) {


Mime
View raw message