camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: CAMEL-10604 - Camel-JacksonXML: Add an option to allow the UnmarshallType header use
Date Thu, 15 Dec 2016 11:03:13 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x 51b0e22df -> 8c862aa11


CAMEL-10604 - Camel-JacksonXML: Add an option to allow the UnmarshallType header use


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

Branch: refs/heads/camel-2.18.x
Commit: 8c862aa11e31d0f804c4a4516a0715e05e3eebcf
Parents: 51b0e22
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Thu Dec 15 11:51:03 2016 +0100
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Dec 15 11:55:21 2016 +0100

----------------------------------------------------------------------
 .../model/dataformat/JacksonXMLDataFormat.java  | 18 +++++++
 .../JacksonXMLDataFormatConfiguration.java      | 14 ++++++
 .../src/main/docs/jacksonxml-dataformat.adoc    |  3 +-
 .../jacksonxml/JacksonXMLDataFormat.java        | 19 ++++++-
 ...arshalUnmarshalTypeHeaderNotAllowedTest.java | 53 ++++++++++++++++++++
 .../JacksonMarshalUnmarshalTypeHeaderTest.java  |  1 +
 6 files changed, 106 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8c862aa1/camel-core/src/main/java/org/apache/camel/model/dataformat/JacksonXMLDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/JacksonXMLDataFormat.java
b/camel-core/src/main/java/org/apache/camel/model/dataformat/JacksonXMLDataFormat.java
index 1780228..75ad17e 100644
--- a/camel-core/src/main/java/org/apache/camel/model/dataformat/JacksonXMLDataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/JacksonXMLDataFormat.java
@@ -68,6 +68,8 @@ public class JacksonXMLDataFormat extends DataFormatDefinition {
     private String enableFeatures;
     @XmlAttribute
     private String disableFeatures;
+    @XmlAttribute
+    private Boolean allowUnmarshallType;
 
     public JacksonXMLDataFormat() {
         super("jacksonxml");
@@ -256,6 +258,19 @@ public class JacksonXMLDataFormat extends DataFormatDefinition {
     public void setDisableFeatures(String disableFeatures) {
         this.disableFeatures = disableFeatures;
     }
+    
+    public Boolean getAllowUnmarshallType() {
+        return allowUnmarshallType;
+    }
+
+    /**
+     * If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType
header during the unmarshalling.
+     * <p/>
+     * This should only be enabled when desired to be used.
+     */
+    public void setAllowUnmarshallType(Boolean allowUnmarshallType) {
+        this.allowUnmarshallType = allowUnmarshallType;
+    }
 
     @Override
     public String getDataFormatName() {
@@ -326,6 +341,9 @@ public class JacksonXMLDataFormat extends DataFormatDefinition {
         if (disableFeatures != null) {
             setProperty(camelContext, dataFormat, "disableFeatures", disableFeatures);
         }
+        if (allowUnmarshallType != null) {
+            setProperty(camelContext, dataFormat, "allowUnmarshallType", allowUnmarshallType);
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/8c862aa1/components-starter/camel-jacksonxml-starter/src/main/java/org/apache/camel/component/jacksonxml/springboot/JacksonXMLDataFormatConfiguration.java
----------------------------------------------------------------------
diff --git a/components-starter/camel-jacksonxml-starter/src/main/java/org/apache/camel/component/jacksonxml/springboot/JacksonXMLDataFormatConfiguration.java
b/components-starter/camel-jacksonxml-starter/src/main/java/org/apache/camel/component/jacksonxml/springboot/JacksonXMLDataFormatConfiguration.java
index 49e244a..75734c0 100644
--- a/components-starter/camel-jacksonxml-starter/src/main/java/org/apache/camel/component/jacksonxml/springboot/JacksonXMLDataFormatConfiguration.java
+++ b/components-starter/camel-jacksonxml-starter/src/main/java/org/apache/camel/component/jacksonxml/springboot/JacksonXMLDataFormatConfiguration.java
@@ -101,6 +101,12 @@ public class JacksonXMLDataFormatConfiguration {
      * separated by comma
      */
     private String disableFeatures;
+    /**
+     * If enabled then Jackson is allowed to attempt to use the
+     * CamelJacksonUnmarshalType header during the unmarshalling. This should
+     * only be enabled when desired to be used.
+     */
+    private Boolean allowUnmarshallType = false;
 
     public String getXmlMapper() {
         return xmlMapper;
@@ -205,4 +211,12 @@ public class JacksonXMLDataFormatConfiguration {
     public void setDisableFeatures(String disableFeatures) {
         this.disableFeatures = disableFeatures;
     }
+
+    public Boolean getAllowUnmarshallType() {
+        return allowUnmarshallType;
+    }
+
+    public void setAllowUnmarshallType(Boolean allowUnmarshallType) {
+        this.allowUnmarshallType = allowUnmarshallType;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/8c862aa1/components/camel-jacksonxml/src/main/docs/jacksonxml-dataformat.adoc
----------------------------------------------------------------------
diff --git a/components/camel-jacksonxml/src/main/docs/jacksonxml-dataformat.adoc b/components/camel-jacksonxml/src/main/docs/jacksonxml-dataformat.adoc
index f631701..85c362e 100644
--- a/components/camel-jacksonxml/src/main/docs/jacksonxml-dataformat.adoc
+++ b/components/camel-jacksonxml/src/main/docs/jacksonxml-dataformat.adoc
@@ -36,7 +36,7 @@ JacksonXML Options
 
 
 // dataformat options: START
-The JacksonXML dataformat supports 13 options which are listed below.
+The JacksonXML dataformat supports 14 options which are listed below.
 
 
 
@@ -57,6 +57,7 @@ The JacksonXML dataformat supports 13 options which are listed below.
 | moduleRefs |  | String | To use custom Jackson modules referred from the Camel registry.
Multiple modules can be separated by comma.
 | enableFeatures |  | String | Set of features to enable on the Jackson com.fasterxml.jackson.databind.ObjectMapper.
The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature
com.fasterxml.jackson.databind.DeserializationFeature or com.fasterxml.jackson.databind.MapperFeature
Multiple features can be separated by comma
 | disableFeatures |  | String | Set of features to disable on the Jackson com.fasterxml.jackson.databind.ObjectMapper.
The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature
com.fasterxml.jackson.databind.DeserializationFeature or com.fasterxml.jackson.databind.MapperFeature
Multiple features can be separated by comma
+| allowUnmarshallType | false | Boolean | If enabled then Jackson is allowed to attempt to
use the CamelJacksonUnmarshalType header during the unmarshalling. This should only be enabled
when desired to be used.
 |=======================================================================
 {% endraw %}
 // dataformat options: END

http://git-wip-us.apache.org/repos/asf/camel/blob/8c862aa1/components/camel-jacksonxml/src/main/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-jacksonxml/src/main/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormat.java
b/components/camel-jacksonxml/src/main/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormat.java
index 869fe66..dd70cd5 100644
--- a/components/camel-jacksonxml/src/main/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormat.java
+++ b/components/camel-jacksonxml/src/main/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormat.java
@@ -68,6 +68,7 @@ public class JacksonXMLDataFormat extends ServiceSupport implements DataFormat,
     private String enableFeatures;
     private String disableFeatures;
     private boolean enableJacksonTypeConverter;
+    private boolean allowUnmarshallType;
 
     /**
      * Use the default Jackson {@link XmlMapper} and {@link Map}
@@ -158,7 +159,10 @@ public class JacksonXMLDataFormat extends ServiceSupport implements DataFormat,
 
         // is there a header with the unmarshal type?
         Class<?> clazz = unmarshalType;
-        String type = exchange.getIn().getHeader(JacksonXMLConstants.UNMARSHAL_TYPE, String.class);
+        String type = null;
+        if (allowUnmarshallType) {
+            type = exchange.getIn().getHeader(JacksonXMLConstants.UNMARSHAL_TYPE, String.class);
+        }
         if (type == null && isAllowJmsType()) {
             type = exchange.getIn().getHeader("JMSType", String.class);
         }
@@ -326,6 +330,19 @@ public class JacksonXMLDataFormat extends ServiceSupport implements DataFormat,
     public void setEnableJacksonTypeConverter(boolean enableJacksonTypeConverter) {
         this.enableJacksonTypeConverter = enableJacksonTypeConverter;
     }
+    
+    public boolean isAllowUnmarshallType() {
+        return allowUnmarshallType;
+    }
+
+    /**
+     * If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType
header during the unmarshalling.
+     * <p/>
+     * This should only be enabled when desired to be used.
+     */
+    public void setAllowUnmarshallType(boolean allowJacksonUnmarshallType) {
+        this.allowUnmarshallType = allowJacksonUnmarshallType;
+    }
 
     public String getEnableFeatures() {
         return enableFeatures;

http://git-wip-us.apache.org/repos/asf/camel/blob/8c862aa1/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalTypeHeaderNotAllowedTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalTypeHeaderNotAllowedTest.java
b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalTypeHeaderNotAllowedTest.java
new file mode 100644
index 0000000..579e3be
--- /dev/null
+++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalTypeHeaderNotAllowedTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.camel.component.jacksonxml;
+
+import java.util.LinkedHashMap;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class JacksonMarshalUnmarshalTypeHeaderNotAllowedTest extends CamelTestSupport {
+
+    @Test
+    public void testUnmarshalPojo() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:reversePojo");
+        mock.expectedMessageCount(1);
+
+        String json = "<pojo name=\"Camel\"/>";
+        template.sendBodyAndHeader("direct:backPojo", json, JacksonXMLConstants.UNMARSHAL_TYPE,
TestPojo.class.getName());
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+
+            @Override
+            public void configure() throws Exception {
+                JacksonXMLDataFormat format = new JacksonXMLDataFormat();
+
+                from("direct:backPojo").unmarshal(format).to("mock:reversePojo");
+
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/8c862aa1/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalTypeHeaderTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalTypeHeaderTest.java
b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalTypeHeaderTest.java
index 56e3b35..68dd3fe 100644
--- a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalTypeHeaderTest.java
+++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalTypeHeaderTest.java
@@ -46,6 +46,7 @@ public class JacksonMarshalUnmarshalTypeHeaderTest extends CamelTestSupport
{
             @Override
             public void configure() throws Exception {
                 JacksonXMLDataFormat format = new JacksonXMLDataFormat();
+                format.setAllowUnmarshallType(true);
 
                 from("direct:backPojo").unmarshal(format).to("mock:reversePojo");
 


Mime
View raw message