use of org.eclipse.jetty.server.Handler in project crnk-framework by crnk-project.
the class SecurityModuleIntTest method getTestContainerFactory.
protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
final TestContainerFactory testContainerFactory = super.getTestContainerFactory();
return new TestContainerFactory() {
@Override
public TestContainer create(URI baseUri, DeploymentContext deploymentContext) {
TestContainer container = testContainerFactory.create(baseUri, deploymentContext);
try {
Field field = container.getClass().getDeclaredField("server");
field.setAccessible(true);
Server server = (Server) field.get(container);
Handler handler = server.getHandler();
SecurityHandler securityHandler = identityManager.getSecurityHandler();
if (securityHandler.getHandler() == null) {
securityHandler.setHandler(handler);
}
server.setHandler(securityHandler);
} catch (Exception e) {
throw new IllegalStateException(e);
}
return container;
}
};
}
use of org.eclipse.jetty.server.Handler in project core by weld.
the class EclipseWeldServletHandler method findWAC.
protected static WebAppContext findWAC(ServletContext context) {
if (context instanceof ContextHandler.Context) {
ContextHandler.Context sContext = (ContextHandler.Context) context;
ContextHandler contextHandler = sContext.getContextHandler();
Handler handler = contextHandler.getHandler();
if (handler instanceof ServletHandler) {
ServletHandler servletHandler = (ServletHandler) handler;
Server server = servletHandler.getServer();
Handler serverHandler = server.getHandler();
if (serverHandler instanceof HandlerCollection) {
HandlerCollection hc = (HandlerCollection) serverHandler;
for (Handler h : hc.getHandlers()) {
if (h instanceof WebAppContext) {
WebAppContext wac = (WebAppContext) h;
if (wac.getServletHandler() == servletHandler) {
return wac;
}
}
}
}
}
}
return null;
}
use of org.eclipse.jetty.server.Handler in project ddf by codice.
the class DelegatingHttpFilterHandlerTest method testDelegatingHttpFilterHandler.
@Test
public void testDelegatingHttpFilterHandler() throws Exception {
Request mockBaseRequest = mock(Request.class);
HttpServletRequest mockRequest = mock(HttpServletRequest.class);
HttpServletResponse mockResponse = mock(HttpServletResponse.class);
HttpFilter mockFilter = mockHttpFilter();
ServiceReference<HttpFilter> mockServiceReference = mock(ServiceReference.class);
BundleContext mockBundleContext = mock(BundleContext.class);
when(mockBundleContext.getServiceReferences(any(Class.class), anyString())).thenReturn(Collections.singletonList(mockServiceReference));
when(mockBundleContext.getService(mockServiceReference)).thenReturn(mockFilter);
Handler handler = mock(Handler.class);
DelegatingHttpFilterHandler underTest = new DelegatingHttpFilterHandler(mockBundleContext);
underTest.setHandler(handler);
underTest.handle("/", mockBaseRequest, mockRequest, mockResponse);
verify(mockFilter).doFilter(any(), any(), any());
verify(handler).handle("/", mockBaseRequest, mockRequest, mockResponse);
}
use of org.eclipse.jetty.server.Handler in project ddf by codice.
the class DelegatingHttpFilterHandlerTest method testDelegatingHttpFilterHandlerWithServiceRanking.
@Test
public void testDelegatingHttpFilterHandlerWithServiceRanking() throws Exception {
Request mockBaseRequest = mock(Request.class);
HttpServletRequest mockRequest = mock(HttpServletRequest.class);
HttpServletResponse mockResponse = mock(HttpServletResponse.class);
HttpFilter filter1 = mockHttpFilter();
HttpFilter filter2 = mockHttpFilter();
HttpFilter filter3 = mockHttpFilter();
ServiceReference<HttpFilter> reference1 = mock(ServiceReference.class);
ServiceReference<HttpFilter> reference2 = mock(ServiceReference.class);
ServiceReference<HttpFilter> reference3 = mock(ServiceReference.class);
rankServiceReferences(reference1, reference2, reference3);
BundleContext mockBundleContext = mock(BundleContext.class);
when(mockBundleContext.getService(reference1)).thenReturn(filter1);
when(mockBundleContext.getService(reference2)).thenReturn(filter2);
when(mockBundleContext.getService(reference3)).thenReturn(filter3);
when(mockBundleContext.getServiceReferences(any(Class.class), anyString())).thenReturn(Arrays.asList(reference2, reference3, reference1));
Handler handler = mock(Handler.class);
DelegatingHttpFilterHandler underTest = new DelegatingHttpFilterHandler(mockBundleContext);
underTest.setHandler(handler);
underTest.handle("/", mockBaseRequest, mockRequest, mockResponse);
InOrder inOrder = Mockito.inOrder(filter1, filter2, filter3);
inOrder.verify(filter1).doFilter(any(), any(), any());
inOrder.verify(filter2).doFilter(any(), any(), any());
inOrder.verify(filter3).doFilter(any(), any(), any());
inOrder.verifyNoMoreInteractions();
}
use of org.eclipse.jetty.server.Handler in project helios by spotify.
the class MasterService method setUpRequestLogging.
private void setUpRequestLogging(final Path stateDirectory) {
// Set up request logging
final Handler originalHandler = server.getHandler();
final HandlerCollection handlerCollection;
if (originalHandler instanceof HandlerCollection) {
handlerCollection = (HandlerCollection) originalHandler;
} else {
handlerCollection = new HandlerCollection();
handlerCollection.addHandler(originalHandler);
}
final RequestLogHandler requestLogHandler = new RequestLogHandler();
final RequestLogImpl requestLog = new RequestLogImpl();
requestLog.setQuiet(true);
if (stateDirectory.resolve(LOGBACK_ACCESS_CONFIG).toFile().exists()) {
requestLog.setFileName(stateDirectory.resolve(LOGBACK_ACCESS_CONFIG).toString());
} else if (this.getClass().getResource(LOGBACK_ACCESS_RESOURCE) != null) {
requestLog.setResource(LOGBACK_ACCESS_RESOURCE);
}
requestLogHandler.setRequestLog(requestLog);
handlerCollection.addHandler(requestLogHandler);
server.setHandler(handlerCollection);
}
Aggregations