private String createMessagingErrorMessage(String description) { InvocableHandlerMethod handlerMethod = getHandlerMethod(); StringBuilder sb = new StringBuilder(description).append("\n") .append("Endpoint handler details:\n") .append("Method [").append(handlerMethod.getMethod()).append("]\n") .append("Bean [").append(handlerMethod.getBean()).append("]\n"); return sb.toString(); }
/** * Invoke the handler, wrapping any exception to a {@link ListenerExecutionFailedException} * with a dedicated error message. */ @Nullable private Object invokeHandler(javax.jms.Message jmsMessage, @Nullable Session session, Message<?> message) { InvocableHandlerMethod handlerMethod = getHandlerMethod(); try { return handlerMethod.invoke(message, jmsMessage, session); } catch (MessagingException ex) { throw new ListenerExecutionFailedException( createMessagingErrorMessage("Listener method could not be invoked with incoming message"), ex); } catch (Exception ex) { throw new ListenerExecutionFailedException("Listener method '" + handlerMethod.getMethod().toGenericString() + "' threw exception", ex); } }
HandlerMethod(InvocableHandlerMethod invocableHandlerMethod, boolean canProcessMessageList) { this.invocableHandlerMethod = invocableHandlerMethod; this.canProcessMessageList = canProcessMessageList; this.expressionString = generateExpression(this.invocableHandlerMethod.getMethod()); }
public String getMethodAsString(Object payload) { if (this.invokerHandlerMethod != null) { return this.invokerHandlerMethod.getMethod().toGenericString(); } else { return this.delegatingHandler.getMethodNameFor(payload); } }
/** * Return a string representation of the method that will be invoked for this payload. * @param payload the payload. * @return the method name. */ public String getMethodNameFor(Object payload) { InvocableHandlerMethod handlerForPayload = getHandlerForPayload(payload.getClass()); return handlerForPayload == null ? "no match" : handlerForPayload.getMethod().toGenericString(); //NOSONAR }
protected InvocableHandlerMethod findHandlerForPayload(Class<? extends Object> payloadClass) { InvocableHandlerMethod result = null; for (InvocableHandlerMethod handler : this.handlers) { if (matchHandlerMethod(payloadClass, handler)) { if (result != null) { boolean resultIsDefault = result.equals(this.defaultHandler); if (!handler.equals(this.defaultHandler) && !resultIsDefault) { throw new KafkaException("Ambiguous methods for payload type: " + payloadClass + ": " + result.getMethod().getName() + " and " + handler.getMethod().getName()); } if (!resultIsDefault) { continue; // otherwise replace the result with the actual match } } result = handler; } } return result != null ? result : this.defaultHandler; }
private void setupReplyTo(InvocableHandlerMethod handler) { String replyTo = null; Method method = handler.getMethod(); if (method != null) { SendTo ann = AnnotationUtils.getAnnotation(method, SendTo.class); replyTo = extractSendTo(method.toString(), ann); } if (replyTo == null) { SendTo ann = AnnotationUtils.getAnnotation(this.bean.getClass(), SendTo.class); replyTo = extractSendTo(this.getBean().getClass().getSimpleName(), ann); } if (replyTo != null) { this.handlerSendTo.put(handler, PARSER.parseExpression(replyTo, PARSER_CONTEXT)); } this.handlerReturnsMessage.put(handler, KafkaUtils.returnTypeMessageOrCollectionOf(method)); }
protected boolean matchHandlerMethod(Class<? extends Object> payloadClass, InvocableHandlerMethod handler) { Method method = handler.getMethod(); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); // Single param; no annotation or not @Header if (parameterAnnotations.length == 1) { MethodParameter methodParameter = new MethodParameter(method, 0); if ((methodParameter.getParameterAnnotations().length == 0 || !methodParameter.hasParameterAnnotation(Header.class)) && methodParameter.getParameterType().isAssignableFrom(payloadClass)) { return true; } } boolean foundCandidate = false; for (int i = 0; i < parameterAnnotations.length; i++) { MethodParameter methodParameter = new MethodParameter(method, i); if ((methodParameter.getParameterAnnotations().length == 0 || !methodParameter.hasParameterAnnotation(Header.class)) && methodParameter.getParameterType().isAssignableFrom(payloadClass)) { if (foundCandidate) { throw new KafkaException("Ambiguous payload parameter for " + method.toGenericString()); } foundCandidate = true; } } return foundCandidate; }
private Class<?> resolveMessagePayloadType(InvocableHandlerMethod method) { Class<?>[] parameterTypes = method.getMethod().getParameterTypes(); Assert.notEmpty(parameterTypes, "Azure message handler method should not have empty parameters"); //TODO: handle parameter of type Message<T> return parameterTypes[0]; }
private Class<?> resolveMessagePayloadType(InvocableHandlerMethod method) { Class<?>[] parameterTypes = method.getMethod().getParameterTypes(); Assert.notEmpty(parameterTypes, "Azure message handler method should not have empty parameters"); //TODO: handle parameter of type Message<T> return parameterTypes[0]; }
public String getMethodAsString(Object payload) { if (this.invokerHandlerMethod != null) { return this.invokerHandlerMethod.getMethod().toGenericString(); } else { return this.delegatingHandler.getMethodNameFor(payload); } }
/** * Return the method that will be invoked for this payload. * @param payload the payload. * @return the method. * @since 2.0 */ public Method getMethodFor(Object payload) { return getHandlerForPayload(payload.getClass()).getMethod(); }
HandlerMethod(InvocableHandlerMethod invocableHandlerMethod, boolean canProcessMessageList) { this.invocableHandlerMethod = invocableHandlerMethod; this.canProcessMessageList = canProcessMessageList; this.expressionString = generateExpression(this.invocableHandlerMethod.getMethod()); }
/** * Return the method that will be invoked for this payload. * @param payload the payload. * @return the method. * @since 2.0 */ public Method getMethodFor(Object payload) { return getHandlerForPayload(payload.getClass()).getMethod(); }
public String getMethodAsString(Object payload) { if (this.invokerHandlerMethod != null) { return this.invokerHandlerMethod.getMethod().toGenericString(); } else { return this.delegatingHandler.getMethodNameFor(payload); } }
private String createMessagingErrorMessage(String description) { StringBuilder sb = new StringBuilder(description).append("\n") .append("Endpoint handler details:\n") .append("Method [").append(this.handlerMethod.getMethod()).append("]\n") .append("Bean [").append(this.handlerMethod.getBean()).append("]\n"); return sb.toString(); }
private String createMessagingErrorMessage(String description) { InvocableHandlerMethod handlerMethod = getHandlerMethod(); StringBuilder sb = new StringBuilder(description).append("\n").append("Endpoint handler details:\n").append("Method [") .append(handlerMethod.getMethod()).append("]\n").append("Bean [") .append(handlerMethod.getBean()).append("]\n"); return sb.toString(); }
private String createMessagingErrorMessage(String description) { InvocableHandlerMethod handlerMethod = getHandlerMethod(); StringBuilder sb = new StringBuilder(description).append("\n") .append("Endpoint handler details:\n") .append("Method [").append(handlerMethod.getMethod()).append("]\n") .append("Bean [").append(handlerMethod.getBean()).append("]\n"); return sb.toString(); }
private String createMessagingErrorMessage(String description) { InvocableHandlerMethod handlerMethod = getHandlerMethod(); StringBuilder sb = new StringBuilder(description).append("\n").append("Endpoint handler details:\n").append("Method [") .append(handlerMethod.getMethod()).append("]\n").append("Bean [") .append(handlerMethod.getBean()).append("]\n"); return sb.toString(); }
@Override public void handleMessage(Message<?> message) throws MessagingException { InvocableHandlerMethod handlerMethod = getHandlerMethod(); try { handlerMethod.invoke(message); } catch (MessagingException ex) { throw new ListenerExecutionFailedException( createMessagingErrorMessage("Listener method could not be invoked with incoming message"), ex); } catch (Exception ex) { throw new ListenerExecutionFailedException( "Listener method '" + handlerMethod.getMethod().toGenericString() + "' threw exception", ex); } }