use of org.eclipse.jetty.server.RequestLog in project jetty.project by eclipse.
the class AsyncServletTest method setUp.
@Before
public void setUp() throws Exception {
_connector = new ServerConnector(_server);
_server.setConnectors(new Connector[] { _connector });
_log = new ArrayList<>();
RequestLog log = new Log();
RequestLogHandler logHandler = new RequestLogHandler();
logHandler.setRequestLog(log);
_server.setHandler(logHandler);
_expectedLogs = 1;
_expectedCode = "200 ";
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/ctx");
logHandler.setHandler(context);
context.addEventListener(new DebugListener());
_errorHandler = new ErrorPageErrorHandler();
context.setErrorHandler(_errorHandler);
_errorHandler.addErrorPage(300, 599, "/error/custom");
_servletHandler = context.getServletHandler();
ServletHolder holder = new ServletHolder(_servlet);
holder.setAsyncSupported(true);
_servletHandler.addServletWithMapping(holder, "/error/*");
_servletHandler.addServletWithMapping(holder, "/path/*");
_servletHandler.addServletWithMapping(holder, "/path1/*");
_servletHandler.addServletWithMapping(holder, "/path2/*");
_servletHandler.addServletWithMapping(holder, "/p th3/*");
_servletHandler.addServletWithMapping(new ServletHolder(new FwdServlet()), "/fwd/*");
ServletHolder holder2 = new ServletHolder("NoAsync", _servlet);
holder2.setAsyncSupported(false);
_servletHandler.addServletWithMapping(holder2, "/noasync/*");
_server.start();
_port = _connector.getLocalPort();
__history.clear();
__latch = new CountDownLatch(1);
}
use of org.eclipse.jetty.server.RequestLog in project hbase by apache.
the class TestHttpRequestLog method testAppenderUndefined.
@Test
public void testAppenderUndefined() {
RequestLog requestLog = HttpRequestLog.getRequestLog("test");
assertNull("RequestLog should be null", requestLog);
}
use of org.eclipse.jetty.server.RequestLog in project hadoop by apache.
the class TestHttpRequestLog method testAppenderDefined.
@Test
public void testAppenderDefined() {
HttpRequestLogAppender requestLogAppender = new HttpRequestLogAppender();
requestLogAppender.setName("testrequestlog");
Logger.getLogger("http.requests.test").addAppender(requestLogAppender);
RequestLog requestLog = HttpRequestLog.getRequestLog("test");
Logger.getLogger("http.requests.test").removeAppender(requestLogAppender);
assertNotNull("RequestLog should not be null", requestLog);
assertEquals("Class mismatch", NCSARequestLog.class, requestLog.getClass());
}
use of org.eclipse.jetty.server.RequestLog in project hadoop by apache.
the class HttpRequestLog method getRequestLog.
public static RequestLog getRequestLog(String name) {
String lookup = serverToComponent.get(name);
if (lookup != null) {
name = lookup;
}
String loggerName = "http.requests." + name;
String appenderName = name + "requestlog";
Log logger = LogFactory.getLog(loggerName);
boolean isLog4JLogger;
;
try {
isLog4JLogger = logger instanceof Log4JLogger;
} catch (NoClassDefFoundError err) {
// In some dependent projects, log4j may not even be on the classpath at
// runtime, in which case the above instanceof check will throw
// NoClassDefFoundError.
LOG.debug("Could not load Log4JLogger class", err);
isLog4JLogger = false;
}
if (isLog4JLogger) {
Log4JLogger httpLog4JLog = (Log4JLogger) logger;
Logger httpLogger = httpLog4JLog.getLogger();
Appender appender = null;
try {
appender = httpLogger.getAppender(appenderName);
} catch (LogConfigurationException e) {
LOG.warn("Http request log for " + loggerName + " could not be created");
throw e;
}
if (appender == null) {
LOG.info("Http request log for " + loggerName + " is not defined");
return null;
}
if (appender instanceof HttpRequestLogAppender) {
HttpRequestLogAppender requestLogAppender = (HttpRequestLogAppender) appender;
NCSARequestLog requestLog = new NCSARequestLog();
requestLog.setFilename(requestLogAppender.getFilename());
requestLog.setRetainDays(requestLogAppender.getRetainDays());
return requestLog;
} else {
LOG.warn("Jetty request log for " + loggerName + " was of the wrong class");
return null;
}
} else {
LOG.warn("Jetty request log can only be enabled using Log4j");
return null;
}
}
use of org.eclipse.jetty.server.RequestLog in project hadoop by apache.
the class HttpServer2 method initializeWebServer.
private void initializeWebServer(String name, String hostName, Configuration conf, String[] pathSpecs) throws IOException {
Preconditions.checkNotNull(webAppContext);
int maxThreads = conf.getInt(HTTP_MAX_THREADS_KEY, -1);
// If HTTP_MAX_THREADS is not configured, QueueThreadPool() will use the
// default value (currently 250).
QueuedThreadPool threadPool = (QueuedThreadPool) webServer.getThreadPool();
threadPool.setDaemon(true);
if (maxThreads != -1) {
threadPool.setMaxThreads(maxThreads);
}
SessionManager sm = webAppContext.getSessionHandler().getSessionManager();
if (sm instanceof AbstractSessionManager) {
AbstractSessionManager asm = (AbstractSessionManager) sm;
asm.setHttpOnly(true);
asm.getSessionCookieConfig().setSecure(true);
}
ContextHandlerCollection contexts = new ContextHandlerCollection();
RequestLog requestLog = HttpRequestLog.getRequestLog(name);
handlers.addHandler(contexts);
if (requestLog != null) {
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(requestLog);
handlers.addHandler(requestLogHandler);
}
handlers.addHandler(webAppContext);
final String appDir = getWebAppsPath(name);
addDefaultApps(contexts, appDir, conf);
webServer.setHandler(handlers);
Map<String, String> xFrameParams = new HashMap<>();
xFrameParams.put(X_FRAME_ENABLED, String.valueOf(this.xFrameOptionIsEnabled));
xFrameParams.put(X_FRAME_VALUE, this.xFrameOption.toString());
addGlobalFilter("safety", QuotingInputFilter.class.getName(), xFrameParams);
final FilterInitializer[] initializers = getFilterInitializers(conf);
if (initializers != null) {
conf = new Configuration(conf);
conf.set(BIND_ADDRESS, hostName);
for (FilterInitializer c : initializers) {
c.initFilter(this, conf);
}
}
addDefaultServlets();
if (pathSpecs != null) {
for (String path : pathSpecs) {
LOG.info("adding path spec: " + path);
addFilterPathMapping(path, webAppContext);
}
}
}
Aggregations