use of org.eclipse.jetty.server.HttpConfiguration in project cxf by apache.
the class JettyHTTPServerEngineTest method testSetConnector.
@Test
public void testSetConnector() throws Exception {
URL url = new URL("http://localhost:" + PORT4 + "/hello/test");
JettyHTTPTestHandler handler1 = new JettyHTTPTestHandler("string1", true);
JettyHTTPTestHandler handler2 = new JettyHTTPTestHandler("string2", true);
JettyHTTPServerEngine engine = new JettyHTTPServerEngine();
engine.setPort(PORT4);
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(PORT4);
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.addCustomizer(new org.eclipse.jetty.server.ForwardedRequestCustomizer());
HttpConnectionFactory httpFactory = new HttpConnectionFactory(httpConfig);
Collection<ConnectionFactory> connectionFactories = new ArrayList<>();
connectionFactories.add(httpFactory);
connector.setConnectionFactories(connectionFactories);
engine.setConnector(connector);
List<Handler> handlers = new ArrayList<>();
handlers.add(handler1);
engine.setHandlers(handlers);
engine.finalizeConfig();
engine.addServant(url, handler2);
String response = null;
try {
response = getResponse(url.toString());
assertEquals("the jetty http handler1 did not take effect", response, "string1string2");
} catch (Exception ex) {
fail("Can't get the reponse from the server " + ex);
}
engine.stop();
JettyHTTPServerEngineFactory.destroyForPort(PORT4);
}
use of org.eclipse.jetty.server.HttpConfiguration in project scheduling by ow2-proactive.
the class ErrorCases method startHttpsServer.
@BeforeClass
public static void startHttpsServer() throws Exception {
skipIfHeadlessEnvironment();
server = new Server();
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(ErrorCases.class.getResource("keystore").getPath());
sslContextFactory.setKeyStorePassword("activeeon");
HttpConfiguration httpConfig = new HttpConfiguration();
HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
ServerConnector sslConnector = new ServerConnector(server, new ConnectionFactory[] { new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig) });
server.addConnector(sslConnector);
server.start();
serverUrl = "https://localhost:" + sslConnector.getLocalPort() + "/rest";
}
use of org.eclipse.jetty.server.HttpConfiguration in project athenz by yahoo.
the class AthenzJettyContainer method addHTTPSConnector.
void addHTTPSConnector(HttpConfiguration httpConfig, int httpsPort, boolean proxyProtocol, String listenHost, int idleTimeout, boolean needClientAuth) {
// SSL Context Factory
SslContextFactory sslContextFactory = createSSLContextObject(needClientAuth);
// SSL HTTP Configuration
HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
httpsConfig.setSecureScheme("https");
httpsConfig.setSecurePort(httpsPort);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
// SSL Connector
ServerConnector sslConnector = null;
if (proxyProtocol) {
sslConnector = new ServerConnector(server, new ProxyConnectionFactory(), new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
} else {
sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
}
sslConnector.setPort(httpsPort);
sslConnector.setIdleTimeout(idleTimeout);
server.addConnector(sslConnector);
}
use of org.eclipse.jetty.server.HttpConfiguration in project athenz by yahoo.
the class AthenzJettyContainer method createJettyContainer.
public static AthenzJettyContainer createJettyContainer() {
AthenzJettyContainer container = null;
// retrieve our http and https port numbers
int httpPort = ConfigProperties.getPortNumber(AthenzConsts.ATHENZ_PROP_HTTP_PORT, AthenzConsts.ATHENZ_HTTP_PORT_DEFAULT);
int httpsPort = ConfigProperties.getPortNumber(AthenzConsts.ATHENZ_PROP_HTTPS_PORT, AthenzConsts.ATHENZ_HTTPS_PORT_DEFAULT);
// for status port we'll use the protocol specified for the regular http
// port. if both http and https are provided then https will be picked
// it could also be either one of the values specified as well
int statusPort = ConfigProperties.getPortNumber(AthenzConsts.ATHENZ_PROP_STATUS_PORT, 0);
String serverHostName = getServerHostName();
container = new AthenzJettyContainer();
container.setBanner("http://" + serverHostName + " http port: " + httpPort + " https port: " + httpsPort + " status port: " + statusPort);
int maxThreads = Integer.parseInt(System.getProperty(AthenzConsts.ATHENZ_PROP_MAX_THREADS, Integer.toString(AthenzConsts.ATHENZ_HTTP_MAX_THREADS)));
container.createServer(maxThreads);
HttpConfiguration httpConfig = container.newHttpConfiguration();
container.addHTTPConnectors(httpConfig, httpPort, httpsPort, statusPort);
container.addServletHandlers(serverHostName);
container.addRequestLogHandler();
return container;
}
use of org.eclipse.jetty.server.HttpConfiguration in project athenz by yahoo.
the class AthenzJettyContainerTest method testHttpConfigurationValidHttpsPort.
@Test
public void testHttpConfigurationValidHttpsPort() {
AthenzJettyContainer container = new AthenzJettyContainer();
container.createServer(100);
System.setProperty(AthenzConsts.ATHENZ_PROP_SEND_SERVER_VERSION, "true");
System.setProperty(AthenzConsts.ATHENZ_PROP_SEND_DATE_HEADER, "false");
System.setProperty(AthenzConsts.ATHENZ_PROP_OUTPUT_BUFFER_SIZE, "128");
System.setProperty(AthenzConsts.ATHENZ_PROP_REQUEST_HEADER_SIZE, "256");
System.setProperty(AthenzConsts.ATHENZ_PROP_RESPONSE_HEADER_SIZE, "512");
HttpConfiguration httpConfig = container.newHttpConfiguration();
assertNotNull(httpConfig);
assertEquals(httpConfig.getOutputBufferSize(), 128);
assertFalse(httpConfig.getSendDateHeader());
assertTrue(httpConfig.getSendServerVersion());
assertEquals(httpConfig.getRequestHeaderSize(), 256);
assertEquals(httpConfig.getResponseHeaderSize(), 512);
// it defaults to https even if we have no value specified
assertEquals(httpConfig.getSecureScheme(), "https");
}
Aggregations