mirror of https://github.com/apache/nifi.git
NIFI-2609: Ensure that we handle URIs for Remote Process Groups that do not have a path of /nifi or /nifi/
This closes #902. Signed-off-by: Bryan Bende <bbende@apache.org>
This commit is contained in:
parent
95b5877f5d
commit
5fab783b50
|
@ -146,14 +146,17 @@ public class StandardRemoteProcessGroup implements RemoteProcessGroup {
|
|||
this.flowController = requireNonNull(flowController);
|
||||
final URI uri;
|
||||
try {
|
||||
uri = new URI(requireNonNull(targetUri));
|
||||
uri = new URI(requireNonNull(targetUri.trim()));
|
||||
|
||||
// Trim the trailing /
|
||||
String uriPath = uri.getPath();
|
||||
if (uriPath.endsWith("/")) {
|
||||
if (uriPath == null || uriPath.equals("/") || uriPath.trim().isEmpty()) {
|
||||
uriPath = "/nifi";
|
||||
} else if (uriPath.endsWith("/")) {
|
||||
uriPath = uriPath.substring(0, uriPath.length() - 1);
|
||||
}
|
||||
final String apiPath = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + uriPath + "-api";
|
||||
|
||||
final String apiPath = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + uriPath.trim() + "-api";
|
||||
apiUri = new URI(apiPath);
|
||||
} catch (final URISyntaxException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
|
@ -856,7 +859,7 @@ public class StandardRemoteProcessGroup implements RemoteProcessGroup {
|
|||
writeLock.unlock();
|
||||
}
|
||||
|
||||
throw new CommunicationsException("Unable to communicate with Remote NiFi at URI " + apiUri + " due to: " + e.getMessage());
|
||||
throw new CommunicationsException("Unable to communicate with Remote NiFi at URI " + getApiUri() + " due to: " + e.getMessage());
|
||||
}
|
||||
|
||||
writeLock.lock();
|
||||
|
@ -927,12 +930,16 @@ public class StandardRemoteProcessGroup implements RemoteProcessGroup {
|
|||
|
||||
private SiteToSiteRestApiClient getSiteToSiteRestApiClient() {
|
||||
SiteToSiteRestApiClient apiClient = new SiteToSiteRestApiClient(sslContext, new HttpProxy(proxyHost, proxyPort, proxyUser, proxyPassword));
|
||||
apiClient.setBaseUrl(apiUri.toString());
|
||||
apiClient.setBaseUrl(getApiUri());
|
||||
apiClient.setConnectTimeoutMillis(getCommunicationsTimeout(TimeUnit.MILLISECONDS));
|
||||
apiClient.setReadTimeoutMillis(getCommunicationsTimeout(TimeUnit.MILLISECONDS));
|
||||
return apiClient;
|
||||
}
|
||||
|
||||
protected String getApiUri() {
|
||||
return apiUri.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a set of ports into a set of remote process group ports.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* 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.remote;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.apache.nifi.controller.FlowController;
|
||||
import org.apache.nifi.groups.ProcessGroup;
|
||||
import org.apache.nifi.util.NiFiProperties;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
public class TestStandardRemoteProcessGroup {
|
||||
|
||||
@Test
|
||||
public void testApiUri() {
|
||||
final NiFiProperties properties = Mockito.mock(NiFiProperties.class);
|
||||
final FlowController controller = Mockito.mock(FlowController.class);
|
||||
final ProcessGroup group = Mockito.mock(ProcessGroup.class);
|
||||
|
||||
final String expectedUri = "http://localhost:8080/nifi-api";
|
||||
StandardRemoteProcessGroup rpg = new StandardRemoteProcessGroup("id", "http://localhost:8080/nifi", group, controller, null, properties);
|
||||
assertEquals(expectedUri, rpg.getApiUri());
|
||||
|
||||
rpg = new StandardRemoteProcessGroup("id", "http://localhost:8080/nifi/", group, controller, null, properties);
|
||||
assertEquals(expectedUri, rpg.getApiUri());
|
||||
|
||||
rpg = new StandardRemoteProcessGroup("id", "http://localhost:8080/nifi/ ", group, controller, null, properties);
|
||||
assertEquals(expectedUri, rpg.getApiUri());
|
||||
|
||||
rpg = new StandardRemoteProcessGroup("id", " http://localhost:8080/nifi/ ", group, controller, null, properties);
|
||||
assertEquals(expectedUri, rpg.getApiUri());
|
||||
|
||||
rpg = new StandardRemoteProcessGroup("id", "http://localhost:8080/", group, controller, null, properties);
|
||||
assertEquals(expectedUri, rpg.getApiUri());
|
||||
|
||||
rpg = new StandardRemoteProcessGroup("id", "http://localhost:8080", group, controller, null, properties);
|
||||
assertEquals(expectedUri, rpg.getApiUri());
|
||||
|
||||
rpg = new StandardRemoteProcessGroup("id", "http://localhost:8080 ", group, controller, null, properties);
|
||||
assertEquals(expectedUri, rpg.getApiUri());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue