private List<HttpMessageConverter<?>> getDefaultConverters() { List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>(); if (ClassUtils.isPresent("org.springframework.web.servlet.config.annotation." + "WebMvcConfigurationSupport", null)) { converters.addAll(new WebMvcConfigurationSupport() { public List<HttpMessageConverter<?>> defaultMessageConverters() { return super.getMessageConverters(); } }.defaultMessageConverters()); } else { converters.addAll(new RestTemplate().getMessageConverters()); } reorderXmlConvertersToEnd(converters); return converters; }
protected ServletRegistration.Dynamic initSpringRestComponent(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext, String restContextRoot, Class<? extends WebMvcConfigurationSupport> webConfigClass) { LOGGER.debug("Configuring Spring Web application context - {} REST", restContextRoot); AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext(); dispatcherServletConfiguration.setParent(rootContext); dispatcherServletConfiguration.register(webConfigClass); LOGGER.debug("Registering Spring MVC Servlet - {} REST", restContextRoot); ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet(restContextRoot + "-dispatcher", new DispatcherServlet(dispatcherServletConfiguration)); dispatcherServlet.addMapping("/" + restContextRoot + "/*"); dispatcherServlet.setLoadOnStartup(1); dispatcherServlet.setAsyncSupported(true); return dispatcherServlet; }
protected ServletRegistration.Dynamic initSpringRestComponent(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext, String name, String restContextRoot, Class<? extends WebMvcConfigurationSupport> webConfigClass) { LOGGER.debug("Configuring Spring Web application context - {} REST", name); AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext(); dispatcherServletConfiguration.setParent(rootContext); dispatcherServletConfiguration.register(webConfigClass); LOGGER.debug("Registering Spring MVC Servlet - {} REST", name); ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet(name + "-dispatcher", new DispatcherServlet(dispatcherServletConfiguration)); dispatcherServlet.addMapping(restContextRoot + "/*"); dispatcherServlet.setLoadOnStartup(1); dispatcherServlet.setAsyncSupported(true); return dispatcherServlet; }
@SuppressWarnings("unchecked") @Test public void testInterceptorIsConfigured() { final Object configurerAdapter = context.getBean(TraceeSpringMvcConfiguration.TRACEE_WEBMVCCONFIGURERADAPTER_INTERNAL); assertNotNull(configurerAdapter); final WebMvcConfigurationSupport webmvc = context.getBean(WebMvcConfigurationSupport.class); final List<Object> listeners = FieldAccessUtil.getFieldVal(webmvc, "interceptors"); Assert.assertThat(listeners, Matchers.hasItem(Matchers.instanceOf(TraceeInterceptor.class))); }
@RequestMapping("/test") public String test() { return beanFactory.getBean(WebMvcConfigurationSupport.class).toString(); }