Example usage for org.springframework.messaging MessagingException getFailedMessage

List of usage examples for org.springframework.messaging MessagingException getFailedMessage

Introduction

In this page you can find the example usage for org.springframework.messaging MessagingException getFailedMessage.

Prototype

@Nullable
    public Message<?> getFailedMessage() 

Source Link

Usage

From source file:nz.co.senanque.messaging.ErrorEndpoint.java

public void processErrorMessage(final Message<MessagingException> message) {
    MessageHeaders messageHeaders = message.getHeaders();
    final MessagingException messagingException = (MessagingException) message.getPayload();
    Long correlationId = message.getHeaders().get(IntegrationMessageHeaderAccessor.CORRELATION_ID, Long.class);
    if (correlationId == null) {
        correlationId = messagingException.getFailedMessage().getHeaders()
                .get(IntegrationMessageHeaderAccessor.CORRELATION_ID, Long.class);
    }//from   w w w  .  j a v  a 2 s  . co  m
    log.debug("ProcessInstance: correlationId {}", correlationId);
    if (correlationId == null) {
        log.error("correlation Id is null");
        throw new WorkflowException("correlation Id is null");
    }
    final ProcessInstance processInstance = getWorkflowDAO().findProcessInstance(correlationId);
    if (processInstance == null) {
        throw new WorkflowException("Failed to find processInstance for " + correlationId);
    }
    getBundleSelector().selectBundle(processInstance);
    List<Lock> locks = ContextUtils.getLocks(processInstance, getLockFactory(),
            "nz.co.senanque.messaging.ErrorEndpoint.processErrorMessage");
    LockTemplate lockTemplate = new LockTemplate(locks, new LockAction() {

        public void doAction() {

            if (processInstance.getStatus() != TaskStatus.WAIT) {
                throw new WorkflowException("Process is not in a wait state");
            }
            getWorkflowManager().processMessage(processInstance, message, getMessageMapper());
        }

    });
    if (!lockTemplate.doAction()) {
        throw new WorkflowRetryableException("Failed to get a lock"); // This will be retried 
    }
}

From source file:org.springframework.cloud.sleuth.instrument.messaging.TracingChannelInterceptor.java

private Message<?> getMessage(Message<?> message) {
    Object payload = message.getPayload();
    if (payload instanceof MessagingException) {
        MessagingException e = (MessagingException) payload;
        return e.getFailedMessage();
    }/*from w  w  w.j  ava2  s.  c  o  m*/
    return message;
}

From source file:org.springframework.integration.core.ErrorMessagePublisher.java

/**
 * Publish an error message for the supplied exception.
 * @param exception the exception.//from ww w .j  a  v  a 2  s. c  om
 */
public void publish(MessagingException exception) {
    publish(null, exception.getFailedMessage(), exception);
}

From source file:org.springframework.integration.core.ErrorMessagePublisher.java

/**
 * Publish an error message for the supplied exception.
 * @param inputMessage the message that started the subflow.
 * @param exception the exception./* ww  w .jav  a 2 s.  c  o  m*/
 */
public void publish(Message<?> inputMessage, MessagingException exception) {
    publish(inputMessage, exception.getFailedMessage(), exception);
}

From source file:org.springframework.integration.core.ErrorMessagePublisher.java

/**
 * Publish an error message for the supplied throwable and context.
 * The {@link #errorMessageStrategy} is used to build a {@link ErrorMessage}
 * to publish./* ww w.ja va  2  s .  c om*/
 * @param throwable the throwable. May be null.
 * @param context the context for {@link ErrorMessage} properties.
 */
public void publish(Throwable throwable, AttributeAccessor context) {
    populateChannel();
    Throwable payload = determinePayload(throwable, context);
    ErrorMessage errorMessage = this.errorMessageStrategy.buildErrorMessage(payload, context);
    if (this.logger.isDebugEnabled() && payload instanceof MessagingException) {
        MessagingException exception = (MessagingException) errorMessage.getPayload();
        this.logger.debug("Sending ErrorMessage: failedMessage: " + exception.getFailedMessage(), exception);
    }
    this.messagingTemplate.send(errorMessage);
}

From source file:org.springframework.integration.ip.tcp.connection.ConnectionEventTests.java

@Test
public void testOutboundGatewayNoConnectionEvents() {
    TcpOutboundGateway gw = new TcpOutboundGateway();
    AbstractClientConnectionFactory ccf = new AbstractClientConnectionFactory("localhost", 0) {
    };/*from   w  ww  .j  a  va  2  s  .c  om*/
    final AtomicReference<ApplicationEvent> theEvent = new AtomicReference<ApplicationEvent>();
    ccf.setApplicationEventPublisher(new ApplicationEventPublisher() {

        @Override
        public void publishEvent(Object event) {
        }

        @Override
        public void publishEvent(ApplicationEvent event) {
            theEvent.set(event);
        }

    });
    gw.setConnectionFactory(ccf);
    DirectChannel requestChannel = new DirectChannel();
    requestChannel
            .subscribe(message -> ((MessageChannel) message.getHeaders().getReplyChannel()).send(message));
    gw.start();
    Message<String> message = MessageBuilder.withPayload("foo").setHeader(IpHeaders.CONNECTION_ID, "bar")
            .build();
    gw.onMessage(message);
    assertNotNull(theEvent.get());
    TcpConnectionFailedCorrelationEvent event = (TcpConnectionFailedCorrelationEvent) theEvent.get();
    assertEquals("bar", event.getConnectionId());
    MessagingException messagingException = (MessagingException) event.getCause();
    assertSame(message, messagingException.getFailedMessage());
    assertEquals("Cannot correlate response - no pending reply for bar", messagingException.getMessage());

    message = new GenericMessage<String>("foo");
    gw.onMessage(message);
    assertNotNull(theEvent.get());
    event = (TcpConnectionFailedCorrelationEvent) theEvent.get();
    assertNull(event.getConnectionId());
    messagingException = (MessagingException) event.getCause();
    assertSame(message, messagingException.getFailedMessage());
    assertEquals("Cannot correlate response - no connection id", messagingException.getMessage());
}