Skip to content

Commit

Permalink
Invoke CamelContextCustomizer as part of DefaultConfigurationConfigur…
Browse files Browse the repository at this point in the history
…er::afterConfigure
  • Loading branch information
lburgazzoli committed Mar 4, 2024
1 parent d492f09 commit 21597f0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.camel.spi.AsyncProcessorAwaitManager;
import org.apache.camel.spi.BacklogDebugger;
import org.apache.camel.spi.BeanIntrospection;
import org.apache.camel.spi.CamelContextCustomizer;
import org.apache.camel.spi.ClassResolver;
import org.apache.camel.spi.CliConnectorFactory;
import org.apache.camel.spi.CompileStrategy;
Expand Down Expand Up @@ -605,6 +606,12 @@ public static void afterConfigure(final CamelContext camelContext) throws Except
vault.setHashicorpVaultConfiguration(hashicorp);
}
configureVault(camelContext);

// apply custom configurations if any
Set<CamelContextCustomizer> customizers = registry.findByType(CamelContextCustomizer.class);
if (!customizers.isEmpty()) {
customizers.forEach(c -> c.configure(camelContext));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

import org.apache.camel.BindToRegistry;
import org.apache.camel.CamelConfiguration;
import org.apache.camel.CamelContext;
import org.apache.camel.component.log.LogComponent;
import org.apache.camel.spi.CamelContextCustomizer;
import org.apache.camel.spi.ComponentCustomizer;
import org.apache.camel.support.CustomizersSupport;
import org.apache.camel.support.processor.DefaultExchangeFormatter;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -76,6 +79,27 @@ public void testComponentCustomizerDisabledWithProperties() {
}
}

@Test
public void testContextCustomizer() {
Main main = new Main();

try {
main.configure().addConfiguration(MyConfiguration.class);
main.bind("name-customizer", new CamelContextCustomizer() {
@Override
public void configure(CamelContext camelContext) {
camelContext.getCamelContextExtension().setName("customized-name");
}
});

main.start();

assertEquals("customized-name", main.getCamelContext().getName());
} finally {
main.stop();
}
}

// ****************************
//
// Helpers
Expand Down

0 comments on commit 21597f0

Please sign in to comment.