use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class IncludedServletTest method startServer.
@Before
public void startServer() throws Exception {
this.server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setHost("localhost");
connector.setPort(0);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.addServlet(TopServlet.class, "/top");
context.addServlet(IncludedServlet.class, "/included");
server.setHandler(context);
server.start();
int port = connector.getLocalPort();
String host = connector.getHost();
baseUri = URI.create("http://" + host + ":" + port + "/");
}
use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class RequestURITest method startServer.
@BeforeClass
public static void startServer() throws Exception {
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
server.setHandler(context);
context.addServlet(RequestUriServlet.class, "/*");
server.start();
String host = connector.getHost();
if (host == null) {
host = "localhost";
}
int port = connector.getLocalPort();
serverURI = new URI(String.format("http://%s:%d/", host, port));
}
use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class ServletTester method createConnector.
/** Create a port based connector.
* This methods adds a port connector to the server
* @param localhost true if connector should use localhost, false for default host behavior.
* @return A URL to access the server via the connector.
* @throws Exception on test failure
*/
public String createConnector(boolean localhost) throws Exception {
ServerConnector connector = new ServerConnector(_server);
if (localhost)
connector.setHost("127.0.0.1");
_server.addConnector(connector);
if (_server.isStarted())
connector.start();
else
connector.open();
return "http://" + (localhost ? "127.0.0.1" : InetAddress.getLocalHost().getHostAddress()) + ":" + connector.getLocalPort();
}
use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class DigestPostTest method setUpServer.
@BeforeClass
public static void setUpServer() {
try {
_server = new Server();
_server.setConnectors(new Connector[] { new ServerConnector(_server) });
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SECURITY);
context.setContextPath("/test");
context.addServlet(PostServlet.class, "/");
TestLoginService realm = new TestLoginService("test");
realm.putUser("testuser", new Password("password"), new String[] { "test" });
_server.addBean(realm);
ConstraintSecurityHandler security = (ConstraintSecurityHandler) context.getSecurityHandler();
security.setAuthenticator(new DigestAuthenticator());
security.setLoginService(realm);
Constraint constraint = new Constraint("SecureTest", "test");
constraint.setAuthenticate(true);
ConstraintMapping mapping = new ConstraintMapping();
mapping.setConstraint(constraint);
mapping.setPathSpec("/*");
security.setConstraintMappings(Collections.singletonList(mapping));
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[] { context, new DefaultHandler() });
_server.setHandler(handlers);
_server.start();
} catch (final Exception e) {
e.printStackTrace();
}
}
use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class HttpInputIntegrationTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
__config = new HttpConfiguration();
__server = new Server();
LocalConnector local = new LocalConnector(__server, new HttpConnectionFactory(__config));
local.setIdleTimeout(4000);
__server.addConnector(local);
ServerConnector http = new ServerConnector(__server, new HttpConnectionFactory(__config), new HTTP2CServerConnectionFactory(__config));
http.setIdleTimeout(4000);
__server.addConnector(http);
// SSL Context Factory for HTTPS and HTTP/2
String jetty_distro = System.getProperty("jetty.distro", "../../jetty-distribution/target/distribution");
__sslContextFactory = new SslContextFactory();
__sslContextFactory.setKeyStorePath(jetty_distro + "/../../../jetty-server/src/test/config/etc/keystore");
__sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
__sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
// HTTPS Configuration
__sslConfig = new HttpConfiguration(__config);
__sslConfig.addCustomizer(new SecureRequestCustomizer());
// HTTP/1 Connection Factory
HttpConnectionFactory h1 = new HttpConnectionFactory(__sslConfig);
/* TODO
// HTTP/2 Connection Factory
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(__sslConfig);
NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(h1.getProtocol());
*/
// SSL Connection Factory
SslConnectionFactory ssl = new SslConnectionFactory(__sslContextFactory, h1.getProtocol());
// HTTP/2 Connector
ServerConnector http2 = new ServerConnector(__server, ssl, /*TODO alpn,h2,*/
h1);
http2.setIdleTimeout(4000);
__server.addConnector(http2);
ServletContextHandler context = new ServletContextHandler(__server, "/ctx");
ServletHolder holder = new ServletHolder(new TestServlet());
holder.setAsyncSupported(true);
context.addServlet(holder, "/*");
__server.start();
}
Aggregations