private String createMessagingErrorMessage(String description, Object payload) { return description + "\n" + "Endpoint handler details:\n" + "Method [" + this.handlerAdapter.getMethodAsString(payload) + "]\n" + "Bean [" + this.handlerAdapter.getBean() + "]"; }
/** * Invoke the handler, wrapping any exception to a {@link ListenerExecutionFailedException} * with a dedicated error message. * @param amqpMessage the raw message. * @param channel the channel. * @param message the messaging message. * @return the result of invoking the handler. */ private InvocationResult invokeHandler(org.springframework.amqp.core.Message amqpMessage, Channel channel, Message<?> message) { try { return this.handlerAdapter.invoke(message, amqpMessage, channel); } catch (MessagingException ex) { throw new ListenerExecutionFailedException(createMessagingErrorMessage("Listener method could not " + "be invoked with the incoming message", message.getPayload()), ex, amqpMessage); } catch (Exception ex) { throw new ListenerExecutionFailedException("Listener method '" + this.handlerAdapter.getMethodAsString(message.getPayload()) + "' threw exception", ex, amqpMessage); } }
/** * Create a {@link HandlerAdapter} for this listener adapter. * @param messageListener the listener adapter. * @return the handler adapter. */ protected HandlerAdapter configureListenerAdapter(MessagingMessageListenerAdapter messageListener) { InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod()); return new HandlerAdapter(invocableHandlerMethod); }
private void returnOrThrow(org.springframework.amqp.core.Message amqpMessage, Channel channel, Message<?> message, Throwable throwableToReturn, Exception exceptionToThrow) throws Exception { // NOSONAR if (!this.returnExceptions) { throw exceptionToThrow; } try { handleResult(new InvocationResult(new RemoteInvocationResult(throwableToReturn), null, null), amqpMessage, channel, message); } catch (ReplyFailureException rfe) { if (void.class.equals(this.handlerAdapter.getReturnType(message.getPayload()))) { throw exceptionToThrow; } else { throw rfe; } } }
/** * Create a {@link HandlerAdapter} for this listener adapter. * @param messageListener the listener adapter. * @return the handler adapter. */ protected HandlerAdapter configureListenerAdapter(MessagingMessageListenerAdapter messageListener) { InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod()); return new HandlerAdapter(invocableHandlerMethod); }
private void returnOrThrow(org.springframework.amqp.core.Message amqpMessage, Channel channel, Message<?> message, Throwable throwableToReturn, Exception exceptionToThrow) throws Exception { // NOSONAR if (!this.returnExceptions) { throw exceptionToThrow; } try { handleResult(new InvocationResult(new RemoteInvocationResult(throwableToReturn), null, null), amqpMessage, channel, message); } catch (ReplyFailureException rfe) { if (void.class.equals(this.handlerAdapter.getReturnType(message.getPayload()))) { throw exceptionToThrow; } else { throw rfe; } } }
@Override protected HandlerAdapter configureListenerAdapter(MessagingMessageListenerAdapter messageListener) { List<InvocableHandlerMethod> invocableHandlerMethods = new ArrayList<InvocableHandlerMethod>(); InvocableHandlerMethod defaultHandler = null; for (Method method : this.methods) { InvocableHandlerMethod handler = getMessageHandlerMethodFactory() .createInvocableHandlerMethod(getBean(), method); invocableHandlerMethods.add(handler); if (method.equals(this.defaultMethod)) { defaultHandler = handler; } } return new HandlerAdapter(new DelegatingInvocableHandler(invocableHandlerMethods, defaultHandler, getBean(), getResolver(), getBeanExpressionContext())); }
private String createMessagingErrorMessage(String description, Object payload) { return description + "\n" + "Endpoint handler details:\n" + "Method [" + this.handlerAdapter.getMethodAsString(payload) + "]\n" + "Bean [" + this.handlerAdapter.getBean() + "]"; }
/** * Invoke the handler, wrapping any exception to a {@link ListenerExecutionFailedException} * with a dedicated error message. * @param amqpMessage the raw message. * @param channel the channel. * @param message the messaging message. * @return the result of invoking the handler. */ private InvocationResult invokeHandler(org.springframework.amqp.core.Message amqpMessage, Channel channel, Message<?> message) { try { return this.handlerAdapter.invoke(message, amqpMessage, channel); } catch (MessagingException ex) { throw new ListenerExecutionFailedException(createMessagingErrorMessage("Listener method could not " + "be invoked with the incoming message", message.getPayload()), ex, amqpMessage); } catch (Exception ex) { throw new ListenerExecutionFailedException("Listener method '" + this.handlerAdapter.getMethodAsString(message.getPayload()) + "' threw exception", ex, amqpMessage); } }
@Override protected HandlerAdapter configureListenerAdapter(MessagingMessageListenerAdapter messageListener) { List<InvocableHandlerMethod> invocableHandlerMethods = new ArrayList<InvocableHandlerMethod>(); InvocableHandlerMethod defaultHandler = null; for (Method method : this.methods) { InvocableHandlerMethod handler = getMessageHandlerMethodFactory() .createInvocableHandlerMethod(getBean(), method); invocableHandlerMethods.add(handler); if (method.equals(this.defaultMethod)) { defaultHandler = handler; } } return new HandlerAdapter(new DelegatingInvocableHandler(invocableHandlerMethods, defaultHandler, getBean(), getResolver(), getBeanExpressionContext())); }
protected MessagingMessageListenerAdapter createMultiInstance(Method m1, Method m2, boolean returnExceptions) { MessagingMessageListenerAdapter adapter = new MessagingMessageListenerAdapter(null, null, returnExceptions, null); List<InvocableHandlerMethod> methods = new ArrayList<>(); methods.add(this.factory.createInvocableHandlerMethod(sample, m1)); methods.add(this.factory.createInvocableHandlerMethod(sample, m2)); DelegatingInvocableHandler handler = new DelegatingInvocableHandler(methods, this.sample, null, null); adapter.setHandlerAdapter(new HandlerAdapter(handler)); return adapter; }
protected MessagingMessageListenerAdapter createInstance(Method m, boolean returnExceptions) { MessagingMessageListenerAdapter adapter = new MessagingMessageListenerAdapter(null, m, returnExceptions, null); adapter.setHandlerAdapter(new HandlerAdapter(factory.createInvocableHandlerMethod(sample, m))); return adapter; }