本文整理汇总了Java中org.springframework.core.MethodParameter类的典型用法代码示例。如果您正苦于以下问题:Java MethodParameter类的具体用法?Java MethodParameter怎么用?Java MethodParameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MethodParameter类属于org.springframework.core包,在下文中一共展示了MethodParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveArgument
import org.springframework.core.MethodParameter; //导入依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
String nonceBase64 = getNonceOrThrow(webRequest);
String nonceSignatureBase64 = getNonceSignatureOrThrow(webRequest);
if (!isBase64(nonceBase64)) {
throw new BadRequestException("Nonce must be base64");
}
if (!isBase64(nonceSignatureBase64)) {
throw new BadRequestException("Nonce signature must be base64");
}
return NonceAuthenticationImpl.builder()
.nonceBase64(nonceBase64)
.nonceSignatureBase64(nonceSignatureBase64)
.build();
}
示例2: handleMissingValue
import org.springframework.core.MethodParameter; //导入依赖的package包/类
@Override
protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request)
throws Exception {
HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
if (MultipartResolutionDelegate.isMultipartArgument(parameter)) {
if (!MultipartResolutionDelegate.isMultipartRequest(servletRequest)) {
throw new MultipartException("Current request is not a multipart request");
} else {
throw new MissingServletRequestPartException(name);
}
} else {
throw new MissingServletRequestParameterException(name,
parameter.getNestedParameterType().getSimpleName());
}
}
示例3: getAccessUser
import org.springframework.core.MethodParameter; //导入依赖的package包/类
protected AdminUser getAccessUser(HttpServletRequest request, LoggingContext loggingContext) {
if(loggingContext.getHttpAccessLogging().isLogin()){ //用户正在登录
HandlerMethod handlerMethod = loggingContext.getHandlerMethod();
MethodParameter[] methodParameters = handlerMethod.getMethodParameters();
if(methodParameters != null){
for(MethodParameter methodParameter : methodParameters){
if(methodParameter.hasParameterAnnotation(RequestBody.class) && AdminUser.class.equals(methodParameter.getParameterType())){
HttpRequestParameter requestParameter = loggingContext.getHttpAccessLog().getRequestParameter();
Object requestBody = requestParameter.getBody();
MediaType contentType = loggingContext.getHttpAccessLog().getRequestContentType();
if (contentType != null && requestBody != null && requestBody instanceof Map && MediaType.APPLICATION_JSON.getType().equals(contentType.getType())) {
Map<String,Object> requestBodyMap = (Map<String, Object>) requestBody;
return adminUserService.getUserByUserName(MapUtils.getString(requestBodyMap, "userName"), false);
}
}
}
}
return null;
}else{ //用户已登录
LoginToken<AdminUser> loginToken = (LoginToken<AdminUser>) ShiroUtils.getSessionAttribute(LoginToken.LOGIN_TOKEN_SESSION_KEY);
return loginToken == null ? null : loginToken.getLoginUser();
}
}
示例4: getPropertyType
import org.springframework.core.MethodParameter; //导入依赖的package包/类
@Override
public synchronized Class<?> getPropertyType() {
if (this.propertyType == null) {
if (this.readMethod != null) {
this.propertyType = GenericTypeResolver.resolveReturnType(this.readMethod, this.beanClass);
}
else {
MethodParameter writeMethodParam = getWriteMethodParameter();
if (writeMethodParam != null) {
this.propertyType = writeMethodParam.getParameterType();
}
else {
this.propertyType = super.getPropertyType();
}
}
}
return this.propertyType;
}
示例5: supportsReturnType
import org.springframework.core.MethodParameter; //导入依赖的package包/类
/**
* 有WxAsyncMessage注解且
* 返回值是WxMessage的子类
* 或者是CharSequence的子类,且有注解WxButton或者WXMessageMapping
*
* @param returnType
* @return dummy
*/
@Override
public boolean supportsReturnType(MethodParameter returnType) {
// 如果是iterable或者array,都作为asyncMessage消息处理
boolean isIterableType = Iterable.class.isAssignableFrom(returnType.getParameterType());
boolean isArrayType = returnType.getParameterType().isArray();
boolean isGroupMessage = WxGroupMessage.class.isAssignableFrom(returnType.getParameterType());
boolean isTemplateMessage = WxTemplateMessage.class.isAssignableFrom(returnType.getParameterType());
// 理论上WxAsyncMessage已经被上层处理过了,这里保险起见再处理一次
boolean needAsyncSend = isIterableType || isArrayType || isGroupMessage || isTemplateMessage;
Class realType = getGenericType(returnType);
boolean isWxMessage = WxMessage.class.isAssignableFrom(realType);
boolean isWxStringMessage = CharSequence.class.isAssignableFrom(realType) &&
returnType.hasMethodAnnotation(WxMapping.class);
return needAsyncSend && (isWxMessage || isWxStringMessage);
}
示例6: testToBigDecimal
import org.springframework.core.MethodParameter; //导入依赖的package包/类
@Test
public void testToBigDecimal() throws NoSuchMethodException, SecurityException {
Method testMethod = getClass().getDeclaredMethod("BigDecimalParam",
BigDecimal.class);
MethodParameter param = new MethodParameter(testMethod, 0);
assertThat(this.invocableHandlerMethod.convert(param, null)).isNull();
assertThat(this.invocableHandlerMethod.convert(param, (byte) 1))
.isEqualTo(new BigDecimal("1"));
assertThat(this.invocableHandlerMethod.convert(param, (short) 2))
.isEqualTo(new BigDecimal("2"));
assertThat(this.invocableHandlerMethod.convert(param, 3))
.isEqualTo(new BigDecimal("3"));
assertThat(this.invocableHandlerMethod.convert(param, 4L))
.isEqualTo(new BigDecimal("4"));
assertThat(this.invocableHandlerMethod.convert(param, 5.5f))
.isEqualTo(new BigDecimal("5.5"));
assertThat(this.invocableHandlerMethod.convert(param, 6.6))
.isEqualTo(new BigDecimal("6.6"));
assertThat(this.invocableHandlerMethod.convert(param, new BigDecimal("3.141")))
.isEqualTo(new BigDecimal("3.141"));
}
示例7: handleReturnValue
import org.springframework.core.MethodParameter; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
if (returnValue == null) {
mavContainer.setRequestHandled(true);
return;
}
final AsyncResponseEntity<?> asyncResponseEntity = AsyncResponseEntity.class.cast(returnValue);
Observable<?> observable = asyncResponseEntity.getObservable();
Single<?> single = asyncResponseEntity.getSingle();
MultiValueMap<String, String> headers = asyncResponseEntity.getHeaders();
HttpStatus status = asyncResponseEntity.getStatus();
if(observable != null)
WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(new ObservableDeferredResult<>(observable, headers, status), mavContainer);
else if(single != null)
WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(new SingleDeferredResult<>(single, headers, status), mavContainer);
}
示例8: isAutowireCandidate
import org.springframework.core.MethodParameter; //导入依赖的package包/类
/**
* Determine whether the provided bean definition is an autowire candidate.
* <p>To be considered a candidate the bean's <em>autowire-candidate</em>
* attribute must not have been set to 'false'. Also, if an annotation on
* the field or parameter to be autowired is recognized by this bean factory
* as a <em>qualifier</em>, the bean must 'match' against the annotation as
* well as any attributes it may contain. The bean definition must contain
* the same qualifier or match by meta attributes. A "value" attribute will
* fallback to match against the bean name or an alias if a qualifier or
* attribute does not match.
* @see Qualifier
*/
@Override
public boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor) {
boolean match = super.isAutowireCandidate(bdHolder, descriptor);
if (match && descriptor != null) {
match = checkQualifiers(bdHolder, descriptor.getAnnotations());
if (match) {
MethodParameter methodParam = descriptor.getMethodParameter();
if (methodParam != null) {
Method method = methodParam.getMethod();
if (method == null || void.class.equals(method.getReturnType())) {
match = checkQualifiers(bdHolder, methodParam.getMethodAnnotations());
}
}
}
}
return match;
}
示例9: beforeBodyWrite
import org.springframework.core.MethodParameter; //导入依赖的package包/类
@Override
public BizRes beforeBodyWrite(BizRes body, MethodParameter returnType, MediaType selectedContentType,
Class<? extends HttpMessageConverter<?>> selectedConverterType,
ServerHttpRequest request, ServerHttpResponse response) {
String deviceToken = response.getHeaders().getFirst(requestHeaderProperties.getDeviceToken());
if (body instanceof ErrorRes) {
((ErrorRes) body).setVd(deviceToken);
return body;
}
if (body instanceof SuccessRes) {
((SuccessRes) body).setVd(deviceToken);
return body;
}
SuccessRes res = new SuccessRes(body);
res.setVd(deviceToken);
return res;
}
示例10: execute
import org.springframework.core.MethodParameter; //导入依赖的package包/类
@Override
public TypedValue execute(EvaluationContext context, Object target, Object... arguments) throws AccessException {
try {
if (arguments != null) {
ReflectionHelper.convertArguments(context.getTypeConverter(), arguments, this.method, this.varargsPosition);
}
if (this.method.isVarArgs()) {
arguments = ReflectionHelper.setupArgumentsForVarargsInvocation(this.method.getParameterTypes(), arguments);
}
ReflectionUtils.makeAccessible(this.method);
Object value = this.method.invoke(target, arguments);
return new TypedValue(value, new TypeDescriptor(new MethodParameter(this.method, -1)).narrow(value));
}
catch (Exception ex) {
throw new AccessException("Problem invoking method: " + this.method, ex);
}
}
示例11: applyContributors
import org.springframework.core.MethodParameter; //导入依赖的package包/类
private UriComponents applyContributors(UriComponentsBuilder builder, Method method, Object... args) {
CompositeUriComponentsContributor contributor = defaultUriComponentsContributor;
int paramCount = method.getParameterTypes().length;
int argCount = args.length;
if (paramCount != argCount) {
throw new IllegalArgumentException("方法参数量为" + paramCount + " 与真实参数量不匹配,真实参数量为" + argCount);
}
final Map<String, Object> uriVars = new HashMap<>(8);
for (int i = 0; i < paramCount; i++) {
MethodParameter param = new SynthesizingMethodParameter(method, i);
param.initParameterNameDiscovery(parameterNameDiscoverer);
contributor.contributeMethodArgument(param, args[i], builder, uriVars);
}
// We may not have all URI var values, expand only what we have
return builder.build().expand(name -> uriVars.containsKey(name) ? uriVars.get(name) : UriComponents.UriTemplateVariables.SKIP_VALUE);
}
示例12: handleReturnValue
import org.springframework.core.MethodParameter; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest) throws Exception {
if (returnValue == null) {
mavContainer.setRequestHandled(true);
return;
}
final DeferredResult<Object> deferredResult = new DeferredResult<>();
@SuppressWarnings("unchecked")
ListenableFuture<Object> futureValue = (ListenableFuture<Object>) returnValue;
Futures.addCallback(futureValue, new FutureCallback<Object>() {
@Override
public void onSuccess(@Nullable Object result) {
deferredResult.setResult(result);
}
@Override
public void onFailure(Throwable ex) {
deferredResult.setErrorResult(ex);
}
});
startDeferredResultProcessing(mavContainer, webRequest, deferredResult);
}
示例13: handleReturnValue
import org.springframework.core.MethodParameter; //导入依赖的package包/类
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void handleReturnValue(
Object returnValue, MethodParameter returnType,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
throws Exception {
if (returnValue == null) {
return;
}
else if (returnValue instanceof Map){
mavContainer.addAllAttributes((Map) returnValue);
}
else {
// should not happen
throw new UnsupportedOperationException("Unexpected return type: " +
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
}
}
示例14: resolveModelAttribute
import org.springframework.core.MethodParameter; //导入依赖的package包/类
private WebDataBinder resolveModelAttribute(String attrName, MethodParameter methodParam,
ExtendedModelMap implicitModel, NativeWebRequest webRequest, Object handler) throws Exception {
// Bind request parameter onto object...
String name = attrName;
if ("".equals(name)) {
name = Conventions.getVariableNameForParameter(methodParam);
}
Class<?> paramType = methodParam.getParameterType();
Object bindObject;
if (implicitModel.containsKey(name)) {
bindObject = implicitModel.get(name);
}
else if (this.methodResolver.isSessionAttribute(name, paramType)) {
bindObject = this.sessionAttributeStore.retrieveAttribute(webRequest, name);
if (bindObject == null) {
raiseSessionRequiredException("Session attribute '" + name + "' required - not found in session");
}
}
else {
bindObject = BeanUtils.instantiateClass(paramType);
}
WebDataBinder binder = createBinder(webRequest, bindObject, name);
initBinder(handler, name, binder, webRequest);
return binder;
}
示例15: resolveArgument
import org.springframework.core.MethodParameter; //导入依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
//取出存入的用户ID
String currentUserId = (String) webRequest.getAttribute(Constant.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST);
if (currentUserId != null) {
return userDao.findById(currentUserId);
}
return new MissingServletRequestPartException(Constant.CURRENT_USER_ID);
}