use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class InvocableHandlerMethod method getMethodArgumentValues.
/**
* Get the method argument values for the current request.
*/
private Object[] getMethodArgumentValues(Message<?> message, Object... providedArgs) throws Exception {
MethodParameter[] parameters = getMethodParameters();
Object[] args = new Object[parameters.length];
for (int i = 0; i < parameters.length; i++) {
MethodParameter parameter = parameters[i];
parameter.initParameterNameDiscovery(this.parameterNameDiscoverer);
args[i] = resolveProvidedArgument(parameter, providedArgs);
if (args[i] != null) {
continue;
}
if (this.argumentResolvers.supportsParameter(parameter)) {
try {
args[i] = this.argumentResolvers.resolveArgument(parameter, message);
continue;
} catch (Exception ex) {
if (logger.isDebugEnabled()) {
logger.debug(getArgumentResolutionErrorMessage("Failed to resolve", i), ex);
}
throw ex;
}
}
if (args[i] == null) {
throw new MethodArgumentResolutionException(message, parameter, getArgumentResolutionErrorMessage("No suitable resolver for", i));
}
}
return args;
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class MappingJackson2MessageConverter method getSerializationView.
/**
* Determine a Jackson serialization view based on the given conversion hint.
* @param conversionHint the conversion hint Object as passed into the
* converter for the current conversion attempt
* @return the serialization view class, or {@code null} if none
* @since 4.2
*/
protected Class<?> getSerializationView(Object conversionHint) {
if (conversionHint instanceof MethodParameter) {
MethodParameter param = (MethodParameter) conversionHint;
JsonView annotation = (param.getParameterIndex() >= 0 ? param.getParameterAnnotation(JsonView.class) : param.getMethodAnnotation(JsonView.class));
if (annotation != null) {
return extractViewClass(annotation, conversionHint);
}
} else if (conversionHint instanceof JsonView) {
return extractViewClass((JsonView) conversionHint, conversionHint);
} else if (conversionHint instanceof Class) {
return (Class<?>) conversionHint;
}
// No JSON view specified...
return null;
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method toTextMessageWithReturnTypeAndNoJsonView.
@Test
public void toTextMessageWithReturnTypeAndNoJsonView() throws JMSException, NoSuchMethodException {
Method method = this.getClass().getDeclaredMethod("none");
MethodParameter returnType = new MethodParameter(method, -1);
testToTextMessageWithReturnType(returnType);
verify(sessionMock).createTextMessage("{\"name\":\"test\",\"description\":\"lengthy description\"}");
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method toTextMessageWithReturnTypeAndMultipleJsonViews.
@Test
public void toTextMessageWithReturnTypeAndMultipleJsonViews() throws JMSException, NoSuchMethodException {
Method method = this.getClass().getDeclaredMethod("invalid");
MethodParameter returnType = new MethodParameter(method, -1);
thrown.expect(IllegalArgumentException.class);
testToTextMessageWithReturnType(returnType);
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class HeadersMethodArgumentResolverTests method setup.
@Before
public void setup() throws Exception {
this.resolver = new HeadersMethodArgumentResolver();
Method method = getClass().getDeclaredMethod("handleMessage", Map.class, String.class, MessageHeaders.class, MessageHeaderAccessor.class, TestMessageHeaderAccessor.class);
this.paramAnnotated = new MethodParameter(method, 0);
this.paramAnnotatedNotMap = new MethodParameter(method, 1);
this.paramMessageHeaders = new MethodParameter(method, 2);
this.paramMessageHeaderAccessor = new MethodParameter(method, 3);
this.paramMessageHeaderAccessorSubclass = new MethodParameter(method, 4);
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "bar");
this.message = MessageBuilder.withPayload(new byte[0]).copyHeaders(headers).build();
}
Aggregations