本文整理汇总了Java中org.springframework.web.bind.support.WebArgumentResolver类的典型用法代码示例。如果您正苦于以下问题:Java WebArgumentResolver类的具体用法?Java WebArgumentResolver怎么用?Java WebArgumentResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebArgumentResolver类属于org.springframework.web.bind.support包,在下文中一共展示了WebArgumentResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: supportsParameter
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
/**
* 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;
}
}
示例2: resolveArgument
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
/**
* 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;
}
示例3: resolveHandlerArguments
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
/**
* 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;
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:AnnotationMethodHandlerExceptionResolver.java
示例4: wrapLegacyResolvers
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) {
ManagedList<Object> result = new ManagedList<Object>();
for (Object object : list) {
if (object instanceof BeanDefinitionHolder) {
BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object;
String className = beanDef.getBeanDefinition().getBeanClassName();
Class<?> clazz = ClassUtils.resolveClassName(className, context.getReaderContext().getBeanClassLoader());
if (WebArgumentResolver.class.isAssignableFrom(clazz)) {
RootBeanDefinition adapter = new RootBeanDefinition(ServletWebArgumentResolverAdapter.class);
adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef);
result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter"));
continue;
}
}
result.add(object);
}
return result;
}
示例5: resolveHandlerArguments
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
/**
* 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 MethodParameter(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;
}
示例6: wrapWebArgumentResolverBeanDefs
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
private ManagedList<BeanDefinitionHolder> wrapWebArgumentResolverBeanDefs(
List<BeanDefinitionHolder> beanDefs, ParserContext parserContext) {
ManagedList<BeanDefinitionHolder> result = new ManagedList<BeanDefinitionHolder>();
for (BeanDefinitionHolder beanDef : beanDefs) {
String className = beanDef.getBeanDefinition().getBeanClassName();
Class<?> clazz = ClassUtils.resolveClassName(className, parserContext.getReaderContext().getBeanClassLoader());
if (WebArgumentResolver.class.isAssignableFrom(clazz)) {
RootBeanDefinition adapter = new RootBeanDefinition(ServletWebArgumentResolverAdapter.class);
adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef);
result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter"));
}
else {
result.add(beanDef);
}
}
return result;
}
示例7: supportsParameter
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
/**
* Actually resolve the value and check the resolved value is not
* {@link WebArgumentResolver#UNRESOLVED} absorbing _any_ exceptions.
*/
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;
}
}
示例8: resolveArgument
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
/**
* Delegate to the {@link WebArgumentResolver} instance.
* @exception IllegalStateException if the resolved value is not assignable
* to the method parameter.
*/
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;
}
示例9: testResolveArgument
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
@Test
public void testResolveArgument() throws Exception {
// given
ModelAndViewContainer mavContainer = mock(ModelAndViewContainer.class);
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
NativeWebRequest webRequest = mock(NativeWebRequest.class);
User stubUser = new User(USER_NAME, "", Collections.emptyList());
Principal stubPrincipal = new UsernamePasswordAuthenticationToken(stubUser, null);
when(webRequest.getUserPrincipal()).thenReturn(stubPrincipal);
// when/then
assertEquals(stubUser,
resolver.resolveArgument(validParam, mavContainer, webRequest,binderFactory));
assertEquals(WebArgumentResolver.UNRESOLVED,
resolver.resolveArgument(notAnnotatedParam, mavContainer, webRequest,binderFactory));
assertEquals(WebArgumentResolver.UNRESOLVED,
resolver.resolveArgument(wrongTypeParam, mavContainer, webRequest,binderFactory));
}
开发者ID:vdenotaris,项目名称:spring-boot-security-saml-sample,代码行数:19,代码来源:CurrentUserHandlerMethodArgumentResolverTest.java
示例10: HandlerMethodInvoker
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
public HandlerMethodInvoker(HandlerMethodResolver methodResolver, WebBindingInitializer bindingInitializer,
SessionAttributeStore sessionAttributeStore, ParameterNameDiscoverer parameterNameDiscoverer,
WebArgumentResolver[] customArgumentResolvers, HttpMessageConverter<?>[] messageConverters) {
this.methodResolver = methodResolver;
this.bindingInitializer = bindingInitializer;
this.sessionAttributeStore = sessionAttributeStore;
this.parameterNameDiscoverer = parameterNameDiscoverer;
this.customArgumentResolvers = customArgumentResolvers;
this.messageConverters = messageConverters;
}
示例11: resolveArgument
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
/**
* 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;
}
示例12: setUp
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
adaptee = mock(WebArgumentResolver.class);
adapter = new TestWebArgumentResolverAdapter(adaptee);
parameter = new MethodParameter(getClass().getMethod("handle", Integer.TYPE), 0);
webRequest = new ServletWebRequest(new MockHttpServletRequest());
// Expose request to the current thread (for SpEL expressions)
RequestContextHolder.setRequestAttributes(webRequest);
}
示例13: supportsParameterUnresolved
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
@Test
public void supportsParameterUnresolved() throws Exception {
given(adaptee.resolveArgument(parameter, webRequest)).willReturn(WebArgumentResolver.UNRESOLVED);
assertFalse("Parameter supported", adapter.supportsParameter(parameter));
verify(adaptee).resolveArgument(parameter, webRequest);
}
示例14: resolveArgument
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
@Override
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
if (supportsParameter(methodParameter)) {
return createUserDetails(webRequest);
}
else {
return WebArgumentResolver.UNRESOLVED;
}
}
示例15: resolveArgument
import org.springframework.web.bind.support.WebArgumentResolver; //导入依赖的package包/类
public Object resolveArgument(MethodParameter methodParameter,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
WebDataBinderFactory binderFactory) throws Exception {
if (this.supportsParameter(methodParameter)) {
return securityUtils.getCurrentUser();
} else {
return WebArgumentResolver.UNRESOLVED;
}
}