Search in sources :

Example 86 with Handler

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;
        }
    };
}
Also used : DeploymentContext(org.glassfish.jersey.test.DeploymentContext) Field(java.lang.reflect.Field) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) TestContainer(org.glassfish.jersey.test.spi.TestContainer) Server(org.eclipse.jetty.server.Server) Handler(org.eclipse.jetty.server.Handler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) URI(java.net.URI) UnauthorizedException(io.crnk.core.exception.UnauthorizedException) IOException(java.io.IOException) TestContainerException(org.glassfish.jersey.test.spi.TestContainerException) ForbiddenException(io.crnk.core.exception.ForbiddenException) TestContainerFactory(org.glassfish.jersey.test.spi.TestContainerFactory)

Example 87 with Handler

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;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServletContext(javax.servlet.ServletContext) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server) Handler(org.eclipse.jetty.server.Handler) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Example 88 with Handler

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Handler(org.eclipse.jetty.server.Handler) HttpFilter(org.codice.ddf.platform.filter.http.HttpFilter) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 89 with Handler

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();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) InOrder(org.mockito.InOrder) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Handler(org.eclipse.jetty.server.Handler) HttpFilter(org.codice.ddf.platform.filter.http.HttpFilter) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 90 with Handler

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);
}
Also used : RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) RequestLogImpl(ch.qos.logback.access.jetty.RequestLogImpl) Handler(org.eclipse.jetty.server.Handler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Aggregations

Handler (org.eclipse.jetty.server.Handler)119 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)37 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)37 Server (org.eclipse.jetty.server.Server)35 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)26 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)25 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)23 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)22 ArrayList (java.util.ArrayList)21 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)18 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)18 IOException (java.io.IOException)15 Test (org.junit.Test)15 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 ServerConnector (org.eclipse.jetty.server.ServerConnector)13 ErrorHandler (org.eclipse.jetty.server.handler.ErrorHandler)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 Request (org.eclipse.jetty.server.Request)12 URI (java.net.URI)11 SecurityHandler (org.eclipse.jetty.security.SecurityHandler)11