This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 2f37fb2 CAMEL-15964 - Polished
2f37fb2 is described below
commit 2f37fb2b84d58c0503b694e8c1ed7f6b242191bd
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Feb 17 09:56:13 2021 +0100
CAMEL-15964 - Polished
---
.../storage/GoogleCloudStorageComponent.java | 7 ++---
.../google/storage/GoogleCloudStorageConsumer.java | 9 ++----
.../google/storage/GoogleCloudStorageEndpoint.java | 34 ++++++++--------------
.../google/storage/GoogleCloudStorageProducer.java | 17 +++++------
4 files changed, 25 insertions(+), 42 deletions(-)
diff --git
a/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageComponent.java
b/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageComponent.java
index c42e29d..04f377b 100644
---
a/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageComponent.java
+++
b/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageComponent.java
@@ -39,19 +39,18 @@ public class GoogleCloudStorageComponent extends
DefaultComponent {
}
protected Endpoint createEndpoint(String uri, String remaining,
Map<String, Object> parameters) throws Exception {
-
if (remaining == null || remaining.trim().length() == 0) {
throw new IllegalArgumentException("Bucket name must be
specified.");
}
if (remaining.startsWith("arn:")) {
- remaining = remaining.substring(remaining.lastIndexOf(':') + 1,
remaining.length());
+ remaining = remaining.substring(remaining.lastIndexOf(':') + 1);
}
final GoogleCloudStorageConfiguration configuration
= this.configuration != null ? this.configuration.copy() : new
GoogleCloudStorageConfiguration();
- setProperties(configuration, parameters);
configuration.setBucketName(remaining);
- Endpoint endpoint = new GoogleCloudStorageEndpoint(uri, this,
configuration);
+ Endpoint endpoint = new GoogleCloudStorageEndpoint(uri, this,
configuration);
+ setProperties(endpoint, parameters);
return endpoint;
}
diff --git
a/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConsumer.java
b/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConsumer.java
index 1a03c26..935b7e6 100644
---
a/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConsumer.java
+++
b/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConsumer.java
@@ -50,7 +50,6 @@ public class GoogleCloudStorageConsumer extends
ScheduledBatchPollingConsumer {
super.doStart();
if (getConfiguration().isMoveAfterRead()) {
-
Bucket bucket =
getStorageClient().get(getConfiguration().getDestinationBucket());
if (bucket != null) {
LOG.trace("Bucket [{}] already exists", bucket.getName());
@@ -63,7 +62,6 @@ public class GoogleCloudStorageConsumer extends
ScheduledBatchPollingConsumer {
getStorageClient());
}
}
-
}
}
@@ -116,12 +114,10 @@ public class GoogleCloudStorageConsumer extends
ScheduledBatchPollingConsumer {
Queue<Exchange> answer = new LinkedList<>();
try {
for (Blob blob : blobList) {
-
if (includeObject(blob)) {
Exchange exchange = getEndpoint().createExchange(blob,
blob.getBlobId().getName());
answer.add(exchange);
}
-
}
} catch (Exception e) {
LOG.warn("Error getting object due: {}", e.getMessage(), e);
@@ -134,11 +130,10 @@ public class GoogleCloudStorageConsumer extends
ScheduledBatchPollingConsumer {
/**
* Decide whether to include the Objects in the results
*
- * @param Object
- * @return true to include, false to exclude
+ * @param blob the blob
+ * @return true to include, false to exclude
*/
protected boolean includeObject(Blob blob) {
-
if (getConfiguration().isIncludeFolders()) {
return true;
}
diff --git
a/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpoint.java
b/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpoint.java
index ba4b69c..f3fe59a 100644
---
a/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpoint.java
+++
b/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpoint.java
@@ -44,11 +44,9 @@ import org.slf4j.LoggerFactory;
*
* Google Storage Endpoint definition represents a bucket within the storage
and contains configuration to customize the
* behavior of Consumer and Producer.
- *
*/
@UriEndpoint(firstVersion = "3.9.0", scheme = "google-storage", title =
"Google Storage", syntax = "google-storage:bucketName",
- category = {
- Category.CLOUD })
+ category = { Category.CLOUD })
public class GoogleCloudStorageEndpoint extends ScheduledPollEndpoint {
private static final Logger LOG =
LoggerFactory.getLogger(GoogleCloudStorageEndpoint.class);
@@ -86,20 +84,13 @@ public class GoogleCloudStorageEndpoint extends
ScheduledPollEndpoint {
}
if (configuration.isAutoCreateBucket()) {
-
- try {
-
- Bucket bucket =
this.storageClient.get(configuration.getBucketName());
- if (bucket != null) {
- LOG.trace("Bucket [{}] already exists", bucket.getName());
- return;
- } else {
- // creates the new bucket because it doesn't exist yet
- createNewBucket(configuration.getBucketName(),
configuration, this.storageClient);
- }
- } catch (Exception e) {
- LOG.error("Error - autocreatebucket", e);
- throw e;
+ Bucket bucket =
this.storageClient.get(configuration.getBucketName());
+ if (bucket != null) {
+ LOG.trace("Bucket [{}] already exists", bucket.getName());
+ return;
+ } else {
+ // creates the new bucket because it doesn't exist yet
+ createNewBucket(configuration.getBucketName(), configuration,
this.storageClient);
}
}
}
@@ -123,8 +114,6 @@ public class GoogleCloudStorageEndpoint extends
ScheduledPollEndpoint {
/**
* Setup configuration
- *
- * @param configuration
*/
public void setConfiguration(GoogleCloudStorageConfiguration
configuration) {
this.configuration = configuration;
@@ -139,9 +128,10 @@ public class GoogleCloudStorageEndpoint extends
ScheduledPollEndpoint {
}
public Exchange createExchange(ExchangePattern pattern, Blob blob, String
key) {
- LOG.trace("Getting object with key [{}] from bucket [{}]...", key,
getConfiguration().getBucketName());
-
- LOG.trace("Got object [{}]", blob);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Getting object with key [{}] from bucket [{}]...", key,
getConfiguration().getBucketName());
+ LOG.trace("Got object [{}]", blob);
+ }
Exchange exchange = super.createExchange(pattern);
Message message = exchange.getIn();
diff --git
a/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageProducer.java
b/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageProducer.java
index fbce312..6f479a8 100644
---
a/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageProducer.java
+++
b/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageProducer.java
@@ -101,8 +101,8 @@ public class GoogleCloudStorageProducer extends
DefaultProducer {
Map<String, String> objectMetadata = determineMetadata(exchange);
- File filePayload = null;
- InputStream is = null;
+ File filePayload;
+ InputStream is;
ByteArrayOutputStream baos = null;
Object obj = exchange.getIn().getMandatoryBody();
@@ -133,7 +133,7 @@ public class GoogleCloudStorageProducer extends
DefaultProducer {
}
}
- Blob createdBlob = null;
+ Blob createdBlob;
BlobId blobId = BlobId.of(bucketName, objectName);
BlobInfo blobInfo =
BlobInfo.newBuilder(blobId).setMetadata(objectMetadata).build();
if (baos.size() > 1_000_000) {
@@ -155,7 +155,6 @@ public class GoogleCloudStorageProducer extends
DefaultProducer {
IOHelper.close(baos);
IOHelper.close(is);
-
}
private ByteArrayOutputStream determineLengthInputStream(InputStream is)
throws IOException {
@@ -178,28 +177,28 @@ public class GoogleCloudStorageProducer extends
DefaultProducer {
String contentType =
exchange.getIn().getHeader(GoogleCloudStorageConstants.CONTENT_TYPE,
String.class);
if (contentType != null) {
- objectMetadata.put("Content-Type", String.valueOf(contentType));
+ objectMetadata.put("Content-Type", contentType);
}
String cacheControl =
exchange.getIn().getHeader(GoogleCloudStorageConstants.CACHE_CONTROL,
String.class);
if (cacheControl != null) {
- objectMetadata.put("Cache-Control", String.valueOf(cacheControl));
+ objectMetadata.put("Cache-Control", cacheControl);
}
String contentDisposition =
exchange.getIn().getHeader(GoogleCloudStorageConstants.CONTENT_DISPOSITION,
String.class);
if (contentDisposition != null) {
- objectMetadata.put("Content-Disposition",
String.valueOf(contentDisposition));
+ objectMetadata.put("Content-Disposition", contentDisposition);
}
String contentEncoding =
exchange.getIn().getHeader(GoogleCloudStorageConstants.CONTENT_ENCODING,
String.class);
if (contentEncoding != null) {
- objectMetadata.put("Content-Encoding",
String.valueOf(contentEncoding));
+ objectMetadata.put("Content-Encoding", contentEncoding);
}
String contentMD5 =
exchange.getIn().getHeader(GoogleCloudStorageConstants.CONTENT_MD5,
String.class);
if (contentMD5 != null) {
- objectMetadata.put("Content-Md5", String.valueOf(contentMD5));
+ objectMetadata.put("Content-Md5", contentMD5);
}
return objectMetadata;