You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2013/10/23 15:42:29 UTC
[1/2] git commit: CAMEL-6887 Supporting to set the ContentMetadata of
the Payload object through message header
Updated Branches:
refs/heads/master edf0e1d35 -> 494af0005
CAMEL-6887 Supporting to set the ContentMetadata of the Payload object through message header
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/494af000
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/494af000
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/494af000
Branch: refs/heads/master
Commit: 494af000565e256281091850688a632f7c15ec3c
Parents: 626a5ab
Author: Willem Jiang <ni...@apache.org>
Authored: Wed Oct 23 21:39:53 2013 +0800
Committer: Willem Jiang <ni...@apache.org>
Committed: Wed Oct 23 21:41:47 2013 +0800
----------------------------------------------------------------------
.../component/jclouds/JcloudsConstants.java | 5 +++
.../jclouds/JcloudsPayloadConverter.java | 42 +++++++++++++++++++-
2 files changed, 45 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/494af000/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConstants.java b/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConstants.java
index fd15f86..e5481ef 100644
--- a/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConstants.java
+++ b/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConstants.java
@@ -34,6 +34,11 @@ public final class JcloudsConstants {
public static final String CREATE_NODE = "CamelJcloudsCreateNode";
public static final String DESTROY_NODE = "CamelJcloudsDestroyNode";
public static final String RUN_SCRIPT = "CamelJcloudsRunScript";
+
+ public static final String CONTENT_LANGUAGE = "CamelJcloudsContentLanguage";
+ public static final String CONTENT_ENCODING = "CamelJcloudsContentEncoding";
+ public static final String CONTENT_DISPOSITION = "CamelJcloudsContentDisposition";
+ public static final String PAYLOAD_EXPIRES = "CamelJcloudsPayloadExpires";
public static final String IMAGE_ID = "CamelJcloudsImageId";
public static final String LOCATION_ID = "CamelJcloudsLocationId";
http://git-wip-us.apache.org/repos/asf/camel/blob/494af000/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsPayloadConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsPayloadConverter.java b/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsPayloadConverter.java
index 11e904b..57a9269 100644
--- a/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsPayloadConverter.java
+++ b/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsPayloadConverter.java
@@ -19,6 +19,8 @@ package org.apache.camel.component.jclouds;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Date;
+
import javax.xml.transform.stream.StreamSource;
import com.google.common.io.ByteStreams;
import com.google.common.io.InputSupplier;
@@ -31,6 +33,7 @@ import org.apache.camel.converter.stream.CachedOutputStream;
import org.apache.camel.converter.stream.StreamSourceCache;
import org.apache.camel.spi.TypeConverterRegistry;
import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.ObjectHelper;
import org.jclouds.io.Payload;
import org.jclouds.io.payloads.ByteArrayPayload;
import org.jclouds.io.payloads.FilePayload;
@@ -58,6 +61,40 @@ public final class JcloudsPayloadConverter {
public static Payload toPayload(File file) {
return new FilePayload(file);
}
+
+ protected static Payload setContentMetadata(Payload payload, Exchange exchange) {
+ // Just add an NPE check on the payload
+ if (exchange == null) {
+ return payload;
+ }
+
+ String contentType = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class);
+ String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
+ String contentDisposition = exchange.getIn().getHeader(JcloudsConstants.CONTENT_DISPOSITION, String.class);
+ String contentLanguage = exchange.getIn().getHeader(JcloudsConstants.CONTENT_LANGUAGE, String.class);
+ Date payloadExpires = exchange.getIn().getHeader(JcloudsConstants.PAYLOAD_EXPIRES, Date.class);
+
+ if (ObjectHelper.isNotEmpty(contentType)) {
+ payload.getContentMetadata().setContentType(contentType);
+ }
+
+ if (ObjectHelper.isNotEmpty(contentEncoding)) {
+ payload.getContentMetadata().setContentEncoding(contentEncoding);
+ }
+
+ if (ObjectHelper.isNotEmpty(contentDisposition)) {
+ payload.getContentMetadata().setContentDisposition(contentDisposition);
+ }
+
+ if (ObjectHelper.isNotEmpty(contentLanguage)) {
+ payload.getContentMetadata().setContentLanguage(contentLanguage);
+ }
+
+ if (ObjectHelper.isNotEmpty(payloadExpires)) {
+ payload.getContentMetadata().setExpires(payloadExpires);
+ }
+ return payload;
+ }
@Converter
public static Payload toPayload(InputStream is, Exchange exchange) throws IOException {
@@ -76,11 +113,11 @@ public final class JcloudsPayloadConverter {
@Converter
public static Payload toPayload(StreamSource source, Exchange exchange) throws IOException {
- return toPayload(new StreamSourceCache(source, exchange));
+ return toPayload(new StreamSourceCache(source, exchange), exchange);
}
@Converter
- public static Payload toPayload(final StreamSourceCache cache) throws IOException {
+ public static Payload toPayload(final StreamSourceCache cache, Exchange exchange) throws IOException {
long contentLength = ByteStreams.length(new InputSupplier<InputStream>() {
@Override
public InputStream getInput() throws IOException {
@@ -90,6 +127,7 @@ public final class JcloudsPayloadConverter {
cache.reset();
InputStreamPayload payload = new InputStreamPayload(cache.getInputStream());
payload.getContentMetadata().setContentLength(contentLength);
+ setContentMetadata(payload, exchange);
return payload;
}
[2/2] git commit: CAMEL-6888 fixed the stream copy issue of
JcloudsPayloadConverter
Posted by ni...@apache.org.
CAMEL-6888 fixed the stream copy issue of JcloudsPayloadConverter
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/626a5abb
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/626a5abb
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/626a5abb
Branch: refs/heads/master
Commit: 626a5abb326ccd334ffafa006f9be41b515e1bbe
Parents: edf0e1d
Author: Willem Jiang <ni...@apache.org>
Authored: Wed Oct 23 21:20:00 2013 +0800
Committer: Willem Jiang <ni...@apache.org>
Committed: Wed Oct 23 21:41:47 2013 +0800
----------------------------------------------------------------------
.../apache/camel/component/jclouds/JcloudsPayloadConverter.java | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/626a5abb/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsPayloadConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsPayloadConverter.java b/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsPayloadConverter.java
index 4f41197..11e904b 100644
--- a/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsPayloadConverter.java
+++ b/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsPayloadConverter.java
@@ -30,6 +30,7 @@ import org.apache.camel.component.file.GenericFile;
import org.apache.camel.converter.stream.CachedOutputStream;
import org.apache.camel.converter.stream.StreamSourceCache;
import org.apache.camel.spi.TypeConverterRegistry;
+import org.apache.camel.util.IOHelper;
import org.jclouds.io.Payload;
import org.jclouds.io.payloads.ByteArrayPayload;
import org.jclouds.io.payloads.FilePayload;
@@ -68,6 +69,7 @@ public final class JcloudsPayloadConverter {
return payload;
} else {
CachedOutputStream cos = new CachedOutputStream(exchange);
+ IOHelper.copy(is, cos);
return toPayload(cos.getWrappedInputStream(), exchange);
}
}