use of org.eclipse.jetty.server.handler.DefaultHandler in project jetty.project by eclipse.
the class ServerConnectorTest method testReuseAddress_Default.
@Test
public void testReuseAddress_Default() throws Exception {
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.addConnector(connector);
HandlerList handlers = new HandlerList();
handlers.addHandler(new ReuseInfoHandler());
handlers.addHandler(new DefaultHandler());
server.setHandler(handlers);
try {
server.start();
URI uri = toServerURI(connector);
String response = getResponse(uri);
assertThat("Response", response, containsString("connector.getReuseAddress() = true"));
assertThat("Response", response, containsString("connector._reuseAddress() = true"));
// Java on Windows is incapable of propagating reuse-address this to the opened socket.
if (!OS.IS_WINDOWS) {
assertThat("Response", response, containsString("socket.getReuseAddress() = true"));
}
} finally {
server.stop();
}
}
use of org.eclipse.jetty.server.handler.DefaultHandler in project jetty.project by eclipse.
the class ServerConnectorTest method testReuseAddress_True.
@Test
public void testReuseAddress_True() throws Exception {
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
connector.setReuseAddress(true);
server.addConnector(connector);
HandlerList handlers = new HandlerList();
handlers.addHandler(new ReuseInfoHandler());
handlers.addHandler(new DefaultHandler());
server.setHandler(handlers);
try {
server.start();
URI uri = toServerURI(connector);
String response = getResponse(uri);
assertThat("Response", response, containsString("connector.getReuseAddress() = true"));
assertThat("Response", response, containsString("connector._reuseAddress() = true"));
// Java on Windows is incapable of propagating reuse-address this to the opened socket.
if (!OS.IS_WINDOWS) {
assertThat("Response", response, containsString("socket.getReuseAddress() = true"));
}
} finally {
server.stop();
}
}
use of org.eclipse.jetty.server.handler.DefaultHandler in project jetty.project by eclipse.
the class ServerConnectorTest method testReuseAddress_False.
@Test
public void testReuseAddress_False() throws Exception {
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
connector.setReuseAddress(false);
server.addConnector(connector);
HandlerList handlers = new HandlerList();
handlers.addHandler(new ReuseInfoHandler());
handlers.addHandler(new DefaultHandler());
server.setHandler(handlers);
try {
server.start();
URI uri = toServerURI(connector);
String response = getResponse(uri);
assertThat("Response", response, containsString("connector.getReuseAddress() = false"));
assertThat("Response", response, containsString("connector._reuseAddress() = false"));
// Java on Windows is incapable of propagating reuse-address this to the opened socket.
if (!OS.IS_WINDOWS) {
assertThat("Response", response, containsString("socket.getReuseAddress() = false"));
}
} finally {
server.stop();
}
}
use of org.eclipse.jetty.server.handler.DefaultHandler in project jetty.project by eclipse.
the class JettyHttpServerProvider method createHttpServer.
@Override
public HttpServer createHttpServer(InetSocketAddress addr, int backlog) throws IOException {
Server server = _server;
boolean shared = true;
if (server == null) {
ThreadPool threadPool = new DelegatingThreadPool(new QueuedThreadPool());
server = new Server(threadPool);
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { new ContextHandlerCollection(), new DefaultHandler() });
server.setHandler(handlerCollection);
shared = false;
}
JettyHttpServer jettyHttpServer = new JettyHttpServer(server, shared);
jettyHttpServer.bind(addr, backlog);
return jettyHttpServer;
}
use of org.eclipse.jetty.server.handler.DefaultHandler in project Openfire by igniterealtime.
the class AdminConsolePlugin method startup.
/**
* Starts the Jetty instance.
*/
public void startup() {
restartNeeded = false;
// Add listener for certificate events
certificateListener = new CertificateListener();
CertificateManager.addListener(certificateListener);
// the number of threads allocated to each connector/port
int serverThreads = JiveGlobals.getXMLProperty("adminConsole.serverThreads", 2);
adminPort = JiveGlobals.getXMLProperty("adminConsole.port", 9090);
adminSecurePort = JiveGlobals.getXMLProperty("adminConsole.securePort", 9091);
final QueuedThreadPool tp = new QueuedThreadPool();
tp.setName("Jetty-QTP-AdminConsole");
adminServer = new Server(tp);
if (JMXManager.isEnabled()) {
JMXManager jmx = JMXManager.getInstance();
adminServer.addBean(jmx.getContainer());
}
// Create connector for http traffic if it's enabled.
if (adminPort > 0) {
final HttpConfiguration httpConfig = new HttpConfiguration();
// Do not send Jetty info in HTTP headers
httpConfig.setSendServerVersion(false);
final ServerConnector httpConnector = new ServerConnector(adminServer, null, null, null, -1, serverThreads, new HttpConnectionFactory(httpConfig));
// Listen on a specific network interface if it has been set.
String bindInterface = getBindInterface();
httpConnector.setHost(bindInterface);
httpConnector.setPort(adminPort);
adminServer.addConnector(httpConnector);
}
// Create a connector for https traffic if it's enabled.
sslEnabled = false;
try {
IdentityStore identityStore = null;
if (XMPPServer.getInstance().getCertificateStoreManager() == null) {
Log.warn("Admin console: CertifcateStoreManager has not been initialized yet. HTTPS will be unavailable.");
} else {
identityStore = XMPPServer.getInstance().getCertificateStoreManager().getIdentityStore(ConnectionType.WEBADMIN);
}
if (identityStore != null && adminSecurePort > 0) {
if (identityStore.getAllCertificates().isEmpty()) {
Log.warn("Admin console: Identity store does not have any certificates. HTTPS will be unavailable.");
} else {
if (!identityStore.containsDomainCertificate("RSA")) {
Log.warn("Admin console: Using RSA certificates but they are not valid for the hosted domain");
}
final ConnectionManagerImpl connectionManager = ((ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager());
final ConnectionConfiguration configuration = connectionManager.getListener(ConnectionType.WEBADMIN, true).generateConnectionConfiguration();
final SslContextFactory sslContextFactory = new EncryptionArtifactFactory(configuration).getSslContextFactory();
final ServerConnector httpsConnector;
if ("npn".equals(JiveGlobals.getXMLProperty("spdy.protocol", ""))) {
httpsConnector = new HTTPSPDYServerConnector(adminServer, sslContextFactory);
} else {
final HttpConfiguration httpsConfig = new HttpConfiguration();
httpsConfig.setSendServerVersion(false);
httpsConfig.setSecureScheme("https");
httpsConfig.setSecurePort(adminSecurePort);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
final HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(httpsConfig);
final SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory, org.eclipse.jetty.http.HttpVersion.HTTP_1_1.toString());
httpsConnector = new ServerConnector(adminServer, null, null, null, -1, serverThreads, sslConnectionFactory, httpConnectionFactory);
}
final String bindInterface = getBindInterface();
httpsConnector.setHost(bindInterface);
httpsConnector.setPort(adminSecurePort);
adminServer.addConnector(httpsConnector);
sslEnabled = true;
}
}
} catch (Exception e) {
Log.error("An exception occurred while trying to make available the admin console via HTTPS.", e);
}
// Make sure that at least one connector was registered.
if (adminServer.getConnectors() == null || adminServer.getConnectors().length == 0) {
adminServer = null;
// Log warning.
log(LocaleUtils.getLocalizedString("admin.console.warning"));
return;
}
HandlerCollection collection = new HandlerCollection();
adminServer.setHandler(collection);
collection.setHandlers(new Handler[] { contexts, new DefaultHandler() });
try {
adminServer.start();
// Log the ports that the admin server is listening on.
logAdminConsolePorts();
} catch (Exception e) {
Log.error("Could not start admin console server", e);
}
}
Aggregations