Search in sources :

Example 1 with DefaultAnnotationHandlerMapping

use of org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping in project brave by openzipkin.

the class ITTracingHandlerInterceptor method init.

@Override
public void init(ServletContextHandler handler) {
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.getBeanFactory().registerSingleton("testController", // the test resource
    new TestController(httpTracing));
    DefaultAnnotationHandlerMapping mapping = new DefaultAnnotationHandlerMapping();
    mapping.setInterceptors(new Object[] { TracingHandlerInterceptor.create(httpTracing) });
    mapping.setApplicationContext(wac);
    wac.getBeanFactory().registerSingleton(HANDLER_MAPPING_BEAN_NAME, mapping);
    wac.getBeanFactory().registerSingleton(HANDLER_ADAPTER_BEAN_NAME, new AnnotationMethodHandlerAdapter());
    handler.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    handler.addServlet(new ServletHolder(new DispatcherServlet() {

        {
            wac.refresh();
            setDetectAllHandlerMappings(false);
            setDetectAllHandlerAdapters(false);
            setPublishEvents(false);
        }

        @Override
        protected WebApplicationContext initWebApplicationContext() throws BeansException {
            onRefresh(wac);
            return wac;
        }
    }), "/*");
}
Also used : DefaultAnnotationHandlerMapping(org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) AnnotationMethodHandlerAdapter(org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter)

Example 2 with DefaultAnnotationHandlerMapping

use of org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping in project brave by openzipkin.

the class ITSpanCustomizingHandlerInterceptor method init.

@Override
public void init(ServletContextHandler handler) {
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.getBeanFactory().registerSingleton("httpTracing", httpTracing);
    wac.getBeanFactory().registerSingleton("testController", // the test resource
    new TestController(httpTracing));
    DefaultAnnotationHandlerMapping mapping = new DefaultAnnotationHandlerMapping();
    mapping.setInterceptors(new Object[] { new SpanCustomizingHandlerInterceptor() });
    mapping.setApplicationContext(wac);
    wac.getBeanFactory().registerSingleton(HANDLER_MAPPING_BEAN_NAME, mapping);
    wac.getBeanFactory().registerSingleton(HANDLER_ADAPTER_BEAN_NAME, new AnnotationMethodHandlerAdapter());
    handler.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    handler.addServlet(new ServletHolder(new DispatcherServlet() {

        {
            wac.refresh();
            setDetectAllHandlerMappings(false);
            setDetectAllHandlerAdapters(false);
            setPublishEvents(false);
        }

        @Override
        protected WebApplicationContext initWebApplicationContext() throws BeansException {
            onRefresh(wac);
            return wac;
        }
    }), "/*");
    handler.addFilter(DelegatingTracingFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
}
Also used : DefaultAnnotationHandlerMapping(org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) DispatcherType(org.eclipse.jetty.server.DispatcherType) AnnotationMethodHandlerAdapter(org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter)

Aggregations

ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)2 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)2 AnnotationMethodHandlerAdapter (org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter)2 DefaultAnnotationHandlerMapping (org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping)2 DispatcherType (org.eclipse.jetty.server.DispatcherType)1