Package org.springframework.web.context.request

Examples of org.springframework.web.context.request.NativeWebRequest


        request.setParameter("foo_page.size", String.valueOf(pageSize));
        request.setParameter("foo_sort2.id", "desc");
        request.setParameter("foo_sort1.baseInfo.realname", "asc");

        MethodParameter parameter = new MethodParameter(customNamePrefixPageableAndSort, 0);
        NativeWebRequest webRequest = new ServletWebRequest(request);
        Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null, webRequest, null);

        //内部会自动-1,从0开始
        assertEquals(pn - 1, pageable.getPageNumber());
        assertEquals(pageSize, pageable.getPageSize());
View Full Code Here


        request.setParameter("foo_page.size", String.valueOf(pageSize));
        request.setParameter("foo_sort2.id$", "desc");
        request.setParameter("foo_sort1.baseInfo.realname", "asc");

        MethodParameter parameter = new MethodParameter(customNamePrefixPageableAndSort, 0);
        NativeWebRequest webRequest = new ServletWebRequest(request);
        Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null, webRequest, null);

    }
View Full Code Here

  @Test
  public void stripsUriTemplateVariablesFromUri() throws Exception {

    Method method = ReflectionUtils.findMethod(SampleController.class, "resolveId", Serializable.class);
    MethodParameter parameter = new MethodParameter(method, 0);
    NativeWebRequest request = new ServletWebRequest(new MockHttpServletRequest("GET", "/orders/5{?projection}"));

    Object resolvedId = resolver.resolveArgument(parameter, null, request, null);

    assertThat(resolvedId, is((Object) "5"));
  }
View Full Code Here

  @Test
  public void translatesUriToBackendId() throws Exception {

    Method method = ReflectionUtils.findMethod(SampleController.class, "resolveId", Serializable.class);
    MethodParameter parameter = new MethodParameter(method, 0);
    NativeWebRequest request = new ServletWebRequest(new MockHttpServletRequest("GET", "/books/5-5-5-5-5"));

    Object resolvedId = resolver.resolveArgument(parameter, null, request, null);

    assertThat(resolvedId, is((Object) 5L));
  }
View Full Code Here

      @Override
      protected RequestMapping getDeclaringClassRequestMapping(MethodParameter parameter) {
        return requestMappingOnType;
      }
    };
    NativeWebRequest nativeWebRequestMock = mock(NativeWebRequest.class);
    when(nativeWebRequestMock.getAttribute(anyString(), anyInt())).thenReturn("/list/script/hello/world");
    assertThat((String) resolver.resolveArgument(mock2, null, nativeWebRequestMock, null), is("hello/world"));

  }
View Full Code Here

      PortletRequest request, MimeResponse response, Object handler, Exception ex) {

    if (handler != null) {
      Method handlerMethod = findBestExceptionHandlerMethod(handler, ex);
      if (handlerMethod != null) {
        NativeWebRequest webRequest = new PortletWebRequest(request, response);
        try {
          Object[] args = resolveHandlerArguments(handlerMethod, handler, webRequest, ex);
          if (logger.isDebugEnabled()) {
            logger.debug("Invoking request handler method: " + handlerMethod);
          }
View Full Code Here

   * {@link WebArgumentResolver#UNRESOLVED} absorbing _any_ exceptions.
   */
  @Override
  public boolean supportsParameter(MethodParameter parameter) {
    try {
      NativeWebRequest webRequest = getWebRequest();
      Object result = this.adaptee.resolveArgument(parameter, webRequest);
      if (result == WebArgumentResolver.UNRESOLVED) {
        return false;
      }
      else {
View Full Code Here

    assertEquals(0, mapping.getOrder());
    assertTrue(mapping.getUrlPathHelper().shouldRemoveSemicolonContent());
    mapping.setDefaultHandler(handlerMethod);

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json");
    NativeWebRequest webRequest = new ServletWebRequest(request);
    ContentNegotiationManager manager = mapping.getContentNegotiationManager();
    assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));

    RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
    assertNotNull(adapter);
View Full Code Here

    RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
    ContentNegotiationManager manager = mapping.getContentNegotiationManager();

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.xml");
    NativeWebRequest webRequest = new ServletWebRequest(request);
    assertEquals(Arrays.asList(MediaType.valueOf("application/rss+xml")), manager.resolveMediaTypes(webRequest));
  }
View Full Code Here

  }

  @Test
  public void contentNegotiation() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json");
    NativeWebRequest webRequest = new ServletWebRequest(request);

    ContentNegotiationManager manager = this.config.requestMappingHandlerMapping().getContentNegotiationManager();
    assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));

    request.setRequestURI("/foo.xml");
View Full Code Here

TOP

Related Classes of org.springframework.web.context.request.NativeWebRequest

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.