Java Code Examples for org.springframework.web.bind.support.WebArgumentResolver#UNRESOLVED
The following examples show how to use
org.springframework.web.bind.support.WebArgumentResolver#UNRESOLVED .
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: AbstractWebArgumentResolverAdapter.java From spring-analysis-note with MIT License | 6 votes |
/** * Delegate to the {@link WebArgumentResolver} instance. * @throws IllegalStateException if the resolved value is not assignable * to the method parameter. */ @Override @Nullable public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { Class<?> paramType = parameter.getParameterType(); Object result = this.adaptee.resolveArgument(parameter, webRequest); if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) { throw new IllegalStateException( "Standard argument type [" + paramType.getName() + "] in method " + parameter.getMethod() + "resolved to incompatible value of type [" + (result != null ? result.getClass() : null) + "]. Consider declaring the argument type in a less specific fashion."); } return result; }
Example 2
Source File: AbstractWebArgumentResolverAdapter.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Actually resolve the value and check the resolved value is not * {@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 { return ClassUtils.isAssignableValue(parameter.getParameterType(), result); } } catch (Exception ex) { // ignore (see class-level doc) logger.debug("Error in checking support for parameter [" + parameter + "], message: " + ex.getMessage()); return false; } }
Example 3
Source File: AnnotationMethodHandlerExceptionResolver.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Resolves the arguments for the given method. Delegates to {@link #resolveCommonArgument}. */ private Object[] resolveHandlerArguments(Method handlerMethod, Object handler, NativeWebRequest webRequest, Exception thrownException) throws Exception { Class<?>[] paramTypes = handlerMethod.getParameterTypes(); Object[] args = new Object[paramTypes.length]; Class<?> handlerType = handler.getClass(); for (int i = 0; i < args.length; i++) { MethodParameter methodParam = new SynthesizingMethodParameter(handlerMethod, i); GenericTypeResolver.resolveParameterType(methodParam, handlerType); Class<?> paramType = methodParam.getParameterType(); Object argValue = resolveCommonArgument(methodParam, webRequest, thrownException); if (argValue != WebArgumentResolver.UNRESOLVED) { args[i] = argValue; } else { throw new IllegalStateException("Unsupported argument [" + paramType.getName() + "] for @ExceptionHandler method: " + handlerMethod); } } return args; }
Example 4
Source File: AnnotationMethodHandlerExceptionResolver.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Resolves the arguments for the given method. Delegates to {@link #resolveCommonArgument}. */ private Object[] resolveHandlerArguments(Method handlerMethod, Object handler, NativeWebRequest webRequest, Exception thrownException) throws Exception { Class<?>[] paramTypes = handlerMethod.getParameterTypes(); Object[] args = new Object[paramTypes.length]; Class<?> handlerType = handler.getClass(); for (int i = 0; i < args.length; i++) { MethodParameter methodParam = new SynthesizingMethodParameter(handlerMethod, i); GenericTypeResolver.resolveParameterType(methodParam, handlerType); Class<?> paramType = methodParam.getParameterType(); Object argValue = resolveCommonArgument(methodParam, webRequest, thrownException); if (argValue != WebArgumentResolver.UNRESOLVED) { args[i] = argValue; } else { throw new IllegalStateException("Unsupported argument [" + paramType.getName() + "] for @ExceptionHandler method: " + handlerMethod); } } return args; }
Example 5
Source File: AbstractWebArgumentResolverAdapter.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Actually resolve the value and check the resolved value is not * {@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 { return ClassUtils.isAssignableValue(parameter.getParameterType(), result); } } catch (Exception ex) { // ignore (see class-level doc) logger.debug("Error in checking support for parameter [" + parameter + "], message: " + ex.getMessage()); return false; } }
Example 6
Source File: AnnotationMethodHandlerExceptionResolver.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Resolves the arguments for the given method. Delegates to {@link #resolveCommonArgument}. */ private Object[] resolveHandlerArguments(Method handlerMethod, Object handler, NativeWebRequest webRequest, Exception thrownException) throws Exception { Class<?>[] paramTypes = handlerMethod.getParameterTypes(); Object[] args = new Object[paramTypes.length]; Class<?> handlerType = handler.getClass(); for (int i = 0; i < args.length; i++) { MethodParameter methodParam = new SynthesizingMethodParameter(handlerMethod, i); GenericTypeResolver.resolveParameterType(methodParam, handlerType); Class<?> paramType = methodParam.getParameterType(); Object argValue = resolveCommonArgument(methodParam, webRequest, thrownException); if (argValue != WebArgumentResolver.UNRESOLVED) { args[i] = argValue; } else { throw new IllegalStateException("Unsupported argument [" + paramType.getName() + "] for @ExceptionHandler method: " + handlerMethod); } } return args; }
Example 7
Source File: AbstractWebArgumentResolverAdapter.java From java-technology-stack with MIT License | 6 votes |
/** * Delegate to the {@link WebArgumentResolver} instance. * @throws IllegalStateException if the resolved value is not assignable * to the method parameter. */ @Override @Nullable public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { Class<?> paramType = parameter.getParameterType(); Object result = this.adaptee.resolveArgument(parameter, webRequest); if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) { throw new IllegalStateException( "Standard argument type [" + paramType.getName() + "] in method " + parameter.getMethod() + "resolved to incompatible value of type [" + (result != null ? result.getClass() : null) + "]. Consider declaring the argument type in a less specific fashion."); } return result; }
Example 8
Source File: AbstractWebArgumentResolverAdapter.java From java-technology-stack with MIT License | 6 votes |
/** * Actually resolve the value and check the resolved value is not * {@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 { return ClassUtils.isAssignableValue(parameter.getParameterType(), result); } } catch (Exception ex) { // ignore (see class-level doc) logger.debug("Error in checking support for parameter [" + parameter + "], message: " + ex.getMessage()); return false; } }
Example 9
Source File: AbstractWebArgumentResolverAdapter.java From spring-analysis-note with MIT License | 6 votes |
/** * Actually resolve the value and check the resolved value is not * {@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 { return ClassUtils.isAssignableValue(parameter.getParameterType(), result); } } catch (Exception ex) { // ignore (see class-level doc) if (logger.isDebugEnabled()) { logger.debug("Error in checking support for parameter [" + parameter + "]: " + ex.getMessage()); } return false; } }
Example 10
Source File: AbstractWebArgumentResolverAdapter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Delegate to the {@link WebArgumentResolver} instance. * @exception IllegalStateException if the resolved value is not assignable * to the method parameter. */ @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { Class<?> paramType = parameter.getParameterType(); Object result = this.adaptee.resolveArgument(parameter, webRequest); if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) { throw new IllegalStateException( "Standard argument type [" + paramType.getName() + "] in method " + parameter.getMethod() + "resolved to incompatible value of type [" + (result != null ? result.getClass() : null) + "]. Consider declaring the argument type in a less specific fashion."); } return result; }
Example 11
Source File: CurrentUserHandlerMethodArgumentResolver.java From spring-boot-security-saml-sample with Apache License 2.0 | 5 votes |
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { if (this.supportsParameter(methodParameter)) { Principal principal = (Principal) webRequest.getUserPrincipal(); return (User) ((Authentication) principal).getPrincipal(); } else { return WebArgumentResolver.UNRESOLVED; } }
Example 12
Source File: UserDetailsArgumentResolver.java From slackspace-angular-spring-keycloak with Apache License 2.0 | 5 votes |
@Override public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { if (supportsParameter(methodParameter)) { return createUserDetails(webRequest); } else { return WebArgumentResolver.UNRESOLVED; } }
Example 13
Source File: CurrentUserHandlerMethodArgumentResolver.java From spring-tsers-auth with Apache License 2.0 | 5 votes |
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { if (this.supportsParameter(methodParameter)) { return securityUtils.getCurrentUser(); } else { return WebArgumentResolver.UNRESOLVED; } }
Example 14
Source File: AnnotationMethodHandlerExceptionResolver.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Resolves standard method arguments. The default implementation handles {@link NativeWebRequest}, * {@link ServletRequest}, {@link ServletResponse}, {@link HttpSession}, {@link Principal}, * {@link Locale}, request {@link InputStream}, request {@link Reader}, response {@link OutputStream}, * response {@link Writer}, and the given {@code thrownException}. * @param parameterType the method parameter type * @param webRequest the request * @param thrownException the exception thrown * @return the argument value, or {@link WebArgumentResolver#UNRESOLVED} */ protected Object resolveStandardArgument(Class<?> parameterType, NativeWebRequest webRequest, Exception thrownException) throws Exception { if (parameterType.isInstance(thrownException)) { return thrownException; } else if (WebRequest.class.isAssignableFrom(parameterType)) { return webRequest; } HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class); if (ServletRequest.class.isAssignableFrom(parameterType)) { return request; } else if (ServletResponse.class.isAssignableFrom(parameterType)) { return response; } else if (HttpSession.class.isAssignableFrom(parameterType)) { return request.getSession(); } else if (Principal.class.isAssignableFrom(parameterType)) { return request.getUserPrincipal(); } else if (Locale.class == parameterType) { return RequestContextUtils.getLocale(request); } else if (InputStream.class.isAssignableFrom(parameterType)) { return request.getInputStream(); } else if (Reader.class.isAssignableFrom(parameterType)) { return request.getReader(); } else if (OutputStream.class.isAssignableFrom(parameterType)) { return response.getOutputStream(); } else if (Writer.class.isAssignableFrom(parameterType)) { return response.getWriter(); } else { return WebArgumentResolver.UNRESOLVED; } }
Example 15
Source File: HandlerMethodInvoker.java From lams with GNU General Public License v2.0 | 4 votes |
private Object[] resolveInitBinderArguments(Object handler, Method initBinderMethod, WebDataBinder binder, NativeWebRequest webRequest) throws Exception { Class<?>[] initBinderParams = initBinderMethod.getParameterTypes(); Object[] initBinderArgs = new Object[initBinderParams.length]; for (int i = 0; i < initBinderArgs.length; i++) { MethodParameter methodParam = new SynthesizingMethodParameter(initBinderMethod, i); methodParam.initParameterNameDiscovery(this.parameterNameDiscoverer); GenericTypeResolver.resolveParameterType(methodParam, handler.getClass()); String paramName = null; boolean paramRequired = false; String paramDefaultValue = null; String pathVarName = null; Annotation[] paramAnns = methodParam.getParameterAnnotations(); for (Annotation paramAnn : paramAnns) { if (RequestParam.class.isInstance(paramAnn)) { RequestParam requestParam = (RequestParam) paramAnn; paramName = requestParam.name(); paramRequired = requestParam.required(); paramDefaultValue = parseDefaultValueAttribute(requestParam.defaultValue()); break; } else if (ModelAttribute.class.isInstance(paramAnn)) { throw new IllegalStateException( "@ModelAttribute is not supported on @InitBinder methods: " + initBinderMethod); } else if (PathVariable.class.isInstance(paramAnn)) { PathVariable pathVar = (PathVariable) paramAnn; pathVarName = pathVar.value(); } } if (paramName == null && pathVarName == null) { Object argValue = resolveCommonArgument(methodParam, webRequest); if (argValue != WebArgumentResolver.UNRESOLVED) { initBinderArgs[i] = argValue; } else { Class<?> paramType = initBinderParams[i]; if (paramType.isInstance(binder)) { initBinderArgs[i] = binder; } else if (BeanUtils.isSimpleProperty(paramType)) { paramName = ""; } else { throw new IllegalStateException("Unsupported argument [" + paramType.getName() + "] for @InitBinder method: " + initBinderMethod); } } } if (paramName != null) { initBinderArgs[i] = resolveRequestParam(paramName, paramRequired, paramDefaultValue, methodParam, webRequest, null); } else if (pathVarName != null) { initBinderArgs[i] = resolvePathVariable(pathVarName, methodParam, webRequest, null); } } return initBinderArgs; }
Example 16
Source File: HandlerMethodInvoker.java From lams with GNU General Public License v2.0 | 4 votes |
protected Object resolveStandardArgument(Class<?> parameterType, NativeWebRequest webRequest) throws Exception { if (WebRequest.class.isAssignableFrom(parameterType)) { return webRequest; } return WebArgumentResolver.UNRESOLVED; }
Example 17
Source File: AnnotationMethodHandlerExceptionResolver.java From spring4-understanding with Apache License 2.0 | 4 votes |
/** * Resolves standard method arguments. The default implementation handles {@link NativeWebRequest}, * {@link ServletRequest}, {@link ServletResponse}, {@link HttpSession}, {@link Principal}, * {@link Locale}, request {@link InputStream}, request {@link Reader}, response {@link OutputStream}, * response {@link Writer}, and the given {@code thrownException}. * @param parameterType the method parameter type * @param webRequest the request * @param thrownException the exception thrown * @return the argument value, or {@link org.springframework.web.bind.support.WebArgumentResolver#UNRESOLVED} */ protected Object resolveStandardArgument(Class<?> parameterType, NativeWebRequest webRequest, Exception thrownException) throws Exception { if (parameterType.isInstance(thrownException)) { return thrownException; } else if (WebRequest.class.isAssignableFrom(parameterType)) { return webRequest; } PortletRequest request = webRequest.getNativeRequest(PortletRequest.class); PortletResponse response = webRequest.getNativeResponse(PortletResponse.class); if (PortletRequest.class.isAssignableFrom(parameterType)) { return request; } else if (PortletResponse.class.isAssignableFrom(parameterType)) { return response; } else if (PortletSession.class.isAssignableFrom(parameterType)) { return request.getPortletSession(); } else if (PortletPreferences.class.isAssignableFrom(parameterType)) { return request.getPreferences(); } else if (PortletMode.class.isAssignableFrom(parameterType)) { return request.getPortletMode(); } else if (WindowState.class.isAssignableFrom(parameterType)) { return request.getWindowState(); } else if (PortalContext.class.isAssignableFrom(parameterType)) { return request.getPortalContext(); } else if (Principal.class.isAssignableFrom(parameterType)) { return request.getUserPrincipal(); } else if (Locale.class == parameterType) { return request.getLocale(); } else if (InputStream.class.isAssignableFrom(parameterType)) { if (!(request instanceof ClientDataRequest)) { throw new IllegalStateException("InputStream can only get obtained for Action/ResourceRequest"); } return ((ClientDataRequest) request).getPortletInputStream(); } else if (Reader.class.isAssignableFrom(parameterType)) { if (!(request instanceof ClientDataRequest)) { throw new IllegalStateException("Reader can only get obtained for Action/ResourceRequest"); } return ((ClientDataRequest) request).getReader(); } else if (OutputStream.class.isAssignableFrom(parameterType)) { if (!(response instanceof MimeResponse)) { throw new IllegalStateException("OutputStream can only get obtained for Render/ResourceResponse"); } return ((MimeResponse) response).getPortletOutputStream(); } else if (Writer.class.isAssignableFrom(parameterType)) { if (!(response instanceof MimeResponse)) { throw new IllegalStateException("Writer can only get obtained for Render/ResourceResponse"); } return ((MimeResponse) response).getWriter(); } else if (Event.class == parameterType) { if (!(request instanceof EventRequest)) { throw new IllegalStateException("Event can only get obtained from EventRequest"); } return ((EventRequest) request).getEvent(); } else { return WebArgumentResolver.UNRESOLVED; } }
Example 18
Source File: AnnotationMethodHandlerExceptionResolver.java From spring4-understanding with Apache License 2.0 | 4 votes |
/** * Resolves standard method arguments. The default implementation handles {@link NativeWebRequest}, * {@link ServletRequest}, {@link ServletResponse}, {@link HttpSession}, {@link Principal}, * {@link Locale}, request {@link InputStream}, request {@link Reader}, response {@link OutputStream}, * response {@link Writer}, and the given {@code thrownException}. * @param parameterType the method parameter type * @param webRequest the request * @param thrownException the exception thrown * @return the argument value, or {@link WebArgumentResolver#UNRESOLVED} */ protected Object resolveStandardArgument(Class<?> parameterType, NativeWebRequest webRequest, Exception thrownException) throws Exception { if (parameterType.isInstance(thrownException)) { return thrownException; } else if (WebRequest.class.isAssignableFrom(parameterType)) { return webRequest; } HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class); if (ServletRequest.class.isAssignableFrom(parameterType)) { return request; } else if (ServletResponse.class.isAssignableFrom(parameterType)) { return response; } else if (HttpSession.class.isAssignableFrom(parameterType)) { return request.getSession(); } else if (Principal.class.isAssignableFrom(parameterType)) { return request.getUserPrincipal(); } else if (Locale.class == parameterType) { return RequestContextUtils.getLocale(request); } else if (InputStream.class.isAssignableFrom(parameterType)) { return request.getInputStream(); } else if (Reader.class.isAssignableFrom(parameterType)) { return request.getReader(); } else if (OutputStream.class.isAssignableFrom(parameterType)) { return response.getOutputStream(); } else if (Writer.class.isAssignableFrom(parameterType)) { return response.getWriter(); } else { return WebArgumentResolver.UNRESOLVED; } }
Example 19
Source File: HandlerMethodInvoker.java From spring4-understanding with Apache License 2.0 | 4 votes |
private Object[] resolveInitBinderArguments(Object handler, Method initBinderMethod, WebDataBinder binder, NativeWebRequest webRequest) throws Exception { Class<?>[] initBinderParams = initBinderMethod.getParameterTypes(); Object[] initBinderArgs = new Object[initBinderParams.length]; for (int i = 0; i < initBinderArgs.length; i++) { MethodParameter methodParam = new SynthesizingMethodParameter(initBinderMethod, i); methodParam.initParameterNameDiscovery(this.parameterNameDiscoverer); GenericTypeResolver.resolveParameterType(methodParam, handler.getClass()); String paramName = null; boolean paramRequired = false; String paramDefaultValue = null; String pathVarName = null; Annotation[] paramAnns = methodParam.getParameterAnnotations(); for (Annotation paramAnn : paramAnns) { if (RequestParam.class.isInstance(paramAnn)) { RequestParam requestParam = (RequestParam) paramAnn; paramName = requestParam.name(); paramRequired = requestParam.required(); paramDefaultValue = parseDefaultValueAttribute(requestParam.defaultValue()); break; } else if (ModelAttribute.class.isInstance(paramAnn)) { throw new IllegalStateException( "@ModelAttribute is not supported on @InitBinder methods: " + initBinderMethod); } else if (PathVariable.class.isInstance(paramAnn)) { PathVariable pathVar = (PathVariable) paramAnn; pathVarName = pathVar.value(); } } if (paramName == null && pathVarName == null) { Object argValue = resolveCommonArgument(methodParam, webRequest); if (argValue != WebArgumentResolver.UNRESOLVED) { initBinderArgs[i] = argValue; } else { Class<?> paramType = initBinderParams[i]; if (paramType.isInstance(binder)) { initBinderArgs[i] = binder; } else if (BeanUtils.isSimpleProperty(paramType)) { paramName = ""; } else { throw new IllegalStateException("Unsupported argument [" + paramType.getName() + "] for @InitBinder method: " + initBinderMethod); } } } if (paramName != null) { initBinderArgs[i] = resolveRequestParam(paramName, paramRequired, paramDefaultValue, methodParam, webRequest, null); } else if (pathVarName != null) { initBinderArgs[i] = resolvePathVariable(pathVarName, methodParam, webRequest, null); } } return initBinderArgs; }
Example 20
Source File: HandlerMethodInvoker.java From spring4-understanding with Apache License 2.0 | 4 votes |
protected Object resolveStandardArgument(Class<?> parameterType, NativeWebRequest webRequest) throws Exception { if (WebRequest.class.isAssignableFrom(parameterType)) { return webRequest; } return WebArgumentResolver.UNRESOLVED; }