use of org.eclipse.jetty.util.log.StdErrLog in project jetty.project by eclipse.
the class WebSocketServletRFCTest method enableStacks.
/**
* @param clazz the class to enable
* @param enabled true to enable the stack traces (or not)
* @deprecated use {@link StacklessLogging} in a try-with-resources block instead
*/
@Deprecated
private void enableStacks(Class<?> clazz, boolean enabled) {
StdErrLog log = StdErrLog.getLogger(clazz);
log.setHideStacks(!enabled);
}
use of org.eclipse.jetty.util.log.StdErrLog in project jetty.project by eclipse.
the class TestServer method main.
public static void main(String[] args) throws Exception {
((StdErrLog) Log.getLog()).setSource(false);
String jetty_root = "../../..";
// Setup Threadpool
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(100);
// Setup server
Server server = new Server(threadPool);
server.manage(threadPool);
// Setup JMX
MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer);
server.addBean(Log.getLog());
// Common HTTP configuration
HttpConfiguration config = new HttpConfiguration();
config.setSecurePort(8443);
config.addCustomizer(new ForwardedRequestCustomizer());
config.addCustomizer(new SecureRequestCustomizer());
config.setSendDateHeader(true);
config.setSendServerVersion(true);
// Http Connector
HttpConnectionFactory http = new HttpConnectionFactory(config);
ServerConnector httpConnector = new ServerConnector(server, http);
httpConnector.setPort(8080);
httpConnector.setIdleTimeout(30000);
server.addConnector(httpConnector);
// Handlers
HandlerCollection handlers = new HandlerCollection();
ContextHandlerCollection contexts = new ContextHandlerCollection();
RequestLogHandler requestLogHandler = new RequestLogHandler();
handlers.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
// Add restart handler to test the ability to save sessions and restart
RestartHandler restart = new RestartHandler();
restart.setHandler(handlers);
server.setHandler(restart);
// Setup context
HashLoginService login = new HashLoginService();
login.setName("Test Realm");
login.setConfig(jetty_root + "/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/realm.properties");
server.addBean(login);
File log = File.createTempFile("jetty-yyyy_mm_dd", "log");
NCSARequestLog requestLog = new NCSARequestLog(log.toString());
requestLog.setExtended(false);
requestLogHandler.setRequestLog(requestLog);
server.setStopAtShutdown(true);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/test");
webapp.setParentLoaderPriority(true);
webapp.setResourceBase("./src/main/webapp");
webapp.setAttribute("testAttribute", "testValue");
File sessiondir = File.createTempFile("sessions", null);
if (sessiondir.exists())
sessiondir.delete();
sessiondir.mkdir();
sessiondir.deleteOnExit();
DefaultSessionCache ss = new DefaultSessionCache(webapp.getSessionHandler());
FileSessionDataStore sds = new FileSessionDataStore();
ss.setSessionDataStore(sds);
sds.setStoreDir(sessiondir);
webapp.getSessionHandler().setSessionCache(ss);
contexts.addHandler(webapp);
ContextHandler srcroot = new ContextHandler();
srcroot.setResourceBase(".");
srcroot.setHandler(new ResourceHandler());
srcroot.setContextPath("/src");
contexts.addHandler(srcroot);
server.start();
server.join();
}
use of org.eclipse.jetty.util.log.StdErrLog in project jetty.project by eclipse.
the class TestTransparentProxyServer method main.
public static void main(String[] args) throws Exception {
((StdErrLog) Log.getLog()).setSource(false);
String jetty_root = "../../..";
// Setup Threadpool
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(100);
// Setup server
Server server = new Server(threadPool);
server.manage(threadPool);
// Setup JMX
MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer);
server.addBean(Log.getLog());
// Common HTTP configuration
HttpConfiguration config = new HttpConfiguration();
config.setSecurePort(8443);
config.addCustomizer(new ForwardedRequestCustomizer());
config.setSendDateHeader(true);
config.setSendServerVersion(true);
// Http Connector
HttpConnectionFactory http = new HttpConnectionFactory(config);
ServerConnector httpConnector = new ServerConnector(server, http);
httpConnector.setPort(8080);
httpConnector.setIdleTimeout(30000);
server.addConnector(httpConnector);
// SSL configurations
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(jetty_root + "/jetty-server/src/main/config/etc/keystore");
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
sslContextFactory.setTrustStorePath(jetty_root + "/jetty-server/src/main/config/etc/keystore");
sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
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");
sslContextFactory.setCipherComparator(new HTTP2Cipher.CipherComparator());
// HTTPS Configuration
HttpConfiguration https_config = new HttpConfiguration(config);
https_config.addCustomizer(new SecureRequestCustomizer());
// HTTP2 factory
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(h2.getProtocol());
// SSL Factory
SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
// HTTP2 Connector
ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config));
http2Connector.setPort(8443);
http2Connector.setIdleTimeout(15000);
server.addConnector(http2Connector);
// Handlers
HandlerCollection handlers = new HandlerCollection();
ContextHandlerCollection contexts = new ContextHandlerCollection();
handlers.setHandlers(new Handler[] { contexts, new DefaultHandler() });
server.setHandler(handlers);
// Setup proxy webapp
WebAppContext webapp = new WebAppContext();
webapp.setResourceBase("src/main/webapp");
contexts.addHandler(webapp);
// start server
server.setStopAtShutdown(true);
server.start();
server.join();
}
use of org.eclipse.jetty.util.log.StdErrLog in project jetty.project by eclipse.
the class AbstractABCase method enableStacks.
/**
* @param clazz the class to enable
* @param enabled true to enable the stack traces (or not)
* @deprecated use {@link StacklessLogging} in a try-with-resources block instead
*/
@Deprecated
protected void enableStacks(Class<?> clazz, boolean enabled) {
StdErrLog log = StdErrLog.getLogger(clazz);
log.setHideStacks(!enabled);
}
use of org.eclipse.jetty.util.log.StdErrLog in project jetty.project by eclipse.
the class ManyConnectionsCleanupTest method testOpenSessionCleanup.
/**
* Test session open session cleanup (bug #474936)
*
* @throws Exception
* on test failure
*/
@Test
public void testOpenSessionCleanup() throws Exception {
int iterationCount = 100;
StdErrLog.getLogger(FastFailSocket.class).setLevel(StdErrLog.LEVEL_OFF);
StdErrLog sessLog = StdErrLog.getLogger(WebSocketSession.class);
int oldLevel = sessLog.getLevel();
sessLog.setLevel(StdErrLog.LEVEL_OFF);
for (int requests = 0; requests < iterationCount; requests++) {
fastFail();
fastClose();
dropConnection();
}
sessLog.setLevel(oldLevel);
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) {
client.setProtocols("container");
client.setTimeout(1, TimeUnit.SECONDS);
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.write(new TextFrame().setPayload("calls"));
client.write(new TextFrame().setPayload("openSessions"));
EventQueue<WebSocketFrame> frames = client.readFrames(3, 6, TimeUnit.SECONDS);
WebSocketFrame frame;
String resp;
frame = frames.poll();
assertThat("frames[0].opcode", frame.getOpCode(), is(OpCode.TEXT));
resp = frame.getPayloadAsUTF8();
assertThat("Should only have 1 open session", resp, containsString("calls=" + ((iterationCount * 2) + 1)));
frame = frames.poll();
assertThat("frames[1].opcode", frame.getOpCode(), is(OpCode.TEXT));
resp = frame.getPayloadAsUTF8();
assertThat("Should only have 1 open session", resp, containsString("openSessions.size=1\n"));
frame = frames.poll();
assertThat("frames[2].opcode", frame.getOpCode(), is(OpCode.CLOSE));
CloseInfo close = new CloseInfo(frame);
assertThat("Close Status Code", close.getStatusCode(), is(StatusCode.NORMAL));
// respond with close
client.write(close.asFrame());
// ensure server socket got close event
assertThat("Open Sessions Latch", closeSocket.closeLatch.await(1, TimeUnit.SECONDS), is(true));
assertThat("Open Sessions.statusCode", closeSocket.closeStatusCode, is(StatusCode.NORMAL));
assertThat("Open Sessions.errors", closeSocket.errors.size(), is(0));
}
}
Aggregations