Search in sources :

Example 1 with LoggingHandler

use of org.springframework.integration.handler.LoggingHandler in project spring-integration-samples by spring-projects.

the class Application method logger.

private LoggingHandler logger() {
    LoggingHandler loggingHandler = new LoggingHandler("INFO");
    loggingHandler.setLoggerName("siSample");
    return loggingHandler;
}
Also used : LoggingHandler(org.springframework.integration.handler.LoggingHandler)

Example 2 with LoggingHandler

use of org.springframework.integration.handler.LoggingHandler in project spring-integration by spring-projects.

the class LoggingChannelAdapterParserTests method verifyExpressionAndOtherDefaultConfig.

@Test
public void verifyExpressionAndOtherDefaultConfig() {
    LoggingHandler loggingHandler = TestUtils.getPropertyValue(loggerWithExpression, "handler", LoggingHandler.class);
    assertEquals("org.springframework.integration.handler.LoggingHandler", TestUtils.getPropertyValue(loggingHandler, "messageLogger.logger.name"));
    assertEquals(Ordered.LOWEST_PRECEDENCE, TestUtils.getPropertyValue(loggingHandler, "order"));
    assertEquals("INFO", TestUtils.getPropertyValue(loggingHandler, "level").toString());
    assertEquals("payload.foo", TestUtils.getPropertyValue(loggingHandler, "expression.expression"));
    assertNotNull(TestUtils.getPropertyValue(loggingHandler, "evaluationContext.beanResolver"));
}
Also used : LoggingHandler(org.springframework.integration.handler.LoggingHandler) Test(org.junit.Test)

Example 3 with LoggingHandler

use of org.springframework.integration.handler.LoggingHandler in project spring-integration-samples by spring-projects.

the class Application method loggingChannelAdapter.

@Bean
@ServiceActivator(inputChannel = "sendTimeChannel")
public MessageHandler loggingChannelAdapter() {
    LoggingHandler loggingHandler = new LoggingHandler("info");
    loggingHandler.setLogExpressionString("'The time ' + payload + ' has been sent to the WebSocketSession ' + headers.simpSessionId");
    return loggingHandler;
}
Also used : LoggingHandler(org.springframework.integration.handler.LoggingHandler) ServiceActivator(org.springframework.integration.annotation.ServiceActivator) Bean(org.springframework.context.annotation.Bean)

Example 4 with LoggingHandler

use of org.springframework.integration.handler.LoggingHandler in project spring-integration by spring-projects.

the class LoggingChannelAdapterParserTests method verifyConfig.

@Test
public void verifyConfig() {
    LoggingHandler loggingHandler = TestUtils.getPropertyValue(loggerConsumer, "handler", LoggingHandler.class);
    assertEquals("org.springframework.integration.test.logger", TestUtils.getPropertyValue(loggingHandler, "messageLogger.logger.name"));
    assertEquals(1, TestUtils.getPropertyValue(loggingHandler, "order"));
    assertEquals("WARN", TestUtils.getPropertyValue(loggingHandler, "level").toString());
    assertEquals("#root", TestUtils.getPropertyValue(loggingHandler, "expression.expression"));
}
Also used : LoggingHandler(org.springframework.integration.handler.LoggingHandler) Test(org.junit.Test)

Example 5 with LoggingHandler

use of org.springframework.integration.handler.LoggingHandler in project spring-integration by spring-projects.

the class ChainParserTests method chainWithLoggingChannelAdapter.

// INT-2275, INT-2958
@Test
public void chainWithLoggingChannelAdapter() {
    Log logger = mock(Log.class);
    final AtomicReference<String> log = new AtomicReference<String>();
    when(logger.isWarnEnabled()).thenReturn(true);
    doAnswer(invocation -> {
        log.set(invocation.getArgument(0));
        return null;
    }).when(logger).warn(any());
    @SuppressWarnings("unchecked") List<MessageHandler> handlers = TestUtils.getPropertyValue(this.logChain, "handlers", List.class);
    MessageHandler handler = handlers.get(2);
    assertTrue(handler instanceof LoggingHandler);
    DirectFieldAccessor dfa = new DirectFieldAccessor(handler);
    dfa.setPropertyValue("messageLogger", logger);
    this.loggingChannelAdapterChannel.send(MessageBuilder.withPayload(new byte[] { 116, 101, 115, 116 }).build());
    assertNotNull(log.get());
    assertEquals("TEST", log.get());
}
Also used : LoggingHandler(org.springframework.integration.handler.LoggingHandler) MessageHandler(org.springframework.messaging.MessageHandler) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) Log(org.apache.commons.logging.Log) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

LoggingHandler (org.springframework.integration.handler.LoggingHandler)6 Test (org.junit.Test)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Log (org.apache.commons.logging.Log)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 Bean (org.springframework.context.annotation.Bean)1 ServiceActivator (org.springframework.integration.annotation.ServiceActivator)1 FixedSubscriberChannel (org.springframework.integration.channel.FixedSubscriberChannel)1 FluxMessageChannel (org.springframework.integration.channel.FluxMessageChannel)1 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)1 MessageChannel (org.springframework.messaging.MessageChannel)1 MessageHandler (org.springframework.messaging.MessageHandler)1