Package org.springframework.web.servlet.mvc.method.annotation

Examples of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter


  }

  @Test
  public void requestMappingHandlerAdapter() throws Exception {
    ApplicationContext context = initContext(WebConfig.class);
    RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
    List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
    assertEquals(9, converters.size());
    for(HttpMessageConverter<?> converter : converters) {
      if (converter instanceof AbstractJackson2HttpMessageConverter) {
        ObjectMapper objectMapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper();
        assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
        assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
        assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
        if (converter instanceof MappingJackson2XmlHttpMessageConverter) {
          assertEquals(XmlMapper.class, objectMapper.getClass());
        }
      }
    }

    ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
    assertNotNull(initializer);

    ConversionService conversionService = initializer.getConversionService();
    assertNotNull(conversionService);
    assertTrue(conversionService instanceof FormattingConversionService);
View Full Code Here


  @Test
  public void requestMappingHandlerAdapter() throws Exception {

    delegatingConfig.setConfigurers(Arrays.asList(webMvcConfigurer));
    RequestMappingHandlerAdapter adapter = delegatingConfig.requestMappingHandlerAdapter();

    ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
    ConversionService initializerConversionService = initializer.getConversionService();
    assertTrue(initializer.getValidator() instanceof LocalValidatorFactoryBean);

    verify(webMvcConfigurer).configureMessageConverters(converters.capture());
    verify(webMvcConfigurer).configureContentNegotiation(contentNegotiationConfigurer.capture());
    verify(webMvcConfigurer).addFormatters(conversionService.capture());
    verify(webMvcConfigurer).addArgumentResolvers(resolvers.capture());
    verify(webMvcConfigurer).addReturnValueHandlers(handlers.capture());
    verify(webMvcConfigurer).configureAsyncSupport(asyncConfigurer.capture());

    assertSame(conversionService.getValue(), initializerConversionService);
    assertEquals(0, resolvers.getValue().size());
    assertEquals(0, handlers.getValue().size());
    assertEquals(converters.getValue(), adapter.getMessageConverters());
    assertNotNull(asyncConfigurer);
  }
View Full Code Here

      }
    });
    delegatingConfig = new DelegatingWebMvcConfiguration();
    delegatingConfig.setConfigurers(configurers);

    RequestMappingHandlerAdapter adapter = delegatingConfig.requestMappingHandlerAdapter();
    assertEquals("Only one custom converter should be registered", 1, adapter.getMessageConverters().size());
  }
View Full Code Here

    hm.setServletContext(wac.getServletContext());
    hm.setApplicationContext(wac);
    hm.registerHandlers(this.controllers);
    wac.addBean("requestMappingHandlerMapping", hm);

    RequestMappingHandlerAdapter handlerAdapter = config.requestMappingHandlerAdapter();
    handlerAdapter.setServletContext(wac.getServletContext());
    handlerAdapter.setApplicationContext(wac);
    handlerAdapter.afterPropertiesSet();
    wac.addBean("requestMappingHandlerAdapter", handlerAdapter);

    wac.addBean("handlerExceptionResolver", config.handlerExceptionResolver());

    wac.addBeans(initViewResolvers(wac));
View Full Code Here

    reset(this.applicationContext);
    given(this.applicationContext.getBeanNamesForType(Object.class)).willReturn(new String[] { "bean" });
    given(this.applicationContext.getType("bean")).willReturn((Class) bean.getClass());
    given(this.applicationContext.getBean("bean")).willReturn(bean);
    if (includeRequestMappingHandlerAdapter) {
      RequestMappingHandlerAdapter requestHandlerAdapter = createMockRequestHandlerAdapter();
      given(this.applicationContext.getBean(RequestMappingHandlerAdapter.class))
          .willReturn(requestHandlerAdapter);
    }
  }
View Full Code Here

    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new ByteArrayHttpMessageConverter());
    messageConverters.add(stringHttpMessageConverter);
    messageConverters.add(new SourceHttpMessageConverter<Source>());
    messageConverters.add(new XmlAwareFormHttpMessageConverter());
    RequestMappingHandlerAdapter adapter = mock(RequestMappingHandlerAdapter.class);
    given(adapter.getMessageConverters()).willReturn(messageConverters);
    return adapter;
  }
View Full Code Here

  @Test
  public void shouldCreateDefaultMessageConverters() throws Exception {
    this.resolver.setApplicationContext(this.applicationContext);
    this.resolver.afterPropertiesSet();
    List<HttpMessageConverter<?>> expected = new RequestMappingHandlerAdapter().getMessageConverters();
    List<HttpMessageConverter<?>> actual = this.resolver.getMessageConverters();
    assertClasses(expected, actual);
  }
View Full Code Here

  }

  private void initMessageConverters() {
    if (this.messageConverters == null) {
      try {
        RequestMappingHandlerAdapter adapter = getApplicationContext().getBean(
            RequestMappingHandlerAdapter.class);
        Assert.state(adapter != null, "Unable to find RequestMappingHandlerAdapter bean");
        this.messageConverters = new ArrayList<HttpMessageConverter<?>>();
        this.messageConverters.addAll(adapter.getMessageConverters());
      } catch (Exception e) {
        throw new IllegalStateException(
            "Unable to configure messageConverters using RequestMappingHandlerAdapter bean, "
                + "please configure messageConverters directly", e);
      }
View Full Code Here

    return dispatcherServlet;
  }

  @Bean
  public HandlerAdapter handlerAdapter(HttpMessageConverters converters) {
    RequestMappingHandlerAdapter adapter = new RequestMappingHandlerAdapter();
    adapter.setMessageConverters(converters.getConverters());
    return adapter;
  }
View Full Code Here

        config.setReturnBodyOnUpdate(true);
    }

    @Override
    public RequestMappingHandlerAdapter repositoryExporterHandlerAdapter() {
        RequestMappingHandlerAdapter requestMappingHandlerAdapter = super.repositoryExporterHandlerAdapter();
        configureRepositoryExporterHandlerAdapter(requestMappingHandlerAdapter);
        return requestMappingHandlerAdapter;
    }
View Full Code Here

TOP

Related Classes of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.