/** * Configures an HTTP connector and adds it to the server. * * @param server the Jetty server instance * @param httpConfiguration the configuration object for the HTTP protocol settings */ private void configureHttpConnector(Server server, HttpConfiguration httpConfiguration) { String hostname = props.getProperty(NiFiProperties.WEB_HTTP_HOST); final Integer port = props.getPort(); String connectorLabel = "HTTP"; final Map<String, String> httpNetworkInterfaces = props.getHttpNetworkInterfaces(); ServerConnectorCreator<Server, HttpConfiguration, ServerConnector> scc = (s, c) -> new ServerConnector(s, new HttpConnectionFactory(c)); configureGenericConnector(server, httpConfiguration, hostname, port, connectorLabel, httpNetworkInterfaces, scc); }
/** * Extracts the list of IP addresses from custom bound network interfaces. If both HTTPS and HTTP interfaces are * defined and HTTPS is enabled, only HTTPS interfaces will be returned. If none are defined, an empty list will be * returned. * * @param niFiProperties the NiFiProperties object * @return the list of IP addresses */ static List<String> extractIPsFromNetworkInterfaces(NiFiProperties niFiProperties) { Map<String, String> networkInterfaces = niFiProperties.isHTTPSConfigured() ? niFiProperties.getHttpsNetworkInterfaces() : niFiProperties.getHttpNetworkInterfaces(); if (isNotDefined(networkInterfaces)) { // No custom interfaces defined return new ArrayList<>(0); } else { List<String> allIPAddresses = new ArrayList<>(); for (Map.Entry<String, String> entry : networkInterfaces.entrySet()) { final String networkInterfaceName = entry.getValue(); try { NetworkInterface ni = NetworkInterface.getByName(networkInterfaceName); List<String> ipAddresses = Collections.list(ni.getInetAddresses()).stream().map(inetAddress -> inetAddress.getHostAddress().toLowerCase()).collect(Collectors.toList()); logger.debug("Resolved the following IP addresses for network interface {}: {}", new Object[]{networkInterfaceName, StringUtils.join(ipAddresses, ", ")}); allIPAddresses.addAll(ipAddresses); } catch (SocketException e) { logger.warn("Cannot resolve network interface named " + networkInterfaceName); } } // Dedupe while maintaining order return uniqueList(allIPAddresses); } }