This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 0fad6a84fdd CAMEL-19069 (#9369)
0fad6a84fdd is described below

commit 0fad6a84fdd8a63d9ac522ed32131ef4b8300c5b
Author: Hitesh C <jainhitesh9...@gmail.com>
AuthorDate: Fri Feb 17 22:43:52 2023 +0530

    CAMEL-19069 (#9369)
    
    * CAMEL-19069
    Added createDownloadUrl and createUploadUrl feature to camel-minio component
    
    * CAMEL-19069
    Fixed the documentation as suggested
---
 .../org/apache/camel/component/minio/minio.json    |   9 +-
 .../camel-minio/src/main/docs/minio-component.adoc |  38 +++++++-
 .../camel/component/minio/MinioConfiguration.java  |   2 +-
 .../camel/component/minio/MinioConstants.java      |   2 +
 .../camel/component/minio/MinioOperations.java     |   4 +-
 .../camel/component/minio/MinioProducer.java       |  37 ++++++++
 .../minio/integration/MinioPresignedUrlIT.java     | 105 +++++++++++++++++++++
 7 files changed, 190 insertions(+), 7 deletions(-)

diff --git 
a/components/camel-minio/src/generated/resources/org/apache/camel/component/minio/minio.json
 
b/components/camel-minio/src/generated/resources/org/apache/camel/component/minio/minio.json
index 45f0cc6d857..166d70375a5 100644
--- 
a/components/camel-minio/src/generated/resources/org/apache/camel/component/minio/minio.json
+++ 
b/components/camel-minio/src/generated/resources/org/apache/camel/component/minio/minio.json
@@ -63,7 +63,7 @@
     "deleteAfterWrite": { "kind": "property", "displayName": "Delete After 
Write", "group": "producer", "label": "producer", "required": false, "type": 
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": false, "configurationClass": 
"org.apache.camel.component.minio.MinioConfiguration", "configurationField": 
"configuration", "description": "Delete file object after the Minio file has 
been uploaded." },
     "keyName": { "kind": "property", "displayName": "Key Name", "group": 
"producer", "label": "producer", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "configurationClass": 
"org.apache.camel.component.minio.MinioConfiguration", "configurationField": 
"configuration", "description": "Setting the key name for an element in the 
bucket through endpoint parameter." },
     "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start 
Producer", "group": "producer", "label": "producer", "required": false, "type": 
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": false, "description": "Whether the producer 
should be started lazy (on the first message). By starting lazy you can use 
this to allow CamelContext and routes to startup in situations where a producer 
may otherwise fail during star [...]
-    "operation": { "kind": "property", "displayName": "Operation", "group": 
"producer", "label": "producer", "required": false, "type": "object", 
"javaType": "org.apache.camel.component.minio.MinioOperations", "enum": [ 
"copyObject", "listObjects", "deleteObject", "deleteObjects", "deleteBucket", 
"listBuckets", "getObject", "getObjectRange" ], "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.minio.MinioConfiguration", "configurat [...]
+    "operation": { "kind": "property", "displayName": "Operation", "group": 
"producer", "label": "producer", "required": false, "type": "object", 
"javaType": "org.apache.camel.component.minio.MinioOperations", "enum": [ 
"copyObject", "listObjects", "deleteObject", "deleteObjects", "deleteBucket", 
"listBuckets", "getObject", "getObjectRange", "createDownloadLink", 
"createUploadLink" ], "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": "org.apache.camel.compon [...]
     "pojoRequest": { "kind": "property", "displayName": "Pojo Request", 
"group": "producer", "label": "producer", "required": false, "type": "boolean", 
"javaType": "boolean", "deprecated": false, "autowired": false, "secret": 
false, "defaultValue": false, "configurationClass": 
"org.apache.camel.component.minio.MinioConfiguration", "configurationField": 
"configuration", "description": "If we want to use a POJO request as body or 
not." },
     "storageClass": { "kind": "property", "displayName": "Storage Class", 
"group": "producer", "label": "producer", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "configurationClass": 
"org.apache.camel.component.minio.MinioConfiguration", "configurationField": 
"configuration", "description": "The storage class to set in the request." },
     "autowiredEnabled": { "kind": "property", "displayName": "Autowired 
Enabled", "group": "advanced", "label": "advanced", "required": false, "type": 
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": true, "description": "Whether autowiring is 
enabled. This is used for automatic autowiring options (the option must be 
marked as autowired) by looking up in the registry to find if there is a single 
instance of matching type, which t [...]
@@ -86,12 +86,13 @@
     "CamelMinioStorageClass": { "kind": "header", "displayName": "", "group": 
"producer", "label": "producer", "required": false, "javaType": "String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The storage class of this object.", "constantName": 
"org.apache.camel.component.minio.MinioConstants#STORAGE_CLASS" },
     "CamelMinioVersionId": { "kind": "header", "displayName": "", "group": 
"common", "label": "", "required": false, "javaType": "String", "deprecated": 
false, "deprecationNote": "", "autowired": false, "secret": false, 
"description": "Producer: The version Id of the object to be stored or returned 
from the current operation. Consumer: The version ID of the associated Minio 
object if available. Version IDs are only assigned to objects when an object is 
uploaded to an Minio bucket that ha [...]
     "CamelMinioCannedAcl": { "kind": "header", "displayName": "", "group": 
"producer", "label": "producer", "required": false, "javaType": "String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The canned acl that will be applied to the object. see 
com.amazonaws.services.s3.model.CannedAccessControlList for allowed values.", 
"constantName": "org.apache.camel.component.minio.MinioConstants#CANNED_ACL" },
-    "CamelMinioOperation": { "kind": "header", "displayName": "", "group": 
"producer", "label": "producer", "required": false, "javaType": 
"org.apache.camel.component.minio.MinioOperations", "enum": [ "copyObject", 
"listObjects", "deleteObject", "deleteObjects", "deleteBucket", "listBuckets", 
"getObject", "getPartialObject" ], "deprecated": false, "deprecationNote": "", 
"autowired": false, "secret": false, "description": "The operation to 
perform.", "constantName": "org.apache.camel.comp [...]
+    "CamelMinioOperation": { "kind": "header", "displayName": "", "group": 
"producer", "label": "producer", "required": false, "javaType": 
"org.apache.camel.component.minio.MinioOperations", "enum": [ "copyObject", 
"listObjects", "deleteObject", "deleteObjects", "deleteBucket", "listBuckets", 
"getObject", "getPartialObject", "createDownloadLink", "createUploadLink" ], 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The operation to perform [...]
     "CamelMinioServerSideEncryption": { "kind": "header", "displayName": "", 
"group": "common", "label": "", "required": false, "javaType": "String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "Producer: Sets the server-side encryption algorithm when 
encrypting the object using Minio-managed keys. For example use AES256. 
Consumer: The server-side encryption algorithm when encrypting the object using 
Minio-managed keys.", "constantName" [...]
     "CamelMinioExpirationTime": { "kind": "header", "displayName": "", 
"group": "common", "label": "", "required": false, "javaType": "String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The expiration time", "constantName": 
"org.apache.camel.component.minio.MinioConstants#EXPIRATION_TIME" },
     "CamelMinioReplicationStatus": { "kind": "header", "displayName": "", 
"group": "common", "label": "", "required": false, "javaType": "String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The replication status", "constantName": 
"org.apache.camel.component.minio.MinioConstants#REPLICATION_STATUS" },
     "CamelMinioOffset": { "kind": "header", "displayName": "", "group": 
"producer", "label": "producer", "required": false, "javaType": "String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The offset", "constantName": 
"org.apache.camel.component.minio.MinioConstants#OFFSET" },
-    "CamelMinioLength": { "kind": "header", "displayName": "", "group": 
"producer", "label": "producer", "required": false, "javaType": "String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The length", "constantName": 
"org.apache.camel.component.minio.MinioConstants#LENGTH" }
+    "CamelMinioLength": { "kind": "header", "displayName": "", "group": 
"producer", "label": "producer", "required": false, "javaType": "String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The length", "constantName": 
"org.apache.camel.component.minio.MinioConstants#LENGTH" },
+    "CamelMinioPresignedURLExpirationTime": { "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"int", "deprecated": false, "deprecationNote": "", "autowired": false, 
"secret": false, "description": "Expiration of minio presigned url in Seconds", 
"constantName": 
"org.apache.camel.component.minio.MinioConstants#PRESIGNED_URL_EXPIRATION_TIME" 
}
   },
   "properties": {
     "bucketName": { "kind": "path", "displayName": "Bucket Name", "group": 
"common", "label": "", "required": true, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "configurationClass": 
"org.apache.camel.component.minio.MinioConfiguration", "configurationField": 
"configuration", "description": "Bucket name" },
@@ -138,7 +139,7 @@
     "pollStrategy": { "kind": "parameter", "displayName": "Poll Strategy", 
"group": "consumer (advanced)", "label": "consumer,advanced", "required": 
false, "type": "object", "javaType": 
"org.apache.camel.spi.PollingConsumerPollStrategy", "deprecated": false, 
"autowired": false, "secret": false, "description": "A pluggable 
org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your 
custom implementation to control error handling usually occurred during the 
poll operation  [...]
     "deleteAfterWrite": { "kind": "parameter", "displayName": "Delete After 
Write", "group": "producer", "label": "producer", "required": false, "type": 
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": false, "configurationClass": 
"org.apache.camel.component.minio.MinioConfiguration", "configurationField": 
"configuration", "description": "Delete file object after the Minio file has 
been uploaded." },
     "keyName": { "kind": "parameter", "displayName": "Key Name", "group": 
"producer", "label": "producer", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "configurationClass": 
"org.apache.camel.component.minio.MinioConfiguration", "configurationField": 
"configuration", "description": "Setting the key name for an element in the 
bucket through endpoint parameter." },
-    "operation": { "kind": "parameter", "displayName": "Operation", "group": 
"producer", "label": "producer", "required": false, "type": "object", 
"javaType": "org.apache.camel.component.minio.MinioOperations", "enum": [ 
"copyObject", "listObjects", "deleteObject", "deleteObjects", "deleteBucket", 
"listBuckets", "getObject", "getObjectRange" ], "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.minio.MinioConfiguration", "configura [...]
+    "operation": { "kind": "parameter", "displayName": "Operation", "group": 
"producer", "label": "producer", "required": false, "type": "object", 
"javaType": "org.apache.camel.component.minio.MinioOperations", "enum": [ 
"copyObject", "listObjects", "deleteObject", "deleteObjects", "deleteBucket", 
"listBuckets", "getObject", "getObjectRange", "createDownloadLink", 
"createUploadLink" ], "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": "org.apache.camel.compo [...]
     "pojoRequest": { "kind": "parameter", "displayName": "Pojo Request", 
"group": "producer", "label": "producer", "required": false, "type": "boolean", 
"javaType": "boolean", "deprecated": false, "autowired": false, "secret": 
false, "defaultValue": false, "configurationClass": 
"org.apache.camel.component.minio.MinioConfiguration", "configurationField": 
"configuration", "description": "If we want to use a POJO request as body or 
not." },
     "storageClass": { "kind": "parameter", "displayName": "Storage Class", 
"group": "producer", "label": "producer", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "configurationClass": 
"org.apache.camel.component.minio.MinioConfiguration", "configurationField": 
"configuration", "description": "The storage class to set in the request." },
     "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start 
Producer", "group": "producer (advanced)", "label": "producer,advanced", 
"required": false, "type": "boolean", "javaType": "boolean", "deprecated": 
false, "autowired": false, "secret": false, "defaultValue": false, 
"description": "Whether the producer should be started lazy (on the first 
message). By starting lazy you can use this to allow CamelContext and routes to 
startup in situations where a producer may other [...]
diff --git a/components/camel-minio/src/main/docs/minio-component.adoc 
b/components/camel-minio/src/main/docs/minio-component.adoc
index 325c1576d06..df4039785a5 100644
--- a/components/camel-minio/src/main/docs/minio-component.adoc
+++ b/components/camel-minio/src/main/docs/minio-component.adoc
@@ -83,6 +83,8 @@ Camel-Minio component provides the following operation on the 
producer side:
 - listObjects
 - getObject (this will return a MinioObject instance)
 - getObjectRange (this will return a MinioObject instance)
+- createDownloadLink (this will return a Presigned download Url)
+- createUploadLink (this will return a Presigned upload url)
 
 === Advanced Minio configuration
 
@@ -200,9 +202,42 @@ This operation will return an MinioObject instance related 
to the camelKey objec
   
.to("minio://mycamelbucket?minioClient=#minioClient&operation=getObjectRange")
   .to("mock:result");
 
--------------------------------------------------------------------------------
-
 This operation will return an MinioObject instance related to the camelKey 
object in mycamelbucket bucket, containing bytes from 0 to 9.
 
+- createDownloadLink: this operation will return a presigned url through which 
a file can be downloaded using GET method
+
+[source,java]
+--------------------------------------------------------------------------------
+  from("direct:start").process(new Processor() {
+
+      @Override
+      public void process(Exchange exchange) throws Exception {
+          exchange.getIn().setHeader(MinioConstants.OBJECT_NAME, "camelKey");
+          
exchange.getIn().setHeader(MinioConstants.PRESIGNED_URL_EXPIRATION_TIME, 60 * 
60);
+      }
+  })
+  
.to("minio://mycamelbucket?minioClient=#minioClient&operation=createDownloadLink")
+  .to("mock:result");
+--------------------------------------------------------------------------------
+
+- createUploadLink: this operation will return a presigned url through which a 
file can be uploaded using PUT method
+
+[source,java]
+--------------------------------------------------------------------------------
+  from("direct:start").process(new Processor() {
+
+      @Override
+      public void process(Exchange exchange) throws Exception {
+          exchange.getIn().setHeader(MinioConstants.OBJECT_NAME, "camelKey");
+          
exchange.getIn().setHeader(MinioConstants.PRESIGNED_URL_EXPIRATION_TIME, 60 * 
60);
+      }
+  })
+  
.to("minio://mycamelbucket?minioClient=#minioClient&operation=createUploadLink")
+  .to("mock:result");
+--------------------------------------------------------------------------------
+
+createDownLink and createUploadLink have a default expiry of 3600s which can 
be overridden by setting the header 
MinioConstants.PRESIGNED_URL_EXPIRATION_TIME (value in seconds)
+
 == Bucket Autocreation
 
 With the option `autoCreateBucket` users are able to avoid the autocreation of 
a Minio Bucket in case it doesn't exist. The default for this option is `true`.
@@ -268,3 +303,4 @@ where `$\{camel-version}` must be replaced by the actual 
version of Camel.
 
 
 include::spring-boot:partial$starter.adoc[]
+
diff --git 
a/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioConfiguration.java
 
b/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioConfiguration.java
index 9fd3ec1e383..2914f5f7bc5 100644
--- 
a/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioConfiguration.java
+++ 
b/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioConfiguration.java
@@ -123,7 +123,7 @@ public class MinioConfiguration implements Cloneable {
     @UriParam(label = "producer")
     private String storageClass;
     @UriParam(label = "producer",
-              enums = 
"copyObject,listObjects,deleteObject,deleteObjects,deleteBucket,listBuckets,getObject,getObjectRange")
+              enums = 
"copyObject,listObjects,deleteObject,deleteObjects,deleteBucket,listBuckets,getObject,getObjectRange,createDownloadLink,createUploadLink")
     private MinioOperations operation;
     @UriParam(label = "producer", defaultValue = "false")
     private boolean pojoRequest;
diff --git 
a/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioConstants.java
 
b/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioConstants.java
index 545d17d2239..35af578594b 100644
--- 
a/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioConstants.java
+++ 
b/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioConstants.java
@@ -116,4 +116,6 @@ public interface MinioConstants {
     String OFFSET = "CamelMinioOffset";
     @Metadata(label = "producer", description = "The length", javaType = 
"String")
     String LENGTH = "CamelMinioLength";
+    @Metadata(label = "producer", description = "Expiration of minio presigned 
url in Seconds", javaType = "int")
+    String PRESIGNED_URL_EXPIRATION_TIME = 
"CamelMinioPresignedURLExpirationTime";
 }
diff --git 
a/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioOperations.java
 
b/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioOperations.java
index 17acaee997a..b43197f2ff4 100644
--- 
a/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioOperations.java
+++ 
b/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioOperations.java
@@ -24,5 +24,7 @@ public enum MinioOperations {
     deleteBucket,
     listBuckets,
     getObject,
-    getPartialObject
+    getPartialObject,
+    createDownloadLink,
+    createUploadLink
 }
diff --git 
a/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java
 
b/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java
index 9ccaa86571f..ec963a81cb1 100644
--- 
a/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java
+++ 
b/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java
@@ -31,6 +31,7 @@ import java.util.Map;
 import io.minio.CopyObjectArgs;
 import io.minio.CopySource;
 import io.minio.GetObjectArgs;
+import io.minio.GetPresignedObjectUrlArgs;
 import io.minio.ListObjectsArgs;
 import io.minio.MinioClient;
 import io.minio.ObjectWriteResponse;
@@ -45,6 +46,7 @@ import io.minio.errors.InternalException;
 import io.minio.errors.InvalidResponseException;
 import io.minio.errors.ServerException;
 import io.minio.errors.XmlParserException;
+import io.minio.http.Method;
 import io.minio.messages.Bucket;
 import io.minio.messages.Item;
 import org.apache.camel.Endpoint;
@@ -108,6 +110,12 @@ public class MinioProducer extends DefaultProducer {
                 case getPartialObject:
                     getPartialObject(minioClient, exchange);
                     break;
+                case createDownloadLink:
+                    createPresignedUrl(minioClient, exchange, Method.GET);
+                    break;
+                case createUploadLink:
+                    createPresignedUrl(minioClient, exchange, Method.PUT);
+                    break;
                 default:
                     throw new IllegalArgumentException("Unsupported 
operation");
             }
@@ -395,6 +403,35 @@ public class MinioProducer extends DefaultProducer {
         }
     }
 
+    private void createPresignedUrl(MinioClient minioClient, Exchange 
exchange, Method method) throws Exception {
+        int expiry = 60 * 60;
+        Integer expirationInSeconds = 
exchange.getIn().getHeader(MinioConstants.PRESIGNED_URL_EXPIRATION_TIME, 
Integer.class);
+        Message message = getMessageForResponse(exchange);
+        if (expirationInSeconds != null) {
+            expiry = expirationInSeconds;
+        }
+        if (getConfiguration().isPojoRequest()) {
+            GetPresignedObjectUrlArgs.Builder payload
+                    = 
exchange.getIn().getMandatoryBody(GetPresignedObjectUrlArgs.Builder.class);
+            if (isNotEmpty(payload)) {
+                GetPresignedObjectUrlArgs args = 
payload.expiry(expiry).method(method).build();
+                String response = minioClient.getPresignedObjectUrl(args);
+                message.setBody(response);
+            }
+        } else {
+            final String bucketName = determineBucketName(exchange);
+            final String objectName = determineObjectName(exchange);
+            GetPresignedObjectUrlArgs args = 
GetPresignedObjectUrlArgs.builder()
+                    .bucket(bucketName)
+                    .object(objectName)
+                    .expiry(expiry)
+                    .method(method)
+                    .build();
+            String response = minioClient.getPresignedObjectUrl(args);
+            message.setBody(response);
+        }
+    }
+
     private MinioOperations determineOperation(Exchange exchange) {
         MinioOperations operation = 
exchange.getIn().getHeader(MinioConstants.MINIO_OPERATION, 
MinioOperations.class);
         if (isEmpty(operation)) {
diff --git 
a/components/camel-minio/src/test/java/org/apache/camel/component/minio/integration/MinioPresignedUrlIT.java
 
b/components/camel-minio/src/test/java/org/apache/camel/component/minio/integration/MinioPresignedUrlIT.java
new file mode 100644
index 00000000000..f548eb3a5a2
--- /dev/null
+++ 
b/components/camel-minio/src/test/java/org/apache/camel/component/minio/integration/MinioPresignedUrlIT.java
@@ -0,0 +1,105 @@
+/*
+ * 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.minio.integration;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.minio.MinioClient;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.minio.MinioConstants;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+public class MinioPresignedUrlIT extends MinioIntegrationTestSupport {
+    @BindToRegistry("minioClient")
+    MinioClient client = MinioClient.builder()
+            .endpoint("http://"; + service.host(), service.port(), false)
+            .credentials(service.accessKey(), service.secretKey())
+            .build();
+
+    @EndpointInject
+    private ProducerTemplate template;
+
+    @EndpointInject("mock:result")
+    private MockEndpoint result;
+
+    MinioPresignedUrlIT() throws IOException {
+    }
+
+    @Test
+    void createDownloadLinkTest() throws Exception {
+        result.expectedMessageCount(1);
+        result.message(0).body().contains("test.txt");
+        result.message(0).body().contains("X-Amz-Expires=60");
+
+        template.send("direct:putObject", exchange -> {
+            exchange.getIn().setHeader(MinioConstants.OBJECT_NAME, "test.txt");
+            exchange.getIn().setBody("Test");
+        });
+        template.send("direct:createDownloadLink", exchange -> {
+            Map<String, Object> header = new HashMap<>();
+            header.put(MinioConstants.OBJECT_NAME, "test.txt");
+            header.put(MinioConstants.PRESIGNED_URL_EXPIRATION_TIME, 60);
+            exchange.getIn().setHeaders(header);
+        });
+
+        MockEndpoint.assertIsSatisfied(context);
+    }
+
+    @Test
+    void createUploadLinkTest() throws Exception {
+        result.expectedMessageCount(1);
+        result.message(0).body().contains("test.txt");
+        result.message(0).body().contains("X-Amz-Expires=3600");
+
+        template.send("direct:putObject", exchange -> {
+            exchange.getIn().setHeader(MinioConstants.OBJECT_NAME, "test.txt");
+            exchange.getIn().setBody("Test");
+        });
+        template.send("direct:createUploadLink", exchange -> {
+            Map<String, Object> header = new HashMap<>();
+            header.put(MinioConstants.OBJECT_NAME, "test.txt");
+            header.put(MinioConstants.PRESIGNED_URL_EXPIRATION_TIME, 60 * 60);
+            exchange.getIn().setHeaders(header);
+        });
+
+        MockEndpoint.assertIsSatisfied(context);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                String minioEndpoint = "minio://mycamel?autoCreateBucket=true";
+
+                from("direct:createDownloadLink")
+                        
.to("minio://mycamel?minioClient=#minioClient&operation=createDownloadLink")
+                        .to("mock:result");
+                from("direct:createUploadLink")
+                        
.to("minio://mycamel?minioClient=#minioClient&operation=createUploadLink")
+                        .to("mock:result");
+
+            }
+        };
+    }
+}

Reply via email to