Skip to content

Commit a0679e2

Browse files
committed
NIFI-15156 Update ListenHTTP to be a ListenComponent with a ListenPort
1 parent f215917 commit a0679e2

File tree

1 file changed

+61
-4
lines changed
  • nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard

1 file changed

+61
-4
lines changed

nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenHTTP.java

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
import org.apache.nifi.components.PropertyValue;
3838
import org.apache.nifi.components.ValidationContext;
3939
import org.apache.nifi.components.ValidationResult;
40+
import org.apache.nifi.components.listen.ListenComponent;
41+
import org.apache.nifi.components.listen.ListenPort;
42+
import org.apache.nifi.components.listen.StandardListenPort;
43+
import org.apache.nifi.components.listen.TransportProtocol;
44+
import org.apache.nifi.controller.ConfigurationContext;
4045
import org.apache.nifi.expression.ExpressionLanguageScope;
4146
import org.apache.nifi.flowfile.FlowFile;
4247
import org.apache.nifi.jetty.configuration.connector.StandardServerConnectorFactory;
@@ -140,7 +145,7 @@ and will be automatically unpacked. This will output the original FlowFile(s) fr
140145
""")
141146
}
142147
)
143-
public class ListenHTTP extends AbstractSessionFactoryProcessor {
148+
public class ListenHTTP extends AbstractSessionFactoryProcessor implements ListenComponent {
144149
private static final String MATCH_ALL = ".*";
145150

146151
private final AtomicBoolean initialized = new AtomicBoolean(false);
@@ -183,6 +188,7 @@ public AllowableValue getAllowableValue() {
183188
.name("Listening Port")
184189
.description("The Port to listen on for incoming connections")
185190
.required(true)
191+
.identifiesListenPort(TransportProtocol.TCP, "http/1.1", "h2")
186192
.expressionLanguageSupported(ExpressionLanguageScope.ENVIRONMENT)
187193
.addValidator(StandardValidators.PORT_VALIDATOR)
188194
.build();
@@ -198,6 +204,7 @@ public AllowableValue getAllowableValue() {
198204
"If the processor is set to use one-way SSL, one-way SSL will be used on this port. " +
199205
"If the processor is set to use two-way SSL, one-way SSL will be used on this port (client authentication not required).")
200206
.required(false)
207+
.identifiesListenPort(TransportProtocol.TCP, "http/1.1", "h2")
201208
.expressionLanguageSupported(ExpressionLanguageScope.ENVIRONMENT)
202209
.addValidator(StandardValidators.PORT_VALIDATOR)
203210
.build();
@@ -422,6 +429,43 @@ public void shutdownHttpServer() {
422429
shutdownHttpServer(toShutdown);
423430
}
424431

432+
@Override
433+
public List<ListenPort> getListenPorts(final ConfigurationContext context) {
434+
435+
final List<ListenPort> ports = new ArrayList<>();
436+
437+
final Integer primaryPortNumber = context.getProperty(PORT).evaluateAttributeExpressions().asInteger();
438+
final Integer healthCheckPortNumber = context.getProperty(HEALTH_CHECK_PORT).evaluateAttributeExpressions().asInteger();
439+
final SSLContextProvider sslContextProvider = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextProvider.class);
440+
final HttpProtocolStrategy httpProtocolStrategy = getHttpProtocolStrategy(context, sslContextProvider);
441+
final List<String> applicationProtocols = switch (httpProtocolStrategy) {
442+
case H2 -> List.of("h2");
443+
case HTTP_1_1 -> List.of("http/1.1");
444+
case H2_HTTP_1_1 -> List.of("h2", "http/1.1");
445+
case null -> List.of("h2", "http/1.1");
446+
};
447+
448+
if (primaryPortNumber != null) {
449+
final ListenPort primaryPort = StandardListenPort.builder()
450+
.portNumber(primaryPortNumber)
451+
.transportProtocol(TransportProtocol.TCP)
452+
.applicationProtocols(applicationProtocols)
453+
.build();
454+
ports.add(primaryPort);
455+
}
456+
457+
if (healthCheckPortNumber != null) {
458+
final ListenPort healthCheckPort = StandardListenPort.builder()
459+
.portNumber(healthCheckPortNumber)
460+
.transportProtocol(TransportProtocol.TCP)
461+
.applicationProtocols(applicationProtocols)
462+
.build();
463+
ports.add(healthCheckPort);
464+
}
465+
466+
return ports;
467+
}
468+
425469
Server getServer() {
426470
return this.server;
427471
}
@@ -461,9 +505,7 @@ synchronized private void createHttpServerFromService(final ProcessContext conte
461505

462506
// get the configured port
463507
final int port = context.getProperty(PORT).evaluateAttributeExpressions().asInteger();
464-
final HttpProtocolStrategy httpProtocolStrategy = sslContextProvider == null
465-
? HttpProtocolStrategy.valueOf(HTTP_PROTOCOL_STRATEGY.getDefaultValue())
466-
: context.getProperty(HTTP_PROTOCOL_STRATEGY).asAllowableValue(HttpProtocolStrategy.class);
508+
final HttpProtocolStrategy httpProtocolStrategy = getHttpProtocolStrategy(context, sslContextProvider);
467509
final ServerConnector connector = createServerConnector(server,
468510
port,
469511
requestHeaderSize,
@@ -541,6 +583,21 @@ synchronized private void createHttpServerFromService(final ProcessContext conte
541583
initialized.set(true);
542584
}
543585

586+
private static HttpProtocolStrategy getHttpProtocolStrategy(final ConfigurationContext context, final SSLContextProvider sslContextProvider) {
587+
return getHttpProtocolStrategy(context.getProperty(HTTP_PROTOCOL_STRATEGY).asAllowableValue(HttpProtocolStrategy.class), sslContextProvider);
588+
}
589+
590+
private static HttpProtocolStrategy getHttpProtocolStrategy(final ProcessContext context, final SSLContextProvider sslContextProvider) {
591+
return getHttpProtocolStrategy(context.getProperty(HTTP_PROTOCOL_STRATEGY).asAllowableValue(HttpProtocolStrategy.class), sslContextProvider);
592+
}
593+
594+
private static HttpProtocolStrategy getHttpProtocolStrategy(final HttpProtocolStrategy configuredProtocolStrategy, final SSLContextProvider sslContextProvider) {
595+
final HttpProtocolStrategy httpProtocolStrategy = sslContextProvider == null
596+
? HttpProtocolStrategy.valueOf(HTTP_PROTOCOL_STRATEGY.getDefaultValue())
597+
: configuredProtocolStrategy;
598+
return httpProtocolStrategy;
599+
}
600+
544601
private ClientAuthentication getClientAuthentication(final SSLContextProvider sslContextProvider,
545602
final ProcessContext context) {
546603
ClientAuthentication clientAuthentication = ClientAuthentication.NONE;

0 commit comments

Comments
 (0)