CAMEL-9679: Support for Hessian serialization
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7d1986fc Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7d1986fc Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7d1986fc Branch: refs/heads/master Commit: 7d1986fc5e001943c4970e5e0869f51114818782 Parents: 74934f0 Author: Jaroslaw Strzelecki <jstrzele...@pgs-soft.com> Authored: Tue Mar 8 14:13:22 2016 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Mar 8 17:42:00 2016 +0100 ---------------------------------------------------------------------- .../apache/camel/builder/DataFormatClause.java | 8 + .../model/dataformat/DataFormatsDefinition.java | 1 + .../apache/camel/model/dataformat/jaxb.index | 1 + .../hessian/HessianDataFormatConfigDslTest.java | 57 +++++++ .../hessian/HessianDataFormatConfigXmlTest.java | 47 ++++++ .../HessianDataFormatMarshallingTest.java | 149 +++++++++++++++++++ .../hessian/HessianDataFormatTest.java | 149 ------------------- .../camel/dataformat/hessian/TestObject.java | 2 +- .../dataformat/hessian/HessianTestConfig.xml | 39 +++++ .../features/src/main/resources/features.xml | 5 + 10 files changed, 308 insertions(+), 150 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/7d1986fc/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java b/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java index cb92335..e999b6c 100644 --- a/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java +++ b/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java @@ -34,6 +34,7 @@ import org.apache.camel.model.dataformat.CastorDataFormat; import org.apache.camel.model.dataformat.CsvDataFormat; import org.apache.camel.model.dataformat.CustomDataFormat; import org.apache.camel.model.dataformat.GzipDataFormat; +import org.apache.camel.model.dataformat.HessianDataFormat; import org.apache.camel.model.dataformat.HL7DataFormat; import org.apache.camel.model.dataformat.IcalDataFormat; import org.apache.camel.model.dataformat.JacksonXMLDataFormat; @@ -242,6 +243,13 @@ public class DataFormatClause<T extends ProcessorDefinition<?>> { } /** + * Uses the Hessian data format + */ + public T hessian() { + return dataFormat(new HessianDataFormat()); + } + + /** * Uses the HL7 data format */ public T hl7() { http://git-wip-us.apache.org/repos/asf/camel/blob/7d1986fc/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java b/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java index 81b09f9..880891f 100644 --- a/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java @@ -51,6 +51,7 @@ public class DataFormatsDefinition { @XmlElement(required = false, name = "custom", type = CustomDataFormat.class), @XmlElement(required = false, name = "flatpack", type = FlatpackDataFormat.class), @XmlElement(required = false, name = "gzip", type = GzipDataFormat.class), + @XmlElement(required = false, name = "hessian", type = HessianDataFormat.class), @XmlElement(required = false, name = "hl7", type = HL7DataFormat.class), @XmlElement(required = false, name = "ical", type = IcalDataFormat.class), @XmlElement(required = false, name = "jacksonxml", type = JacksonXMLDataFormat.class), http://git-wip-us.apache.org/repos/asf/camel/blob/7d1986fc/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index ---------------------------------------------------------------------- diff --git a/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index index 9328654..74a63d7 100644 --- a/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index +++ b/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index @@ -26,6 +26,7 @@ CustomDataFormat DataFormatsDefinition FlatpackDataFormat GzipDataFormat +HessianDataFormat HL7DataFormat IcalDataFormat JaxbDataFormat http://git-wip-us.apache.org/repos/asf/camel/blob/7d1986fc/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatConfigDslTest.java ---------------------------------------------------------------------- diff --git a/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatConfigDslTest.java b/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatConfigDslTest.java new file mode 100644 index 0000000..654b11a --- /dev/null +++ b/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatConfigDslTest.java @@ -0,0 +1,57 @@ +/** + * 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.hessian; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +/** + * Test for {@link HessianDataFormat}. + */ +public class HessianDataFormatConfigDslTest extends CamelTestSupport { + + @Test + public void testMarshalAndUnmarshalString() throws Exception { + final String object = "This is a string"; + + final MockEndpoint mock = context().getEndpoint("mock:reverse", MockEndpoint.class); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(object.getClass()); + mock.message(0).body().isEqualTo(object); + + final Object marshalled = template.requestBody("direct:in", object); + template.sendBody("direct:back", marshalled); + + mock.assertIsSatisfied(); + + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:in").marshal().hessian(); + from("direct:back").unmarshal().hessian().to("mock:reverse"); + } + }; + } + + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7d1986fc/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatConfigXmlTest.java ---------------------------------------------------------------------- diff --git a/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatConfigXmlTest.java b/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatConfigXmlTest.java new file mode 100644 index 0000000..76ecd1a --- /dev/null +++ b/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatConfigXmlTest.java @@ -0,0 +1,47 @@ +package org.apache.camel.dataformat.hessian; + +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.spring.CamelSpringTestSupport; +import org.junit.Test; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * 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. + */ +public class HessianDataFormatConfigXmlTest extends CamelSpringTestSupport { + + @Test + public void testMarshalAndUnmarshalString() throws Exception { + final String object = "This is a string"; + + final MockEndpoint mock = context().getEndpoint("mock:reverse", MockEndpoint.class); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(object.getClass()); + mock.message(0).body().isEqualTo(object); + + final Object marshalled = template.requestBody("direct:in", object); + template.sendBody("direct:back", marshalled); + + mock.assertIsSatisfied(); + + } + + @Override + protected AbstractApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/dataformat/hessian/HessianTestConfig.xml"); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/7d1986fc/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatMarshallingTest.java ---------------------------------------------------------------------- diff --git a/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatMarshallingTest.java b/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatMarshallingTest.java new file mode 100644 index 0000000..f426c0c --- /dev/null +++ b/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatMarshallingTest.java @@ -0,0 +1,149 @@ +/** + * 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.hessian; + +import org.apache.camel.Exchange; +import org.apache.camel.Predicate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +import java.util.*; + +/** + * Test for {@link HessianDataFormat}. + */ +public class HessianDataFormatMarshallingTest extends CamelTestSupport { + + @Test + public void testMarshalAndUnmarshalNull() throws Exception { + testMarshalAndUnmarshal(null); + } + + @Test + public void testMarshalAndUnmarshalBoolean() throws Exception { + testMarshalAndUnmarshal(Boolean.TRUE); + } + + @Test + public void testMarshalAndUnmarshalString() throws Exception { + testMarshalAndUnmarshal("This is a string"); + } + + @Test + public void testMarshalAndUnmarshalInteger() throws Exception { + testMarshalAndUnmarshal(42); + } + + @Test + public void testMarshalAndUnmarshalLong() throws Exception { + testMarshalAndUnmarshal(100_000_000_000_000L); + } + + @Test + public void testMarshalAndUnmarshalDouble() throws Exception { + testMarshalAndUnmarshal(6.022e23); + } + + @Test + public void testMarshalAndUnmarshalDate() throws Exception { + testMarshalAndUnmarshal(new Date()) ; + } + + + @Test + public void testMarshalAndUnmarshalArray() throws Exception { + testMarshalAndUnmarshal(new String[]{"one", "two", "three"}); + } + + @Test + public void testMarshalAndUnmarshalList() throws Exception { + testMarshalAndUnmarshal(Arrays.asList("one", "two", "three")); + } + + @Test + public void testMarshalAndUnmarshalMap() throws Exception { + final Map<Integer, String> map = new HashMap<>(); + map.put(1, "one"); + map.put(2, "two"); + map.put(3, "three"); + + testMarshalAndUnmarshal(map); + } + + @Test + public void testMarshalAndUnmarshalObject() throws Exception { + final TestObject object = new TestObject(); + object.setBool(true); + object.setIntNumber(42); + object.setFloatNumber(3.14159f); + object.setCharacter('Z'); + object.setText("random text"); + + testMarshalAndUnmarshal(object); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + final HessianDataFormat format = new HessianDataFormat(); + + from("direct:in").marshal(format); + from("direct:back").unmarshal(format).to("mock:reverse"); + } + }; + } + + private void testMarshalAndUnmarshal(final Object object) throws Exception { + final MockEndpoint mock = getMockEndpoint("mock:reverse"); + mock.expectedMessageCount(1); + + if (object == null) { + mock.message(0).body().isNull(); + } else { + mock.message(0).body().isNotNull(); + + if (object.getClass().isArray()) { + mock.message(0).body().in(arrayEqual((Object[]) object)); + } else { + mock.message(0).body().isEqualTo(object); + } + } + + final Object marshalled = template.requestBody("direct:in", object); + template.sendBody("direct:back", marshalled); + + mock.assertIsSatisfied(); + } + + /** This predicate checks is two arrays have the same content. */ + private static Predicate arrayEqual(final Object[] array) { + return new Predicate() { + @Override + public boolean matches(final Exchange exchange) { + final Object body = exchange.getIn().getBody(); + if (body != null && body.getClass().isArray()) { + return Arrays.equals(array, (Object[]) body); + } + return false; + } + }; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7d1986fc/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatTest.java ---------------------------------------------------------------------- diff --git a/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatTest.java b/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatTest.java deleted file mode 100644 index 3a0e0e9..0000000 --- a/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/HessianDataFormatTest.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * 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.hessian; - -import org.apache.camel.Exchange; -import org.apache.camel.Predicate; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; - -import java.util.*; - -/** - * Test for {@link HessianDataFormat}. - */ -public class HessianDataFormatTest extends CamelTestSupport { - - @Test - public void testMarshalAndUnmarshalNull() throws Exception { - testMarshalAndUnmarshal(null); - } - - @Test - public void testMarshalAndUnmarshalBoolean() throws Exception { - testMarshalAndUnmarshal(Boolean.TRUE); - } - - @Test - public void testMarshalAndUnmarshalString() throws Exception { - testMarshalAndUnmarshal("This is a string"); - } - - @Test - public void testMarshalAndUnmarshalInteger() throws Exception { - testMarshalAndUnmarshal(42); - } - - @Test - public void testMarshalAndUnmarshalLong() throws Exception { - testMarshalAndUnmarshal(100_000_000_000_000L); - } - - @Test - public void testMarshalAndUnmarshalDouble() throws Exception { - testMarshalAndUnmarshal(6.022e23); - } - - @Test - public void testMarshalAndUnmarshalDate() throws Exception { - testMarshalAndUnmarshal(new Date()) ; - } - - - @Test - public void testMarshalAndUnmarshalArray() throws Exception { - testMarshalAndUnmarshal(new String[]{"one", "two", "three"}); - } - - @Test - public void testMarshalAndUnmarshalList() throws Exception { - testMarshalAndUnmarshal(Arrays.asList("one", "two", "three")); - } - - @Test - public void testMarshalAndUnmarshalMap() throws Exception { - final Map<Integer, String> map = new HashMap<>(); - map.put(1, "one"); - map.put(2, "two"); - map.put(3, "three"); - - testMarshalAndUnmarshal(map); - } - - @Test - public void testMarshalAndUnmarshalObject() throws Exception { - final TestObject object = new TestObject(); - object.setBool(true); - object.setIntNumber(42); - object.setFloatNumber(3.14159f); - object.setCharacter('Z'); - object.setText("random text"); - - testMarshalAndUnmarshal(object); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - final HessianDataFormat format = new HessianDataFormat(); - - from("direct:in").marshal(format); - from("direct:back").unmarshal(format).to("mock:reverse"); - } - }; - } - - private void testMarshalAndUnmarshal(final Object object) throws Exception { - final MockEndpoint mock = getMockEndpoint("mock:reverse"); - mock.expectedMessageCount(1); - - if (object == null) { - mock.message(0).body().isNull(); - } else { - mock.message(0).body().isNotNull(); - - if (object.getClass().isArray()) { - mock.message(0).body().in(arrayEqual((Object[]) object)); - } else { - mock.message(0).body().isEqualTo(object); - } - } - - final Object marshalled = template.requestBody("direct:in", object); - template.sendBody("direct:back", marshalled); - - mock.assertIsSatisfied(); - } - - /** This predicate checks is two arrays have the same content. */ - private static Predicate arrayEqual(final Object[] array) { - return new Predicate() { - @Override - public boolean matches(final Exchange exchange) { - final Object body = exchange.getIn().getBody(); - if (body != null && body.getClass().isArray()) { - return Arrays.equals(array, (Object[]) body); - } - return false; - } - }; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7d1986fc/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/TestObject.java ---------------------------------------------------------------------- diff --git a/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/TestObject.java b/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/TestObject.java index bdc14e9..6aa3a08 100644 --- a/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/TestObject.java +++ b/components/camel-hessian/src/test/java/org/apache/camel/dataformat/hessian/TestObject.java @@ -19,7 +19,7 @@ package org.apache.camel.dataformat.hessian; import java.io.Serializable; import java.util.Objects; -/** A simple object used used by {@link HessianDataFormatTest}. */ +/** A simple object used used by {@link HessianDataFormatMarshallingTest}. */ class TestObject implements Serializable { private static final long serialVersionUID = 1L; http://git-wip-us.apache.org/repos/asf/camel/blob/7d1986fc/components/camel-hessian/src/test/resources/org/apache/camel/dataformat/hessian/HessianTestConfig.xml ---------------------------------------------------------------------- diff --git a/components/camel-hessian/src/test/resources/org/apache/camel/dataformat/hessian/HessianTestConfig.xml b/components/camel-hessian/src/test/resources/org/apache/camel/dataformat/hessian/HessianTestConfig.xml new file mode 100644 index 0000000..4a7c524 --- /dev/null +++ b/components/camel-hessian/src/test/resources/org/apache/camel/dataformat/hessian/HessianTestConfig.xml @@ -0,0 +1,39 @@ +<?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. +--> +<bean:beans xmlns="http://camel.apache.org/schema/spring" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:bean="http://www.springframework.org/schema/beans" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <camelContext id="camel"> + + <route> + <from uri="direct:in"/> + <marshal ref="hessian"/> + </route> + + <route> + <from uri="direct:back"/> + <unmarshal ref="hessian"/> + <to uri="mock:reverse"/> + </route> + + </camelContext> +</bean:beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7d1986fc/platforms/karaf/features/src/main/resources/features.xml ---------------------------------------------------------------------- diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml index 3d6f777..33864f4 100644 --- a/platforms/karaf/features/src/main/resources/features.xml +++ b/platforms/karaf/features/src/main/resources/features.xml @@ -697,6 +697,11 @@ <feature version='${project.version}'>camel-core</feature> <bundle>mvn:org.apache.camel/camel-hipchat/${project.version}</bundle> </feature> + <feature name='camel-hessian' version='${project.version}' resolver='(obr)' start-level='50'> + <feature version='${project.version}'>camel-core</feature> + <bundle dependency='true'>mvn:com.caucho/hessian/${hessian-version}}</bundle> + <bundle>mvn:org.apache.camel/camel-hessian/${project.version}</bundle> + </feature> <feature name='camel-hl7' version='${project.version}' resolver='(obr)' start-level='50'> <feature version='${project.version}'>camel-core</feature> <feature version='${project.version}'>camel-netty4</feature>