use of org.eclipse.jetty.webapp.Configuration in project nifi by apache.
the class JettyServer method configureConnectors.
private void configureConnectors(final Server server) throws ServerConfigurationException {
// create the http configuration
final HttpConfiguration httpConfiguration = new HttpConfiguration();
final int headerSize = DataUnit.parseDataSize(props.getWebMaxHeaderSize(), DataUnit.B).intValue();
httpConfiguration.setRequestHeaderSize(headerSize);
httpConfiguration.setResponseHeaderSize(headerSize);
if (props.getPort() != null) {
final Integer port = props.getPort();
if (port < 0 || (int) Math.pow(2, 16) <= port) {
throw new ServerConfigurationException("Invalid HTTP port: " + port);
}
logger.info("Configuring Jetty for HTTP on port: " + port);
final List<Connector> serverConnectors = Lists.newArrayList();
final Map<String, String> httpNetworkInterfaces = props.getHttpNetworkInterfaces();
if (httpNetworkInterfaces.isEmpty() || httpNetworkInterfaces.values().stream().filter(value -> !Strings.isNullOrEmpty(value)).collect(Collectors.toList()).isEmpty()) {
// create the connector
final ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration));
// set host and port
if (StringUtils.isNotBlank(props.getProperty(NiFiProperties.WEB_HTTP_HOST))) {
http.setHost(props.getProperty(NiFiProperties.WEB_HTTP_HOST));
}
http.setPort(port);
serverConnectors.add(http);
} else {
// add connectors for all IPs from http network interfaces
serverConnectors.addAll(Lists.newArrayList(httpNetworkInterfaces.values().stream().map(ifaceName -> {
NetworkInterface iface = null;
try {
iface = NetworkInterface.getByName(ifaceName);
} catch (SocketException e) {
logger.error("Unable to get network interface by name {}", ifaceName, e);
}
if (iface == null) {
logger.warn("Unable to find network interface named {}", ifaceName);
}
return iface;
}).filter(Objects::nonNull).flatMap(iface -> Collections.list(iface.getInetAddresses()).stream()).map(inetAddress -> {
// create the connector
final ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration));
// set host and port
http.setHost(inetAddress.getHostAddress());
http.setPort(port);
return http;
}).collect(Collectors.toList())));
}
// add all connectors
serverConnectors.forEach(server::addConnector);
}
if (props.getSslPort() != null) {
final Integer port = props.getSslPort();
if (port < 0 || (int) Math.pow(2, 16) <= port) {
throw new ServerConfigurationException("Invalid HTTPs port: " + port);
}
logger.info("Configuring Jetty for HTTPs on port: " + port);
final List<Connector> serverConnectors = Lists.newArrayList();
final Map<String, String> httpsNetworkInterfaces = props.getHttpsNetworkInterfaces();
if (httpsNetworkInterfaces.isEmpty() || httpsNetworkInterfaces.values().stream().filter(value -> !Strings.isNullOrEmpty(value)).collect(Collectors.toList()).isEmpty()) {
final ServerConnector https = createUnconfiguredSslServerConnector(server, httpConfiguration);
// set host and port
if (StringUtils.isNotBlank(props.getProperty(NiFiProperties.WEB_HTTPS_HOST))) {
https.setHost(props.getProperty(NiFiProperties.WEB_HTTPS_HOST));
}
https.setPort(port);
serverConnectors.add(https);
} else {
// add connectors for all IPs from https network interfaces
serverConnectors.addAll(Lists.newArrayList(httpsNetworkInterfaces.values().stream().map(ifaceName -> {
NetworkInterface iface = null;
try {
iface = NetworkInterface.getByName(ifaceName);
} catch (SocketException e) {
logger.error("Unable to get network interface by name {}", ifaceName, e);
}
if (iface == null) {
logger.warn("Unable to find network interface named {}", ifaceName);
}
return iface;
}).filter(Objects::nonNull).flatMap(iface -> Collections.list(iface.getInetAddresses()).stream()).map(inetAddress -> {
final ServerConnector https = createUnconfiguredSslServerConnector(server, httpConfiguration);
// set host and port
https.setHost(inetAddress.getHostAddress());
https.setPort(port);
return https;
}).collect(Collectors.toList())));
}
// add all connectors
serverConnectors.forEach(server::addConnector);
}
}
use of org.eclipse.jetty.webapp.Configuration in project shiro by apache.
the class AbstractContainerIT method startContainer.
@BeforeClass
public static void startContainer() throws Exception {
EmbeddedJettyConfiguration config = EmbeddedJettyConfiguration.builder().withWebapp(getWarDir()).build();
jetty = new EmbeddedJetty(config) {
/**
* Overriding with contents of this pull request, to make fragment scanning work.
* https://github.com/mjeanroy/junit-servers/pull/3
*/
protected WebAppContext createdWebAppContext() throws Exception {
final String path = configuration.getPath();
final String webapp = configuration.getWebapp();
final String classpath = configuration.getClasspath();
WebAppContext ctx = new WebAppContext();
ctx.setClassLoader(Thread.currentThread().getContextClassLoader());
ctx.setContextPath(path);
// Useful for WebXmlConfiguration
ctx.setBaseResource(newResource(webapp));
ctx.setConfigurations(new Configuration[] { new WebInfConfiguration(), new WebXmlConfiguration(), new AnnotationConfiguration(), new JettyWebXmlConfiguration(), new MetaInfConfiguration(), new FragmentConfiguration() });
if (isNotBlank(classpath)) {
// Fix to scan Spring WebApplicationInitializer
// This will add compiled classes to jetty classpath
// See: http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration
// And more precisely: http://stackoverflow.com/a/18449506/1215828
File classes = new File(classpath);
FileResource containerResources = new FileResource(classes.toURI());
ctx.getMetaData().addContainerResource(containerResources);
}
Server server = getDelegate();
ctx.setParentLoaderPriority(true);
ctx.setWar(webapp);
ctx.setServer(server);
// Add server context
server.setHandler(ctx);
return ctx;
}
};
jetty.start();
assertTrue(jetty.isStarted());
}
use of org.eclipse.jetty.webapp.Configuration in project spring-boot by spring-projects.
the class JettyServletWebServerFactoryTests method mockConfiguration.
Configuration mockConfiguration(Class<? extends Configuration> type) {
Configuration mock = mock(type);
ClassMatcher classMatcher = new ClassMatcher();
given(mock.getSystemClasses()).willReturn(classMatcher);
given(mock.getServerClasses()).willReturn(classMatcher);
return mock;
}
use of org.eclipse.jetty.webapp.Configuration in project spring-boot by spring-projects.
the class JettyServletWebServerFactoryTests method jettyConfigurations.
@Test
void jettyConfigurations() throws Exception {
JettyServletWebServerFactory factory = getFactory();
Configuration[] configurations = new Configuration[] { mockConfiguration(Configuration1.class), mockConfiguration(Configuration2.class), mockConfiguration(Configuration3.class), mockConfiguration(Configuration4.class) };
factory.setConfigurations(Arrays.asList(configurations[0], configurations[1]));
factory.addConfigurations(configurations[2], configurations[3]);
this.webServer = factory.getWebServer();
InOrder ordered = inOrder((Object[]) configurations);
for (Configuration configuration : configurations) {
ordered.verify(configuration).configure(any(WebAppContext.class));
}
}
Aggregations