markap14 commented on a change in pull request #4669:
URL: https://github.com/apache/nifi/pull/4669#discussion_r525233758



##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/extensions/NexusExtensionClient.java
##########
@@ -0,0 +1,137 @@
+/*
+ * 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.nifi.extensions;
+
+import okhttp3.Call;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+import org.apache.nifi.bundle.BundleCoordinate;
+import org.apache.nifi.security.util.OkHttpClientUtils;
+import org.apache.nifi.security.util.TlsConfiguration;
+import org.apache.nifi.stateless.config.SslConfigurationUtil;
+import org.apache.nifi.stateless.config.SslContextDefinition;
+import org.apache.nifi.util.FormatUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.concurrent.TimeUnit;
+
+public class NexusExtensionClient implements ExtensionClient {
+    private static final Logger logger = 
LoggerFactory.getLogger(NexusExtensionClient.class);
+    private static final long DEFAULT_TIMEOUT_MILLIS = 
TimeUnit.SECONDS.toMillis(30);
+    private static final String URL_CHARSET = "UTF-8";
+
+    private final String baseUrl;
+    private final long timeoutMillis;
+    private final SslContextDefinition sslContextDefinition;
+
+    public NexusExtensionClient(final String baseUrl, final 
SslContextDefinition sslContextDefinition, final String timeout) {
+        this.baseUrl = baseUrl;
+        this.sslContextDefinition = sslContextDefinition;
+        this.timeoutMillis = timeout == null ? DEFAULT_TIMEOUT_MILLIS : 
FormatUtils.getTimeDuration(timeout, TimeUnit.MILLISECONDS);
+    }
+
+    @Override
+    public InputStream getExtension(final BundleCoordinate bundleCoordinate) 
throws IOException {
+        final String url = resolveUrl(bundleCoordinate);
+        logger.debug("Attempting to fetch {} from {}", bundleCoordinate, url);
+
+        final OkHttpClient okHttpClient = createClient();
+        final Request request = new Request.Builder()
+            .get()
+            .url(url)
+            .build();
+
+        final Call call = okHttpClient.newCall(request);
+        final Response response = call.execute();
+        if (response.isSuccessful() && response.body() != null) {
+            logger.debug("Successfully obtained stream for extension {} from 
{}", bundleCoordinate, url);
+            final InputStream extensionByteStream = 
response.body().byteStream();
+            return new FilterInputStream(extensionByteStream) {
+                @Override
+                public void close() throws IOException {
+                    response.close();
+                    super.close();
+                }
+            };
+        } else {
+            try {
+                if (response.code() == 
javax.ws.rs.core.Response.Status.NOT_FOUND.getStatusCode()) {

Review comment:
       The issue with that is that okhttp3.Response is already imported. So not 
sure if Java will allow that or not, but it would arguably be more confusing 
regardless. 




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to