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 2020/09/10 09:33:37 UTC
[camel] branch master updated: Camel-Minio: Lets simplify the
client instantiation
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new fcef39d Camel-Minio: Lets simplify the client instantiation
fcef39d is described below
commit fcef39d2233506badff9139dff0c6614bb5f9c1e
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Sep 10 11:28:23 2020 +0200
Camel-Minio: Lets simplify the client instantiation
---
.../camel/component/minio/MinioEndpoint.java | 37 ++++++++---
.../minio/client/MinioCamelInternalClient.java | 32 ----------
.../component/minio/client/MinioClientFactory.java | 42 -------------
.../minio/client/MinioRemoteClientImpl.java | 72 ----------------------
.../component/minio/MinioClientFactoryTest.java | 34 ----------
5 files changed, 29 insertions(+), 188 deletions(-)
diff --git a/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioEndpoint.java b/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioEndpoint.java
index 0f4f069..5a3a10b 100644
--- a/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioEndpoint.java
+++ b/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioEndpoint.java
@@ -39,7 +39,6 @@ import org.apache.camel.ExtendedExchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
-import org.apache.camel.component.minio.client.MinioClientFactory;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
import org.apache.camel.support.ScheduledPollEndpoint;
@@ -86,9 +85,8 @@ public class MinioEndpoint extends ScheduledPollEndpoint {
public void doStart() throws Exception {
super.doStart();
- minioClient = isNotEmpty(getConfiguration().getMinioClient())
- ? getConfiguration().getMinioClient()
- : MinioClientFactory.getClient(getConfiguration()).getMinioClient();
+ minioClient
+ = isNotEmpty(getConfiguration().getMinioClient()) ? getConfiguration().getMinioClient() : createMinioClient();
String objectName = getConfiguration().getObjectName();
@@ -130,10 +128,7 @@ public class MinioEndpoint extends ScheduledPollEndpoint {
return createExchange(getExchangePattern(), minioObject, objectName);
}
- public Exchange createExchange(
- ExchangePattern pattern,
- InputStream minioObject, String objectName)
- throws Exception {
+ public Exchange createExchange(ExchangePattern pattern, InputStream minioObject, String objectName) throws Exception {
LOG.trace("Getting object with objectName {} from bucket {}...", objectName, getConfiguration().getBucketName());
Exchange exchange = super.createExchange(pattern);
@@ -176,6 +171,32 @@ public class MinioEndpoint extends ScheduledPollEndpoint {
this.minioClient = minioClient;
}
+ MinioClient createMinioClient() {
+ if (isNotEmpty(configuration.getEndpoint())) {
+ MinioClient.Builder minioClientRequest = MinioClient.builder();
+
+ if (isNotEmpty(configuration.getProxyPort())) {
+ minioClientRequest.endpoint(configuration.getEndpoint(), configuration.getProxyPort(),
+ configuration.isSecure());
+ } else {
+ minioClientRequest.endpoint(configuration.getEndpoint());
+ }
+ if (isNotEmpty(configuration.getAccessKey()) && isNotEmpty(configuration.getSecretKey())) {
+ minioClientRequest.credentials(configuration.getAccessKey(), configuration.getSecretKey());
+ }
+ if (isNotEmpty(configuration.getRegion())) {
+ minioClientRequest.region(configuration.getRegion());
+ }
+ if (isNotEmpty(configuration.getCustomHttpClient())) {
+ minioClientRequest.httpClient(configuration.getCustomHttpClient());
+ }
+ return minioClientRequest.build();
+
+ } else {
+ throw new IllegalArgumentException("Endpoint must be specified");
+ }
+ }
+
private String readInputStream(InputStream minioObject) throws IOException {
StringBuilder textBuilder = new StringBuilder();
try (Reader reader = new BufferedReader(new InputStreamReader(minioObject, StandardCharsets.UTF_8))) {
diff --git a/components/camel-minio/src/main/java/org/apache/camel/component/minio/client/MinioCamelInternalClient.java b/components/camel-minio/src/main/java/org/apache/camel/component/minio/client/MinioCamelInternalClient.java
deleted file mode 100644
index 774cc1a..0000000
--- a/components/camel-minio/src/main/java/org/apache/camel/component/minio/client/MinioCamelInternalClient.java
+++ /dev/null
@@ -1,32 +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.component.minio.client;
-
-import io.minio.MinioClient;
-
-/**
- * Create MinioClient using either AWS IAM Credentials or Minio Credentials.
- */
-public interface MinioCamelInternalClient {
-
- /**
- * Returns an minio client after a factory method determines which one to return.
- *
- * @return Minio Minio
- */
- MinioClient getMinioClient();
-}
diff --git a/components/camel-minio/src/main/java/org/apache/camel/component/minio/client/MinioClientFactory.java b/components/camel-minio/src/main/java/org/apache/camel/component/minio/client/MinioClientFactory.java
deleted file mode 100644
index bee8e4a..0000000
--- a/components/camel-minio/src/main/java/org/apache/camel/component/minio/client/MinioClientFactory.java
+++ /dev/null
@@ -1,42 +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.component.minio.client;
-
-import org.apache.camel.component.minio.MinioConfiguration;
-
-/**
- * Factory class to return the correct type of MinioClient.
- */
-public final class MinioClientFactory {
-
- private MinioClientFactory() {
- // Prevent instantiation of this factory class.
- throw new RuntimeException(
- "Do not instantiate a Factory class! Refer to the class "
- + "to learn how to properly use this factory implementation.");
- }
-
- /**
- * Return the correct minio client (based on remote vs local).
- *
- * @param configuration configuration
- * @return MinioClient
- */
- public static MinioCamelInternalClient getClient(MinioConfiguration configuration) {
- return new MinioRemoteClientImpl(configuration);
- }
-}
diff --git a/components/camel-minio/src/main/java/org/apache/camel/component/minio/client/MinioRemoteClientImpl.java b/components/camel-minio/src/main/java/org/apache/camel/component/minio/client/MinioRemoteClientImpl.java
deleted file mode 100644
index 6d99416..0000000
--- a/components/camel-minio/src/main/java/org/apache/camel/component/minio/client/MinioRemoteClientImpl.java
+++ /dev/null
@@ -1,72 +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.component.minio.client;
-
-import io.minio.MinioClient;
-import org.apache.camel.component.minio.MinioConfiguration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.camel.util.ObjectHelper.isNotEmpty;
-
-/**
- * Creates MinIO client object according to the given endpoint, port, access key, secret key, region and secure option.
- */
-public class MinioRemoteClientImpl implements MinioCamelInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(MinioRemoteClientImpl.class);
- private final MinioConfiguration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public MinioRemoteClientImpl(MinioConfiguration configuration) {
- LOG.trace("Creating an Minio client.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the minio client.
- *
- * @return Minio Client.
- */
- @Override
- public MinioClient getMinioClient() {
- if (isNotEmpty(configuration.getEndpoint())) {
- MinioClient.Builder minioClientRequest = MinioClient.builder();
-
- if (isNotEmpty(configuration.getProxyPort())) {
- minioClientRequest.endpoint(configuration.getEndpoint(), configuration.getProxyPort(),
- configuration.isSecure());
- } else {
- minioClientRequest.endpoint(configuration.getEndpoint());
- }
- if (isNotEmpty(configuration.getAccessKey()) && isNotEmpty(configuration.getSecretKey())) {
- minioClientRequest.credentials(configuration.getAccessKey(), configuration.getSecretKey());
- }
- if (isNotEmpty(configuration.getRegion())) {
- minioClientRequest.region(configuration.getRegion());
- }
- if (isNotEmpty(configuration.getCustomHttpClient())) {
- minioClientRequest.httpClient(configuration.getCustomHttpClient());
- }
- return minioClientRequest.build();
-
- } else {
- throw new IllegalArgumentException("Endpoint must be specified");
- }
- }
-}
diff --git a/components/camel-minio/src/test/java/org/apache/camel/component/minio/MinioClientFactoryTest.java b/components/camel-minio/src/test/java/org/apache/camel/component/minio/MinioClientFactoryTest.java
deleted file mode 100644
index 9f8db4a..0000000
--- a/components/camel-minio/src/test/java/org/apache/camel/component/minio/MinioClientFactoryTest.java
+++ /dev/null
@@ -1,34 +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.component.minio;
-
-import org.apache.camel.component.minio.client.MinioCamelInternalClient;
-import org.apache.camel.component.minio.client.MinioClientFactory;
-import org.apache.camel.component.minio.client.MinioRemoteClientImpl;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class MinioClientFactoryTest {
-
- @Test
- void getStandardMinioClientDefault() {
- MinioConfiguration minioConfiguration = new MinioConfiguration();
- MinioCamelInternalClient minioClient = MinioClientFactory.getClient(minioConfiguration);
- assertTrue(minioClient instanceof MinioRemoteClientImpl);
- }
-}