You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/07/11 23:14:06 UTC
git commit: CAMEL-6539: Added spring resource type converter. Thanks
to David Karlsen for patch.
Updated Branches:
refs/heads/master 7b9e146f6 -> d729fbfd7
CAMEL-6539: Added spring resource type converter. Thanks to David Karlsen for patch.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d729fbfd
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d729fbfd
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d729fbfd
Branch: refs/heads/master
Commit: d729fbfd70019b49fe358fe6aaa1d4318fc18c83
Parents: 7b9e146
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 11 23:13:57 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jul 11 23:13:57 2013 +0200
----------------------------------------------------------------------
.../spring/converter/ResourceConverter.java | 36 ++++++++++++++
.../apache/camel/spring/converter/package.html | 25 ++++++++++
.../services/org/apache/camel/TypeConverter | 18 +++++++
.../spring/converter/ResourceConverterTest.java | 52 ++++++++++++++++++++
.../camel/spring/converter/testresource.txt | 1 +
5 files changed, 132 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/d729fbfd/components/camel-spring/src/main/java/org/apache/camel/spring/converter/ResourceConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/converter/ResourceConverter.java b/components/camel-spring/src/main/java/org/apache/camel/spring/converter/ResourceConverter.java
new file mode 100644
index 0000000..b32e6eb
--- /dev/null
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/converter/ResourceConverter.java
@@ -0,0 +1,36 @@
+/**
+ * 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.spring.converter;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.camel.Converter;
+import org.springframework.core.io.Resource;
+
+@Converter
+public final class ResourceConverter {
+
+ private ResourceConverter() {
+ }
+
+ @Converter
+ public static InputStream convertToInputStream(Resource resource) throws IOException {
+ return resource.getInputStream();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/d729fbfd/components/camel-spring/src/main/java/org/apache/camel/spring/converter/package.html
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/converter/package.html b/components/camel-spring/src/main/java/org/apache/camel/spring/converter/package.html
new file mode 100644
index 0000000..102e1e7
--- /dev/null
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/converter/package.html
@@ -0,0 +1,25 @@
+<!--
+ 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.
+-->
+<html>
+<head>
+</head>
+<body>
+
+Spring Type Converters
+
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/camel/blob/d729fbfd/components/camel-spring/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/resources/META-INF/services/org/apache/camel/TypeConverter b/components/camel-spring/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
new file mode 100644
index 0000000..29ca6ef
--- /dev/null
+++ b/components/camel-spring/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
@@ -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.spring.converter.ResourceConverter
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/d729fbfd/components/camel-spring/src/test/java/org/apache/camel/spring/converter/ResourceConverterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/converter/ResourceConverterTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/converter/ResourceConverterTest.java
new file mode 100644
index 0000000..ee9b62d
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/converter/ResourceConverterTest.java
@@ -0,0 +1,52 @@
+/**
+ * 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.spring.converter;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.TestSupport;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.converter.IOConverter;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.Assert;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+
+public class ResourceConverterTest extends TestSupport {
+
+ public void testResourceConverterRegistry() {
+ Assert.assertNotNull(getResourceTypeConverter());
+ }
+
+ public void testNonNullConversion() throws IOException {
+ Resource resource = new ClassPathResource("testresource.txt", ResourceConverterTest.class);
+ Assert.assertTrue(resource.exists());
+ InputStream inputStream = getResourceTypeConverter().convertTo(InputStream.class, resource);
+ byte[] resourceBytes = IOConverter.toBytes(resource.getInputStream());
+ byte[] inputStreamBytes = IOConverter.toBytes(inputStream);
+ Assert.assertArrayEquals(resourceBytes, inputStreamBytes);
+ }
+
+ private TypeConverter getResourceTypeConverter() {
+ CamelContext camelContext = new DefaultCamelContext();
+ TypeConverter typeConverter = camelContext.getTypeConverterRegistry().lookup(InputStream.class, Resource.class);
+ return typeConverter;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/d729fbfd/components/camel-spring/src/test/resources/org/apache/camel/spring/converter/testresource.txt
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/converter/testresource.txt b/components/camel-spring/src/test/resources/org/apache/camel/spring/converter/testresource.txt
new file mode 100644
index 0000000..d6bbd5a
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/converter/testresource.txt
@@ -0,0 +1 @@
+Some contents
\ No newline at end of file