exceptionfactory commented on code in PR #7173:
URL: https://github.com/apache/nifi/pull/7173#discussion_r1166213682
##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/storage/FetchGCSObject.java:
##########
@@ -273,7 +275,15 @@ public void onTrigger(final ProcessContext context, final
ProcessSession session
final long millis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() -
startNanos);
getLogger().info("Successfully retrieved GCS Object for {} in {}
millis; routing to success", new Object[]{flowFile, millis});
- session.getProvenanceReporter().fetch(flowFile, "https://" +
bucketName + ".storage.googleapis.com/" + key, millis);
+
+ String transitUri;
+ try {
+ final URL url = new URL(storage.getOptions().getHost());
+ transitUri = String.format("%s://%s.%s/%s", url.getProtocol(),
bucketName, url.getHost(), key);
+ } catch (MalformedURLException e) {
+ transitUri = e.getClass().getSimpleName();
+ }
Review Comment:
Using `URI.create()` avoids the checked `MalformedURLException` and because
the Storage API URL must be valid for making the request, recommend the
following approach:
```suggestion
final URI storageApiUri = URI.create(storage.getOptions().getHost());
final String transitUri = String.format("%s://%s.%s/%s",
uri,getScheme(), bucketName, uri.getHost(), key);
```
##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/storage/PutGCSObject.java:
##########
@@ -542,9 +544,15 @@ public void process(InputStream rawIn) throws IOException {
}
session.transfer(flowFile, REL_SUCCESS);
final long millis =
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos);
- final String url = "https://" + bucket +
".storage.googleapis.com/" + key;
- session.getProvenanceReporter().send(flowFile, url, millis);
+ String transitUri;
+ try {
+ final URL url = new URL(storage.getOptions().getHost());
+ transitUri = String.format("%s://%s.%s/%s", url.getProtocol(),
bucket, url.getHost(), key);
+ } catch (MalformedURLException e) {
+ transitUri = e.getClass().getSimpleName();
+ }
Review Comment:
It seems like the implementation could be moved to a protected
`getTransitUri()` method in `AbstractGCSProcessor`, or the changed could be
implemented in both classes.
```suggestion
final URI storageApiUri = URI.create(storage.getOptions().getHost());
final String transitUri = String.format("%s://%s.%s/%s",
uri,getScheme(), bucketName, uri.getHost(), key);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]