org.apache.camel.component.log.LogComponent Java Examples

The following examples show how to use org.apache.camel.component.log.LogComponent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CamelMainAutoConfigurationTest.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testComponentAutoConfiguration() {
    // ensure the camel context is started before doing any assertion
    await().atMost(10, TimeUnit.SECONDS).until(main::isStarted);

    // ensure that the exchange formatter explicit set to the LogComponent
    // is not overridden by any ExchangeFormatter instance available from
    // the container
    assertThat(main.getCamelContext().getComponent("myLog", LogComponent.class)).satisfies(component -> {
        assertThat(component.getExchangeFormatter()).isInstanceOf(MyExchangeFormatter.class);
    });

    // ensure that the exchange formatter is taken from the container as
    // LogComponent has no default instance thus it should be auto-wired
    // by camel-main
    assertThat(main.getCamelContext().getComponent("log", LogComponent.class)).satisfies(component -> {
        assertThat(component.getExchangeFormatter()).isInstanceOf(MyOtherExchangeFormatter.class);
    });
}
 
Example #2
Source File: SimpleCamelApplication.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    // add POJOs to the registry here using registry.put("name", <object reference>)

    CamelContext context = new DefaultCamelContext(registry);

    context.addComponent("mylogger", new LogComponent());
    context.addRoutes(new LogMessageOnTimerEventRoute());

    context.start();

    // let the Camel runtime do its job for 5 seconds
    Thread.sleep(5000);

    // shutdown
    context.stop();
}
 
Example #3
Source File: CoreMainResource.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Path("/registry/log/exchange-formatter")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonObject exchangeFormatterConfig() {
    LogComponent component = main.getCamelContext().getRegistry().lookupByNameAndType("log", LogComponent.class);
    DefaultExchangeFormatter def = (DefaultExchangeFormatter) component.getExchangeFormatter();

    JsonObject result = Json.createObjectBuilder()
            .add("show-all", def.isShowAll())
            .add("multi-line", def.isMultiline())
            .build();

    return result;
}
 
Example #4
Source File: CoreResource.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Path("/registry/log/exchange-formatter")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonObject exchangeFormatterConfig() {
    LogComponent component = registry.lookupByNameAndType("log", LogComponent.class);
    DefaultExchangeFormatter def = (DefaultExchangeFormatter) component.getExchangeFormatter();

    JsonObject result = Json.createObjectBuilder()
            .add("show-all", def.isShowAll())
            .add("multi-line", def.isMultiline())
            .build();

    return result;
}
 
Example #5
Source File: Configurations.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Produces a {@link LogComponent} instance with a custom exchange formatter set-up.
 */
@Named
LogComponent log() {
    DefaultExchangeFormatter formatter = new DefaultExchangeFormatter();
    formatter.setShowExchangePattern(false);
    formatter.setShowBodyType(false);

    LogComponent component = new LogComponent();
    component.setExchangeFormatter(formatter);

    return component;
}
 
Example #6
Source File: SupportBuildStep.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelBeanBuildItem logComponent(SupportRecorder recorder) {
    return new CamelBeanBuildItem(
            "log",
            LogComponent.class.getName(),
            recorder.logComponent());
}
 
Example #7
Source File: SupportRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<Component> logComponent() {
    DefaultExchangeFormatter def = new DefaultExchangeFormatter();
    def.setShowAll(true);
    def.setMultiline(true);

    LogComponent component = new LogComponent();
    component.setExchangeFormatter(def);

    return new RuntimeValue<>(component);
}
 
Example #8
Source File: CamelMainAutoConfigurationTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Named
public LogComponent myLog() {
    LogComponent component = new LogComponent();
    component.setExchangeFormatter(new MyExchangeFormatter());

    return component;
}
 
Example #9
Source File: CamelConfigurationTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testComponentAutoConfiguration() {
    // ensure that the component configuration is taken into account
    assertThat(camelContext.getComponent("myLog", LogComponent.class)).satisfies(component -> {
        assertThat(component.getExchangeFormatter()).isInstanceOf(MyExchangeFormatter.class);
    });

    // ensure that no auto-wiring happen
    assertThat(camelContext.getComponent("log", LogComponent.class)).satisfies(component -> {
        assertThat(component.getExchangeFormatter()).isNull();
    });
}
 
Example #10
Source File: CamelConfigurationTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Named
public LogComponent myLog() {
    LogComponent component = new LogComponent();
    component.setExchangeFormatter(new MyExchangeFormatter());

    return component;
}
 
Example #11
Source File: LogComponentAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Lazy
@Bean(name = "log-component")
@ConditionalOnMissingBean(LogComponent.class)
public LogComponent configureLogComponent() throws Exception {
    LogComponent component = new LogComponent();
    component.setCamelContext(camelContext);
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, component,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (ComponentCustomizer<LogComponent> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.component.customizer",
                            "camel.component.log.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.component.customizer",
                            "camel.component.log.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure component {}, with customizer {}",
                        component, customizer);
                customizer.customize(component);
            }
        }
    }
    return component;
}
 
Example #12
Source File: CamelMainAutoConfigurationTest.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@Named
public LogComponent log() {
    return new LogComponent();
}
 
Example #13
Source File: CamelInjectionPointTest.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
public LogComponent getLog() {
    return log;
}
 
Example #14
Source File: CamelInjectionPointTest.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@Inject
public Holder(LogComponent log) {
    this.log = log;
}
 
Example #15
Source File: CamelInjectionPointTest.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
public LogComponent getLog() {
    return log;
}
 
Example #16
Source File: CamelConfigurationTest.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@Named
public LogComponent log() {
    return new LogComponent();
}