You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2016/07/05 11:22:26 UTC
[1/4] camel git commit: CAMEL-10100: Add support for copyObject in
camel aws-s3 - Updated docs
Repository: camel
Updated Branches:
refs/heads/master 3ed19b765 -> 535e1fdc6
CAMEL-10100: Add support for copyObject in camel aws-s3 - Updated docs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/535e1fdc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/535e1fdc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/535e1fdc
Branch: refs/heads/master
Commit: 535e1fdc6b06eab8661b0fce386415786172fc76
Parents: 5086efe
Author: Andrea Cosentino <an...@gmail.com>
Authored: Tue Jul 5 12:46:13 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Tue Jul 5 12:46:50 2016 +0200
----------------------------------------------------------------------
components/camel-aws/src/main/docs/aws-s3.adoc | 12 +++++++++++-
.../apache/camel/component/aws/s3/S3Configuration.java | 2 +-
2 files changed, 12 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/535e1fdc/components/camel-aws/src/main/docs/aws-s3.adoc
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/docs/aws-s3.adoc b/components/camel-aws/src/main/docs/aws-s3.adoc
index 8a7e81b..3163af3 100644
--- a/components/camel-aws/src/main/docs/aws-s3.adoc
+++ b/components/camel-aws/src/main/docs/aws-s3.adoc
@@ -132,7 +132,9 @@ Message headers evaluated by the S3 producer
|=======================================================================
|Header |Type |Description
-|`CamelAwsS3Key` |`String` |The key under which this object will be stored.
+|`CamelAwsS3BucketName` |`String` |The bucket Name which this object will be stored or which will be used for the current operation
+
+|`CamelAwsS3BucketDestinationName` |`String` |*Camel 2.18*: The bucket Destination Name which will be used for the current operation
|`CamelAwsS3ContentLength` |`Long` |The content length of this object.
@@ -146,8 +148,14 @@ Message headers evaluated by the S3 producer
|`CamelAwsS3ContentMD5` |`String` |*Camel 2.8.2:* The md5 checksum of this object.
+|`CamelAwsS3DestinationKey` |`String` |*Camel 2.18*:The Destination key which will be used for the current operation
+
+|`CamelAwsS3Key` |`String` |The key under which this object will be stored or which will be used for the current operation
+
|`CamelAwsS3LastModified` |`java.util.Date` |*Camel 2.8.2:* The last modified timestamp of this object.
+|`CamelAwsS3Operation` |`java.util.Date` |*Camel 2.18*: The operation to perform
+
|`CamelAwsS3StorageClass` |`String` |*Camel 2.8.4:* The storage class of this object.
|`CamelAwsS3CannedAcl` |`String` |*Camel 2.11.0:* The canned acl that will be applied to the object. see
@@ -161,6 +169,8 @@ see `com.amazonaws.services.s3.model.AccessControlList` for more details
|`CamelAwsS3ServerSideEncryption` |String |*Camel 2.16:* Sets the server-side encryption algorithm when encrypting
the object using AWS-managed keys. For example use AES256.
+
+|`CamelAwsS3VersionId` |`String` |The version Id of the object to be stored or returned from the current operation
|=======================================================================
[[AWS-S3-MessageheaderssetbytheS3producer]]
http://git-wip-us.apache.org/repos/asf/camel/blob/535e1fdc/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
index 4939832..d363025 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
@@ -62,7 +62,7 @@ public class S3Configuration implements Cloneable {
private boolean includeBody = true;
@UriParam
private boolean pathStyleAccess;
- @UriParam(label = "producer")
+ @UriParam(label = "producer", enums = "copyObject")
private S3Operations operation;
public long getPartSize() {
[2/4] camel git commit: CAMEL-10100: Add support for copyObject in
camel aws-s3
Posted by ac...@apache.org.
CAMEL-10100: Add support for copyObject in camel aws-s3
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b0596054
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b0596054
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b0596054
Branch: refs/heads/master
Commit: b0596054fd3dde945a5ce93a082644b471b86058
Parents: 02d395d
Author: Andrea Cosentino <an...@gmail.com>
Authored: Tue Jul 5 12:29:00 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Tue Jul 5 12:46:50 2016 +0200
----------------------------------------------------------------------
components/camel-aws/src/main/docs/aws-s3.adoc | 4 +++-
.../java/org/apache/camel/component/aws/s3/S3Configuration.java | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b0596054/components/camel-aws/src/main/docs/aws-s3.adoc
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/docs/aws-s3.adoc b/components/camel-aws/src/main/docs/aws-s3.adoc
index 0b3ba5b..8a7e81b 100644
--- a/components/camel-aws/src/main/docs/aws-s3.adoc
+++ b/components/camel-aws/src/main/docs/aws-s3.adoc
@@ -44,6 +44,7 @@ The AWS S3 Storage Service component has no options.
+
// endpoint options: START
The AWS S3 Storage Service component supports 40 endpoint options which are listed below:
@@ -55,7 +56,6 @@ The AWS S3 Storage Service component supports 40 endpoint options which are list
| accessKey | common | | String | Amazon AWS Access Key
| amazonS3Client | common | | AmazonS3 | Reference to a com.amazonaws.services.sqs.AmazonS3 in the link:registry.htmlRegistry.
| amazonS3Endpoint | common | | String | The region with which the AWS-S3 client wants to work with.
-| operation | common | | S3Operations | Camel 2.18: The operation to do in case the user don't want to do only an upload
| pathStyleAccess | common | false | boolean | Whether or not the S3 client should use path style access
| policy | common | | String | Camel 2.8.4: The policy for this queue to set in the com.amazonaws.services.s3.AmazonS3setBucketPolicy() method.
| proxyHost | common | | String | Camel 2.16: To define a proxy host when instantiating the SQS client
@@ -72,6 +72,7 @@ The AWS S3 Storage Service component supports 40 endpoint options which are list
| pollStrategy | consumer (advanced) | | PollingConsumerPollStrategy | A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel.
| deleteAfterWrite | producer | false | boolean | Camel 2.11.0: Delete file object after the S3 file has been uploaded
| multiPartUpload | producer | false | boolean | Camel 2.15.0: If it is true camel will upload the file with multi part format the part size is decided by the option of partSize
+| operation | producer | | S3Operations | Camel 2.18: The operation to do in case the user don't want to do only an upload
| partSize | producer | 26214400 | long | Camel 2.15.0: Setup the partSize which is used in multi part upload the default size is 25M.
| region | producer | | String | The region where the bucket is located. This option is used in the com.amazonaws.services.s3.model.CreateBucketRequest.
| serverSideEncryption | producer | | String | Camel 2.16: Sets the server-side encryption algorithm when encrypting the object using AWS-managed keys. For example use AES256.
@@ -102,6 +103,7 @@ The AWS S3 Storage Service component supports 40 endpoint options which are list
+
Required S3 component options
You have to provide the amazonS3Client in the
http://git-wip-us.apache.org/repos/asf/camel/blob/b0596054/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
index 9e36157..533bcc8 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
@@ -62,7 +62,7 @@ public class S3Configuration implements Cloneable {
private boolean includeBody = true;
@UriParam
private boolean pathStyleAccess;
- @UriParam
+ @UriParam(label = "producer")
private S3Operations operation;
public long getPartSize() {
[4/4] camel git commit: CAMEL-10100: Add support for copyObject in
camel aws-s3
Posted by ac...@apache.org.
CAMEL-10100: Add support for copyObject in camel aws-s3
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/02d395d4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/02d395d4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/02d395d4
Branch: refs/heads/master
Commit: 02d395d47f5dee17a0dd218d4e17fa950de606a4
Parents: 3ed19b7
Author: Andrea Cosentino <an...@gmail.com>
Authored: Tue Jul 5 12:26:10 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Tue Jul 5 12:46:50 2016 +0200
----------------------------------------------------------------------
components/camel-aws/src/main/docs/aws-s3.adoc | 5 +-
.../camel/component/aws/s3/S3Configuration.java | 16 +++-
.../camel/component/aws/s3/S3Constants.java | 37 ++++----
.../camel/component/aws/s3/S3Operations.java | 22 +++++
.../camel/component/aws/s3/S3Producer.java | 77 +++++++++++++++-
.../component/aws/s3/AmazonS3ClientMock.java | 5 +-
.../aws/s3/S3ComponentCopyObjectSpringTest.java | 84 +++++++++++++++++
.../aws/s3/S3ComponentCopyObjectTest.java | 96 ++++++++++++++++++++
.../aws/s3/S3ComponentSpringTest-context.xml | 6 +-
9 files changed, 322 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/02d395d4/components/camel-aws/src/main/docs/aws-s3.adoc
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/docs/aws-s3.adoc b/components/camel-aws/src/main/docs/aws-s3.adoc
index 04597b7..0b3ba5b 100644
--- a/components/camel-aws/src/main/docs/aws-s3.adoc
+++ b/components/camel-aws/src/main/docs/aws-s3.adoc
@@ -43,8 +43,9 @@ The AWS S3 Storage Service component has no options.
+
// endpoint options: START
-The AWS S3 Storage Service component supports 39 endpoint options which are listed below:
+The AWS S3 Storage Service component supports 40 endpoint options which are listed below:
{% raw %}
[width="100%",cols="2s,1,1m,1m,5",options="header"]
@@ -54,6 +55,7 @@ The AWS S3 Storage Service component supports 39 endpoint options which are list
| accessKey | common | | String | Amazon AWS Access Key
| amazonS3Client | common | | AmazonS3 | Reference to a com.amazonaws.services.sqs.AmazonS3 in the link:registry.htmlRegistry.
| amazonS3Endpoint | common | | String | The region with which the AWS-S3 client wants to work with.
+| operation | common | | S3Operations | Camel 2.18: The operation to do in case the user don't want to do only an upload
| pathStyleAccess | common | false | boolean | Whether or not the S3 client should use path style access
| policy | common | | String | Camel 2.8.4: The policy for this queue to set in the com.amazonaws.services.s3.AmazonS3setBucketPolicy() method.
| proxyHost | common | | String | Camel 2.16: To define a proxy host when instantiating the SQS client
@@ -99,6 +101,7 @@ The AWS S3 Storage Service component supports 39 endpoint options which are list
+
Required S3 component options
You have to provide the amazonS3Client in the
http://git-wip-us.apache.org/repos/asf/camel/blob/02d395d4/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
index abaad4d..9e36157 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws.s3;
import com.amazonaws.services.s3.AmazonS3;
+
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
import org.apache.camel.util.ObjectHelper;
@@ -61,6 +62,8 @@ public class S3Configuration implements Cloneable {
private boolean includeBody = true;
@UriParam
private boolean pathStyleAccess;
+ @UriParam
+ private S3Operations operation;
public long getPartSize() {
return partSize;
@@ -280,7 +283,18 @@ public class S3Configuration implements Cloneable {
return pathStyleAccess;
}
- boolean hasProxyConfiguration() {
+ public S3Operations getOperation() {
+ return operation;
+ }
+
+ /**
+ * *Camel 2.18*: The operation to do in case the user don't want to do only an upload
+ */
+ public void setOperation(S3Operations operation) {
+ this.operation = operation;
+ }
+
+ boolean hasProxyConfiguration() {
return ObjectHelper.isNotEmpty(getProxyHost()) && ObjectHelper.isNotEmpty(getProxyPort());
}
http://git-wip-us.apache.org/repos/asf/camel/blob/02d395d4/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Constants.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Constants.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Constants.java
index 8bd783f..c337f19 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Constants.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Constants.java
@@ -22,21 +22,24 @@ package org.apache.camel.component.aws.s3;
*/
public interface S3Constants {
- String BUCKET_NAME = "CamelAwsS3BucketName";
- String CACHE_CONTROL = "CamelAwsS3ContentControl";
- String CONTENT_DISPOSITION = "CamelAwsS3ContentDisposition";
- String CONTENT_ENCODING = "CamelAwsS3ContentEncoding";
- String CONTENT_LENGTH = "CamelAwsS3ContentLength";
- String CONTENT_MD5 = "CamelAwsS3ContentMD5";
- String CONTENT_TYPE = "CamelAwsS3ContentType";
- String E_TAG = "CamelAwsS3ETag";
- String KEY = "CamelAwsS3Key";
- String LAST_MODIFIED = "CamelAwsS3LastModified";
- String STORAGE_CLASS = "CamelAwsS3StorageClass";
- String VERSION_ID = "CamelAwsS3VersionId";
- String CANNED_ACL = "CamelAwsS3CannedAcl";
- String ACL = "CamelAwsS3Acl";
- String USER_METADATA = "CamelAwsS3UserMetadata";
- String S3_HEADERS = "CamelAwsS3Headers";
- String SERVER_SIDE_ENCRYPTION = "CamelAwsS3ServerSideEncryption";
+ String BUCKET_NAME = "CamelAwsS3BucketName";
+ String BUCKET_DESTINATION_NAME = "CamelAwsS3BucketDestinationName";
+ String CACHE_CONTROL = "CamelAwsS3ContentControl";
+ String CONTENT_DISPOSITION = "CamelAwsS3ContentDisposition";
+ String CONTENT_ENCODING = "CamelAwsS3ContentEncoding";
+ String CONTENT_LENGTH = "CamelAwsS3ContentLength";
+ String CONTENT_MD5 = "CamelAwsS3ContentMD5";
+ String CONTENT_TYPE = "CamelAwsS3ContentType";
+ String E_TAG = "CamelAwsS3ETag";
+ String KEY = "CamelAwsS3Key";
+ String DESTINATION_KEY = "CamelAwsS3DestinationKey";
+ String LAST_MODIFIED = "CamelAwsS3LastModified";
+ String STORAGE_CLASS = "CamelAwsS3StorageClass";
+ String VERSION_ID = "CamelAwsS3VersionId";
+ String CANNED_ACL = "CamelAwsS3CannedAcl";
+ String ACL = "CamelAwsS3Acl";
+ String USER_METADATA = "CamelAwsS3UserMetadata";
+ String S3_HEADERS = "CamelAwsS3Headers";
+ String S3_OPERATION = "CamelAwsS3Operation";
+ String SERVER_SIDE_ENCRYPTION = "CamelAwsS3ServerSideEncryption";
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/02d395d4/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Operations.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Operations.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Operations.java
new file mode 100644
index 0000000..33be0a2
--- /dev/null
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Operations.java
@@ -0,0 +1,22 @@
+/**
+ * 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.component.aws.s3;
+
+public enum S3Operations {
+
+ copyObject
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/02d395d4/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
index 0b97f99..538d413 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
@@ -25,11 +25,14 @@ import java.util.List;
import java.util.Map;
import com.amazonaws.services.cloudfront.model.InvalidArgumentException;
+import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.AbortMultipartUploadRequest;
import com.amazonaws.services.s3.model.AccessControlList;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.CompleteMultipartUploadRequest;
import com.amazonaws.services.s3.model.CompleteMultipartUploadResult;
+import com.amazonaws.services.s3.model.CopyObjectRequest;
+import com.amazonaws.services.s3.model.CopyObjectResult;
import com.amazonaws.services.s3.model.InitiateMultipartUploadRequest;
import com.amazonaws.services.s3.model.InitiateMultipartUploadResult;
import com.amazonaws.services.s3.model.ObjectMetadata;
@@ -42,10 +45,12 @@ import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.WrappedFile;
+import org.apache.camel.component.aws.ec2.EC2Constants;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.util.CastUtils;
import org.apache.camel.util.FileUtil;
import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.URISupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -69,11 +74,22 @@ public class S3Producer extends DefaultProducer {
@Override
public void process(final Exchange exchange) throws Exception {
- if (getConfiguration().isMultiPartUpload()) {
- processMultiPart(exchange);
- } else {
- processSingleOp(exchange);
- }
+ S3Operations operation = determineOperation(exchange);
+ if (ObjectHelper.isEmpty(operation)) {
+ if (getConfiguration().isMultiPartUpload()) {
+ processMultiPart(exchange);
+ } else {
+ processSingleOp(exchange);
+ }
+ } else {
+ switch (operation) {
+ case copyObject:
+ copyObject(getEndpoint().getS3Client(), exchange);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported operation");
+ }
+ }
}
public void processMultiPart(final Exchange exchange) throws Exception {
@@ -225,6 +241,57 @@ public class S3Producer extends DefaultProducer {
FileUtil.deleteFile(filePayload);
}
}
+
+ private void copyObject(AmazonS3 s3Client, Exchange exchange) {
+ String bucketNameDestination;
+ String destinationKey;
+ String sourceKey;
+ String bucketName;
+ String versionId;
+
+ bucketName = exchange.getIn().getHeader(S3Constants.BUCKET_NAME, String.class);
+ if (ObjectHelper.isEmpty(bucketName)) {
+ bucketName = getConfiguration().getBucketName();
+ }
+ sourceKey = exchange.getIn().getHeader(S3Constants.KEY, String.class);
+ destinationKey = exchange.getIn().getHeader(S3Constants.DESTINATION_KEY, String.class);
+ bucketNameDestination = exchange.getIn().getHeader(S3Constants.BUCKET_DESTINATION_NAME, String.class);
+ versionId = exchange.getIn().getHeader(S3Constants.VERSION_ID, String.class);
+
+ if (ObjectHelper.isEmpty(bucketName)) {
+ throw new IllegalArgumentException("Bucket Name must be specified for copyObject Operation");
+ }
+ if (ObjectHelper.isEmpty(bucketNameDestination)) {
+ throw new IllegalArgumentException("Bucket Name Destination must be specified for copyObject Operation");
+ }
+ if (ObjectHelper.isEmpty(sourceKey)) {
+ throw new IllegalArgumentException("Source Key must be specified for copyObject Operation");
+ }
+ if (ObjectHelper.isEmpty(destinationKey)) {
+ throw new IllegalArgumentException("Destination Key must be specified for copyObject Operation");
+ }
+ CopyObjectRequest copyObjectRequest;
+ if (ObjectHelper.isEmpty(versionId)) {
+ copyObjectRequest = new CopyObjectRequest(bucketName, sourceKey, bucketNameDestination, destinationKey);
+ } else {
+ copyObjectRequest = new CopyObjectRequest(bucketName, sourceKey, versionId, bucketNameDestination, destinationKey);
+ }
+ CopyObjectResult copyObjectResult = s3Client.copyObject(copyObjectRequest);
+
+ Message message = getMessageForResponse(exchange);
+ message.setHeader(S3Constants.E_TAG, copyObjectResult.getETag());
+ if (copyObjectResult.getVersionId() != null) {
+ message.setHeader(S3Constants.VERSION_ID, copyObjectResult.getVersionId());
+ }
+ }
+
+ private S3Operations determineOperation(Exchange exchange) {
+ S3Operations operation = exchange.getIn().getHeader(EC2Constants.OPERATION, S3Operations.class);
+ if (operation == null) {
+ operation = getConfiguration().getOperation();
+ }
+ return operation;
+ }
private ObjectMetadata determineMetadata(final Exchange exchange) {
ObjectMetadata objectMetadata = new ObjectMetadata();
http://git-wip-us.apache.org/repos/asf/camel/blob/02d395d4/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/AmazonS3ClientMock.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/AmazonS3ClientMock.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/AmazonS3ClientMock.java
index 60ad8e0..dfbb6a2 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/AmazonS3ClientMock.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/AmazonS3ClientMock.java
@@ -340,7 +340,10 @@ public class AmazonS3ClientMock extends AmazonS3Client {
@Override
public CopyObjectResult copyObject(CopyObjectRequest copyObjectRequest) throws AmazonClientException, AmazonServiceException {
- throw new UnsupportedOperationException();
+ CopyObjectResult copyObjectResult = new CopyObjectResult();
+ copyObjectResult.setETag("3a5c8b1ad448bca04584ecb55b836264");
+ copyObjectResult.setVersionId("11192828ahsh2723");
+ return copyObjectResult;
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/02d395d4/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectSpringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectSpringTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectSpringTest.java
new file mode 100644
index 0000000..5053932
--- /dev/null
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectSpringTest.java
@@ -0,0 +1,84 @@
+/**
+ * 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.component.aws.s3;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class S3ComponentCopyObjectSpringTest extends CamelSpringTestSupport {
+
+ @EndpointInject(uri = "direct:start")
+ private ProducerTemplate template;
+
+ @EndpointInject(uri = "mock:result")
+ private MockEndpoint result;
+
+ private AmazonS3ClientMock client;
+
+ @Test
+ public void sendIn() throws Exception {
+ result.expectedMessageCount(1);
+
+ template.send("direct:copyObject", ExchangePattern.InOnly, new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(S3Constants.BUCKET_DESTINATION_NAME, "camelDestinationBucket");
+ exchange.getIn().setHeader(S3Constants.KEY, "camelKey");
+ exchange.getIn().setHeader(S3Constants.DESTINATION_KEY, "camelDestinationKey");
+ }
+ });
+
+ assertMockEndpointsSatisfied();
+
+ assertResultExchange(result.getExchanges().get(0));
+
+ }
+
+ private void assertResultExchange(Exchange resultExchange) {
+ assertEquals(resultExchange.getIn().getHeader(S3Constants.VERSION_ID), "11192828ahsh2723");
+ assertNull(resultExchange.getIn().getHeader(S3Constants.LAST_MODIFIED));
+ assertEquals(resultExchange.getIn().getHeader(S3Constants.E_TAG), "3a5c8b1ad448bca04584ecb55b836264");
+ assertNull(resultExchange.getIn().getHeader(S3Constants.CONTENT_TYPE));
+ assertNull(resultExchange.getIn().getHeader(S3Constants.CONTENT_ENCODING));
+ assertNull(resultExchange.getIn().getHeader(S3Constants.CONTENT_DISPOSITION));
+ assertNull(resultExchange.getIn().getHeader(S3Constants.CONTENT_MD5));
+ assertNull(resultExchange.getIn().getHeader(S3Constants.CACHE_CONTROL));
+ assertNull(resultExchange.getIn().getHeader(S3Constants.USER_METADATA));
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+
+ client = new AmazonS3ClientMock();
+ registry.bind("amazonS3Client", client);
+
+ return registry;
+ }
+
+ @Override
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/aws/s3/S3ComponentSpringTest-context.xml");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/02d395d4/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectTest.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectTest.java
new file mode 100644
index 0000000..77cacd3
--- /dev/null
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectTest.java
@@ -0,0 +1,96 @@
+/**
+ * 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.component.aws.s3;
+
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class S3ComponentCopyObjectTest extends CamelTestSupport {
+
+ @EndpointInject(uri = "direct:start")
+ private ProducerTemplate template;
+
+ @EndpointInject(uri = "mock:result")
+ private MockEndpoint result;
+
+ private AmazonS3ClientMock client;
+
+ @Test
+ public void sendIn() throws Exception {
+ result.expectedMessageCount(1);
+
+ template.send("direct:start", ExchangePattern.InOnly, new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(S3Constants.BUCKET_DESTINATION_NAME, "camelDestinationBucket");
+ exchange.getIn().setHeader(S3Constants.KEY, "camelKey");
+ exchange.getIn().setHeader(S3Constants.DESTINATION_KEY, "camelDestinationKey");
+ }
+ });
+
+ assertMockEndpointsSatisfied();
+
+ assertResultExchange(result.getExchanges().get(0));
+
+ }
+
+ private void assertResultExchange(Exchange resultExchange) {
+ assertEquals(resultExchange.getIn().getHeader(S3Constants.VERSION_ID), "11192828ahsh2723");
+ assertNull(resultExchange.getIn().getHeader(S3Constants.LAST_MODIFIED));
+ assertEquals(resultExchange.getIn().getHeader(S3Constants.E_TAG), "3a5c8b1ad448bca04584ecb55b836264");
+ assertNull(resultExchange.getIn().getHeader(S3Constants.CONTENT_TYPE));
+ assertNull(resultExchange.getIn().getHeader(S3Constants.CONTENT_ENCODING));
+ assertNull(resultExchange.getIn().getHeader(S3Constants.CONTENT_DISPOSITION));
+ assertNull(resultExchange.getIn().getHeader(S3Constants.CONTENT_MD5));
+ assertNull(resultExchange.getIn().getHeader(S3Constants.CACHE_CONTROL));
+ assertNull(resultExchange.getIn().getHeader(S3Constants.USER_METADATA));
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+
+ client = new AmazonS3ClientMock();
+ registry.bind("amazonS3Client", client);
+
+ return registry;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ String awsEndpoint = "aws-s3://mycamelbucket?amazonS3Client=#amazonS3Client®ion=us-west-1&operation=copyObject";
+
+ from("direct:start")
+ .to(awsEndpoint)
+ .to("mock:result");
+
+ }
+ };
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/02d395d4/components/camel-aws/src/test/resources/org/apache/camel/component/aws/s3/S3ComponentSpringTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/resources/org/apache/camel/component/aws/s3/S3ComponentSpringTest-context.xml b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/s3/S3ComponentSpringTest-context.xml
index df5ef66..bf6212c 100644
--- a/components/camel-aws/src/test/resources/org/apache/camel/component/aws/s3/S3ComponentSpringTest-context.xml
+++ b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/s3/S3ComponentSpringTest-context.xml
@@ -25,7 +25,11 @@
<from uri="direct:start"/>
<to uri="aws-s3://mycamelbucket?amazonS3Client=#amazonS3Client"/>
</route>
-
+ <route>
+ <from uri="direct:copyObject"/>
+ <to uri="aws-s3://mycamelbucket?amazonS3Client=#amazonS3Client&operation=copyObject"/>
+ <to uri="mock:result"/>
+ </route>
<route>
<from uri="aws-s3://mycamelbucket?amazonS3Client=#amazonS3Client&maxMessagesPerPoll=5"/>
<to uri="mock:result"/>
[3/4] camel git commit: Fixed CS
Posted by ac...@apache.org.
Fixed CS
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5086efed
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5086efed
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5086efed
Branch: refs/heads/master
Commit: 5086efed065a922954c1283bab9a68ac69a4a51f
Parents: b059605
Author: Andrea Cosentino <an...@gmail.com>
Authored: Tue Jul 5 12:35:29 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Tue Jul 5 12:46:50 2016 +0200
----------------------------------------------------------------------
.../camel/component/aws/s3/S3Configuration.java | 13 ++++++-------
.../camel/component/aws/s3/S3Producer.java | 20 ++++++++++----------
.../aws/s3/S3ComponentCopyObjectSpringTest.java | 6 +++---
.../aws/s3/S3ComponentCopyObjectTest.java | 6 +++---
4 files changed, 22 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/5086efed/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
index 533bcc8..4939832 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
@@ -284,18 +284,17 @@ public class S3Configuration implements Cloneable {
}
public S3Operations getOperation() {
- return operation;
- }
+ return operation;
+ }
/**
* *Camel 2.18*: The operation to do in case the user don't want to do only an upload
*/
- public void setOperation(S3Operations operation) {
- this.operation = operation;
- }
+ public void setOperation(S3Operations operation) {
+ this.operation = operation;
+ }
- boolean hasProxyConfiguration() {
+ boolean hasProxyConfiguration() {
return ObjectHelper.isNotEmpty(getProxyHost()) && ObjectHelper.isNotEmpty(getProxyPort());
-
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/5086efed/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
index 538d413..e7bab7e 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
@@ -74,14 +74,14 @@ public class S3Producer extends DefaultProducer {
@Override
public void process(final Exchange exchange) throws Exception {
- S3Operations operation = determineOperation(exchange);
- if (ObjectHelper.isEmpty(operation)) {
+ S3Operations operation = determineOperation(exchange);
+ if (ObjectHelper.isEmpty(operation)) {
if (getConfiguration().isMultiPartUpload()) {
processMultiPart(exchange);
} else {
processSingleOp(exchange);
}
- } else {
+ } else {
switch (operation) {
case copyObject:
copyObject(getEndpoint().getS3Client(), exchange);
@@ -89,7 +89,7 @@ public class S3Producer extends DefaultProducer {
default:
throw new IllegalArgumentException("Unsupported operation");
}
- }
+ }
}
public void processMultiPart(final Exchange exchange) throws Exception {
@@ -251,7 +251,7 @@ public class S3Producer extends DefaultProducer {
bucketName = exchange.getIn().getHeader(S3Constants.BUCKET_NAME, String.class);
if (ObjectHelper.isEmpty(bucketName)) {
- bucketName = getConfiguration().getBucketName();
+ bucketName = getConfiguration().getBucketName();
}
sourceKey = exchange.getIn().getHeader(S3Constants.KEY, String.class);
destinationKey = exchange.getIn().getHeader(S3Constants.DESTINATION_KEY, String.class);
@@ -259,22 +259,22 @@ public class S3Producer extends DefaultProducer {
versionId = exchange.getIn().getHeader(S3Constants.VERSION_ID, String.class);
if (ObjectHelper.isEmpty(bucketName)) {
- throw new IllegalArgumentException("Bucket Name must be specified for copyObject Operation");
+ throw new IllegalArgumentException("Bucket Name must be specified for copyObject Operation");
}
if (ObjectHelper.isEmpty(bucketNameDestination)) {
- throw new IllegalArgumentException("Bucket Name Destination must be specified for copyObject Operation");
+ throw new IllegalArgumentException("Bucket Name Destination must be specified for copyObject Operation");
}
if (ObjectHelper.isEmpty(sourceKey)) {
- throw new IllegalArgumentException("Source Key must be specified for copyObject Operation");
+ throw new IllegalArgumentException("Source Key must be specified for copyObject Operation");
}
if (ObjectHelper.isEmpty(destinationKey)) {
- throw new IllegalArgumentException("Destination Key must be specified for copyObject Operation");
+ throw new IllegalArgumentException("Destination Key must be specified for copyObject Operation");
}
CopyObjectRequest copyObjectRequest;
if (ObjectHelper.isEmpty(versionId)) {
copyObjectRequest = new CopyObjectRequest(bucketName, sourceKey, bucketNameDestination, destinationKey);
} else {
- copyObjectRequest = new CopyObjectRequest(bucketName, sourceKey, versionId, bucketNameDestination, destinationKey);
+ copyObjectRequest = new CopyObjectRequest(bucketName, sourceKey, versionId, bucketNameDestination, destinationKey);
}
CopyObjectResult copyObjectResult = s3Client.copyObject(copyObjectRequest);
http://git-wip-us.apache.org/repos/asf/camel/blob/5086efed/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectSpringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectSpringTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectSpringTest.java
index 5053932..35356a1 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectSpringTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectSpringTest.java
@@ -43,9 +43,9 @@ public class S3ComponentCopyObjectSpringTest extends CamelSpringTestSupport {
template.send("direct:copyObject", ExchangePattern.InOnly, new Processor() {
public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(S3Constants.BUCKET_DESTINATION_NAME, "camelDestinationBucket");
- exchange.getIn().setHeader(S3Constants.KEY, "camelKey");
- exchange.getIn().setHeader(S3Constants.DESTINATION_KEY, "camelDestinationKey");
+ exchange.getIn().setHeader(S3Constants.BUCKET_DESTINATION_NAME, "camelDestinationBucket");
+ exchange.getIn().setHeader(S3Constants.KEY, "camelKey");
+ exchange.getIn().setHeader(S3Constants.DESTINATION_KEY, "camelDestinationKey");
}
});
http://git-wip-us.apache.org/repos/asf/camel/blob/5086efed/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectTest.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectTest.java
index 77cacd3..d10d918 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentCopyObjectTest.java
@@ -45,9 +45,9 @@ public class S3ComponentCopyObjectTest extends CamelTestSupport {
template.send("direct:start", ExchangePattern.InOnly, new Processor() {
public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(S3Constants.BUCKET_DESTINATION_NAME, "camelDestinationBucket");
- exchange.getIn().setHeader(S3Constants.KEY, "camelKey");
- exchange.getIn().setHeader(S3Constants.DESTINATION_KEY, "camelDestinationKey");
+ exchange.getIn().setHeader(S3Constants.BUCKET_DESTINATION_NAME, "camelDestinationBucket");
+ exchange.getIn().setHeader(S3Constants.KEY, "camelKey");
+ exchange.getIn().setHeader(S3Constants.DESTINATION_KEY, "camelDestinationKey");
}
});