org.springframework.web.method.support.HandlerMethodArgumentResolver Java Examples
The following examples show how to use
org.springframework.web.method.support.HandlerMethodArgumentResolver.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RequestMappingHandlerAdapterTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void setAlwaysUseRedirectAttributes() throws Exception { HandlerMethodArgumentResolver redirectAttributesResolver = new RedirectAttributesMethodArgumentResolver(); HandlerMethodArgumentResolver modelResolver = new ModelMethodProcessor(); HandlerMethodReturnValueHandler viewHandler = new ViewNameMethodReturnValueHandler(); this.handlerAdapter.setArgumentResolvers(Arrays.asList(redirectAttributesResolver, modelResolver)); this.handlerAdapter.setReturnValueHandlers(Collections.singletonList(viewHandler)); this.handlerAdapter.setIgnoreDefaultModelOnRedirect(true); this.handlerAdapter.afterPropertiesSet(); this.request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap()); HandlerMethod handlerMethod = handlerMethod(new RedirectAttributeController(), "handle", Model.class); ModelAndView mav = this.handlerAdapter.handle(request, response, handlerMethod); assertTrue("Without RedirectAttributes arg, model should be empty", mav.getModel().isEmpty()); }
Example #2
Source File: RequestMappingHandlerAdapterIntegrationTests.java From java-technology-stack with MIT License | 6 votes |
@Before public void setup() throws Exception { ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer(); bindingInitializer.setValidator(new StubValidator()); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>(); customResolvers.add(new ServletWebArgumentResolverAdapter(new ColorArgumentResolver())); GenericWebApplicationContext context = new GenericWebApplicationContext(); context.refresh(); handlerAdapter = new RequestMappingHandlerAdapter(); handlerAdapter.setWebBindingInitializer(bindingInitializer); handlerAdapter.setCustomArgumentResolvers(customResolvers); handlerAdapter.setApplicationContext(context); handlerAdapter.setBeanFactory(context.getBeanFactory()); handlerAdapter.afterPropertiesSet(); request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); request.setMethod("POST"); // Expose request to the current thread (for SpEL expressions) RequestContextHolder.setRequestAttributes(new ServletWebRequest(request)); }
Example #3
Source File: RequestMappingHandlerAdapterTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void setAlwaysUseRedirectAttributes() throws Exception { HandlerMethodArgumentResolver redirectAttributesResolver = new RedirectAttributesMethodArgumentResolver(); HandlerMethodArgumentResolver modelResolver = new ModelMethodProcessor(); HandlerMethodReturnValueHandler viewHandler = new ViewNameMethodReturnValueHandler(); this.handlerAdapter.setArgumentResolvers(Arrays.asList(redirectAttributesResolver, modelResolver)); this.handlerAdapter.setReturnValueHandlers(Collections.singletonList(viewHandler)); this.handlerAdapter.setIgnoreDefaultModelOnRedirect(true); this.handlerAdapter.afterPropertiesSet(); this.request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap()); HandlerMethod handlerMethod = handlerMethod(new RedirectAttributeController(), "handle", Model.class); ModelAndView mav = this.handlerAdapter.handle(request, response, handlerMethod); assertTrue("Without RedirectAttributes arg, model should be empty", mav.getModel().isEmpty()); }
Example #4
Source File: ExceptionHandlerExceptionResolver.java From java-technology-stack with MIT License | 6 votes |
/** * Return the list of argument resolvers to use including built-in resolvers * and custom resolvers provided via {@link #setCustomArgumentResolvers}. */ protected List<HandlerMethodArgumentResolver> getDefaultArgumentResolvers() { List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(); // Annotation-based argument resolution resolvers.add(new SessionAttributeMethodArgumentResolver()); resolvers.add(new RequestAttributeMethodArgumentResolver()); // Type-based argument resolution resolvers.add(new ServletRequestMethodArgumentResolver()); resolvers.add(new ServletResponseMethodArgumentResolver()); resolvers.add(new RedirectAttributesMethodArgumentResolver()); resolvers.add(new ModelMethodProcessor()); // Custom arguments if (getCustomArgumentResolvers() != null) { resolvers.addAll(getCustomArgumentResolvers()); } return resolvers; }
Example #5
Source File: ExceptionHandlerExceptionResolver.java From spring-analysis-note with MIT License | 6 votes |
/** * Return the list of argument resolvers to use including built-in resolvers * and custom resolvers provided via {@link #setCustomArgumentResolvers}. */ protected List<HandlerMethodArgumentResolver> getDefaultArgumentResolvers() { List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(); // Annotation-based argument resolution resolvers.add(new SessionAttributeMethodArgumentResolver()); resolvers.add(new RequestAttributeMethodArgumentResolver()); // Type-based argument resolution resolvers.add(new ServletRequestMethodArgumentResolver()); resolvers.add(new ServletResponseMethodArgumentResolver()); resolvers.add(new RedirectAttributesMethodArgumentResolver()); resolvers.add(new ModelMethodProcessor()); // Custom arguments if (getCustomArgumentResolvers() != null) { resolvers.addAll(getCustomArgumentResolvers()); } return resolvers; }
Example #6
Source File: RequestMappingHandlerAdapterIntegrationTests.java From spring-analysis-note with MIT License | 6 votes |
@Before public void setup() throws Exception { ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer(); bindingInitializer.setValidator(new StubValidator()); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>(); customResolvers.add(new ServletWebArgumentResolverAdapter(new ColorArgumentResolver())); GenericWebApplicationContext context = new GenericWebApplicationContext(); context.refresh(); handlerAdapter = new RequestMappingHandlerAdapter(); handlerAdapter.setWebBindingInitializer(bindingInitializer); handlerAdapter.setCustomArgumentResolvers(customResolvers); handlerAdapter.setApplicationContext(context); handlerAdapter.setBeanFactory(context.getBeanFactory()); handlerAdapter.afterPropertiesSet(); request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); request.setMethod("POST"); // Expose request to the current thread (for SpEL expressions) RequestContextHolder.setRequestAttributes(new ServletWebRequest(request)); }
Example #7
Source File: RequestMappingHandlerAdapterTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void setArgumentResolvers() throws Exception { HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); this.handlerAdapter.setArgumentResolvers(Collections.singletonList(resolver)); this.handlerAdapter.afterPropertiesSet(); assertMethodProcessorCount(1, INIT_BINDER_RESOLVER_COUNT, HANDLER_COUNT); }
Example #8
Source File: ExceptionHandlerExceptionResolverTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void setCustomArgumentResolvers() { HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); this.resolver.setCustomArgumentResolvers(Collections.singletonList(resolver)); this.resolver.afterPropertiesSet(); assertTrue(this.resolver.getArgumentResolvers().getResolvers().contains(resolver)); assertMethodProcessorCount(RESOLVER_COUNT + 1, HANDLER_COUNT); }
Example #9
Source File: WebMvcConfigurationSupport.java From java-technology-stack with MIT License | 5 votes |
/** * Provide access to the shared custom argument resolvers used by the * {@link RequestMappingHandlerAdapter} and the {@link ExceptionHandlerExceptionResolver}. * <p>This method cannot be overridden; use {@link #addArgumentResolvers} instead. * @since 4.3 */ protected final List<HandlerMethodArgumentResolver> getArgumentResolvers() { if (this.argumentResolvers == null) { this.argumentResolvers = new ArrayList<>(); addArgumentResolvers(this.argumentResolvers); } return this.argumentResolvers; }
Example #10
Source File: ExceptionHandlerExceptionResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void setArgumentResolvers() { HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); this.resolver.setArgumentResolvers(Collections.singletonList(resolver)); this.resolver.afterPropertiesSet(); assertMethodProcessorCount(1, HANDLER_COUNT); }
Example #11
Source File: ExceptionHandlerExceptionResolver.java From spring-analysis-note with MIT License | 5 votes |
/** * Configure the complete list of supported argument types thus overriding * the resolvers that would otherwise be configured by default. */ public void setArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) { if (argumentResolvers == null) { this.argumentResolvers = null; } else { this.argumentResolvers = new HandlerMethodArgumentResolverComposite(); this.argumentResolvers.addResolvers(argumentResolvers); } }
Example #12
Source File: RequestMappingHandlerAdapterTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void setCustomArgumentResolvers() throws Exception { HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); this.handlerAdapter.setCustomArgumentResolvers(Collections.singletonList(resolver)); this.handlerAdapter.afterPropertiesSet(); assertTrue(this.handlerAdapter.getArgumentResolvers().contains(resolver)); assertMethodProcessorCount(RESOLVER_COUNT + 1, INIT_BINDER_RESOLVER_COUNT + 1, HANDLER_COUNT); }
Example #13
Source File: RequestMappingHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
/** * Configure the supported argument types in {@code @InitBinder} methods. */ public void setInitBinderArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) { if (argumentResolvers == null) { this.initBinderArgumentResolvers = null; } else { this.initBinderArgumentResolvers = new HandlerMethodArgumentResolverComposite(); this.initBinderArgumentResolvers.addResolvers(argumentResolvers); } }
Example #14
Source File: RequestMappingHandlerAdapterTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void setCustomArgumentResolvers() throws Exception { HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); this.handlerAdapter.setCustomArgumentResolvers(Collections.singletonList(resolver)); this.handlerAdapter.afterPropertiesSet(); assertTrue(this.handlerAdapter.getArgumentResolvers().contains(resolver)); assertMethodProcessorCount(RESOLVER_COUNT + 1, INIT_BINDER_RESOLVER_COUNT + 1, HANDLER_COUNT); }
Example #15
Source File: RequestMappingHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
/** * Return the list of argument resolvers to use for {@code @InitBinder} * methods including built-in and custom resolvers. */ private List<HandlerMethodArgumentResolver> getDefaultInitBinderArgumentResolvers() { List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(); // Annotation-based argument resolution resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false)); resolvers.add(new RequestParamMapMethodArgumentResolver()); resolvers.add(new PathVariableMethodArgumentResolver()); resolvers.add(new PathVariableMapMethodArgumentResolver()); resolvers.add(new MatrixVariableMethodArgumentResolver()); resolvers.add(new MatrixVariableMapMethodArgumentResolver()); resolvers.add(new ExpressionValueMethodArgumentResolver(getBeanFactory())); resolvers.add(new SessionAttributeMethodArgumentResolver()); resolvers.add(new RequestAttributeMethodArgumentResolver()); // Type-based argument resolution resolvers.add(new ServletRequestMethodArgumentResolver()); resolvers.add(new ServletResponseMethodArgumentResolver()); // Custom arguments if (getCustomArgumentResolvers() != null) { resolvers.addAll(getCustomArgumentResolvers()); } // Catch-all resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), true)); return resolvers; }
Example #16
Source File: RequestMappingHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
/** * Configure the complete list of supported argument types thus overriding * the resolvers that would otherwise be configured by default. */ public void setArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) { if (argumentResolvers == null) { this.argumentResolvers = null; } else { this.argumentResolvers = new HandlerMethodArgumentResolverComposite(); this.argumentResolvers.addResolvers(argumentResolvers); } }
Example #17
Source File: RequestMappingHandlerAdapterTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void setInitBinderArgumentResolvers() throws Exception { HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); this.handlerAdapter.setInitBinderArgumentResolvers(Collections.singletonList(resolver)); this.handlerAdapter.afterPropertiesSet(); assertMethodProcessorCount(RESOLVER_COUNT, 1, HANDLER_COUNT); }
Example #18
Source File: ExceptionHandlerExceptionResolverTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void setArgumentResolvers() { HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); this.resolver.setArgumentResolvers(Collections.singletonList(resolver)); this.resolver.afterPropertiesSet(); assertMethodProcessorCount(1, HANDLER_COUNT); }
Example #19
Source File: AnnotationDrivenBeanDefinitionParserTests.java From java-technology-stack with MIT License | 5 votes |
private void testArgumentResolvers(Object bean) { assertNotNull(bean); Object value = new DirectFieldAccessor(bean).getPropertyValue("customArgumentResolvers"); assertNotNull(value); assertTrue(value instanceof List); @SuppressWarnings("unchecked") List<HandlerMethodArgumentResolver> resolvers = (List<HandlerMethodArgumentResolver>) value; assertEquals(3, resolvers.size()); assertTrue(resolvers.get(0) instanceof ServletWebArgumentResolverAdapter); assertTrue(resolvers.get(1) instanceof TestHandlerMethodArgumentResolver); assertTrue(resolvers.get(2) instanceof TestHandlerMethodArgumentResolver); assertNotSame(resolvers.get(1), resolvers.get(2)); }
Example #20
Source File: RequestMappingHandlerAdapterTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void setArgumentResolvers() throws Exception { HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); this.handlerAdapter.setArgumentResolvers(Collections.singletonList(resolver)); this.handlerAdapter.afterPropertiesSet(); assertMethodProcessorCount(1, INIT_BINDER_RESOLVER_COUNT, HANDLER_COUNT); }
Example #21
Source File: RequestMappingHandlerAdapterTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void setInitBinderArgumentResolvers() throws Exception { HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); this.handlerAdapter.setInitBinderArgumentResolvers(Collections.singletonList(resolver)); this.handlerAdapter.afterPropertiesSet(); assertMethodProcessorCount(RESOLVER_COUNT, 1, HANDLER_COUNT); }
Example #22
Source File: RequestMappingHandlerAdapter.java From java-technology-stack with MIT License | 5 votes |
/** * Return the list of argument resolvers to use for {@code @InitBinder} * methods including built-in and custom resolvers. */ private List<HandlerMethodArgumentResolver> getDefaultInitBinderArgumentResolvers() { List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(); // Annotation-based argument resolution resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false)); resolvers.add(new RequestParamMapMethodArgumentResolver()); resolvers.add(new PathVariableMethodArgumentResolver()); resolvers.add(new PathVariableMapMethodArgumentResolver()); resolvers.add(new MatrixVariableMethodArgumentResolver()); resolvers.add(new MatrixVariableMapMethodArgumentResolver()); resolvers.add(new ExpressionValueMethodArgumentResolver(getBeanFactory())); resolvers.add(new SessionAttributeMethodArgumentResolver()); resolvers.add(new RequestAttributeMethodArgumentResolver()); // Type-based argument resolution resolvers.add(new ServletRequestMethodArgumentResolver()); resolvers.add(new ServletResponseMethodArgumentResolver()); // Custom arguments if (getCustomArgumentResolvers() != null) { resolvers.addAll(getCustomArgumentResolvers()); } // Catch-all resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), true)); return resolvers; }
Example #23
Source File: AnnotationDrivenBeanDefinitionParserTests.java From spring-analysis-note with MIT License | 5 votes |
private void testArgumentResolvers(Object bean) { assertNotNull(bean); Object value = new DirectFieldAccessor(bean).getPropertyValue("customArgumentResolvers"); assertNotNull(value); assertTrue(value instanceof List); @SuppressWarnings("unchecked") List<HandlerMethodArgumentResolver> resolvers = (List<HandlerMethodArgumentResolver>) value; assertEquals(3, resolvers.size()); assertTrue(resolvers.get(0) instanceof ServletWebArgumentResolverAdapter); assertTrue(resolvers.get(1) instanceof TestHandlerMethodArgumentResolver); assertTrue(resolvers.get(2) instanceof TestHandlerMethodArgumentResolver); assertNotSame(resolvers.get(1), resolvers.get(2)); }
Example #24
Source File: RequestMappingHandlerAdapter.java From java-technology-stack with MIT License | 5 votes |
/** * Configure the supported argument types in {@code @InitBinder} methods. */ public void setInitBinderArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) { if (argumentResolvers == null) { this.initBinderArgumentResolvers = null; } else { this.initBinderArgumentResolvers = new HandlerMethodArgumentResolverComposite(); this.initBinderArgumentResolvers.addResolvers(argumentResolvers); } }
Example #25
Source File: CometConfig.java From Milkomeda with MIT License | 5 votes |
@Autowired @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") public void configParamResolve(RequestMappingHandlerAdapter adapter) { List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>(); // 动态添加针对注解 @CometParam 处理的解析器 argumentResolvers.add(new CometParamResolver()); argumentResolvers.addAll(Objects.requireNonNull(adapter.getArgumentResolvers())); adapter.setArgumentResolvers(argumentResolvers); }
Example #26
Source File: RequestMappingHandlerAdapter.java From java-technology-stack with MIT License | 5 votes |
/** * Configure the complete list of supported argument types thus overriding * the resolvers that would otherwise be configured by default. */ public void setArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) { if (argumentResolvers == null) { this.argumentResolvers = null; } else { this.argumentResolvers = new HandlerMethodArgumentResolverComposite(); this.argumentResolvers.addResolvers(argumentResolvers); } }
Example #27
Source File: ExceptionHandlerExceptionResolver.java From java-technology-stack with MIT License | 5 votes |
@Override public void afterPropertiesSet() { // Do this first, it may add ResponseBodyAdvice beans initExceptionHandlerAdviceCache(); if (this.argumentResolvers == null) { List<HandlerMethodArgumentResolver> resolvers = getDefaultArgumentResolvers(); this.argumentResolvers = new HandlerMethodArgumentResolverComposite().addResolvers(resolvers); } if (this.returnValueHandlers == null) { List<HandlerMethodReturnValueHandler> handlers = getDefaultReturnValueHandlers(); this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite().addHandlers(handlers); } }
Example #28
Source File: ExceptionHandlerExceptionResolver.java From java-technology-stack with MIT License | 5 votes |
/** * Configure the complete list of supported argument types thus overriding * the resolvers that would otherwise be configured by default. */ public void setArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) { if (argumentResolvers == null) { this.argumentResolvers = null; } else { this.argumentResolvers = new HandlerMethodArgumentResolverComposite(); this.argumentResolvers.addResolvers(argumentResolvers); } }
Example #29
Source File: DefaultWebMvcConfig.java From microservices-platform with Apache License 2.0 | 5 votes |
/** * Token参数解析 * * @param argumentResolvers 解析类 */ @Override public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { //注入用户信息 argumentResolvers.add(new TokenArgumentResolver(userService)); //注入应用信息 argumentResolvers.add(new ClientArgumentResolver()); }
Example #30
Source File: CustomArgumentResolversConfig.java From yue-library with Apache License 2.0 | 5 votes |
@Autowired public void prioritizeCustomMethodArgumentHandlers(RequestMappingHandlerAdapter adapter) { List<HandlerMethodArgumentResolver> prioritizeCustomArgumentResolvers = new ArrayList<>(); prioritizeCustomArgumentResolvers.add(new JSONObjectArgumentResolver()); prioritizeCustomArgumentResolvers.addAll(adapter.getArgumentResolvers()); adapter.setArgumentResolvers(prioritizeCustomArgumentResolvers); }