Search in sources :

Example 1 with DefaultExchangeFormatter

use of org.apache.camel.processor.DefaultExchangeFormatter in project camel by apache.

the class DefaultExchangeFormatterTest method testConfiguration.

public void testConfiguration() {
    DefaultExchangeFormatter formatter = new DefaultExchangeFormatter();
    assertFalse(formatter.isShowExchangeId());
    assertFalse(formatter.isShowProperties());
    assertFalse(formatter.isShowHeaders());
    assertTrue(formatter.isShowBodyType());
    assertTrue(formatter.isShowBody());
    assertFalse(formatter.isShowOut());
    assertFalse(formatter.isShowException());
    assertFalse(formatter.isShowCaughtException());
    assertFalse(formatter.isShowStackTrace());
    assertFalse(formatter.isShowAll());
    assertFalse(formatter.isMultiline());
    assertEquals(10000, formatter.getMaxChars());
}
Also used : DefaultExchangeFormatter(org.apache.camel.processor.DefaultExchangeFormatter)

Example 2 with DefaultExchangeFormatter

use of org.apache.camel.processor.DefaultExchangeFormatter in project camel by apache.

the class LogComponent method createEndpoint.

protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    LoggingLevel level = getLoggingLevel(parameters);
    Logger providedLogger = getLogger(parameters);
    if (providedLogger == null) {
        // try to look up the logger in registry
        Map<String, Logger> availableLoggers = getCamelContext().getRegistry().findByTypeWithName(Logger.class);
        if (availableLoggers.size() == 1) {
            providedLogger = availableLoggers.values().iterator().next();
            LOG.info("Using custom Logger: {}", providedLogger);
        } else if (availableLoggers.size() > 1) {
            LOG.info("More than one {} instance found in the registry. Falling back to creating logger from URI {}.", Logger.class.getName(), uri);
        }
    }
    LogEndpoint endpoint = new LogEndpoint(uri, this);
    endpoint.setLevel(level.name());
    setProperties(endpoint, parameters);
    if (providedLogger == null) {
        endpoint.setLoggerName(remaining);
    } else {
        endpoint.setProvidedLogger(providedLogger);
    }
    // first, try to pick up the ExchangeFormatter from the registry
    ExchangeFormatter localFormatter = getCamelContext().getRegistry().lookupByNameAndType("logFormatter", ExchangeFormatter.class);
    if (localFormatter != null) {
        setProperties(localFormatter, parameters);
    } else if (localFormatter == null && exchangeFormatter != null) {
        // do not set properties, the exchangeFormatter is explicitly set, therefore the
        // user would have set its properties explicitly too
        localFormatter = exchangeFormatter;
    } else {
        // if no formatter is available in the Registry, create a local one of the default type, for a single use
        localFormatter = new DefaultExchangeFormatter();
        setProperties(localFormatter, parameters);
    }
    endpoint.setLocalFormatter(localFormatter);
    return endpoint;
}
Also used : LoggingLevel(org.apache.camel.LoggingLevel) ExchangeFormatter(org.apache.camel.spi.ExchangeFormatter) DefaultExchangeFormatter(org.apache.camel.processor.DefaultExchangeFormatter) DefaultExchangeFormatter(org.apache.camel.processor.DefaultExchangeFormatter) Logger(org.slf4j.Logger) CamelLogger(org.apache.camel.util.CamelLogger)

Example 3 with DefaultExchangeFormatter

use of org.apache.camel.processor.DefaultExchangeFormatter in project camel by apache.

the class ExpressionBuilder method messageHistoryExpression.

/**
     * Returns the message history (including exchange details or not)
     */
public static Expression messageHistoryExpression(final boolean detailed) {
    return new ExpressionAdapter() {

        private ExchangeFormatter formatter;

        public Object evaluate(Exchange exchange) {
            ExchangeFormatter ef = null;
            if (detailed) {
                // use the exchange formatter to log exchange details
                ef = getOrCreateExchangeFormatter(exchange.getContext());
            }
            return MessageHelper.dumpMessageHistoryStacktrace(exchange, ef, false);
        }

        private ExchangeFormatter getOrCreateExchangeFormatter(CamelContext camelContext) {
            if (formatter == null) {
                Set<ExchangeFormatter> formatters = camelContext.getRegistry().findByType(ExchangeFormatter.class);
                if (formatters != null && formatters.size() == 1) {
                    formatter = formatters.iterator().next();
                } else {
                    // setup exchange formatter to be used for message history dump
                    DefaultExchangeFormatter def = new DefaultExchangeFormatter();
                    def.setShowExchangeId(true);
                    def.setMultiline(true);
                    def.setShowHeaders(true);
                    def.setStyle(DefaultExchangeFormatter.OutputStyle.Fixed);
                    try {
                        Integer maxChars = CamelContextHelper.parseInteger(camelContext, camelContext.getGlobalOption(Exchange.LOG_DEBUG_BODY_MAX_CHARS));
                        if (maxChars != null) {
                            def.setMaxChars(maxChars);
                        }
                    } catch (Exception e) {
                        throw ObjectHelper.wrapRuntimeCamelException(e);
                    }
                    formatter = def;
                }
            }
            return formatter;
        }

        @Override
        public String toString() {
            return "messageHistory(" + detailed + ")";
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) CamelContext(org.apache.camel.CamelContext) DefaultExchangeFormatter(org.apache.camel.processor.DefaultExchangeFormatter) ExchangeFormatter(org.apache.camel.spi.ExchangeFormatter) DefaultExchangeFormatter(org.apache.camel.processor.DefaultExchangeFormatter) NoTypeConversionAvailableException(org.apache.camel.NoTypeConversionAvailableException) NoSuchLanguageException(org.apache.camel.NoSuchLanguageException) InvalidPayloadException(org.apache.camel.InvalidPayloadException) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) ExpressionAdapter(org.apache.camel.support.ExpressionAdapter)

Aggregations

DefaultExchangeFormatter (org.apache.camel.processor.DefaultExchangeFormatter)3 ExchangeFormatter (org.apache.camel.spi.ExchangeFormatter)2 CamelContext (org.apache.camel.CamelContext)1 Exchange (org.apache.camel.Exchange)1 InvalidPayloadException (org.apache.camel.InvalidPayloadException)1 LoggingLevel (org.apache.camel.LoggingLevel)1 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)1 NoSuchLanguageException (org.apache.camel.NoSuchLanguageException)1 NoTypeConversionAvailableException (org.apache.camel.NoTypeConversionAvailableException)1 ExpressionAdapter (org.apache.camel.support.ExpressionAdapter)1 CamelLogger (org.apache.camel.util.CamelLogger)1 Logger (org.slf4j.Logger)1