Repository: camel Updated Branches: refs/heads/master af22f502e -> 281528256
http://git-wip-us.apache.org/repos/asf/camel/blob/28152825/components/camel-xmlbeans/src/main/docs/xmlBeans-dataformat.adoc ---------------------------------------------------------------------- diff --git a/components/camel-xmlbeans/src/main/docs/xmlBeans-dataformat.adoc b/components/camel-xmlbeans/src/main/docs/xmlBeans-dataformat.adoc index 612ac26..651ca09 100644 --- a/components/camel-xmlbeans/src/main/docs/xmlBeans-dataformat.adoc +++ b/components/camel-xmlbeans/src/main/docs/xmlBeans-dataformat.adoc @@ -19,7 +19,7 @@ Options ^^^^^^^ // dataformat options: START -The XML Beans dataformat supports 1 options which are listed below. +The XML Beans dataformat supports 2 options which are listed below. @@ -28,6 +28,7 @@ The XML Beans dataformat supports 1 options which are listed below. |======================================================================= | Name | Default | Java Type | Description | prettyPrint | false | Boolean | To enable pretty printing output nicely formatted. Is by default false. +| contentTypeHeader | false | Boolean | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML or application/json for data formats marshalling to JSon etc. |======================================================================= {% endraw %} // dataformat options: END http://git-wip-us.apache.org/repos/asf/camel/blob/28152825/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java ---------------------------------------------------------------------- diff --git a/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java b/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java index 3b034b8..c858d95 100644 --- a/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java +++ b/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java @@ -34,8 +34,6 @@ import org.apache.camel.util.ObjectHelper; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.impl.piccolo.xml.XMLStreamReader; - - /** * A <a href="http://camel.apache.org/type-coverter.html">Type Converter</a> * of XMLBeans objects @@ -53,7 +51,6 @@ public final class XmlBeansConverter { return XmlObject.Factory.parse(value); } }, exchange); - } @Converter http://git-wip-us.apache.org/repos/asf/camel/blob/28152825/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java b/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java index 8e0be84..b421dbc 100644 --- a/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java +++ b/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java @@ -34,6 +34,8 @@ import org.apache.xmlbeans.XmlObject; */ public class XmlBeansDataFormat extends ServiceSupport implements DataFormat, DataFormatName { + private boolean contentTypeHeader = true; + @Override public String getDataFormatName() { return "xmlBeans"; @@ -49,6 +51,13 @@ public class XmlBeansDataFormat extends ServiceSupport implements DataFormat, Da } }, exchange); + if (contentTypeHeader) { + if (exchange.hasOut()) { + exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/xml"); + } else { + exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/xml"); + } + } } public Object unmarshal(final Exchange exchange, final InputStream stream) throws Exception { @@ -69,4 +78,17 @@ public class XmlBeansDataFormat extends ServiceSupport implements DataFormat, Da protected void doStop() throws Exception { // noop } + + + public boolean isContentTypeHeader() { + return contentTypeHeader; + } + + /** + * If enabled then XmlBeans will set the Content-Type header to <tt>application/xml</tt> when marshalling. + */ + public void setContentTypeHeader(boolean contentTypeHeader) { + this.contentTypeHeader = contentTypeHeader; + } + } http://git-wip-us.apache.org/repos/asf/camel/blob/28152825/components/camel-xmljson/src/main/docs/xmljson-dataformat.adoc ---------------------------------------------------------------------- diff --git a/components/camel-xmljson/src/main/docs/xmljson-dataformat.adoc b/components/camel-xmljson/src/main/docs/xmljson-dataformat.adoc index 9a9528b..f94f545 100644 --- a/components/camel-xmljson/src/main/docs/xmljson-dataformat.adoc +++ b/components/camel-xmljson/src/main/docs/xmljson-dataformat.adoc @@ -24,7 +24,7 @@ Options ^^^^^^^ // dataformat options: START -The XML JSon dataformat supports 12 options which are listed below. +The XML JSon dataformat supports 13 options which are listed below. @@ -44,6 +44,7 @@ The XML JSon dataformat supports 12 options which are listed below. | removeNamespacePrefixes | false | Boolean | Removes the namespace prefixes from XML qualified elements so that the resulting JSON string does not contain them. Used for marshalling (XML to JSon conversion). | expandableProperties | | List | With expandable properties JSON 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: 123 normally converted to: 123 (where e can be modified by setting elementName) would instead translate to 123 if number is set as an expandable property Used for unmarshalling (JSON to XML conversion). | typeHints | | String | Adds type hints to the resulting XML to aid conversion back to JSON. Used for unmarshalling (JSON to XML conversion). +| contentTypeHeader | false | Boolean | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML or application/json for data formats marshalling to JSon etc. |======================================================================= {% endraw %} // dataformat options: END http://git-wip-us.apache.org/repos/asf/camel/blob/28152825/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormat.java b/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormat.java index be34928..6acf6cf 100644 --- a/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormat.java +++ b/components/camel-xmljson/src/main/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormat.java @@ -56,6 +56,7 @@ public class XmlJsonDataFormat extends ServiceSupport implements DataFormat, Dat private Boolean removeNamespacePrefixes; private List<String> expandableProperties; private TypeHintsEnum typeHints; + private boolean contentTypeHeader = true; public XmlJsonDataFormat() { } @@ -173,6 +174,13 @@ public class XmlJsonDataFormat extends ServiceSupport implements DataFormat, Dat json.write(osw); osw.flush(); + if (contentTypeHeader) { + if (exchange.hasOut()) { + exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/json"); + } else { + exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json"); + } + } } /** @@ -191,7 +199,17 @@ public class XmlJsonDataFormat extends ServiceSupport implements DataFormat, Dat toConvert = JSONSerializer.toJSON(jsonString); } - return convertToXMLUsingEncoding(toConvert); + Object answer = convertToXMLUsingEncoding(toConvert); + + if (contentTypeHeader) { + if (exchange.hasOut()) { + exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/xml"); + } else { + exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/xml"); + } + } + + return answer; } private String convertToXMLUsingEncoding(JSON json) { @@ -334,6 +352,19 @@ public class XmlJsonDataFormat extends ServiceSupport implements DataFormat, Dat return arrayName; } + + public boolean isContentTypeHeader() { + return contentTypeHeader; + } + + /** + * If enabled then XmlJson will set the Content-Type header to <tt>application/json</tt> when marshalling, + * and <tt>application/xml</tt> when unmarshalling. + */ + public void setContentTypeHeader(boolean contentTypeHeader) { + this.contentTypeHeader = contentTypeHeader; + } + /** * See {@link XMLSerializer#setExpandableProperties(String[])} */ http://git-wip-us.apache.org/repos/asf/camel/blob/28152825/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormatTest.java ---------------------------------------------------------------------- diff --git a/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormatTest.java b/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormatTest.java index d2749e9..27c3bfc 100644 --- a/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormatTest.java +++ b/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/XmlJsonDataFormatTest.java @@ -24,6 +24,7 @@ import java.util.Map; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.sax.SAXSource; +import org.apache.camel.Exchange; import org.w3c.dom.Document; import net.sf.json.JSON; @@ -48,10 +49,12 @@ public class XmlJsonDataFormatTest extends AbstractJsonTestSupport { MockEndpoint mockJSON = getMockEndpoint("mock:json"); mockJSON.expectedMessageCount(1); + mockJSON.expectedHeaderReceived(Exchange.CONTENT_TYPE, "application/json"); mockJSON.message(0).body().isInstanceOf(byte[].class); MockEndpoint mockXML = getMockEndpoint("mock:xml"); mockXML.expectedMessageCount(1); + mockXML.expectedHeaderReceived(Exchange.CONTENT_TYPE, "application/xml"); mockXML.message(0).body().isInstanceOf(String.class); Object json = template.requestBody("direct:marshal", in); http://git-wip-us.apache.org/repos/asf/camel/blob/28152825/components/camel-xmlrpc/src/main/docs/xmlrpc-dataformat.adoc ---------------------------------------------------------------------- diff --git a/components/camel-xmlrpc/src/main/docs/xmlrpc-dataformat.adoc b/components/camel-xmlrpc/src/main/docs/xmlrpc-dataformat.adoc index a7436c3..160087a 100644 --- a/components/camel-xmlrpc/src/main/docs/xmlrpc-dataformat.adoc +++ b/components/camel-xmlrpc/src/main/docs/xmlrpc-dataformat.adoc @@ -41,7 +41,7 @@ XmlRpc Dataformat Options ^^^^^^^^^^^^^^^^^^^^^^^^^ // dataformat options: START -The XML RPC dataformat supports 1 options which are listed below. +The XML RPC dataformat supports 2 options which are listed below. @@ -50,6 +50,7 @@ The XML RPC dataformat supports 1 options which are listed below. |======================================================================= | Name | Default | Java Type | Description | request | false | Boolean | Whether to marshal/unmarshal request or response Is by default false +| contentTypeHeader | false | Boolean | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML or application/json for data formats marshalling to JSon etc. |======================================================================= {% endraw %} // dataformat options: END http://git-wip-us.apache.org/repos/asf/camel/blob/28152825/components/camel-xmlsecurity/src/main/docs/secureXML-dataformat.adoc ---------------------------------------------------------------------- diff --git a/components/camel-xmlsecurity/src/main/docs/secureXML-dataformat.adoc b/components/camel-xmlsecurity/src/main/docs/secureXML-dataformat.adoc index 5d65c99..b9deac1 100644 --- a/components/camel-xmlsecurity/src/main/docs/secureXML-dataformat.adoc +++ b/components/camel-xmlsecurity/src/main/docs/secureXML-dataformat.adoc @@ -40,7 +40,7 @@ XMLSecurity Options ^^^^^^^^^^^^^^^^^^^ // dataformat options: START -The XML Security dataformat supports 11 options which are listed below. +The XML Security dataformat supports 12 options which are listed below. @@ -59,6 +59,7 @@ The XML Security dataformat supports 11 options which are listed below. | digestAlgorithm | SHA1 | String | The digest algorithm to use with the RSA OAEP algorithm. The available choices are: XMLCipher.SHA1 XMLCipher.SHA256 XMLCipher.SHA512 The default value is XMLCipher.SHA1 | mgfAlgorithm | MGF1_SHA1 | String | The MGF Algorithm to use with the RSA OAEP algorithm. The available choices are: EncryptionConstants.MGF1_SHA1 EncryptionConstants.MGF1_SHA256 EncryptionConstants.MGF1_SHA512 The default value is EncryptionConstants.MGF1_SHA1 | addKeyValueForEncryptedKey | true | Boolean | Whether to add the public key used to encrypt the session key as a KeyValue in the EncryptedKey structure or not. +| contentTypeHeader | false | Boolean | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML or application/json for data formats marshalling to JSon etc. |======================================================================= {% endraw %} // dataformat options: END http://git-wip-us.apache.org/repos/asf/camel/blob/28152825/components/camel-xstream/src/main/docs/json-xstream-dataformat.adoc ---------------------------------------------------------------------- diff --git a/components/camel-xstream/src/main/docs/json-xstream-dataformat.adoc b/components/camel-xstream/src/main/docs/json-xstream-dataformat.adoc index 6faf974..9b878c3 100644 --- a/components/camel-xstream/src/main/docs/json-xstream-dataformat.adoc +++ b/components/camel-xstream/src/main/docs/json-xstream-dataformat.adoc @@ -27,7 +27,7 @@ Options ^^^^^^^ // dataformat options: START -The JSon XStream dataformat supports 16 options which are listed below. +The JSon XStream dataformat supports 17 options which are listed below. @@ -51,6 +51,7 @@ The JSon XStream dataformat supports 16 options which are listed below. | 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 | permissions | | String | Adds permissions that controls which Java packages and classes XStream is allowed to use during unmarshal from xml/json to Java beans. A permission must be configured either here or globally using a JVM system property. The permission can be specified in a syntax where a plus sign is allow and minus sign is deny. Wildcards is supported by using . as prefix. For example to allow com.foo and all subpackages then specfy com.foo.. Multiple permissions can be configured separated by comma such as com.foo.-com.foo.bar.MySecretBean. The following default permission is always included: -java.lang.java.util. unless its overridden by specifying a JVM system property with they key org.apache.camel.xstream.permissions. | 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. +| contentTypeHeader | false | Boolean | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML or application/json for data formats marshalling to JSon etc. |======================================================================= {% endraw %} // dataformat options: END http://git-wip-us.apache.org/repos/asf/camel/blob/28152825/components/camel-xstream/src/main/docs/xstream-dataformat.adoc ---------------------------------------------------------------------- diff --git a/components/camel-xstream/src/main/docs/xstream-dataformat.adoc b/components/camel-xstream/src/main/docs/xstream-dataformat.adoc index ea7e217..9155f46 100644 --- a/components/camel-xstream/src/main/docs/xstream-dataformat.adoc +++ b/components/camel-xstream/src/main/docs/xstream-dataformat.adoc @@ -27,7 +27,7 @@ Options ^^^^^^^ // dataformat options: START -The XStream dataformat supports 9 options which are listed below. +The XStream dataformat supports 10 options which are listed below. @@ -44,6 +44,7 @@ The XStream dataformat supports 9 options which are listed below. | aliases | | Map | Alias a Class to a shorter name to be used in XML elements. | omitFields | | Map | Prevents a field from being serialized. To omit a field you must always provide the declaring type and not necessarily the type that is converted. | implicitCollections | | Map | Adds a default implicit collection which is used for any unmapped XML tag. +| contentTypeHeader | false | Boolean | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML or application/json for data formats marshalling to JSon etc. |======================================================================= {% endraw %} // dataformat options: END http://git-wip-us.apache.org/repos/asf/camel/blob/28152825/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java ---------------------------------------------------------------------- diff --git a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java index 41d6d7a..c7dd42b 100644 --- a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java +++ b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java @@ -62,6 +62,7 @@ public abstract class AbstractXStreamWrapper extends ServiceSupport implements D private Map<String, String[]> implicitCollections; private String permissions; private String mode; + private boolean contentTypeHeader = true; public AbstractXStreamWrapper() { } @@ -320,6 +321,19 @@ public abstract class AbstractXStreamWrapper extends ServiceSupport implements D this.mode = mode; } + + public boolean isContentTypeHeader() { + return contentTypeHeader; + } + + /** + * If enabled then XStream will set the Content-Type header to <tt>application/json</tt> when marshalling to JSon + * and <tt>application/xml</tt> when marshalling to XML. + */ + public void setContentTypeHeader(boolean contentTypeHeader) { + this.contentTypeHeader = contentTypeHeader; + } + public XStream getXstream() { return xstream; } http://git-wip-us.apache.org/repos/asf/camel/blob/28152825/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java index 4904b15..6252c8b 100644 --- a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java +++ b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java @@ -69,6 +69,19 @@ public class JsonDataFormat extends AbstractXStreamWrapper { } @Override + public void marshal(Exchange exchange, Object body, OutputStream stream) throws Exception { + super.marshal(exchange, body, stream); + + if (isContentTypeHeader()) { + if (exchange.hasOut()) { + exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/json"); + } else { + exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json"); + } + } + } + + @Override protected XStream createXStream(ClassResolver resolver, ClassLoader classLoader) { XStream xs = super.createXStream(resolver, classLoader); if (getMode() != null) { http://git-wip-us.apache.org/repos/asf/camel/blob/28152825/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java index 84169dc..eb2d13b 100644 --- a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java +++ b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java @@ -64,6 +64,19 @@ public class XStreamDataFormat extends AbstractXStreamWrapper { return encoding; } + @Override + public void marshal(Exchange exchange, Object body, OutputStream stream) throws Exception { + super.marshal(exchange, body, stream); + + if (isContentTypeHeader()) { + if (exchange.hasOut()) { + exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/xml"); + } else { + exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/xml"); + } + } + } + /** * A factory method which takes a collection of types to be annotated */ http://git-wip-us.apache.org/repos/asf/camel/blob/28152825/components/camel-zipfile/src/main/docs/zipfile-dataformat.adoc ---------------------------------------------------------------------- diff --git a/components/camel-zipfile/src/main/docs/zipfile-dataformat.adoc b/components/camel-zipfile/src/main/docs/zipfile-dataformat.adoc index 0b1e10d..1f71e8a 100644 --- a/components/camel-zipfile/src/main/docs/zipfile-dataformat.adoc +++ b/components/camel-zipfile/src/main/docs/zipfile-dataformat.adoc @@ -21,7 +21,7 @@ ZipFile Options // dataformat options: START -The Zip File dataformat supports 1 options which are listed below. +The Zip File dataformat supports 2 options which are listed below. @@ -30,6 +30,7 @@ The Zip File dataformat supports 1 options which are listed below. |======================================================================= | Name | Default | Java Type | Description | usingIterator | false | Boolean | If the zip file has more then one entry the setting this option to true allows to work with the splitter EIP to split the data using an iterator in a streaming mode. +| contentTypeHeader | false | Boolean | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML or application/json for data formats marshalling to JSon etc. |======================================================================= {% endraw %} // dataformat options: END