Java Code Examples for org.springframework.core.MethodParameter#nestedIfOptional()
The following examples show how to use
org.springframework.core.MethodParameter#nestedIfOptional() .
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: RequestResponseBodyMethodProcessor.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Throws MethodArgumentNotValidException if validation fails. * @throws HttpMessageNotReadableException if {@link RequestBody#required()} * is {@code true} and there is no body content or if there is no suitable * converter to read the content with. */ @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { parameter = parameter.nestedIfOptional(); Object arg = readWithMessageConverters(webRequest, parameter, parameter.getNestedGenericParameterType()); String name = Conventions.getVariableNameForParameter(parameter); WebDataBinder binder = binderFactory.createBinder(webRequest, arg, name); if (arg != null) { validateIfApplicable(binder, parameter); if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) { throw new MethodArgumentNotValidException(parameter, binder.getBindingResult()); } } mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult()); return adaptArgumentIfNecessary(arg, parameter); }
Example 2
Source File: RequestResponseBodyMethodProcessor.java From java-technology-stack with MIT License | 6 votes |
/** * Throws MethodArgumentNotValidException if validation fails. * @throws HttpMessageNotReadableException if {@link RequestBody#required()} * is {@code true} and there is no body content or if there is no suitable * converter to read the content with. */ @Override public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { parameter = parameter.nestedIfOptional(); Object arg = readWithMessageConverters(webRequest, parameter, parameter.getNestedGenericParameterType()); String name = Conventions.getVariableNameForParameter(parameter); if (binderFactory != null) { WebDataBinder binder = binderFactory.createBinder(webRequest, arg, name); if (arg != null) { validateIfApplicable(binder, parameter); if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) { throw new MethodArgumentNotValidException(parameter, binder.getBindingResult()); } } if (mavContainer != null) { mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult()); } } return adaptArgumentIfNecessary(arg, parameter); }
Example 3
Source File: RequestResponseBodyMethodProcessor.java From spring-analysis-note with MIT License | 6 votes |
/** * Throws MethodArgumentNotValidException if validation fails. * @throws HttpMessageNotReadableException if {@link RequestBody#required()} * is {@code true} and there is no body content or if there is no suitable * converter to read the content with. */ @Override public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { parameter = parameter.nestedIfOptional(); Object arg = readWithMessageConverters(webRequest, parameter, parameter.getNestedGenericParameterType()); String name = Conventions.getVariableNameForParameter(parameter); if (binderFactory != null) { WebDataBinder binder = binderFactory.createBinder(webRequest, arg, name); if (arg != null) { validateIfApplicable(binder, parameter); if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) { throw new MethodArgumentNotValidException(parameter, binder.getBindingResult()); } } if (mavContainer != null) { mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult()); } } return adaptArgumentIfNecessary(arg, parameter); }
Example 4
Source File: MappingJackson2MessageConverter.java From java-technology-stack with MIT License | 5 votes |
private JavaType getJavaType(Class<?> targetClass, @Nullable Object conversionHint) { if (conversionHint instanceof MethodParameter) { MethodParameter param = (MethodParameter) conversionHint; param = param.nestedIfOptional(); if (Message.class.isAssignableFrom(param.getParameterType())) { param = param.nested(); } Type genericParameterType = param.getNestedGenericParameterType(); Class<?> contextClass = param.getContainingClass(); Type type = GenericTypeResolver.resolveType(genericParameterType, contextClass); return this.objectMapper.getTypeFactory().constructType(type); } return this.objectMapper.constructType(targetClass); }
Example 5
Source File: RequestParamMethodArgumentResolver.java From java-technology-stack with MIT License | 5 votes |
/** * Supports the following: * <ul> * <li>@RequestParam-annotated method arguments. * This excludes {@link Map} params where the annotation does not specify a name. * See {@link RequestParamMapMethodArgumentResolver} instead for such params. * <li>Arguments of type {@link MultipartFile} unless annotated with @{@link RequestPart}. * <li>Arguments of type {@code Part} unless annotated with @{@link RequestPart}. * <li>In default resolution mode, simple type arguments even if not with @{@link RequestParam}. * </ul> */ @Override public boolean supportsParameter(MethodParameter parameter) { if (parameter.hasParameterAnnotation(RequestParam.class)) { if (Map.class.isAssignableFrom(parameter.nestedIfOptional().getNestedParameterType())) { RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class); return (requestParam != null && StringUtils.hasText(requestParam.name())); } else { return true; } } else { if (parameter.hasParameterAnnotation(RequestPart.class)) { return false; } parameter = parameter.nestedIfOptional(); if (MultipartResolutionDelegate.isMultipartArgument(parameter)) { return true; } else if (this.useDefaultResolution) { return BeanUtils.isSimpleProperty(parameter.getNestedParameterType()); } else { return false; } } }
Example 6
Source File: ModelAttributeMethodProcessor.java From java-technology-stack with MIT License | 5 votes |
/** * Extension point to create the model attribute if not found in the model, * with subsequent parameter binding through bean properties (unless suppressed). * <p>The default implementation typically uses the unique public no-arg constructor * if available but also handles a "primary constructor" approach for data classes: * It understands the JavaBeans {@link ConstructorProperties} annotation as well as * runtime-retained parameter names in the bytecode, associating request parameters * with constructor arguments by name. If no such constructor is found, the default * constructor will be used (even if not public), assuming subsequent bean property * bindings through setter methods. * @param attributeName the name of the attribute (never {@code null}) * @param parameter the method parameter declaration * @param binderFactory for creating WebDataBinder instance * @param webRequest the current request * @return the created model attribute (never {@code null}) * @throws BindException in case of constructor argument binding failure * @throws Exception in case of constructor invocation failure * @see #constructAttribute(Constructor, String, MethodParameter, WebDataBinderFactory, NativeWebRequest) * @see BeanUtils#findPrimaryConstructor(Class) */ protected Object createAttribute(String attributeName, MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest webRequest) throws Exception { MethodParameter nestedParameter = parameter.nestedIfOptional(); Class<?> clazz = nestedParameter.getNestedParameterType(); Constructor<?> ctor = BeanUtils.findPrimaryConstructor(clazz); if (ctor == null) { Constructor<?>[] ctors = clazz.getConstructors(); if (ctors.length == 1) { ctor = ctors[0]; } else { try { ctor = clazz.getDeclaredConstructor(); } catch (NoSuchMethodException ex) { throw new IllegalStateException("No primary or default constructor found for " + clazz, ex); } } } Object attribute = constructAttribute(ctor, attributeName, parameter, binderFactory, webRequest); if (parameter != nestedParameter) { attribute = Optional.of(attribute); } return attribute; }
Example 7
Source File: HandlerMethodArgumentResolverSupport.java From java-technology-stack with MIT License | 5 votes |
/** * Evaluate the {@code Predicate} on the method parameter type if it has the * given annotation, nesting within {@link java.util.Optional} if necessary, * but raise an {@code IllegalStateException} if the same matches the generic * type within a reactive type wrapper. */ protected <A extends Annotation> boolean checkAnnotatedParamNoReactiveWrapper( MethodParameter parameter, Class<A> annotationType, BiPredicate<A, Class<?>> typePredicate) { A annotation = parameter.getParameterAnnotation(annotationType); if (annotation == null) { return false; } parameter = parameter.nestedIfOptional(); Class<?> type = parameter.getNestedParameterType(); ReactiveAdapter adapter = getAdapterRegistry().getAdapter(type); if (adapter != null) { assertHasValues(adapter, parameter); parameter = parameter.nested(); type = parameter.getNestedParameterType(); } if (typePredicate.test(annotation, type)) { if (adapter == null) { return true; } throw buildReactiveWrapperException(parameter); } return false; }
Example 8
Source File: AbstractNamedValueArgumentResolver.java From java-technology-stack with MIT License | 5 votes |
@Override public Mono<Object> resolveArgument( MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) { NamedValueInfo namedValueInfo = getNamedValueInfo(parameter); MethodParameter nestedParameter = parameter.nestedIfOptional(); Object resolvedName = resolveStringValue(namedValueInfo.name); if (resolvedName == null) { return Mono.error(new IllegalArgumentException( "Specified name must not resolve to null: [" + namedValueInfo.name + "]")); } Model model = bindingContext.getModel(); return resolveName(resolvedName.toString(), nestedParameter, exchange) .flatMap(arg -> { if ("".equals(arg) && namedValueInfo.defaultValue != null) { arg = resolveStringValue(namedValueInfo.defaultValue); } arg = applyConversion(arg, namedValueInfo, parameter, bindingContext, exchange); handleResolvedValue(arg, namedValueInfo.name, parameter, model, exchange); return Mono.justOrEmpty(arg); }) .switchIfEmpty(getDefaultValue( namedValueInfo, parameter, bindingContext, model, exchange)); }
Example 9
Source File: AbstractNamedValueMethodArgumentResolver.java From java-technology-stack with MIT License | 5 votes |
@Override @Nullable public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { NamedValueInfo namedValueInfo = getNamedValueInfo(parameter); MethodParameter nestedParameter = parameter.nestedIfOptional(); Object resolvedName = resolveStringValue(namedValueInfo.name); if (resolvedName == null) { throw new IllegalArgumentException( "Specified name must not resolve to null: [" + namedValueInfo.name + "]"); } Object arg = resolveArgumentInternal(nestedParameter, message, resolvedName.toString()); if (arg == null) { if (namedValueInfo.defaultValue != null) { arg = resolveStringValue(namedValueInfo.defaultValue); } else if (namedValueInfo.required && !nestedParameter.isOptional()) { handleMissingValue(namedValueInfo.name, nestedParameter, message); } arg = handleNullValue(namedValueInfo.name, arg, nestedParameter.getNestedParameterType()); } else if ("".equals(arg) && namedValueInfo.defaultValue != null) { arg = resolveStringValue(namedValueInfo.defaultValue); } if (parameter != nestedParameter || !ClassUtils.isAssignableValue(parameter.getParameterType(), arg)) { arg = this.conversionService.convert(arg, TypeDescriptor.forObject(arg), new TypeDescriptor(parameter)); } handleResolvedValue(arg, namedValueInfo.name, parameter, message); return arg; }
Example 10
Source File: MappingJackson2MessageConverter.java From spring-analysis-note with MIT License | 5 votes |
private JavaType getJavaType(Class<?> targetClass, @Nullable Object conversionHint) { if (conversionHint instanceof MethodParameter) { MethodParameter param = (MethodParameter) conversionHint; param = param.nestedIfOptional(); if (Message.class.isAssignableFrom(param.getParameterType())) { param = param.nested(); } Type genericParameterType = param.getNestedGenericParameterType(); Class<?> contextClass = param.getContainingClass(); Type type = GenericTypeResolver.resolveType(genericParameterType, contextClass); return this.objectMapper.getTypeFactory().constructType(type); } return this.objectMapper.constructType(targetClass); }
Example 11
Source File: RequestParamMethodArgumentResolver.java From spring-analysis-note with MIT License | 5 votes |
@Override public void contributeMethodArgument(MethodParameter parameter, @Nullable Object value, UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) { Class<?> paramType = parameter.getNestedParameterType(); if (Map.class.isAssignableFrom(paramType) || MultipartFile.class == paramType || Part.class == paramType) { return; } RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class); String name = (requestParam != null && StringUtils.hasLength(requestParam.name()) ? requestParam.name() : parameter.getParameterName()); Assert.state(name != null, "Unresolvable parameter name"); parameter = parameter.nestedIfOptional(); if (value instanceof Optional) { value = ((Optional<?>) value).orElse(null); } if (value == null) { if (requestParam != null && (!requestParam.required() || !requestParam.defaultValue().equals(ValueConstants.DEFAULT_NONE))) { return; } builder.queryParam(name); } else if (value instanceof Collection) { for (Object element : (Collection<?>) value) { element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element); builder.queryParam(name, element); } } else { builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value)); } }
Example 12
Source File: RequestParamMethodArgumentResolver.java From spring-analysis-note with MIT License | 5 votes |
/** * Supports the following: * <ul> * <li>@RequestParam-annotated method arguments. * This excludes {@link Map} params where the annotation does not specify a name. * See {@link RequestParamMapMethodArgumentResolver} instead for such params. * <li>Arguments of type {@link MultipartFile} unless annotated with @{@link RequestPart}. * <li>Arguments of type {@code Part} unless annotated with @{@link RequestPart}. * <li>In default resolution mode, simple type arguments even if not with @{@link RequestParam}. * </ul> */ @Override public boolean supportsParameter(MethodParameter parameter) { if (parameter.hasParameterAnnotation(RequestParam.class)) { if (Map.class.isAssignableFrom(parameter.nestedIfOptional().getNestedParameterType())) { RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class); return (requestParam != null && StringUtils.hasText(requestParam.name())); } else { return true; } } else { if (parameter.hasParameterAnnotation(RequestPart.class)) { return false; } parameter = parameter.nestedIfOptional(); if (MultipartResolutionDelegate.isMultipartArgument(parameter)) { return true; } else if (this.useDefaultResolution) { return BeanUtils.isSimpleProperty(parameter.getNestedParameterType()); } else { return false; } } }
Example 13
Source File: ModelAttributeMethodProcessor.java From spring-analysis-note with MIT License | 5 votes |
/** * Extension point to create the model attribute if not found in the model, * with subsequent parameter binding through bean properties (unless suppressed). * <p>The default implementation typically uses the unique public no-arg constructor * if available but also handles a "primary constructor" approach for data classes: * It understands the JavaBeans {@link ConstructorProperties} annotation as well as * runtime-retained parameter names in the bytecode, associating request parameters * with constructor arguments by name. If no such constructor is found, the default * constructor will be used (even if not public), assuming subsequent bean property * bindings through setter methods. * @param attributeName the name of the attribute (never {@code null}) * @param parameter the method parameter declaration * @param binderFactory for creating WebDataBinder instance * @param webRequest the current request * @return the created model attribute (never {@code null}) * @throws BindException in case of constructor argument binding failure * @throws Exception in case of constructor invocation failure * @see #constructAttribute(Constructor, String, MethodParameter, WebDataBinderFactory, NativeWebRequest) * @see BeanUtils#findPrimaryConstructor(Class) */ protected Object createAttribute(String attributeName, MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest webRequest) throws Exception { MethodParameter nestedParameter = parameter.nestedIfOptional(); Class<?> clazz = nestedParameter.getNestedParameterType(); Constructor<?> ctor = BeanUtils.findPrimaryConstructor(clazz); if (ctor == null) { Constructor<?>[] ctors = clazz.getConstructors(); if (ctors.length == 1) { ctor = ctors[0]; } else { try { ctor = clazz.getDeclaredConstructor(); } catch (NoSuchMethodException ex) { throw new IllegalStateException("No primary or default constructor found for " + clazz, ex); } } } Object attribute = constructAttribute(ctor, attributeName, parameter, binderFactory, webRequest); if (parameter != nestedParameter) { attribute = Optional.of(attribute); } return attribute; }
Example 14
Source File: RequestParamMethodArgumentResolver.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Supports the following: * <ul> * <li>@RequestParam-annotated method arguments. * This excludes {@link Map} params where the annotation doesn't * specify a name. See {@link RequestParamMapMethodArgumentResolver} * instead for such params. * <li>Arguments of type {@link MultipartFile} * unless annotated with @{@link RequestPart}. * <li>Arguments of type {@code javax.servlet.http.Part} * unless annotated with @{@link RequestPart}. * <li>In default resolution mode, simple type arguments * even if not with @{@link RequestParam}. * </ul> */ @Override public boolean supportsParameter(MethodParameter parameter) { if (parameter.hasParameterAnnotation(RequestParam.class)) { if (Map.class.isAssignableFrom(parameter.nestedIfOptional().getNestedParameterType())) { String paramName = parameter.getParameterAnnotation(RequestParam.class).name(); return StringUtils.hasText(paramName); } else { return true; } } else { if (parameter.hasParameterAnnotation(RequestPart.class)) { return false; } parameter = parameter.nestedIfOptional(); if (MultipartResolutionDelegate.isMultipartArgument(parameter)) { return true; } else if (this.useDefaultResolution) { return BeanUtils.isSimpleProperty(parameter.getNestedParameterType()); } else { return false; } } }
Example 15
Source File: AbstractNamedValueArgumentResolver.java From spring-analysis-note with MIT License | 5 votes |
@Override public Mono<Object> resolveArgument( MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) { NamedValueInfo namedValueInfo = getNamedValueInfo(parameter); MethodParameter nestedParameter = parameter.nestedIfOptional(); Object resolvedName = resolveStringValue(namedValueInfo.name); if (resolvedName == null) { return Mono.error(new IllegalArgumentException( "Specified name must not resolve to null: [" + namedValueInfo.name + "]")); } Model model = bindingContext.getModel(); return resolveName(resolvedName.toString(), nestedParameter, exchange) .flatMap(arg -> { if ("".equals(arg) && namedValueInfo.defaultValue != null) { arg = resolveStringValue(namedValueInfo.defaultValue); } arg = applyConversion(arg, namedValueInfo, parameter, bindingContext, exchange); handleResolvedValue(arg, namedValueInfo.name, parameter, model, exchange); return Mono.justOrEmpty(arg); }) .switchIfEmpty(getDefaultValue( namedValueInfo, parameter, bindingContext, model, exchange)); }
Example 16
Source File: AbstractNamedValueMethodArgumentResolver.java From spring-analysis-note with MIT License | 5 votes |
@Override public Object resolveArgumentValue(MethodParameter parameter, Message<?> message) { NamedValueInfo namedValueInfo = getNamedValueInfo(parameter); MethodParameter nestedParameter = parameter.nestedIfOptional(); Object resolvedName = resolveEmbeddedValuesAndExpressions(namedValueInfo.name); if (resolvedName == null) { throw new IllegalArgumentException( "Specified name must not resolve to null: [" + namedValueInfo.name + "]"); } Object arg = resolveArgumentInternal(nestedParameter, message, resolvedName.toString()); if (arg == null) { if (namedValueInfo.defaultValue != null) { arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue); } else if (namedValueInfo.required && !nestedParameter.isOptional()) { handleMissingValue(namedValueInfo.name, nestedParameter, message); } arg = handleNullValue(namedValueInfo.name, arg, nestedParameter.getNestedParameterType()); } else if ("".equals(arg) && namedValueInfo.defaultValue != null) { arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue); } if (parameter != nestedParameter || !ClassUtils.isAssignableValue(parameter.getParameterType(), arg)) { arg = this.conversionService.convert(arg, TypeDescriptor.forObject(arg), new TypeDescriptor(parameter)); } return arg; }
Example 17
Source File: AbstractNamedValueMethodArgumentResolver.java From spring-analysis-note with MIT License | 5 votes |
@Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { NamedValueInfo namedValueInfo = getNamedValueInfo(parameter); MethodParameter nestedParameter = parameter.nestedIfOptional(); Object resolvedName = resolveEmbeddedValuesAndExpressions(namedValueInfo.name); if (resolvedName == null) { throw new IllegalArgumentException( "Specified name must not resolve to null: [" + namedValueInfo.name + "]"); } Object arg = resolveArgumentInternal(nestedParameter, message, resolvedName.toString()); if (arg == null) { if (namedValueInfo.defaultValue != null) { arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue); } else if (namedValueInfo.required && !nestedParameter.isOptional()) { handleMissingValue(namedValueInfo.name, nestedParameter, message); } arg = handleNullValue(namedValueInfo.name, arg, nestedParameter.getNestedParameterType()); } else if ("".equals(arg) && namedValueInfo.defaultValue != null) { arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue); } if (parameter != nestedParameter || !ClassUtils.isAssignableValue(parameter.getParameterType(), arg)) { arg = this.conversionService.convert(arg, TypeDescriptor.forObject(arg), new TypeDescriptor(parameter)); } handleResolvedValue(arg, namedValueInfo.name, parameter, message); return arg; }
Example 18
Source File: RequestPartMethodArgumentResolver.java From spring-analysis-note with MIT License | 4 votes |
@Override @Nullable public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest request, @Nullable WebDataBinderFactory binderFactory) throws Exception { HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class); Assert.state(servletRequest != null, "No HttpServletRequest"); RequestPart requestPart = parameter.getParameterAnnotation(RequestPart.class); boolean isRequired = ((requestPart == null || requestPart.required()) && !parameter.isOptional()); String name = getPartName(parameter, requestPart); parameter = parameter.nestedIfOptional(); Object arg = null; Object mpArg = MultipartResolutionDelegate.resolveMultipartArgument(name, parameter, servletRequest); if (mpArg != MultipartResolutionDelegate.UNRESOLVABLE) { arg = mpArg; } else { try { HttpInputMessage inputMessage = new RequestPartServletServerHttpRequest(servletRequest, name); arg = readWithMessageConverters(inputMessage, parameter, parameter.getNestedGenericParameterType()); if (binderFactory != null) { WebDataBinder binder = binderFactory.createBinder(request, arg, name); if (arg != null) { validateIfApplicable(binder, parameter); if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) { throw new MethodArgumentNotValidException(parameter, binder.getBindingResult()); } } if (mavContainer != null) { mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult()); } } } catch (MissingServletRequestPartException | MultipartException ex) { if (isRequired) { throw ex; } } } if (arg == null && isRequired) { if (!MultipartResolutionDelegate.isMultipartRequest(servletRequest)) { throw new MultipartException("Current request is not a multipart request"); } else { throw new MissingServletRequestPartException(name); } } return adaptArgumentIfNecessary(arg, parameter); }
Example 19
Source File: RequestPartMethodArgumentResolver.java From java-technology-stack with MIT License | 4 votes |
@Override @Nullable public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest request, @Nullable WebDataBinderFactory binderFactory) throws Exception { HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class); Assert.state(servletRequest != null, "No HttpServletRequest"); RequestPart requestPart = parameter.getParameterAnnotation(RequestPart.class); boolean isRequired = ((requestPart == null || requestPart.required()) && !parameter.isOptional()); String name = getPartName(parameter, requestPart); parameter = parameter.nestedIfOptional(); Object arg = null; Object mpArg = MultipartResolutionDelegate.resolveMultipartArgument(name, parameter, servletRequest); if (mpArg != MultipartResolutionDelegate.UNRESOLVABLE) { arg = mpArg; } else { try { HttpInputMessage inputMessage = new RequestPartServletServerHttpRequest(servletRequest, name); arg = readWithMessageConverters(inputMessage, parameter, parameter.getNestedGenericParameterType()); if (binderFactory != null) { WebDataBinder binder = binderFactory.createBinder(request, arg, name); if (arg != null) { validateIfApplicable(binder, parameter); if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) { throw new MethodArgumentNotValidException(parameter, binder.getBindingResult()); } } if (mavContainer != null) { mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult()); } } } catch (MissingServletRequestPartException | MultipartException ex) { if (isRequired) { throw ex; } } } if (arg == null && isRequired) { if (!MultipartResolutionDelegate.isMultipartRequest(servletRequest)) { throw new MultipartException("Current request is not a multipart request"); } else { throw new MissingServletRequestPartException(name); } } return adaptArgumentIfNecessary(arg, parameter); }
Example 20
Source File: RaptorHandlerMethodProcessor.java From raptor with Apache License 2.0 | 4 votes |
private Object convertBody(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { parameter = parameter.nestedIfOptional(); return readWithMessageConverters(webRequest, parameter, parameter.getNestedGenericParameterType()); }