use of org.eclipse.jetty.server.ConnectionFactory in project spark by perwendel.
the class SocketConnectorFactoryTest method testCreateSecureSocketConnector.
@Test
@PrepareForTest({ ServerConnector.class })
public void testCreateSecureSocketConnector() throws Exception {
final String host = "localhost";
final int port = 8888;
final String keystoreFile = "keystoreFile.jks";
final String keystorePassword = "keystorePassword";
final String truststoreFile = "truststoreFile.jks";
final String trustStorePassword = "trustStorePassword";
SslStores sslStores = SslStores.create(keystoreFile, keystorePassword, truststoreFile, trustStorePassword);
Server server = new Server();
ServerConnector serverConnector = SocketConnectorFactory.createSecureSocketConnector(server, host, port, sslStores);
String internalHost = Whitebox.getInternalState(serverConnector, "_host");
int internalPort = Whitebox.getInternalState(serverConnector, "_port");
assertEquals("Server Connector Host should be set to the specified server", host, internalHost);
assertEquals("Server Connector Port should be set to the specified port", port, internalPort);
Map<String, ConnectionFactory> factories = Whitebox.getInternalState(serverConnector, "_factories");
assertTrue("Should return true because factory for SSL should have been set", factories.containsKey("ssl") && factories.get("ssl") != null);
SslConnectionFactory sslConnectionFactory = (SslConnectionFactory) factories.get("ssl");
SslContextFactory sslContextFactory = sslConnectionFactory.getSslContextFactory();
assertEquals("Should return the Keystore file specified", keystoreFile, sslContextFactory.getKeyStoreResource().getFile().getName());
assertEquals("Should return the Truststore file specified", truststoreFile, sslContextFactory.getTrustStoreResource().getFile().getName());
}
use of org.eclipse.jetty.server.ConnectionFactory in project cxf by apache.
the class JettyHTTPServerEngineFactoryTest method testMakeSureJetty9ConnectorConfigured.
@Test
public void testMakeSureJetty9ConnectorConfigured() throws Exception {
URL config = getClass().getResource("server-engine-factory-jetty9-connector.xml");
bus = new SpringBusFactory().createBus(config, true);
JettyHTTPServerEngineFactory factory = bus.getExtension(JettyHTTPServerEngineFactory.class);
assertNotNull("EngineFactory is not configured.", factory);
JettyHTTPServerEngine engine = null;
engine = factory.createJettyHTTPServerEngine(1234, "http");
assertNotNull("Engine is not available.", engine);
assertEquals(1234, engine.getPort());
assertEquals("Not http", "http", engine.getProtocol());
Connector connector = engine.getConnector();
Collection<ConnectionFactory> connectionFactories = connector.getConnectionFactories();
assertEquals("Has one HttpConnectionFactory", 1, connectionFactories.size());
ConnectionFactory connectionFactory = connectionFactories.iterator().next();
assertTrue(connectionFactory instanceof HttpConnectionFactory);
HttpConfiguration httpConfiguration = ((HttpConnectionFactory) connectionFactory).getHttpConfiguration();
assertEquals("Has one ForwardedRequestCustomizer", 1, httpConfiguration.getCustomizers().size());
assertTrue(httpConfiguration.getCustomizers().iterator().next() instanceof org.eclipse.jetty.server.ForwardedRequestCustomizer);
}
use of org.eclipse.jetty.server.ConnectionFactory in project cxf by apache.
the class JettyHTTPServerEngine method createConnectorJetty.
AbstractConnector createConnectorJetty(SslContextFactory sslcf, String hosto, int porto, int major, int minor) {
AbstractConnector result = null;
try {
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSendServerVersion(getSendServerVersion());
HttpConnectionFactory httpFactory = new HttpConnectionFactory(httpConfig);
Collection<ConnectionFactory> connectionFactories = new ArrayList<>();
result = new org.eclipse.jetty.server.ServerConnector(server);
if (tlsServerParameters != null) {
httpConfig.addCustomizer(new org.eclipse.jetty.server.SecureRequestCustomizer());
SslConnectionFactory scf = new SslConnectionFactory(sslcf, "HTTP/1.1");
connectionFactories.add(scf);
String proto = (major > 9 || (major == 9 && minor >= 3)) ? "SSL" : "SSL-HTTP/1.1";
result.setDefaultProtocol(proto);
}
connectionFactories.add(httpFactory);
result.setConnectionFactories(connectionFactories);
if (getMaxIdleTime() > 0) {
result.setIdleTimeout(Long.valueOf(getMaxIdleTime()));
}
} catch (RuntimeException rex) {
throw rex;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
return result;
}
Aggregations