Example usage for org.springframework.integration IntegrationMessageHeaderAccessor CORRELATION_ID

List of usage examples for org.springframework.integration IntegrationMessageHeaderAccessor CORRELATION_ID

Introduction

In this page you can find the example usage for org.springframework.integration IntegrationMessageHeaderAccessor CORRELATION_ID.

Prototype

String CORRELATION_ID

To view the source code for org.springframework.integration IntegrationMessageHeaderAccessor CORRELATION_ID.

Click Source Link

Usage

From source file:com.qpark.eip.core.spring.AbstractAggregator.java

/**
 * Remove the header values of//from   w w w.  j a v  a2 s  . c  o  m
 * {@link IntegrationMessageHeaderAccessor#CORRELATION_ID} and
 * {@link IntegrationMessageHeaderAccessor#SEQUENCE_SIZE}.
 *
 * @param m
 *            the Message
 */
protected static void removeAddedHeader(final Message<?> m) {
    if (m != null) {
        m.getHeaders().remove(IntegrationMessageHeaderAccessor.CORRELATION_ID);
        m.getHeaders().remove(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE);
    }
}

From source file:com.qpark.eip.core.spring.AbstractAggregator.java

/**
 * @param attributeName
 */
public AbstractAggregator() {
    super(IntegrationMessageHeaderAccessor.CORRELATION_ID);
}

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

public void issueResponseFor(Message<org.w3c.dom.Document> orderResponse) {
    log.debug("processed orderResponse: correlationId {}",
            orderResponse.getHeaders().get(IntegrationMessageHeaderAccessor.CORRELATION_ID, Long.class));
    org.w3c.dom.Document doc = orderResponse.getPayload();
    Document document = new DOMBuilder().build(doc);
    Element root = document.getRootElement();

    Order context = new Order();
    @SuppressWarnings("unchecked")
    Iterator<Text> itr = (Iterator<Text>) root
            .getDescendants(new ContentFilter(ContentFilter.TEXT | ContentFilter.CDATA));
    while (itr.hasNext()) {
        Text text = itr.next();//w ww.j a va 2  s.c  o m
        log.debug("name {} value {}", text.getParentElement().getName(), text.getValue());

        String name = getName(text);
        try {
            Class<?> targetType = PropertyUtils.getPropertyType(context, name);
            Object value = ConvertUtils.convert(text.getValue(), targetType);
            PropertyUtils.setProperty(context, name, value);
        } catch (IllegalAccessException e) {
            // Ignore these and move on
            log.debug("{} {}", name, e.getMessage());
        } catch (InvocationTargetException e) {
            // Ignore these and move on
            log.debug("{} {}", name, e.getMessage());
        } catch (NoSuchMethodException e) {
            // Ignore these and move on
            log.debug("{} {}", name, e.getMessage());
        }
    }
}

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

public Message<Order> issueResponseFor(Message<Order> order) {
    if (order.getPayload().getOrderName().equals("fatal error")) {
        throw new RuntimeException("fatal error");
    }/* ww  w. j  a v  a  2  s.  c  o m*/
    if (order.getPayload().getOrderName().equals("recoverable error")) {
        throw new RuntimeException("recoverable error");
    }
    Order ret = new ObjectFactory().createOrder();
    OrderItem orderItem = new ObjectFactory().createOrderItem();
    orderItem.setItemName("#1");
    ret.setRejected(false);
    ret.setOrderName("whatever");
    ret.getOrderItems().add(orderItem);
    log.debug("processed order: correlationId {}",
            order.getHeaders().get(IntegrationMessageHeaderAccessor.CORRELATION_ID, Long.class));
    MessageBuilder<Order> messageBuilder = MessageBuilder.withPayload(ret);
    messageBuilder.copyHeaders(order.getHeaders());
    return messageBuilder.build();
}

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  ww .j  a  v a2  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:nz.co.senanque.messaging.GenericEndpoint.java

public void issueResponseFor(final Message<?> message) {
    MessageHeaders messageHeaders = message.getHeaders();
    Long correlationId = message.getHeaders().get(IntegrationMessageHeaderAccessor.CORRELATION_ID, Long.class);
    log.debug("ProcessInstance: correlationId {}", correlationId);
    if (correlationId == null) {
        log.error("correlation Id is null");
        throw new WorkflowException("correlation Id is null");
    }// w  w  w  .  j  av a2  s  .co  m
    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.GenericEndpoint.issueResponseFor");
    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());
            log.debug("completed lock message processing");
        }
    });
    if (!lockTemplate.doAction()) {
        throw new WorkflowRetryableException("Failed to get a lock"); // this will be retried later, not a hard error
    }
    log.debug("completed incomming message processing");
}

From source file:com.qpark.eip.core.spring.PayloadLogger.java

/**
 * {@link Message} to string./*from www.ja  v  a 2 s.  c om*/
 *
 * @param message
 *            the {@link Message}.
 * @return the {@link Message} as string.
 */
private String getMessage(final Message<?> message) {
    Object logMessage = this.expression.getValue(this.evaluationContext, message);
    if (JAXBElement.class.isInstance(logMessage)) {
        final JAXBElement<?> elem = (JAXBElement<?>) logMessage;
        try {
            if (Objects.nonNull(this.jaxb2Marshaller)) {
                final StringResult sw = new StringResult();
                this.jaxb2Marshaller.marshal(logMessage, sw);
                logMessage = sw.toString();
            } else {
                final Marshaller marshaller = this.getMarshaller();
                if (Objects.nonNull(marshaller)) {
                    final StringWriter sw = new StringWriter();
                    marshaller.marshal(logMessage, sw);
                    logMessage = sw.toString();
                }
            }
        } catch (final Exception e) {
            logMessage = elem.getValue();
        }
    } else if (logMessage instanceof Throwable) {
        final StringWriter stringWriter = new StringWriter();
        if (logMessage instanceof AggregateMessageDeliveryException) {
            stringWriter.append(((Throwable) logMessage).getMessage());
            for (final Exception exception : (List<? extends Exception>) ((AggregateMessageDeliveryException) logMessage)
                    .getAggregatedExceptions()) {
                exception.printStackTrace(new PrintWriter(stringWriter, true));
            }
        } else {
            ((Throwable) logMessage).printStackTrace(new PrintWriter(stringWriter, true));
        }
        logMessage = stringWriter.toString();
    }
    final StringBuffer sb = new StringBuffer(1024);
    sb.append(MessageHeaders.ID).append("=").append(message.getHeaders().getId());
    final Object correlationId = new IntegrationMessageHeaderAccessor(message).getCorrelationId();
    if (correlationId != null) {
        sb.append(", ");
        sb.append(IntegrationMessageHeaderAccessor.CORRELATION_ID).append("=").append(correlationId);
    }
    sb.append("\n");
    sb.append(String.valueOf(logMessage));
    return sb.toString();
}