camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1309934 [1/5] - in /camel/trunk: camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/model/dataformat/ components/camel-xmljson/ components/camel-xmljson/src/ components/camel-xmljson/src/main/ comp...
Date Thu, 05 Apr 2012 16:38:09 GMT
Author: davsclaus
Date: Thu Apr  5 16:38:07 2012
New Revision: 1309934

URL: http://svn.apache.org/viewvc?rev=1309934&view=rev
Log:
CAMEL-4930: New camel-xmljson component. Thanks to Raul for the contribution.

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XmlJsonDataFormat.java   (with props)
    camel/trunk/components/camel-xmljson/   (with props)
    camel/trunk/components/camel-xmljson/pom.xml   (with props)
    camel/trunk/components/camel-xmljson/src/
    camel/trunk/components/camel-xmljson/src/main/
    camel/trunk/components/camel-xmljson/src/main/java/
    camel/trunk/components/camel-xmljson/src/main/java/org/
    camel/trunk/components/camel-xmljson/src/main/java/org/apache/
    camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/
    camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/
    camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/
    camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/TypeHintsEnum.java   (with props)
    camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormat.java   (with props)
    camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/converters/
    camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/converters/XmlJsonConverters.java   (with props)
    camel/trunk/components/camel-xmljson/src/main/resources/
    camel/trunk/components/camel-xmljson/src/main/resources/META-INF/
    camel/trunk/components/camel-xmljson/src/main/resources/META-INF/LICENSE.txt   (with props)
    camel/trunk/components/camel-xmljson/src/main/resources/META-INF/NOTICE.txt   (with props)
    camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/
    camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/org/
    camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/org/apache/
    camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/org/apache/camel/
    camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
    camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/org/apache/camel/dataformat/
    camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/org/apache/camel/dataformat/xmljson
    camel/trunk/components/camel-xmljson/src/test/
    camel/trunk/components/camel-xmljson/src/test/java/
    camel/trunk/components/camel-xmljson/src/test/java/org/
    camel/trunk/components/camel-xmljson/src/test/java/org/apache/
    camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/
    camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/
    camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/
    camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/SpringXmlJsonDataFormatTest.java   (with props)
    camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormatTest.java   (with props)
    camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonExceptionsTest.java   (with props)
    camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonOptionsTest.java   (with props)
    camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonStressTest.java   (with props)
    camel/trunk/components/camel-xmljson/src/test/resources/
    camel/trunk/components/camel-xmljson/src/test/resources/log4j.properties   (with props)
    camel/trunk/components/camel-xmljson/src/test/resources/org/
    camel/trunk/components/camel-xmljson/src/test/resources/org/apache/
    camel/trunk/components/camel-xmljson/src/test/resources/org/apache/camel/
    camel/trunk/components/camel-xmljson/src/test/resources/org/apache/camel/dataformat/
    camel/trunk/components/camel-xmljson/src/test/resources/org/apache/camel/dataformat/xmljson/
    camel/trunk/components/camel-xmljson/src/test/resources/org/apache/camel/dataformat/xmljson/SpringXmlJsonDataFormatTest.xml   (with props)
    camel/trunk/components/camel-xmljson/src/test/resources/org/apache/camel/dataformat/xmljson/testMessage1.json
    camel/trunk/components/camel-xmljson/src/test/resources/org/apache/camel/dataformat/xmljson/testMessage1.xml   (with props)
    camel/trunk/components/camel-xmljson/src/test/resources/org/apache/camel/dataformat/xmljson/testMessage2-namespaces.json
    camel/trunk/components/camel-xmljson/src/test/resources/org/apache/camel/dataformat/xmljson/testMessage2-namespaces.xml   (with props)
    camel/trunk/components/camel-xmljson/src/test/resources/org/apache/camel/dataformat/xmljson/testMessage3-large.json
    camel/trunk/components/camel-xmljson/src/test/resources/org/apache/camel/dataformat/xmljson/testMessage3-large.xml   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
    camel/trunk/parent/pom.xml
    camel/trunk/platforms/karaf/features/pom.xml
    camel/trunk/platforms/karaf/features/src/main/resources/features.xml

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java?rev=1309934&r1=1309933&r2=1309934&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java Thu Apr  5 16:38:07 2012
@@ -21,6 +21,8 @@ import java.util.zip.Deflater;
 
 import org.w3c.dom.Node;
 
+import org.apache.camel.model.dataformat.XmlJsonDataFormat;
+
 import org.apache.camel.model.DataFormatDefinition;
 import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.model.dataformat.AvroDataFormat;
@@ -499,6 +501,20 @@ public class DataFormatClause<T extends 
     }
 
     /**
+     * Uses the xmljson dataformat, based on json-lib
+     */
+    public T xmljson() {
+        return dataFormat(new XmlJsonDataFormat());
+    }
+    
+    /**
+     * Uses the xmljson dataformat, based on json-lib, initializing custom options with a Map
+     */
+    public T xmljson(Map<String, String> options) {
+        return dataFormat(new XmlJsonDataFormat(options));
+    }
+    
+    /**
      * Uses the ZIP deflater data format
      */
     public T zip() {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java?rev=1309934&r1=1309933&r2=1309934&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java Thu Apr  5 16:38:07 2012
@@ -59,6 +59,7 @@ public class DataFormatsDefinition {
         @XmlElement(required = false, name = "syslog", type = SyslogDataFormat.class),
         @XmlElement(required = false, name = "tidyMarkup", type = TidyMarkupDataFormat.class),
         @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
+        @XmlElement(required = false, name = "xmljson", type = XmlJsonDataFormat.class),
         @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class),
         @XmlElement(required = false, name = "pgp", type = PGPDataFormat.class),
         @XmlElement(required = false, name = "zip", type = ZipDataFormat.class)}

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XmlJsonDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XmlJsonDataFormat.java?rev=1309934&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XmlJsonDataFormat.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XmlJsonDataFormat.java Thu Apr  5 16:38:07 2012
@@ -0,0 +1,276 @@
+/**
+ * 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.model.dataformat;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlList;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.DataFormatDefinition;
+import org.apache.camel.spi.DataFormat;
+
+/**
+ * Represents a <a href="http://camel.apache.org/xmljson.html">XML-JSON</a> {@link org.apache.camel.spi.DataFormat}.
+ *
+ * @version 
+ */
+@XmlRootElement(name = "xmljson")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class XmlJsonDataFormat extends DataFormatDefinition {
+    
+	public static final String TYPE_HINTS = "typeHints";
+	public static final String REMOVE_NAMESPACE_PREFIXES = "removeNamespacePrefixes";
+	public static final String SKIP_NAMESPACES = "skipNamespaces";
+	public static final String TRIM_SPACES = "trimSpaces";
+	public static final String SKIP_WHITESPACE = "skipWhitespace";
+	public static final String EXPANDABLE_PROPERTIES = "expandableProperties";
+	public static final String ARRAY_NAME = "arrayName";
+	public static final String ELEMENT_NAME = "elementName";
+	public static final String ROOT_NAME = "rootName";
+	public static final String NAMESPACE_LENIENT = "namespaceLenient";
+	public static final String FORCE_TOP_LEVEL_OBJECT = "forceTopLevelObject";
+	public static final String ENCODING = "encoding";
+    
+    @XmlAttribute
+	private String encoding;
+	@XmlAttribute
+	private String elementName;
+	@XmlAttribute
+	private String arrayName;
+	@XmlAttribute
+	private Boolean forceTopLevelObject;
+	@XmlAttribute
+	private Boolean namespaceLenient;
+	@XmlAttribute
+	private String rootName;
+	@XmlAttribute
+	private Boolean skipWhitespace;
+	@XmlAttribute
+	private Boolean trimSpaces;
+	@XmlAttribute
+	private Boolean skipNamespaces;
+	@XmlAttribute
+	private Boolean removeNamespacePrefixes;
+	@XmlAttribute @XmlList
+	private List<String> expandableProperties;
+	@XmlAttribute
+	private String typeHints;
+	
+    public XmlJsonDataFormat() {
+        super("xmljson");
+    }
+	
+    public XmlJsonDataFormat(Map<String, String> options) {
+        super("xmljson");
+        if (options.containsKey(ENCODING)) {
+            encoding = options.get(ENCODING);
+        }
+        if (options.containsKey(FORCE_TOP_LEVEL_OBJECT)) {
+            forceTopLevelObject = Boolean.parseBoolean(options.get(FORCE_TOP_LEVEL_OBJECT));
+        }
+        if (options.containsKey(NAMESPACE_LENIENT)) {
+            namespaceLenient = Boolean.parseBoolean(options.get(NAMESPACE_LENIENT));
+        }
+        if (options.containsKey(ROOT_NAME)) {
+            rootName = options.get(ROOT_NAME);
+        }
+        if (options.containsKey(ELEMENT_NAME)) {
+            encoding = options.get(ELEMENT_NAME);
+        }
+        if (options.containsKey(ARRAY_NAME)) {
+            elementName = options.get(ARRAY_NAME);
+        }
+        if (options.containsKey(EXPANDABLE_PROPERTIES)) {
+            expandableProperties = Arrays.asList(options.get(EXPANDABLE_PROPERTIES).split(" "));
+        }
+        if (options.containsKey(SKIP_WHITESPACE)) {
+            skipWhitespace = Boolean.parseBoolean(options.get(SKIP_WHITESPACE));
+        }
+        if (options.containsKey(TRIM_SPACES)) {
+            trimSpaces = Boolean.parseBoolean(options.get(TRIM_SPACES));
+        }
+        if (options.containsKey(SKIP_NAMESPACES)) {
+            skipNamespaces = Boolean.parseBoolean(options.get(SKIP_NAMESPACES));
+        }
+        if (options.containsKey(REMOVE_NAMESPACE_PREFIXES)) {
+            removeNamespacePrefixes = Boolean.parseBoolean(options.get(REMOVE_NAMESPACE_PREFIXES));
+        }
+        if (options.containsKey(TYPE_HINTS)) {
+            typeHints = options.get(TYPE_HINTS);
+        }
+    }
+
+    @Override
+    protected void configureDataFormat(DataFormat dataFormat) {
+    	if (encoding != null) {
+    		setProperty(dataFormat, ENCODING, encoding);
+		}
+    	
+    	if (forceTopLevelObject != null) {
+    		setProperty(dataFormat, FORCE_TOP_LEVEL_OBJECT, forceTopLevelObject);
+		}
+    	
+    	if (namespaceLenient != null) {
+    		setProperty(dataFormat, NAMESPACE_LENIENT, namespaceLenient);
+		}
+    	
+    	if (rootName != null) {
+    		setProperty(dataFormat, ROOT_NAME, rootName);
+		}
+    	
+    	if (elementName != null) {
+    		setProperty(dataFormat, ELEMENT_NAME, elementName);
+		}
+    	
+    	if (arrayName != null) {
+    		setProperty(dataFormat, ARRAY_NAME, arrayName);
+		}
+    	
+		if (expandableProperties != null && expandableProperties.size() != 0) {
+			setProperty(dataFormat, EXPANDABLE_PROPERTIES, expandableProperties);
+		}
+    	
+    	if (skipWhitespace != null) {
+    		setProperty(dataFormat, SKIP_WHITESPACE, skipWhitespace);
+		}
+    	
+    	if (trimSpaces != null) {
+    		setProperty(dataFormat, TRIM_SPACES, trimSpaces);
+		}
+    	
+		if (skipNamespaces != null) {
+			setProperty(dataFormat, SKIP_NAMESPACES, skipNamespaces);
+		}
+    	
+    	if (removeNamespacePrefixes != null) {
+    		setProperty(dataFormat, REMOVE_NAMESPACE_PREFIXES, removeNamespacePrefixes);
+		}
+    	
+    	// will end up calling the setTypeHints(String s) which does the parsing from the Enum String key to the Enum value
+		if (typeHints != null) {
+    		setProperty(typeHints, TYPE_HINTS, typeHints);
+		}
+    	
+		// TODO: xmljson: element-namespace mapping is not implemented in the XML DSL
+		// depending on adoption rate of this data format, we'll make this data format NamespaceAware so that it gets
+		// the prefix-namespaceURI mappings from the context, and with a new attribute called "namespacedElements",
+		// we'll associate named elements with prefixes following a format "element1:prefix1,element2:prefix2,..."
+    }
+
+    public String getEncoding() {
+        return encoding;
+    }
+
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+
+    public String getElementName() {
+        return elementName;
+    }
+
+    public void setElementName(String elementName) {
+        this.elementName = elementName;
+    }
+
+    public String getArrayName() {
+        return arrayName;
+    }
+
+    public void setArrayName(String arrayName) {
+        this.arrayName = arrayName;
+    }
+
+    public Boolean getForceTopLevelObject() {
+        return forceTopLevelObject;
+    }
+
+    public void setForceTopLevelObject(Boolean forceTopLevelObject) {
+        this.forceTopLevelObject = forceTopLevelObject;
+    }
+
+    public Boolean getNamespaceLenient() {
+        return namespaceLenient;
+    }
+
+    public void setNamespaceLenient(Boolean namespaceLenient) {
+        this.namespaceLenient = namespaceLenient;
+    }
+
+    public String getRootName() {
+        return rootName;
+    }
+
+    public void setRootName(String rootName) {
+        this.rootName = rootName;
+    }
+
+    public Boolean getSkipWhitespace() {
+        return skipWhitespace;
+    }
+
+    public void setSkipWhitespace(Boolean skipWhitespace) {
+        this.skipWhitespace = skipWhitespace;
+    }
+
+    public Boolean getTrimSpaces() {
+        return trimSpaces;
+    }
+
+    public void setTrimSpaces(Boolean trimSpaces) {
+        this.trimSpaces = trimSpaces;
+    }
+
+    public Boolean getSkipNamespaces() {
+        return skipNamespaces;
+    }
+
+    public void setSkipNamespaces(Boolean skipNamespaces) {
+        this.skipNamespaces = skipNamespaces;
+    }
+
+    public Boolean getRemoveNamespacePrefixes() {
+        return removeNamespacePrefixes;
+    }
+
+    public void setRemoveNamespacePrefixes(Boolean removeNamespacePrefixes) {
+        this.removeNamespacePrefixes = removeNamespacePrefixes;
+    }
+
+    public List<String> getExpandableProperties() {
+        return expandableProperties;
+    }
+
+    public void setExpandableProperties(List<String> expandableProperties) {
+        this.expandableProperties = expandableProperties;
+    }
+
+    public String getTypeHints() {
+        return typeHints;
+    }
+
+    public void setTypeHints(String typeHints) {
+        this.typeHints = typeHints;
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XmlJsonDataFormat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XmlJsonDataFormat.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-xmljson/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Apr  5 16:38:07 2012
@@ -0,0 +1,17 @@
+.pmd
+.checkstyle
+.ruleset
+target
+.settings
+.classpath
+.project
+.wtpmodules
+prj.el
+.jdee_classpath
+.jdee_sources
+velocity.log
+eclipse-classes
+*.ipr
+*.iml
+*.iws
+*.idea

Added: camel/trunk/components/camel-xmljson/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmljson/pom.xml?rev=1309934&view=auto
==============================================================================
--- camel/trunk/components/camel-xmljson/pom.xml (added)
+++ camel/trunk/components/camel-xmljson/pom.xml Thu Apr  5 16:38:07 2012
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-parent</artifactId>
+    <version>2.10-SNAPSHOT</version>
+    <relativePath>../../parent</relativePath>
+  </parent>
+
+  <artifactId>camel-xmljson</artifactId>
+  <packaging>bundle</packaging>
+  <name>Camel :: XML JSON</name>
+  <description>Camel XML JSON Data Format</description>
+
+  <properties>
+    <camel.osgi.export.pkg>org.apache.camel.dataformat.xmljson.*</camel.osgi.export.pkg>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>net.sf.json-lib</groupId>
+      <artifactId>json-lib</artifactId>
+      <version>${jsonlib-version}</version>
+      <classifier>jdk15</classifier>
+    </dependency>
+    <dependency>
+      <groupId>xom</groupId>
+      <artifactId>xom</artifactId>
+      <version>${xom-version}</version>
+    </dependency>
+
+    <!-- testing -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test-spring</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+  </dependencies>
+
+</project>

Propchange: camel/trunk/components/camel-xmljson/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-xmljson/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-xmljson/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/TypeHintsEnum.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/TypeHintsEnum.java?rev=1309934&view=auto
==============================================================================
--- camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/TypeHintsEnum.java (added)
+++ camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/TypeHintsEnum.java Thu Apr  5 16:38:07 2012
@@ -0,0 +1,29 @@
+/**
+ * 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.dataformat.xmljson;
+
+/**
+ * Enumeration with the different Type Hints that can be used.
+ * @see <a href="http://json-lib.sourceforge.net/snippets.html">Examples of type hints usage</a> 
+ */
+public enum TypeHintsEnum {
+
+    YES, 
+    NO, 
+    WITH_PREFIX
+
+}

Propchange: camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/TypeHintsEnum.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/TypeHintsEnum.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormat.java?rev=1309934&view=auto
==============================================================================
--- camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormat.java (added)
+++ camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormat.java Thu Apr  5 16:38:07 2012
@@ -0,0 +1,410 @@
+/**
+ * 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.dataformat.xmljson;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import net.sf.json.JSON;
+import net.sf.json.JSONSerializer;
+import net.sf.json.xml.XMLSerializer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.DataFormat;
+
+/**
+ * A <a href="http://camel.apache.org/data-format.html">data format</a> ({@link DataFormat}) using 
+ * <a href="http://json-lib.sourceforge.net/">json-lib</a> to convert between XML
+ * and JSON directly.
+ */
+public class XmlJsonDataFormat implements DataFormat {
+
+    private XMLSerializer serializer;
+
+    private String encoding;
+    private String elementName;
+    private String arrayName;
+    private Boolean forceTopLevelObject;
+    private Boolean namespaceLenient;
+    private List<NamespacesPerElementMapping> namespaceMappings;
+    private String rootName;
+    private Boolean skipWhitespace;
+    private Boolean trimSpaces;
+    private Boolean skipNamespaces;
+    private Boolean removeNamespacePrefixes;
+    private List<String> expandableProperties;
+    private TypeHintsEnum typeHints;
+
+    public XmlJsonDataFormat() {
+    }
+
+    public void initSerializer() {
+        serializer = new XMLSerializer();
+
+        if (forceTopLevelObject != null) {
+            serializer.setForceTopLevelObject(forceTopLevelObject);
+        }
+
+        if (namespaceLenient != null) {
+            serializer.setNamespaceLenient(namespaceLenient);
+        }
+
+        if (namespaceMappings != null) {
+            for (NamespacesPerElementMapping nsMapping : namespaceMappings) {
+                for (Entry<String, String> entry : nsMapping.namespaces.entrySet()) {
+                    // prefix, URI, elementName (which can be null or empty
+                    // string, in which case the
+                    // mapping is added to the root element
+                    serializer.addNamespace(entry.getKey(), entry.getValue(), nsMapping.element);
+                }
+            }
+        }
+
+        if (rootName != null) {
+            serializer.setRootName(rootName);
+        }
+
+        if (elementName != null) {
+            serializer.setElementName(elementName);
+        }
+
+        if (arrayName != null) {
+            serializer.setArrayName(arrayName);
+        }
+
+        if (expandableProperties != null && expandableProperties.size() != 0) {
+            serializer.setExpandableProperties(expandableProperties.toArray(new String[expandableProperties.size()]));
+        }
+
+        if (skipWhitespace != null) {
+            serializer.setSkipWhitespace(skipWhitespace);
+        }
+
+        if (trimSpaces != null) {
+            serializer.setTrimSpaces(trimSpaces);
+        }
+
+        if (skipNamespaces != null) {
+            serializer.setSkipNamespaces(skipNamespaces);
+        }
+
+        if (removeNamespacePrefixes != null) {
+            serializer.setRemoveNamespacePrefixFromElements(removeNamespacePrefixes);
+        }
+
+        if (typeHints == TypeHintsEnum.YES || typeHints == TypeHintsEnum.WITH_PREFIX) {
+            serializer.setTypeHintsEnabled(true);
+            if (typeHints == TypeHintsEnum.WITH_PREFIX) {
+                serializer.setTypeHintsCompatibility(true);
+            }
+        } else {
+            serializer.setTypeHintsEnabled(false);
+        }
+
+    }
+
+    /**
+     * Marshal from XML to JSON
+     * 
+     * @param exchange
+     * @param graph
+     * @param stream
+     * @throws Exception
+     */
+    @Override
+    public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
+        if (serializer == null) {
+            initSerializer();
+        }
+
+        boolean streamTreatment = true;
+        // try to process as an InputStream if it's not a String
+        Object xml = graph instanceof String ? null : exchange.getContext().getTypeConverter().convertTo(InputStream.class, graph);
+        // if conversion to InputStream was unfeasible, fall back to String
+        if (xml == null) {
+            xml = exchange.getContext().getTypeConverter().mandatoryConvertTo(String.class, graph);
+            streamTreatment = false;
+        }
+
+        JSON json;
+        // perform the marshaling to JSON
+        if (streamTreatment) {
+            json = serializer.readFromStream((InputStream) xml);
+        } else {
+            json = serializer.read((String) xml);
+        }
+
+        OutputStreamWriter osw = new OutputStreamWriter(stream);
+        json.write(osw);
+        osw.flush();
+
+    }
+
+    /**
+     * Convert from JSON to XML
+     * 
+     * @param exchange
+     * @param stream
+     * @throws Exception
+     */
+    @Override
+    public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
+        if (serializer == null) {
+            initSerializer();
+        }
+
+        Object inBody = exchange.getIn().getBody();
+        JSON toConvert;
+        // if the incoming object is already a JSON object, process as-is,
+        // otherwise parse it as a String
+        if (inBody instanceof JSON) {
+            toConvert = (JSON) inBody;
+        } else {
+            String jsonString = exchange.getContext().getTypeConverter().convertTo(String.class, inBody);
+            toConvert = JSONSerializer.toJSON(jsonString);
+        }
+
+        return convertToXMLUsingEncoding(toConvert);
+    }
+
+    private String convertToXMLUsingEncoding(JSON json) {
+        if (encoding == null) {
+            return serializer.write(json);
+        } else {
+            return serializer.write(json, encoding);
+        }
+    }
+
+    // Properties
+    // -------------------------------------------------------------------------
+
+    public XMLSerializer getSerializer() {
+        return serializer;
+    }
+
+    public String getEncoding() {
+        return encoding;
+    }
+
+    /**
+     * Sets the encoding for the call to {@link XMLSerializer#write(JSON, String)}
+     * @param encoding
+     */
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+
+    public Boolean getForceTopLevelObject() {
+        return forceTopLevelObject;
+    }
+
+    /**
+     * See {@link XMLSerializer#setForceTopLevelObject(boolean)}
+     * @param forceTopLevelObject
+     */
+    public void setForceTopLevelObject(Boolean forceTopLevelObject) {
+        this.forceTopLevelObject = forceTopLevelObject;
+    }
+
+    public Boolean getNamespaceLenient() {
+        return namespaceLenient;
+    }
+
+    /**
+     * See {@link XMLSerializer#setNamespaceLenient(boolean)}
+     * @param namespaceLenient
+     */
+    public void setNamespaceLenient(Boolean namespaceLenient) {
+        this.namespaceLenient = namespaceLenient;
+    }
+
+    public List<NamespacesPerElementMapping> getNamespaceMappings() {
+        return namespaceMappings;
+    }
+
+    /**
+     * Sets associations between elements and namespace mappings. Will only be used when converting from JSON to XML.
+     * For every association, the whenever a JSON element is found that matches {@link NamespacesPerElementMapping#element},
+     * the namespaces declarations specified by {@link NamespacesPerElementMapping#namespaces} will be output.
+     * @see Uses {@link XMLSerializer#addNamespace(String, String, String)}
+     * @param namespaceMappings
+     */
+    public void setNamespaceMappings(List<NamespacesPerElementMapping> namespaceMappings) {
+        this.namespaceMappings = namespaceMappings;
+    }
+
+    public String getRootName() {
+        return rootName;
+    }
+
+    /**
+     * See {@link XMLSerializer#setRootName(String)}
+     * @param rootName
+     */
+    public void setRootName(String rootName) {
+        this.rootName = rootName;
+    }
+
+    public Boolean getSkipWhitespace() {
+        return skipWhitespace;
+    }
+
+    /**
+     * See {@link XMLSerializer#setSkipWhitespace(boolean)}
+     * @param skipWhitespace
+     */
+    public void setSkipWhitespace(Boolean skipWhitespace) {
+        this.skipWhitespace = skipWhitespace;
+    }
+
+    public Boolean getTrimSpaces() {
+        return trimSpaces;
+    }
+    
+    /**
+     * See {@link XMLSerializer#setTrimSpaces(boolean)}
+     * @param trimSpaces
+     */
+    public void setTrimSpaces(Boolean trimSpaces) {
+        this.trimSpaces = trimSpaces;
+    }
+
+    public TypeHintsEnum getTypeHints() {
+        return typeHints;
+    }
+    
+    /**
+     * See {@link XMLSerializer#setTypeHintsEnabled(boolean)} and {@link XMLSerializer#setTypeHintsCompatibility(boolean)}
+     * @param typeHints a key in the {@link TypeHintsEnum} enumeration
+     */
+    public void setTypeHints(String typeHints) {
+        this.typeHints = TypeHintsEnum.valueOf(typeHints);
+    }
+
+    public Boolean getSkipNamespaces() {
+        return skipNamespaces;
+    }
+
+    /**
+     * See {@link XMLSerializer#setSkipNamespaces(boolean)}
+     * @param skipNamespaces 
+     */
+    public void setSkipNamespaces(Boolean skipNamespaces) {
+        this.skipNamespaces = skipNamespaces;
+    }
+
+    /**
+     * See {@link XMLSerializer#setElementName(String)}
+     * @param elementName 
+     */
+    public void setElementName(String elementName) {
+        this.elementName = elementName;
+    }
+
+    public String getElementName() {
+        return elementName;
+    }
+
+    /**
+     * See {@link XMLSerializer#setArrayName(String)}
+     * @param arrayName 
+     */
+    public void setArrayName(String arrayName) {
+        this.arrayName = arrayName;
+    }
+
+    public String getArrayName() {
+        return arrayName;
+    }
+
+    /**
+     * See {@link XMLSerializer#setExpandableProperties(String[])}
+     * @param expandableProperties 
+     */
+    public void setExpandableProperties(List<String> expandableProperties) {
+        this.expandableProperties = expandableProperties;
+    }
+
+    public List<String> getExpandableProperties() {
+        return expandableProperties;
+    }
+
+    /**
+     * See {@link XMLSerializer#setRemoveNamespacePrefixFromElements(boolean)}
+     * @param removeNamespacePrefixes 
+     */
+    public void setRemoveNamespacePrefixes(Boolean removeNamespacePrefixes) {
+        this.removeNamespacePrefixes = removeNamespacePrefixes;
+    }
+
+    public Boolean getRemoveNamespacePrefixes() {
+        return removeNamespacePrefixes;
+    }
+
+    /**
+     * Encapsulates the information needed to bind namespace declarations to XML elements when performing JSON to XML conversions
+     * Given the following JSON: { "root:": { "element": "value", "element2": "value2" }}, it will produce the following XML when "element" is
+     * bound to prefix "ns1" and namespace URI "http://mynamespace.org":
+     * <root><element xmlns:ns1="http://mynamespace.org">value</element><element2>value2</element2></root>
+     * For convenience, the {@link NamespacesPerElementMapping#NamespacesPerElementMapping(String, String)} constructor allows to specify
+     * multiple prefix-namespaceURI pairs in just one String line, the format being: |ns1|http://mynamespace.org|ns2|http://mynamespace2.org|
+     * 
+     * @author Raul Kripalani
+     *
+     */
+    public static class NamespacesPerElementMapping {
+        public String element;
+        public Map<String, String> namespaces;
+
+        public NamespacesPerElementMapping(String element, Map<String, String> namespaces) {
+            this.element = element;
+            this.namespaces = namespaces;
+        }
+
+        public NamespacesPerElementMapping(String element, String prefix, String uri) {
+            this.element = element;
+            this.namespaces = new HashMap<String, String>();
+            this.namespaces.put(prefix, uri);
+        }
+
+        public NamespacesPerElementMapping(String element, String pipeSeparatedMappings) {
+            this.element = element;
+            this.namespaces = new HashMap<String, String>();
+            String[] origTokens = pipeSeparatedMappings.split("\\|");
+            // drop the first token
+            String[] tokens = Arrays.copyOfRange(origTokens, 1, origTokens.length);
+
+            if (tokens.length % 2 != 0) {
+                throw new IllegalArgumentException("Even number of prefix-namespace tokens is expected, number of tokens parsed: " + tokens.length);
+            }
+            int i = 0;
+            // |ns1|http://test.org|ns2|http://test2.org|
+            while (i < (tokens.length - 1)) {
+                this.namespaces.put(tokens[i], tokens[++i]);
+                i++;
+            }
+        }
+
+    }
+
+}

Propchange: camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormat.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/converters/XmlJsonConverters.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/converters/XmlJsonConverters.java?rev=1309934&view=auto
==============================================================================
--- camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/converters/XmlJsonConverters.java (added)
+++ camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/converters/XmlJsonConverters.java Thu Apr  5 16:38:07 2012
@@ -0,0 +1,49 @@
+/**
+ * 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.dataformat.xmljson.converters;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import net.sf.json.JSON;
+
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.converter.IOConverter;
+
+/**
+ * Contains type converters to cater for Camel's unconditional conversion of the message body to an 
+ * InputStream prior to marshaling
+ */
+@Converter
+public final class XmlJsonConverters {
+
+    private XmlJsonConverters() {
+        // Helper class
+    }
+    
+    /**
+     * Converts from an existing JSON object circulating as such to an
+     * InputStream, by dumping it to a String first and then using camel-core's
+     * {@link IOConverter#toInputStream(String, Exchange)}
+     */
+    @Converter
+    public static InputStream fromJSONtoInputStream(JSON json, Exchange exchange) throws IOException {
+        return IOConverter.toInputStream(json.toString(), exchange);
+    }
+
+}

Propchange: camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/converters/XmlJsonConverters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/converters/XmlJsonConverters.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-xmljson/src/main/resources/META-INF/LICENSE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmljson/src/main/resources/META-INF/LICENSE.txt?rev=1309934&view=auto
==============================================================================
--- camel/trunk/components/camel-xmljson/src/main/resources/META-INF/LICENSE.txt (added)
+++ camel/trunk/components/camel-xmljson/src/main/resources/META-INF/LICENSE.txt Thu Apr  5 16:38:07 2012
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+

Propchange: camel/trunk/components/camel-xmljson/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-xmljson/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: camel/trunk/components/camel-xmljson/src/main/resources/META-INF/NOTICE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmljson/src/main/resources/META-INF/NOTICE.txt?rev=1309934&view=auto
==============================================================================
--- camel/trunk/components/camel-xmljson/src/main/resources/META-INF/NOTICE.txt (added)
+++ camel/trunk/components/camel-xmljson/src/main/resources/META-INF/NOTICE.txt Thu Apr  5 16:38:07 2012
@@ -0,0 +1,11 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Apache Camel distribution.                    ==
+   =========================================================================
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+
+   Please read the different LICENSE files present in the licenses directory of
+   this distribution.

Propchange: camel/trunk/components/camel-xmljson/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-xmljson/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?rev=1309934&view=auto
==============================================================================
--- camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/org/apache/camel/TypeConverter (added)
+++ camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/org/apache/camel/TypeConverter Thu Apr  5 16:38:07 2012
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.camel.dataformat.xmljson.converters.XmlJsonConverters

Added: camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/org/apache/camel/dataformat/xmljson
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/org/apache/camel/dataformat/xmljson?rev=1309934&view=auto
==============================================================================
--- camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/org/apache/camel/dataformat/xmljson (added)
+++ camel/trunk/components/camel-xmljson/src/main/resources/META-INF/services/org/apache/camel/dataformat/xmljson Thu Apr  5 16:38:07 2012
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.dataformat.xmljson.XmlJsonDataFormat

Added: camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/SpringXmlJsonDataFormatTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/SpringXmlJsonDataFormatTest.java?rev=1309934&view=auto
==============================================================================
--- camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/SpringXmlJsonDataFormatTest.java (added)
+++ camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/SpringXmlJsonDataFormatTest.java Thu Apr  5 16:38:07 2012
@@ -0,0 +1,91 @@
+/**
+ * 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.dataformat.xmljson;
+
+import java.io.InputStream;
+
+import org.w3c.dom.Document;
+
+import net.sf.json.JSONObject;
+import net.sf.json.JSONSerializer;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * Test the Spring DSL
+ */
+public class SpringXmlJsonDataFormatTest extends CamelSpringTestSupport {
+
+    @Test
+    public void testMarshalAndUnmarshal() throws Exception {
+        InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage1.xml");
+        String in = context.getTypeConverter().convertTo(String.class, inStream);
+
+        MockEndpoint mockJSON = getMockEndpoint("mock:json");
+        mockJSON.expectedMessageCount(1);
+        mockJSON.message(0).body().isInstanceOf(byte[].class);
+
+        MockEndpoint mockXML = getMockEndpoint("mock:xml");
+        mockXML.expectedMessageCount(1);
+        mockXML.message(0).body().isInstanceOf(String.class);
+
+        Object json = template.requestBody("direct:marshal", in);
+        String jsonString = context.getTypeConverter().convertTo(String.class, json);
+        JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
+        assertEquals("JSONObject doesn't contain 7 keys", 7, obj.entrySet().size());
+
+        template.sendBody("direct:unmarshal", jsonString);
+
+        mockJSON.assertIsSatisfied();
+        mockXML.assertIsSatisfied();
+    }
+
+    @Test
+    public void testSomeOptionsToXML() throws Exception {
+        InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage1.json");
+        String in = context.getTypeConverter().convertTo(String.class, inStream);
+
+        MockEndpoint mockXML = getMockEndpoint("mock:xmlWithOptions");
+        mockXML.expectedMessageCount(1);
+        mockXML.message(0).body().isInstanceOf(String.class);
+
+        Object marshalled = template.requestBody("direct:unmarshalWithOptions", in);
+        Document document = context.getTypeConverter().convertTo(Document.class, marshalled);
+        assertEquals("The XML document doesn't carry newRoot as the root name", "newRoot", document.getDocumentElement().getLocalName());
+        // with expandable properties, array elements are converted to XML as a
+        // sequence of repetitive XML elements with the local name equal to the
+        // JSON key
+        // for example: { number: [1,2,3] }, normally converted to:
+        // <number><e>1</e><e>2</e><e>3</e></number> (where e can be modified by
+        // setting elementName)
+        // would be converted to
+        // <number>1</number><number>2</number><number>3</number>, if number is
+        // set as an expandable property
+        assertEquals("The number of direct child elements of newRoot with tag d (expandable property) is not 3", 3, document.getDocumentElement().getElementsByTagName("d").getLength());
+        assertEquals("The number of direct child elements of newRoot with tag e (expandable property) is not 3", 3, document.getDocumentElement().getElementsByTagName("e").getLength());
+        mockXML.assertIsSatisfied();
+    }
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/dataformat/xmljson/SpringXmlJsonDataFormatTest.xml");
+    }
+
+}

Propchange: camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/SpringXmlJsonDataFormatTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/SpringXmlJsonDataFormatTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormatTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormatTest.java?rev=1309934&view=auto
==============================================================================
--- camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormatTest.java (added)
+++ camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormatTest.java Thu Apr  5 16:38:07 2012
@@ -0,0 +1,215 @@
+/**
+ * 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.dataformat.xmljson;
+
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+
+import org.w3c.dom.Document;
+
+import net.sf.json.JSON;
+import net.sf.json.JSONObject;
+import net.sf.json.JSONSerializer;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * Basic tests for the XML JSON data format
+ */
+public class XmlJsonDataFormatTest extends CamelTestSupport {
+
+    @Test
+    public void testMarshalAndUnmarshal() throws Exception {
+        InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage1.xml");
+        String in = context.getTypeConverter().convertTo(String.class, inStream);
+
+        MockEndpoint mockJSON = getMockEndpoint("mock:json");
+        mockJSON.expectedMessageCount(1);
+        mockJSON.message(0).body().isInstanceOf(byte[].class);
+
+        MockEndpoint mockXML = getMockEndpoint("mock:xml");
+        mockXML.expectedMessageCount(1);
+        mockXML.message(0).body().isInstanceOf(String.class);
+
+        Object json = template.requestBody("direct:marshal", in);
+        String jsonString = context.getTypeConverter().convertTo(String.class, json);
+        JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
+        assertEquals("JSONObject doesn't contain 7 keys", 7, obj.entrySet().size());
+
+        template.sendBody("direct:unmarshal", jsonString);
+
+        mockJSON.assertIsSatisfied();
+        mockXML.assertIsSatisfied();
+    }
+
+    @Test
+    public void testUnmarshalJSONObject() throws Exception {
+        InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage1.json");
+        String in = context.getTypeConverter().convertTo(String.class, inStream);
+        JSON json = JSONSerializer.toJSON(in);
+
+        MockEndpoint mockXML = getMockEndpoint("mock:xml");
+        mockXML.expectedMessageCount(1);
+        mockXML.message(0).body().isInstanceOf(String.class);
+
+        Object marshalled = template.requestBody("direct:unmarshal", json);
+        Document document = context.getTypeConverter().convertTo(Document.class, marshalled);
+        assertEquals("The XML document has an unexpected root node", "o", document.getDocumentElement().getLocalName());
+
+        mockXML.assertIsSatisfied();
+    }
+
+    @Test
+    public void testMarshalXMLSources() throws Exception {
+        InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage1.xml");
+        DOMSource inDOM = context.getTypeConverter().convertTo(DOMSource.class, inStream);
+        inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage1.xml");
+        SAXSource inSAX = context.getTypeConverter().convertTo(SAXSource.class, inStream);
+        inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage1.xml");
+        Document inDocument = context.getTypeConverter().convertTo(Document.class, inStream);
+
+        // save the expected body of the message to set it later
+        Object expectedBody = template.requestBody("direct:marshal", inDOM);
+
+        MockEndpoint mockJSON = getMockEndpoint("mock:json");
+        // reset the mock endpoint to get rid of the previous message
+        mockJSON.reset();
+        // all three messages should arrive, should be of type byte[] and
+        // identical to one another
+        mockJSON.expectedMessageCount(3);
+        mockJSON.allMessages().body().isInstanceOf(byte[].class);
+        mockJSON.expectedBodiesReceived(Arrays.asList(expectedBody, expectedBody, expectedBody));
+
+        // start bombarding the route
+        Object json = template.requestBody("direct:marshal", inDOM);
+        String jsonString = context.getTypeConverter().convertTo(String.class, json);
+        JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
+        assertEquals("JSONObject doesn't contain 7 keys", 7, obj.entrySet().size());
+        template.requestBody("direct:marshal", inSAX);
+        template.requestBody("direct:marshal", inDocument);
+
+        mockJSON.assertIsSatisfied();
+    }
+    
+    @Test
+    public void testMarshalAndUnmarshalInline() throws Exception {
+        InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage1.xml");
+        String in = context.getTypeConverter().convertTo(String.class, inStream);
+
+        MockEndpoint mockJSON = getMockEndpoint("mock:jsonInline");
+        mockJSON.expectedMessageCount(1);
+        mockJSON.message(0).body().isInstanceOf(byte[].class);
+
+        MockEndpoint mockXML = getMockEndpoint("mock:xmlInline");
+        mockXML.expectedMessageCount(1);
+        mockXML.message(0).body().isInstanceOf(String.class);
+
+        Object json = template.requestBody("direct:marshalInline", in);
+        String jsonString = context.getTypeConverter().convertTo(String.class, json);
+        JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
+        assertEquals("JSONObject doesn't contain 7 keys", 7, obj.entrySet().size());
+
+        template.sendBody("direct:unmarshalInline", jsonString);
+
+        mockJSON.assertIsSatisfied();
+        mockXML.assertIsSatisfied();
+    }
+    
+    @Test
+    public void testNamespacesDroppedInlineWithOptions() throws Exception {
+        InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage2-namespaces.xml");
+        String in = context.getTypeConverter().convertTo(String.class, inStream);
+
+        MockEndpoint mockJSON = getMockEndpoint("mock:jsonInlineOptions");
+        mockJSON.expectedMessageCount(1);
+        mockJSON.message(0).body().isInstanceOf(byte[].class);
+
+        Object json = template.requestBody("direct:marshalInlineOptions", in);
+        String jsonString = context.getTypeConverter().convertTo(String.class, json);
+        JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
+        assertEquals("JSON must contain 1 top-level element", 1, obj.entrySet().size());
+        assertTrue("Top-level element must be named root", obj.has("root"));
+        // check that no child of the top-level element has a colon in its key,
+        // which would denote that
+        // a namespace prefix exists
+        for (Object key : obj.getJSONObject("root").keySet()) {
+            assertFalse("A key contains a colon", ((String) key).contains(":"));
+        }
+
+        mockJSON.assertIsSatisfied();
+    }
+    
+    @Test
+    public void testUnmarshalToXMLInlineOptions() throws Exception {
+        InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage1.json");
+        String in = context.getTypeConverter().convertTo(String.class, inStream);
+
+        MockEndpoint mockXML = getMockEndpoint("mock:xmlInlineOptions");
+        mockXML.expectedMessageCount(1);
+        mockXML.message(0).body().isInstanceOf(String.class);
+
+        Object marshalled = template.requestBody("direct:unmarshalInlineOptions", in);
+        Document document = context.getTypeConverter().convertTo(Document.class, marshalled);
+        assertEquals("The XML document doesn't carry newRoot as the root name", "newRoot", document.getDocumentElement().getLocalName());
+        assertEquals("The number of direct child elements of newRoot with tag d (expandable property) is not 3", 3, document.getDocumentElement().getElementsByTagName("d").getLength());
+        assertEquals("The number of direct child elements of newRoot with tag e (expandable property) is not 3", 3, document.getDocumentElement().getElementsByTagName("e").getLength());
+        mockXML.assertIsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                XmlJsonDataFormat format = new XmlJsonDataFormat();
+
+                // from XML to JSON
+                from("direct:marshal").marshal(format).to("mock:json");
+                // from JSON to XML
+                from("direct:unmarshal").unmarshal(format).to("mock:xml");
+
+                // from XML to JSON - inline dataformat
+                from("direct:marshalInline").marshal().xmljson().to("mock:jsonInline");
+                // form JSON to XML - inline dataformat
+                from("direct:unmarshalInline").unmarshal().xmljson().to("mock:xmlInline");
+                
+                Map<String, String> xmlJsonOptions = new HashMap<String, String>();
+                xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.ENCODING, "UTF-8");
+                xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.FORCE_TOP_LEVEL_OBJECT, "true");
+                xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.TRIM_SPACES, "true");
+                xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.ROOT_NAME, "newRoot");
+                xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.SKIP_NAMESPACES, "true");
+                xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.REMOVE_NAMESPACE_PREFIXES, "true");
+                xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.EXPANDABLE_PROPERTIES, "d e");
+
+                // from XML to JSON - inline dataformat w/ options
+                from("direct:marshalInlineOptions").marshal().xmljson(xmlJsonOptions).to("mock:jsonInlineOptions");
+                // form JSON to XML - inline dataformat w/ options
+                from("direct:unmarshalInlineOptions").unmarshal().xmljson(xmlJsonOptions).to("mock:xmlInlineOptions");
+
+            }
+        };
+    }
+
+}

Propchange: camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormatTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormatTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonExceptionsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonExceptionsTest.java?rev=1309934&view=auto
==============================================================================
--- camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonExceptionsTest.java (added)
+++ camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonExceptionsTest.java Thu Apr  5 16:38:07 2012
@@ -0,0 +1,134 @@
+/**
+ * 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.dataformat.xmljson;
+
+import java.util.List;
+
+import net.sf.json.JSONException;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * Tests for exception cases in the XML JSON data format
+ */
+public class XmlJsonExceptionsTest extends CamelTestSupport {
+
+    @Test
+    public void testMalformedXML() throws Exception {
+        String in = "<noRoot>abc</noRoot><noRoot>abc</noRoot>";
+
+        MockEndpoint mockJSON = getMockEndpoint("mock:json");
+        mockJSON.expectedMessageCount(0);
+
+        MockEndpoint mockException = getMockEndpoint("mock:exception");
+        mockException.expectedMessageCount(1);
+
+        try {
+            template.requestBody("direct:marshal", in);
+            fail("Exception expected");
+        } catch (CamelExecutionException e) {
+            assertEquals("JSONException expected", JSONException.class, e.getCause().getClass());
+        }
+
+        List<Exchange> exchs = mockException.getExchanges();
+        assertEquals("Only one exchange was expected in mock:exception", 1, exchs.size());
+
+        Exception e = (Exception) exchs.get(0).getProperty(Exchange.EXCEPTION_CAUGHT);
+        assertNotNull("Exception expected", e);
+        assertEquals("JSONException expected", JSONException.class, e.getClass());
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testMalformedJson() throws Exception {
+        String in = "{ \"a\": 123, \"b\": true, \"c\": true2 }";
+
+        MockEndpoint mockXML = getMockEndpoint("mock:xml");
+        mockXML.expectedMessageCount(0);
+
+        MockEndpoint mockException = getMockEndpoint("mock:exception");
+        mockException.expectedMessageCount(1);
+
+        try {
+            template.requestBody("direct:unmarshal", in);
+            fail("Exception expected");
+        } catch (CamelExecutionException e) {
+            assertEquals("JSONException expected", JSONException.class, e.getCause().getClass());
+        }
+
+        List<Exchange> exchs = mockException.getExchanges();
+        assertEquals("Only one exchange was expected in mock:exception", 1, exchs.size());
+
+        Exception e = (Exception) exchs.get(0).getProperty(Exchange.EXCEPTION_CAUGHT);
+        assertNotNull("Exception expected", e);
+        assertEquals("JSONException expected", JSONException.class, e.getClass());
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testSendJsonToXML() throws Exception {
+        String in = "{ \"a\": 123, \"b\": true, \"c\": true2 }";
+
+        MockEndpoint mockJSON = getMockEndpoint("mock:xml");
+        mockJSON.expectedMessageCount(0);
+
+        MockEndpoint mockException = getMockEndpoint("mock:exception");
+        mockException.expectedMessageCount(1);
+
+        try {
+            template.requestBody("direct:unmarshal", in);
+            fail("Exception expected");
+        } catch (CamelExecutionException e) {
+            assertEquals("JSONException expected", JSONException.class, e.getCause().getClass());
+        }
+
+        List<Exchange> exchs = mockException.getExchanges();
+        assertEquals("Only one exchange was expected in mock:exception", 1, exchs.size());
+
+        Exception e = (Exception) exchs.get(0).getProperty(Exchange.EXCEPTION_CAUGHT);
+        assertNotNull("Exception expected", e);
+        assertEquals("JSONException expected", JSONException.class, e.getClass());
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                XmlJsonDataFormat format = new XmlJsonDataFormat();
+
+                onException(Exception.class).handled(false).to("mock:exception");
+
+                // from XML to JSON
+                from("direct:marshal").marshal(format).to("mock:json");
+                // from JSON to XML
+                from("direct:unmarshal").unmarshal(format).to("mock:xml");
+
+            }
+        };
+    }
+
+}

Propchange: camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonExceptionsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonExceptionsTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message