Example usage for org.springframework.messaging MessageChannel toString

List of usage examples for org.springframework.messaging MessageChannel toString

Introduction

In this page you can find the example usage for org.springframework.messaging MessageChannel toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.thingsplode.server.bus.interceptors.LoggingInterceptor.java

@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {

    if (logger.isDebugEnabled()) {
        logger.debug("On channel: " + channel.toString() + " -> Message: " + message.toString());
    }//  w w  w .  j  av a  2s  .c  o  m
    return message;

    //        if (message == null) {
    //            return;
    //        }
    //
    //        Object payload = message.getPayload();
    //        AbstractRequest req;
    //        if (payload == null || !(payload instanceof AbstractRequest)) {
    //            return;
    //        } else {
    //            req = (AbstractRequest) payload;
    //        }
    //        Device d = deviceRepo.findBydeviceId(req.getDeviceId());
    //        if (d != null) {
    //            message.getHeaders().put(Device.MAIN_TYPE, d);
    //        }
    //
    //        message.getHeaders().put(AbstractMessage.MESSAGE_TYPE, req.getClass().getSimpleName());
}

From source file:com.qpark.eip.core.spring.statistics.impl.AppUserStatisticsChannelAdapter.java

/**
 * Add the request time stamp to the {@link #requestMap}.
 *
 * @see org.springframework.integration.channel.ChannelInterceptor#preSend(org.springframework.integration.Message,
 *      org.springframework.integration.MessageChannel)
 *///www .  j  a  v  a 2  s  .  c o  m
@Override
public Message<?> preSend(final Message<?> message, final MessageChannel channel) {
    if (channel.toString().contains("Request")) {
        UUID requestId = (UUID) message.getHeaders().get(RequestIdMessageHeaderEnhancer.HEADER_NAME_REQUEST_ID);
        if (requestId == null) {
            requestId = message.getHeaders().getId();
        }
        this.requestMap.put(requestId, new SimpleEntry<String, Long>(
                this.messageContentProvider.getUserName(message), System.currentTimeMillis()));
    }
    return message;
}

From source file:com.qpark.eip.core.spring.statistics.impl.AppUserStatisticsChannelAdapter.java

/**
 * @see org.springframework.integration.channel.ChannelInterceptor#postSend(org.springframework.integration.Message,
 *      org.springframework.integration.MessageChannel, boolean)
 *//*from  w ww . j av a  2  s  .c  om*/
@Override
public void postSend(final Message<?> message, final MessageChannel channel, final boolean sent) {
    UUID requestId = (UUID) message.getHeaders().get(RequestIdMessageHeaderEnhancer.HEADER_NAME_REQUEST_ID);
    if (channel.toString().contains("Response") && requestId != null) {
        SimpleEntry<String, Long> entry = this.requestMap.get(requestId);
        if (entry != null) {
            ApplicationUserLogType log = new ApplicationUserLogType();
            log.setStopItem(new Date());
            log.setDurationMillis(log.getStopItem().getTime() - entry.getValue().longValue());
            log.setStartItem(new Date(entry.getValue().longValue()));
            log.setDurationString(AppUserStatisticsChannelAdapter.getDuration(log.getDurationMillis()));

            log.setContext(this.contextNameProvider.getContextName());
            log.setVersion(this.contextNameProvider.getContextVersion());
            log.setUserName(entry.getKey());
            log.setServiceName(EipRoleVoter.getServiceName(message, ".service.", ".msg."));
            log.setOperationName(EipRoleVoter.getOperationName(message));

            log.setReturnedEntities(this.messageContentProvider.getNumberOfReturns(message));
            log.setReturnedFailures(this.messageContentProvider.getNumberOfFailures(message));

            log.setHostName(this.getHostName());
            if (this.logger.isTraceEnabled()) {
                this.logger.trace("{},{},{},{},{},{},{},{}", log.getContext(), log.getHostName(),
                        log.getServiceName(), log.getOperationName(), log.getUserName(),
                        log.getReturnedFailures(), log.getDurationString(), log.getStartItem());
            }

            this.submitApplicationUserLogType(log);
        }
    }
}

From source file:com.consol.citrus.samples.bookstore.validation.XmlSchemaValidatingChannelInterceptor.java

/**
 * Validates the payload of the message// w  w  w . j a va2 s .  com
 * 
 * @param message
 * @param channel
 */
public void validateSchema(Message<?> message, MessageChannel channel) {
    try {
        SAXParseException[] exceptions = xmlValidator.validate(converter.convertToSource(message.getPayload()));
        if (exceptions.length > 0) {
            StringBuilder msg = new StringBuilder("Invalid XML message on channel ");
            if (channel != null) {
                msg.append(channel.toString());
            } else {
                msg.append("<unknown>");
            }
            msg.append(":\n");
            for (SAXParseException e : exceptions) {
                msg.append("\t").append(e.getMessage());
                msg.append(" (line=").append(e.getLineNumber());
                msg.append(", col=").append(e.getColumnNumber()).append(")\n");
            }
            log.warn("XSD schema validation failed: ", msg.toString());
            throw new XmlSchemaValidationException(message, exceptions[0]);
        }
    } catch (IOException ioE) {
        throw new MessagingException("Exception applying schema validation", ioE);
    }
}

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

private String channelName(MessageChannel channel) {
    String name = null;//  w w w  .  j  av a  2 s  .  c  om
    if (this.integrationObjectSupportPresent) {
        if (channel instanceof IntegrationObjectSupport) {
            name = ((IntegrationObjectSupport) channel).getComponentName();
        }
        if (name == null && channel instanceof AbstractMessageChannel) {
            name = ((AbstractMessageChannel) channel).getFullChannelName();
        }
    }
    if (name == null) {
        name = channel.toString();
    }
    return name;
}