[ 
https://issues.apache.org/jira/browse/NIFI-6767?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17009209#comment-17009209
 ] 

Kristjan Antunovic edited comment on NIFI-6767 at 1/6/20 11:01 PM:
-------------------------------------------------------------------

[~bbende] This is the problematic piece of code:
{code:java}
final String registryBaseUrl = uri.getScheme() + "://" + uri.getHost() + ":" + 
uri.getPort();
{code}

I would rewrite the method as so:


{code:java}
    import org.apache.http.client.utils.URIBuilder;

    @Override
    public FlowRegistry addFlowRegistry(final String registryId, final String 
registryName, final String registryUrl, final String description) {
        final URI uri;
        try {
            URIBuilder uriBuilder = new URIBuilder(registryUrl);
            uriBuilder.setPath("");             // This should remove any 
trailing paths such as /nifi-registry or /../..
            uriBuilder.removeQuery();     // This should remove any query 
parameters ?a=b

            uri = uriBuilder.build();
            //uri = new URI(registryUrl);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("The given Registry URL is not 
valid: " + registryUrl);
        }

        final String uriScheme = uri.getScheme();
        if (uriScheme == null) {
            throw new IllegalArgumentException("The given Registry URL is not 
valid: " + registryUrl);
        }

        // Handles case where the URI entered has a trailing slash, or includes 
the trailing /nifi-registry-api
        // final String registryBaseUrl = uri.getScheme() + "://" + 
uri.getHost() + ":" + uri.getPort();
        
        final String registryBaseUrl = uri.toString();  // This will be the 
base URI with no paths or params. But will include the port if set initially.

        final FlowRegistry registry;
        if (uriScheme.equalsIgnoreCase("http") || 
uriScheme.equalsIgnoreCase("https")) {
            final SSLContext sslContext = 
SslContextFactory.createSslContext(nifiProperties);
            if (sslContext == null && uriScheme.equalsIgnoreCase("https")) {
                throw new IllegalStateException("Failed to create Flow Registry 
for URI " + registryUrl
                    + " because this NiFi is not configured with a 
Keystore/Truststore, so it is not capable of communicating with a secure 
Registry. "
                    + "Please populate NiFi's Keystore/Truststore properties or 
connect to a NiFi Registry over http instead of https.");
            }

            registry = new RestBasedFlowRegistry(this, registryId, 
registryBaseUrl, sslContext, registryName);
            registry.setDescription(description);
        } else {
            throw new IllegalArgumentException("Cannot create Flow Registry 
with URI of " + registryUrl
                + " because there are no known implementations of Flow 
Registries that can handle URIs of scheme " + uriScheme);
        }

        addFlowRegistry(registry);
        return registry;
    }
{code}



was (Author: superkool):
[~bbende] This is the problematic piece of code:
{code:java}
final String registryBaseUrl = uri.getScheme() + "://" + uri.getHost() + ":" + 
uri.getPort();
{code}

> NiFi Registry Config does not persist after a cluster restart
> -------------------------------------------------------------
>
>                 Key: NIFI-6767
>                 URL: https://issues.apache.org/jira/browse/NIFI-6767
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Flow Versioning
>    Affects Versions: 1.10.0, 1.9.2
>            Reporter: John E Fortin
>            Priority: Major
>         Attachments: registry-bad.png
>
>
> After configuring the NiFi Registery and versioning flows the Registry works 
> fine.  However, after restarting the NiFI cluster the Registry Config now has 
> "https://null:-1"; as the value for the Registry URL.  
> If I reconfigure the URL it works fine until the next Cluster restart.
> This has been happening since 1.9.1 (that I know of) and continues into 1.10
> It's not a show stopper, but is quite annoying



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to