use of org.eclipse.jetty.server.RequestLog in project hbase by apache.
the class HttpServer method initializeWebServer.
private void initializeWebServer(String name, String hostName, Configuration conf, String[] pathSpecs) throws FileNotFoundException, IOException {
Preconditions.checkNotNull(webAppContext);
HandlerCollection handlerCollection = new HandlerCollection();
ContextHandlerCollection contexts = new ContextHandlerCollection();
RequestLog requestLog = HttpRequestLog.getRequestLog(name);
if (requestLog != null) {
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(requestLog);
handlerCollection.addHandler(requestLogHandler);
}
final String appDir = getWebAppsPath(name);
handlerCollection.addHandler(contexts);
handlerCollection.addHandler(webAppContext);
webServer.setHandler(handlerCollection);
addDefaultApps(contexts, appDir, conf);
addGlobalFilter("safety", QuotingInputFilter.class.getName(), null);
Map<String, String> params = new HashMap<>();
params.put("xframeoptions", conf.get("hbase.http.filter.xframeoptions.mode", "DENY"));
addGlobalFilter("clickjackingprevention", ClickjackingPreventionFilter.class.getName(), params);
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);
}
}
}
use of org.eclipse.jetty.server.RequestLog in project hadoop 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 athenz by yahoo.
the class AthenzJettyContainerTest method testSlf4jRequestLogHandler.
@Test
public void testSlf4jRequestLogHandler() {
System.setProperty(AthenzConsts.ATHENZ_PROP_ACCESS_SLF4J_LOGGER, "AthenzAccessLogger");
AthenzJettyContainer container = new AthenzJettyContainer();
container.createServer(100);
container.addRequestLogHandler();
// now retrieve the request log handler
Handler[] handlers = container.getHandlers().getHandlers();
RequestLogHandler logHandler = null;
for (Handler handler : handlers) {
if (handler instanceof RequestLogHandler) {
logHandler = (RequestLogHandler) handler;
break;
}
}
assertNotNull(logHandler);
RequestLog reqLog = logHandler.getRequestLog();
assertNotNull(reqLog);
assertEquals(reqLog.getClass(), Slf4jRequestLog.class);
assertEquals(((Slf4jRequestLog) reqLog).getLoggerName(), "AthenzAccessLogger");
System.clearProperty(AthenzConsts.ATHENZ_PROP_ACCESS_SLF4J_LOGGER);
}
use of org.eclipse.jetty.server.RequestLog in project felix by apache.
the class RequestLogTrackerTest method testInvokeRequestLog.
@Test
public void testInvokeRequestLog() throws Exception {
RequestLogTracker tracker = new RequestLogTracker(context, null);
RequestLog mockRequestLog = mock(RequestLog.class);
ServiceReference<RequestLog> mockSvcRef = mock(ServiceReference.class);
when(context.getService(mockSvcRef)).thenReturn(mockRequestLog);
// These invocations not passed through to the mock because it is not registered yet
for (int i = 0; i < 10; i++) tracker.log(null, null);
tracker.addingService(mockSvcRef);
// These will pass through
for (int i = 0; i < 15; i++) tracker.log(null, null);
tracker.removedService(mockSvcRef, mockRequestLog);
// And these will not.
for (int i = 0; i < 50; i++) tracker.log(null, null);
verify(mockRequestLog, times(15)).log(isNull(Request.class), isNull(Response.class));
}
use of org.eclipse.jetty.server.RequestLog in project felix by apache.
the class RequestLogTrackerTest method testNaughtyService.
@Test
public void testNaughtyService() throws Exception {
RequestLogTracker tracker = new RequestLogTracker(context, null);
AtomicInteger counter = new AtomicInteger(0);
RequestLog mockRequestLog = new RequestLog() {
@Override
public void log(Request request, Response response) {
counter.addAndGet(1);
throw new RuntimeException("This service always explodes");
}
};
ServiceReference<RequestLog> mockSvcRef = mock(ServiceReference.class);
Bundle mockBundle = mock(Bundle.class);
when(mockSvcRef.getBundle()).thenReturn(mockBundle);
when(mockBundle.getSymbolicName()).thenReturn("org.example");
when(mockBundle.getVersion()).thenReturn(new Version("1.0.0"));
when(context.getService(mockSvcRef)).thenReturn(mockRequestLog);
tracker.addingService(mockSvcRef);
// Invoke 200 times
for (int i = 0; i < 200; i++) tracker.log(null, null);
tracker.removedService(mockSvcRef, mockRequestLog);
// Invoked 100 times and then removed
assertEquals(100, counter.get());
}
Aggregations