org.apache.camel.spi.Registry Java Examples

The following examples show how to use org.apache.camel.spi.Registry. 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: EncryptionDynamicRoute.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Override
public void configure() throws Exception {
    final CryptoDataFormat crypto = new CryptoDataFormat("DES", null);

    from("direct:encrypt")
        .process(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                Registry registry = exchange.getContext().getRegistry();
                Message in = exchange.getIn();
                Key key = registry.lookupByNameAndType("shared_" + in.getHeader("system"), Key.class);
                in.setHeader(CryptoDataFormat.KEY, key);
            }
        })
        .log("Encrypting message: ${body} using ${header[CamelCryptoKey]}")
        .marshal(crypto)
        .log("Message encrypted: ${body}")
        .to("direct:decrypt");

    from("direct:decrypt")
        .log("Decrypting message: ${body} using ${header[CamelCryptoKey]}")
        .unmarshal(crypto)
        .log("Message decrypted: ${body}")
        .to("mock:decrypted");
}
 
Example #2
Source File: JsonSimplePredicate.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public JsonSimplePredicate(final String expression, final CamelContext context) {
    final Language language = ObjectHelper.notNull(context.resolveLanguage("simple"), "simple language");
    final String ognlExpression = convertSimpleToOGNLForMaps(expression);

    predicate = language.createPredicate(expression);
    ognlPredicate = language.createPredicate(ognlExpression);

    final Registry registry = context.getRegistry();
    final Set<ObjectMapper> mappers = registry.findByType(ObjectMapper.class);

    if (mappers.size() != 1) {
        mapper = MAPPER;
    } else {
        mapper = mappers.iterator().next();
    }
}
 
Example #3
Source File: OrderDAO.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
public void insertOrder(InputOrder order, Registry registry) {
    DataSource ds = registry.lookupByNameAndType("myDataSource", DataSource.class);
    JdbcTemplate jdbc = new JdbcTemplate(ds);

    Object[] args = new Object[] { order.getCustomerId(), order.getRefNo(), order.getPartId(), order.getAmount()};
    jdbc.update("insert into riders_order (customer_id, ref_no, part_id, amount) values (?, ?, ?, ?)", args);
}
 
Example #4
Source File: OrderDAO.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public void insertOrder(InputOrder order, Registry registry) {
    DataSource ds = registry.lookupByNameAndType("myDataSource", DataSource.class);
    JdbcTemplate jdbc = new JdbcTemplate(ds);

    Object[] args = new Object[] { order.getCustomerId(), order.getRefNo(), order.getPartId(), order.getAmount()};
    jdbc.update("insert into riders_order (customer_id, ref_no, part_id, amount) values (?, ?, ?, ?)", args);
}
 
Example #5
Source File: CamelContextRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<CamelContext> createContext(
        RuntimeValue<Registry> registry,
        RuntimeValue<TypeConverterRegistry> typeConverterRegistry,
        RuntimeValue<ModelJAXBContextFactory> contextFactory,
        RuntimeValue<XMLRoutesDefinitionLoader> xmlLoader,
        RuntimeValue<ModelToXMLDumper> xmlModelDumper,
        RuntimeValue<FactoryFinderResolver> factoryFinderResolver,
        BeanContainer beanContainer,
        String version,
        CamelConfig config) {

    FastCamelContext context = new FastCamelContext(
            factoryFinderResolver.getValue(),
            version,
            xmlLoader.getValue(),
            xmlModelDumper.getValue());

    context.setDefaultExtension(RuntimeCamelCatalog.class, () -> new CamelRuntimeCatalog(config.runtimeCatalog));
    context.setRegistry(registry.getValue());
    context.setTypeConverterRegistry(typeConverterRegistry.getValue());
    context.setLoadTypeConverters(false);
    context.setModelJAXBContextFactory(contextFactory.getValue());
    context.build();
    context.addLifecycleStrategy(new CamelLifecycleEventBridge());
    context.getManagementStrategy().addEventNotifier(new CamelManagementEventBridge());

    // register to the container
    beanContainer.instance(CamelProducers.class).setContext(context);

    return new RuntimeValue<>(context);
}
 
Example #6
Source File: CamelRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public void bind(
        RuntimeValue<Registry> runtime,
        String name,
        Class<?> type,
        Object instance) {

    runtime.getValue().bind(name, type, instance);
}
 
Example #7
Source File: CamelRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public void bind(
        RuntimeValue<Registry> runtime,
        String name,
        Class<?> type,
        RuntimeValue<?> instance) {

    runtime.getValue().bind(name, type, instance.getValue());
}
 
Example #8
Source File: CamelRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public void bind(
        RuntimeValue<Registry> runtime,
        String name,
        Class<?> type) {

    try {
        runtime.getValue().bind(name, type, type.newInstance());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #9
Source File: MicroProfileHealthResource.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Path("/checks/failing/{enabled}")
@GET
public void toggleFailingHealthCheck(@PathParam("enabled") boolean enabled) {
    Registry registry = camelContext.getRegistry();
    FailingHealthCheck failingHealthCheck = registry.lookupByNameAndType(FailingHealthCheck.class.getSimpleName(),
            FailingHealthCheck.class);
    failingHealthCheck.getConfiguration().setEnabled(enabled);
}
 
Example #10
Source File: LoaderRegistration.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public boolean accept(final Phase phase, final Runtime runtime) {
    if (phase == Phase.ConfigureContext) {
        final Registry registry = runtime.getRegistry();
        registry.bind("syndesis", new IntegrationRouteLoader());

        return true;
    }

    return false;
}
 
Example #11
Source File: ComponentProxyWithCustomComponentTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private void validate(Registry registry) throws Exception {
    final CamelContext context = new DefaultCamelContext(registry);

    try {
        context.setAutoStartup(false);
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:start")
                    .to("my-sql-proxy")
                    .to("mock:result");
            }
        });

        context.start();

        Collection<String> names = context.getComponentNames();

        assertThat(names).contains("my-sql-proxy");
        assertThat(names).contains("sql-my-sql-proxy");

        SqlComponent sqlComponent = context.getComponent("sql-my-sql-proxy", SqlComponent.class);
        DataSource sqlDatasource = sqlComponent.getDataSource();

        assertThat(sqlDatasource).isEqualTo(this.ds);

        Map<String, Endpoint> endpoints = context.getEndpointMap();
        assertThat(endpoints).containsKey("sql-my-sql-proxy://select%20from%20dual");
    } finally {
        context.stop();
    }
}
 
Example #12
Source File: CamelProducers.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@Singleton
@Produces
Registry camelRegistry() {
    return this.context.getRegistry();
}
 
Example #13
Source File: Runtime.java    From camel-k-runtime with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the registry associated to this runtime.
 */
default Registry getRegistry() {
    return getCamelContext().getRegistry();
}
 
Example #14
Source File: CamelAutoConfigurationTest.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldComposeRegistries() {
    final Registry registry = camelContext.getRegistry();
    Assertions.assertThat(registry.lookupByName("bean")).isEqualTo(Ordered.HIGHEST_PRECEDENCE);
}
 
Example #15
Source File: CamelRecorder.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
public RuntimeValue<Registry> createRegistry() {
    return new RuntimeValue<>(new RuntimeRegistry());
}
 
Example #16
Source File: CamelRegistryBuildItem.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
public RuntimeValue<Registry> getRegistry() {
    return value;
}
 
Example #17
Source File: CamelRegistryBuildItem.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
public CamelRegistryBuildItem(RuntimeValue<Registry> value) {
    this.value = value;
}
 
Example #18
Source File: CoreResource.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@Path("/registry/lookup-registry")
@GET
@Produces(MediaType.TEXT_PLAIN)
public boolean lookupRegistry() {
    return registry.findByType(Registry.class).size() == 1;
}