use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class SslSelectChannelTimeoutTest method init.
@Before
public void init() throws Exception {
String keystorePath = System.getProperty("basedir", ".") + "/src/test/resources/keystore";
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(keystorePath);
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setKeyManagerPassword("keypwd");
sslContextFactory.setTrustStorePath(keystorePath);
sslContextFactory.setTrustStorePassword("storepwd");
ServerConnector connector = new ServerConnector(_server, 1, 1, sslContextFactory);
//250 msec max idle
connector.setIdleTimeout(MAX_IDLE_TIME);
startServer(connector);
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
try (InputStream stream = new FileInputStream(keystorePath)) {
keystore.load(stream, "storepwd".toCharArray());
}
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keystore);
__sslContext = SSLContext.getInstance("SSL");
__sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
}
use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class SSLCloseTest method testClose.
@Test
public void testClose() throws Exception {
File keystore = MavenTestingUtils.getTestResourceFile("keystore");
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStoreResource(Resource.newResource(keystore));
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setKeyManagerPassword("keypwd");
Server server = new Server();
ServerConnector connector = new ServerConnector(server, sslContextFactory);
connector.setPort(0);
server.addConnector(connector);
server.setHandler(new WriteHandler());
server.start();
SSLContext ctx = SSLContext.getInstance("TLSv1.2");
ctx.init(null, SslContextFactory.TRUST_ALL_CERTS, new java.security.SecureRandom());
int port = connector.getLocalPort();
Socket socket = ctx.getSocketFactory().createSocket("localhost", port);
OutputStream os = socket.getOutputStream();
os.write(("GET /test HTTP/1.1\r\n" + "Host:test\r\n" + "Connection:close\r\n\r\n").getBytes());
os.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
if (line.trim().length() == 0)
break;
}
Thread.sleep(2000);
while (in.readLine() != null) Thread.yield();
}
use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class SSLEngineTest method startServer.
@Before
public void startServer() throws Exception {
String keystore = MavenTestingUtils.getTestResourceFile("keystore").getAbsolutePath();
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(keystore);
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setKeyManagerPassword("keypwd");
server = new Server();
HttpConnectionFactory http = new HttpConnectionFactory();
http.setInputBufferSize(512);
http.getHttpConfiguration().setRequestHeaderSize(512);
connector = new ServerConnector(server, sslContextFactory, http);
connector.setPort(0);
connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setSendDateHeader(false);
server.addConnector(connector);
}
use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class SSLSelectChannelConnectorLoadTest method startServer.
@BeforeClass
public static void startServer() throws Exception {
String keystorePath = System.getProperty("basedir", ".") + "/src/test/resources/keystore";
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(keystorePath);
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setKeyManagerPassword("keypwd");
sslContextFactory.setTrustStorePath(keystorePath);
sslContextFactory.setTrustStorePassword("storepwd");
server = new Server();
connector = new ServerConnector(server, sslContextFactory);
server.addConnector(connector);
server.setHandler(new EmptyHandler());
server.start();
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
try (InputStream stream = new FileInputStream(keystorePath)) {
keystore.load(stream, "storepwd".toCharArray());
}
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keystore);
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
}
use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class AsyncContextListenersTest method prepare.
public void prepare(String path, HttpServlet servlet) throws Exception {
_server = new Server();
_connector = new ServerConnector(_server);
_server.addConnector(_connector);
ServletContextHandler context = new ServletContextHandler(_server, "/", false, false);
context.addServlet(new ServletHolder(servlet), path);
_server.start();
}
Aggregations