You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/10/31 12:54:34 UTC

[camel] branch camel-2.20.x updated: CAMEL-11967: Restlet binding should not create jaxb/json marshaller when binding mode is not configure to use either of them.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-2.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.20.x by this push:
     new d957119  CAMEL-11967: Restlet binding should not create jaxb/json marshaller when binding mode is not configure to use either of them.
d957119 is described below

commit d9571193cedb2458a497bc1ce3acc155fa88b07d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Oct 31 13:07:09 2017 +0100

    CAMEL-11967: Restlet binding should not create jaxb/json marshaller when binding mode is not configure to use either of them.
---
 .../camel/model/rest/RestBindingDefinition.java    | 159 +++++++++++----------
 1 file changed, 81 insertions(+), 78 deletions(-)

diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java
index bde862e..4e111fd 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java
@@ -108,95 +108,98 @@ public class RestBindingDefinition extends OptionalIdentifiedDefinition<RestBind
         }
 
         // setup json data format
-        String name = config.getJsonDataFormat();
-        if (name != null) {
-            // must only be a name, not refer to an existing instance
-            Object instance = context.getRegistry().lookupByName(name);
-            if (instance != null) {
-                throw new IllegalArgumentException("JsonDataFormat name: " + name + " must not be an existing bean instance from the registry");
-            }
-        } else {
-            name = "json-jackson";
-        }
-        // this will create a new instance as the name was not already pre-created
-        DataFormat json = context.resolveDataFormat(name);
-        DataFormat outJson = context.resolveDataFormat(name);
-
-        // is json binding required?
-        if (mode.contains("json") && json == null) {
-            throw new IllegalArgumentException("JSon DataFormat " + name + " not found.");
-        }
-
-        if (json != null) {
-            Class<?> clazz = null;
-            if (type != null) {
-                String typeName = type.endsWith("[]") ? type.substring(0, type.length() - 2) : type;
-                clazz = context.getClassResolver().resolveMandatoryClass(typeName);
-            }
-            if (clazz != null) {
-                IntrospectionSupport.setProperty(context.getTypeConverter(), json, "unmarshalType", clazz);
-                IntrospectionSupport.setProperty(context.getTypeConverter(), json, "useList", type.endsWith("[]"));
+        DataFormat json = null;
+        DataFormat outJson = null;
+        if (mode.contains("json") || "auto".equals(mode)) {
+            String name = config.getJsonDataFormat();
+            if (name != null) {
+                // must only be a name, not refer to an existing instance
+                Object instance = context.getRegistry().lookupByName(name);
+                if (instance != null) {
+                    throw new IllegalArgumentException("JsonDataFormat name: " + name + " must not be an existing bean instance from the registry");
+                }
+            } else {
+                name = "json-jackson";
             }
-            setAdditionalConfiguration(config, context, json, "json.in.");
+            // this will create a new instance as the name was not already pre-created
+            json = context.resolveDataFormat(name);
+            outJson = context.resolveDataFormat(name);
+
+            if (json != null) {
+                Class<?> clazz = null;
+                if (type != null) {
+                    String typeName = type.endsWith("[]") ? type.substring(0, type.length() - 2) : type;
+                    clazz = context.getClassResolver().resolveMandatoryClass(typeName);
+                }
+                if (clazz != null) {
+                    IntrospectionSupport.setProperty(context.getTypeConverter(), json, "unmarshalType", clazz);
+                    IntrospectionSupport.setProperty(context.getTypeConverter(), json, "useList", type.endsWith("[]"));
+                }
+                setAdditionalConfiguration(config, context, json, "json.in.");
 
-            Class<?> outClazz = null;
-            if (outType != null) {
-                String typeName = outType.endsWith("[]") ? outType.substring(0, outType.length() - 2) : outType;
-                outClazz = context.getClassResolver().resolveMandatoryClass(typeName);
-            }
-            if (outClazz != null) {
-                IntrospectionSupport.setProperty(context.getTypeConverter(), outJson, "unmarshalType", outClazz);
-                IntrospectionSupport.setProperty(context.getTypeConverter(), outJson, "useList", outType.endsWith("[]"));
+                Class<?> outClazz = null;
+                if (outType != null) {
+                    String typeName = outType.endsWith("[]") ? outType.substring(0, outType.length() - 2) : outType;
+                    outClazz = context.getClassResolver().resolveMandatoryClass(typeName);
+                }
+                if (outClazz != null) {
+                    IntrospectionSupport.setProperty(context.getTypeConverter(), outJson, "unmarshalType", outClazz);
+                    IntrospectionSupport.setProperty(context.getTypeConverter(), outJson, "useList", outType.endsWith("[]"));
+                }
+                setAdditionalConfiguration(config, context, outJson, "json.out.");
             }
-            setAdditionalConfiguration(config, context, outJson, "json.out.");
         }
 
         // setup xml data format
-        name = config.getXmlDataFormat();
-        if (name != null) {
-            // must only be a name, not refer to an existing instance
-            Object instance = context.getRegistry().lookupByName(name);
-            if (instance != null) {
-                throw new IllegalArgumentException("XmlDataFormat name: " + name + " must not be an existing bean instance from the registry");
+        DataFormat jaxb = null;
+        DataFormat outJaxb = null;
+        if (mode.contains("xml") || "auto".equals(mode)) {
+            String name = config.getXmlDataFormat();
+            if (name != null) {
+                // must only be a name, not refer to an existing instance
+                Object instance = context.getRegistry().lookupByName(name);
+                if (instance != null) {
+                    throw new IllegalArgumentException("XmlDataFormat name: " + name + " must not be an existing bean instance from the registry");
+                }
+            } else {
+                name = "jaxb";
             }
-        } else {
-            name = "jaxb";
-        }
-        // this will create a new instance as the name was not already pre-created
-        DataFormat jaxb = context.resolveDataFormat(name);
-        DataFormat outJaxb = context.resolveDataFormat(name);
-
-        // is xml binding required?
-        if (mode.contains("xml") && jaxb == null) {
-            throw new IllegalArgumentException("XML DataFormat " + name + " not found.");
-        }
+            // this will create a new instance as the name was not already pre-created
+            jaxb = context.resolveDataFormat(name);
+            outJaxb = context.resolveDataFormat(name);
 
-        if (jaxb != null) {
-            Class<?> clazz = null;
-            if (type != null) {
-                String typeName = type.endsWith("[]") ? type.substring(0, type.length() - 2) : type;
-                clazz = context.getClassResolver().resolveMandatoryClass(typeName);
-            }
-            if (clazz != null) {
-                JAXBContext jc = JAXBContext.newInstance(clazz);
-                IntrospectionSupport.setProperty(context.getTypeConverter(), jaxb, "context", jc);
+            // is xml binding required?
+            if (mode.contains("xml") && jaxb == null) {
+                throw new IllegalArgumentException("XML DataFormat " + name + " not found.");
             }
-            setAdditionalConfiguration(config, context, jaxb, "xml.in.");
 
-            Class<?> outClazz = null;
-            if (outType != null) {
-                String typeName = outType.endsWith("[]") ? outType.substring(0, outType.length() - 2) : outType;
-                outClazz = context.getClassResolver().resolveMandatoryClass(typeName);
-            }
-            if (outClazz != null) {
-                JAXBContext jc = JAXBContext.newInstance(outClazz);
-                IntrospectionSupport.setProperty(context.getTypeConverter(), outJaxb, "context", jc);
-            } else if (clazz != null) {
-                // fallback and use the context from the input
-                JAXBContext jc = JAXBContext.newInstance(clazz);
-                IntrospectionSupport.setProperty(context.getTypeConverter(), outJaxb, "context", jc);
+            if (jaxb != null) {
+                Class<?> clazz = null;
+                if (type != null) {
+                    String typeName = type.endsWith("[]") ? type.substring(0, type.length() - 2) : type;
+                    clazz = context.getClassResolver().resolveMandatoryClass(typeName);
+                }
+                if (clazz != null) {
+                    JAXBContext jc = JAXBContext.newInstance(clazz);
+                    IntrospectionSupport.setProperty(context.getTypeConverter(), jaxb, "context", jc);
+                }
+                setAdditionalConfiguration(config, context, jaxb, "xml.in.");
+
+                Class<?> outClazz = null;
+                if (outType != null) {
+                    String typeName = outType.endsWith("[]") ? outType.substring(0, outType.length() - 2) : outType;
+                    outClazz = context.getClassResolver().resolveMandatoryClass(typeName);
+                }
+                if (outClazz != null) {
+                    JAXBContext jc = JAXBContext.newInstance(outClazz);
+                    IntrospectionSupport.setProperty(context.getTypeConverter(), outJaxb, "context", jc);
+                } else if (clazz != null) {
+                    // fallback and use the context from the input
+                    JAXBContext jc = JAXBContext.newInstance(clazz);
+                    IntrospectionSupport.setProperty(context.getTypeConverter(), outJaxb, "context", jc);
+                }
+                setAdditionalConfiguration(config, context, outJaxb, "xml.out.");
             }
-            setAdditionalConfiguration(config, context, outJaxb, "xml.out.");
         }
 
         return new RestBindingAdvice(context, json, jaxb, outJson, outJaxb, consumes, produces, mode, skip, cors, corsHeaders, defaultValues);

-- 
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].