use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.
the class ResourceHandlerTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
File dir = MavenTestingUtils.getTargetFile("test-classes/simple");
File bigger = new File(dir, "bigger.txt");
File big = new File(dir, "big.txt");
try (OutputStream out = new FileOutputStream(bigger)) {
for (int i = 0; i < 100; i++) {
try (InputStream in = new FileInputStream(big)) {
IO.copy(in, out);
}
}
}
bigger.deleteOnExit();
// determine how the SCM of choice checked out the big.txt EOL
// we can't just use whatever is the OS default.
// because, for example, a windows system using git can be configured for EOL handling using
// local, remote, file lists, patterns, etc, rendering assumptions about the OS EOL choice
// wrong for unit tests.
LN = System.getProperty("line.separator");
try (BufferedReader reader = Files.newBufferedReader(big.toPath(), StandardCharsets.UTF_8)) {
// a buffer large enough to capture at least 1 EOL
char[] cbuf = new char[128];
reader.read(cbuf);
String sample = new String(cbuf);
if (sample.contains("\r\n")) {
LN = "\r\n";
} else if (sample.contains("\n\r")) {
LN = "\n\r";
} else {
LN = "\n";
}
}
_server = new Server();
_config = new HttpConfiguration();
_config.setOutputBufferSize(2048);
_connector = new ServerConnector(_server, new HttpConnectionFactory(_config));
_local = new LocalConnector(_server);
_server.setConnectors(new Connector[] { _connector, _local });
_resourceHandler = new ResourceHandler();
_resourceHandler.setResourceBase(MavenTestingUtils.getTargetFile("test-classes/simple").getAbsolutePath());
_resourceHandler.setWelcomeFiles(new String[] { "welcome.txt" });
_contextHandler = new ContextHandler("/resource");
_contextHandler.setHandler(_resourceHandler);
_server.setHandler(_contextHandler);
_server.start();
}
use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.
the class SimpleServletServer method start.
public void start() throws Exception {
// Configure Server
server = new Server();
if (ssl) {
// HTTP Configuration
HttpConfiguration http_config = new HttpConfiguration();
http_config.setSecureScheme("https");
http_config.setSecurePort(0);
http_config.setOutputBufferSize(32768);
http_config.setRequestHeaderSize(8192);
http_config.setResponseHeaderSize(8192);
http_config.setSendServerVersion(true);
http_config.setSendDateHeader(false);
sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(MavenTestingUtils.getTestResourceFile("keystore").getAbsolutePath());
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setKeyManagerPassword("keypwd");
sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA", "SSL_DHE_RSA_WITH_DES_CBC_SHA", "SSL_DHE_DSS_WITH_DES_CBC_SHA", "SSL_RSA_EXPORT_WITH_RC4_40_MD5", "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
// SSL HTTP Configuration
HttpConfiguration https_config = new HttpConfiguration(http_config);
https_config.addCustomizer(new SecureRequestCustomizer());
// SSL Connector
connector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config));
connector.setPort(0);
} else {
// Basic HTTP connector
connector = new ServerConnector(server);
connector.setPort(0);
}
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
configureServletContextHandler(context);
server.setHandler(context);
// Serve capture servlet
context.addServlet(new ServletHolder(servlet), "/*");
// Start Server
server.start();
// Establish the Server URI
String host = connector.getHost();
if (host == null) {
host = "localhost";
}
int port = connector.getLocalPort();
serverUri = new URI(String.format("%s://%s:%d/", ssl ? "wss" : "ws", host, port));
// Some debugging
if (LOG.isDebugEnabled()) {
LOG.debug(server.dump());
}
}
use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.
the class JDK9ALPNTest method startServer.
public void startServer(Handler handler) throws Exception {
server = new Server();
HttpConfiguration httpConfiguration = new HttpConfiguration();
HttpConnectionFactory h1 = new HttpConnectionFactory(httpConfiguration);
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpConfiguration);
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(h1.getProtocol());
connector = new ServerConnector(server, newSslContextFactory(), alpn, h1, h2);
server.addConnector(connector);
server.setHandler(handler);
server.start();
}
use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.
the class JDK9HTTP2Server method main.
public static void main(String... args) throws Exception {
Server server = new Server();
HttpConfiguration httpsConfig = new HttpConfiguration();
httpsConfig.setSecureScheme("https");
httpsConfig.setSecurePort(8443);
httpsConfig.setSendXPoweredBy(true);
httpsConfig.setSendServerVersion(true);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
HttpConnectionFactory http = new HttpConnectionFactory(httpsConfig);
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpsConfig);
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(http.getProtocol());
SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, http);
http2Connector.setPort(8443);
server.addConnector(http2Connector);
server.start();
}
use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.
the class RewriteServer method main.
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
HttpConfiguration config = server.getConnectors()[0].getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration();
RewriteCustomizer rewrite = new RewriteCustomizer();
config.addCustomizer(rewrite);
rewrite.addRule(new CompactPathRule());
rewrite.addRule(new RewriteRegexRule("(.*)foo(.*)", "$1FOO$2"));
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
context.addServlet(DumpServlet.class, "/*");
server.start();
server.join();
}
Aggregations