Java Code Examples for org.apache.camel.Component
The following examples show how to use
org.apache.camel.Component.
These examples are extracted from open source projects.
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 Project: camel-quarkus Author: apache File: InjectionPointsRecorder.java License: Apache License 2.0 | 6 votes |
public Supplier<? extends Component> componentSupplier(String componentName, String componentType) { return new Supplier<Component>() { @Override public Component get() { // We can't inject the CamelContext from the BuildStep as it will create a // dependency cycle as the BuildStep that creates the CamelContext requires // BeanManger instance. As this is a fairly trivial job, we can safely keep // the context lookup-at runtime. final CamelContext camelContext = Arc.container().instance(CamelContext.class).get(); if (camelContext == null) { throw new IllegalStateException("No CamelContext found"); } return camelContext.getComponent( componentName, camelContext.getClassResolver().resolveClass(componentType, Component.class)); } }; }
Example #2
Source Project: syndesis Author: syndesisio File: ComponentProxyWithCustomComponentTest.java License: Apache License 2.0 | 6 votes |
@Test public void testCreateDelegateComponent() throws Exception{ Map<String, Object> properties = new HashMap<>(); properties.put("dataSource", ds); properties.put("query", "select from dual"); ComponentProxyComponent component = new ComponentProxyComponent("my-sql-proxy", "sql") { @Override protected Optional<Component> createDelegateComponent(ComponentDefinition definition, Map<String, Object> options) { return Optional.of(new SqlComponent()); } }; component.setOptions(properties); SimpleRegistry registry = new SimpleRegistry(); registry.bind(component.getComponentId() + "-component", component); validate(registry); }
Example #3
Source Project: syndesis Author: syndesisio File: ComponentVerifier.java License: Apache License 2.0 | 6 votes |
@SuppressWarnings("PMD.AvoidDeeplyNestedIfStmts") protected ComponentVerifierExtension resolveComponentVerifierExtension(CamelContext context, String scheme) { if (verifierExtension == null) { synchronized (this) { if (verifierExtension == null) { Component component = context.getComponent(scheme, true, false); if (component == null) { LOG.error("Component {} does not exist", scheme); } else { verifierExtension = component.getExtension(verifierExtensionClass).orElse(null); if (verifierExtension == null) { LOG.warn("Component {} does not support verifier extension", scheme); } } } } } return verifierExtension; }
Example #4
Source Project: syndesis Author: syndesisio File: ActiveMQConnector.java License: Apache License 2.0 | 6 votes |
@Override protected Optional<Component> createDelegateComponent(ComponentDefinition definition, Map<String, Object> options) { SjmsComponent component = lookupComponent(); if (component == null) { ConnectionFactory connectionFactory = ActiveMQUtil.createActiveMQConnectionFactory( this.brokerUrl, this.username, this.password, this.brokerCertificate, this.clientCertificate, this.skipCertificateCheck ); component = new SjmsComponent(); component.setConnectionFactory(connectionFactory); component.setConnectionClientId(clientID); } return Optional.of(component); }
Example #5
Source Project: camel-quarkus Author: apache File: CoreMainResource.java License: Apache License 2.0 | 5 votes |
@Path("/registry/component/{name}") @GET @Produces(MediaType.APPLICATION_JSON) public JsonObject describeRegistryComponent(@PathParam("name") String name) { final Map<String, Object> properties = new HashMap<>(); final DefaultRegistry registry = main.getCamelContext().getRegistry(DefaultRegistry.class); final JsonObjectBuilder builder = Json.createObjectBuilder(); Component component = registry.getFallbackRegistry().lookupByNameAndType(name, Component.class); if (component != null) { builder.add("type", component.getClass().getName()); builder.add("registry", "fallback"); builder.add("registry-type", registry.getFallbackRegistry().getClass().getName()); } else { for (BeanRepository repository : registry.getRepositories()) { component = repository.lookupByNameAndType(name, Component.class); if (component != null) { builder.add("type", component.getClass().getName()); builder.add("registry", "repository"); builder.add("registry-type", repository.getClass().getName()); break; } } } if (component != null) { main.getCamelContext().adapt(ExtendedCamelContext.class).getBeanIntrospection().getProperties(component, properties, null); properties.forEach((k, v) -> { if (v != null) { builder.add(k, Objects.toString(v)); } }); } return builder.build(); }
Example #6
Source Project: camel-quarkus Author: apache File: SupportRecorder.java License: Apache License 2.0 | 5 votes |
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 #7
Source Project: camel-quarkus Author: apache File: CamelRegistryTest.java License: Apache License 2.0 | 5 votes |
@Test public void testLookupCustomServices() { assertThat(registry.lookupByNameAndType("my-df", DataFormat.class)).isNotNull(); assertThat(registry.lookupByNameAndType("my-language", Language.class)).isNotNull(); assertThat(registry.lookupByNameAndType("my-component", Component.class)).isNotNull(); assertThat(registry.lookupByNameAndType("my-predicate", Predicate.class)).isNotNull(); assertThat(registry.lookupByNameAndType("my-processor", Processor.class)).isNotNull(); }
Example #8
Source Project: camel-k-runtime Author: apache File: Components.java License: Apache License 2.0 | 5 votes |
public Component make(String scheme, String type) { final Class<?> clazz = context.getClassResolver().resolveClass(type); final Component instance = (Component)context.getInjector().newInstance(clazz); context.addComponent(scheme, instance); return instance; }
Example #9
Source Project: camel-k-runtime Author: apache File: Components.java License: Apache License 2.0 | 5 votes |
public Component make(String scheme, String type) { final Class<?> clazz = context.getClassResolver().resolveClass(type); final Component instance = (Component)context.getInjector().newInstance(clazz); context.addComponent(scheme, instance); return instance; }
Example #10
Source Project: syndesis Author: syndesisio File: ComponentProxyComponent.java License: Apache License 2.0 | 5 votes |
protected Optional<Component> createDelegateComponent(ComponentDefinition definition, Map<String, Object> options) { final String componentClass = definition.getComponent().getJavaType(); // configure component with extra options if (componentClass != null && !options.isEmpty()) { // Get the list of options from the connector catalog that // are configured to target the endpoint final Collection<String> endpointOptions = definition.getEndpointProperties().keySet(); // Check if any of the option applies to the component, if not // there's no need to create a dedicated component. boolean hasComponentOptions = options.keySet().stream().anyMatch(Predicates.negate(endpointOptions::contains)); // Options set on a step are strings so if any of the options is // not a string, is should have been added by a customizer so try to // bind them to the component first. boolean hasPojoOptions = options.values().stream().anyMatch(Predicates.negate(String.class::isInstance)); if (hasComponentOptions || hasPojoOptions) { final CamelContext context = getCamelContext(); // create a new instance of this base component final Class<Component> type = context.getClassResolver().resolveClass(componentClass, Component.class); final Component component = context.getInjector().newInstance(type); component.setCamelContext(context); return Optional.of(component); } } return Optional.empty(); }
Example #11
Source Project: syndesis Author: syndesisio File: HandlerCustomizer.java License: Apache License 2.0 | 5 votes |
public static void customizeComponent(final CamelContext context, final Connector connector, final ConnectorDescriptor descriptor, final Component component, final Map<String, Object> properties) { final List<String> customizers = CollectionsUtils.aggregate(ArrayList::new, connector.getConnectorCustomizers(), descriptor.getConnectorCustomizers()); // Set input/output data shape if the component proxy implements // Input/OutputDataShapeAware descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(component, ds)); descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(component, ds)); for (final String customizerType : customizers) { final ComponentCustomizer<Component> customizer = resolveCustomizer(context, customizerType); // Set the camel context if the customizer implements // the CamelContextAware interface. CamelContextAware.trySetCamelContext(customizer, context); // Set input/output data shape if the customizer implements // Input/OutputDataShapeAware descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(customizer, ds)); descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(customizer, ds)); // Try to set properties to the component setProperties(context, customizer, properties); // Invoke the customizer customizer.customize(component, properties); } }
Example #12
Source Project: syndesis Author: syndesisio File: HandlerCustomizer.java License: Apache License 2.0 | 5 votes |
private static ComponentCustomizer<Component> resolveCustomizer(final CamelContext context, final String customizerType) { @SuppressWarnings("rawtypes") final Class<ComponentCustomizer> type = context.getClassResolver().resolveClass(customizerType, ComponentCustomizer.class); if (type == null) { throw new IllegalArgumentException("Unable to resolve a ComponentProxyCustomizer of type: " + customizerType); } @SuppressWarnings("unchecked") final ComponentCustomizer<Component> customizer = context.getInjector().newInstance(type); if (customizer == null) { throw new IllegalArgumentException("Unable to instantiate a ComponentProxyCustomizer of type: " + customizerType); } return customizer; }
Example #13
Source Project: syndesis Author: syndesisio File: EMailComponent.java License: Apache License 2.0 | 5 votes |
@Override protected Optional<Component> createDelegateComponent(ComponentDefinition definition, Map<String, Object> options) { String protocol = getProtocol(); if (protocol == null) { throw new IllegalStateException("No protocol specified for email component"); } MailConfiguration configuration = new MailConfiguration(getCamelContext()); configuration.configureProtocol(protocol); configuration.setHost(getHost()); configuration.setPort(getPort()); configuration.setUsername(getUsername()); configuration.setPassword(getPassword()); configuration.setUnseen(isUnseenOnly()); if (getFolderName() != null) { configuration.setFolderName(getFolderName()); } Map<String, Object> resolvedOptions = bundleOptions(); SSLContextParameters sslContextParameters = EMailUtil.createSSLContextParameters(resolvedOptions); if (sslContextParameters != null) { configuration.setSslContextParameters(sslContextParameters); } else if (SecureType.STARTTLS.equals(secureType)) { Properties properties = new Properties(); properties.put("mail." + protocol + ".starttls.enable", "true"); properties.put("mail." + protocol + ".starttls.required", "true"); configuration.setAdditionalJavaMailProperties(properties); } configuration.setFetchSize(getMaxResults()); // Decode mime headers like the subject from Quoted-Printable encoding to normal text configuration.setMimeDecodeHeaders(true); MailComponent component = new MailComponent(getCamelContext()); component.setConfiguration(configuration); return Optional.of(component); }
Example #14
Source Project: syndesis Author: syndesisio File: BoxConnector.java License: Apache License 2.0 | 5 votes |
@Override protected void configureDelegateComponent(ComponentDefinition definition, Component component, Map<String, Object> options) { super.configureDelegateComponent(definition, component, options); if (component instanceof BoxComponent) { BoxConfiguration configuration = new BoxConfiguration(); configuration.setAuthenticationType(authenticationType); configuration.setUserName(userName); configuration.setUserPassword(userPassword); configuration.setClientId(clientId); configuration.setClientSecret(clientSecret); ((BoxComponent) component).setConfiguration(configuration); } }
Example #15
Source Project: syndesis Author: syndesisio File: ComponentMetadataRetrieval.java License: Apache License 2.0 | 5 votes |
protected MetaDataExtension resolveMetaDataExtension(CamelContext context, Class<? extends MetaDataExtension> metaDataExtensionClass, String componentId, String actionId) { Component component = context.getComponent(componentId, true, false); if (component == null) { throw new IllegalArgumentException( String.format("Component %s does not exists", componentId) ); } return component.getExtension(metaDataExtensionClass).orElse(null); }
Example #16
Source Project: syndesis Author: syndesisio File: ActiveMQConnector.java License: Apache License 2.0 | 5 votes |
private SjmsComponent lookupComponent() { final CamelContext context = getCamelContext(); final List<String> names = context.getComponentNames(); if (ObjectHelper.isEmpty(names)) { return null; } // Try to check if a component with same set-up has already been // configured, if so reuse it. for (String name : names) { Component cmp = context.getComponent(name, false, false); if (!(cmp instanceof SjmsComponent)) { continue; } ConnectionFactory factory = ((SjmsComponent) cmp).getConnectionFactory(); if (factory instanceof ActiveMQConnectionFactory) { ActiveMQConnectionFactory amqFactory = (ActiveMQConnectionFactory) factory; if (!Objects.equals(brokerUrl, amqFactory.getBrokerURL())) { continue; } if (!Objects.equals(username, amqFactory.getUserName())) { continue; } if (!Objects.equals(password, amqFactory.getPassword())) { continue; } return (SjmsComponent) cmp; } } return null; }
Example #17
Source Project: Ardulink-2 Author: Ardulink File: ArdulinkEndpoint.java License: Apache License 2.0 | 5 votes |
public ArdulinkEndpoint(String uri, Component ardulinkComponent, EndpointConfig config) throws IOException { super(uri, ardulinkComponent); this.config = config; this.link = createLink(); for (Pin pin : config.getPins()) { this.link.startListening(pin); } }
Example #18
Source Project: servicemix Author: apache File: ActiveMQComponentResolver.java License: Apache License 2.0 | 5 votes |
public Component resolveComponent(String name, CamelContext camelContext) throws Exception { if (name.equals(ActiveMQComponent.NAME)) { LOGGER.info("Creating an instance of the ActiveMQComponent (" + name + ":)"); return new ActiveMQComponent(camelContext, connectionFactory); } return null; }
Example #19
Source Project: wildfly-camel Author: wildfly-extras File: UndertowSubsystemExtension.java License: Apache License 2.0 | 5 votes |
@Override public Component resolveComponent(String name, SubsystemState subsystemState) { if (name.equals("cxf")) { return new WildFlyCxfComponent(); } else if (name.equals("undertow")) { return new WildFlyUndertowComponent(subsystemState.getRuntimeState()); } return null; }
Example #20
Source Project: wildfly-camel Author: wildfly-extras File: ComponentResolverAssociationHandler.java License: Apache License 2.0 | 5 votes |
@Override public Component resolveComponent(String name, CamelContext context) throws Exception { Component component = null; Iterator<CamelSubsytemExtension> iterator = subsystemState.getCamelSubsytemExtensions().iterator(); for (; iterator.hasNext() && component == null;) { CamelSubsytemExtension plugin = iterator.next(); component = plugin.resolveComponent(name, subsystemState); } return component != null ? component : delegate.resolveComponent(name, context); }
Example #21
Source Project: camel-quarkus Author: apache File: CoreMainResource.java License: Apache License 2.0 | 4 votes |
@Path("/main/describe") @GET @Produces(MediaType.APPLICATION_JSON) public JsonObject describeMain() { final ExtendedCamelContext camelContext = main.getCamelContext().adapt(ExtendedCamelContext.class); JsonArrayBuilder listeners = Json.createArrayBuilder(); main.getMainListeners().forEach(listener -> listeners.add(listener.getClass().getName())); JsonArrayBuilder routeBuilders = Json.createArrayBuilder(); main.configure().getRoutesBuilders().forEach(builder -> routeBuilders.add(builder.getClass().getName())); JsonArrayBuilder routes = Json.createArrayBuilder(); camelContext.getRoutes().forEach(route -> routes.add(route.getId())); JsonObjectBuilder collector = Json.createObjectBuilder(); collector.add("type", main.getRoutesCollector().getClass().getName()); if (main.getRoutesCollector() instanceof CamelMainRoutesCollector) { CamelMainRoutesCollector crc = (CamelMainRoutesCollector) main.getRoutesCollector(); collector.add("type-registry", crc.getRegistryRoutesLoader().getClass().getName()); collector.add("type-xml", crc.getXmlRoutesLoader().getClass().getName()); } JsonObjectBuilder dataformatsInRegistry = Json.createObjectBuilder(); camelContext.getRegistry().findByTypeWithName(DataFormat.class) .forEach((name, value) -> dataformatsInRegistry.add(name, value.getClass().getName())); JsonObjectBuilder languagesInRegistry = Json.createObjectBuilder(); camelContext.getRegistry().findByTypeWithName(Language.class) .forEach((name, value) -> languagesInRegistry.add(name, value.getClass().getName())); JsonObjectBuilder componentsInRegistry = Json.createObjectBuilder(); camelContext.getRegistry().findByTypeWithName(Component.class) .forEach((name, value) -> componentsInRegistry.add(name, value.getClass().getName())); JsonObjectBuilder factoryClassMap = Json.createObjectBuilder(); FactoryFinderResolver factoryFinderResolver = camelContext.getFactoryFinderResolver(); if (factoryFinderResolver instanceof FastFactoryFinderResolver) { ((FastFactoryFinderResolver) factoryFinderResolver).getClassMap().forEach((k, v) -> { factoryClassMap.add(k, v.getName()); }); } return Json.createObjectBuilder() .add("xml-loader", camelContext.getXMLRoutesDefinitionLoader().getClass().getName()) .add("xml-model-dumper", camelContext.getModelToXMLDumper().getClass().getName()) .add("routes-collector", collector) .add("listeners", listeners) .add("routeBuilders", routeBuilders) .add("routes", routes) .add("lru-cache-factory", LRUCacheFactory.getInstance().getClass().getName()) .add("autoConfigurationLogSummary", main.getMainConfigurationProperties().isAutoConfigurationLogSummary()) .add("config", Json.createObjectBuilder() .add("rest-port", camelContext.getRestConfiguration().getPort()) .add("resilience4j-sliding-window-size", camelContext.adapt(ModelCamelContext.class) .getResilience4jConfiguration(null) .getSlidingWindowSize())) .add("registry", Json.createObjectBuilder() .add("components", componentsInRegistry) .add("dataformats", dataformatsInRegistry) .add("languages", languagesInRegistry)) .add("factory-finder", Json.createObjectBuilder() .add("class-map", factoryClassMap)) .build(); }
Example #22
Source Project: camel-quarkus Author: apache File: WebhookComponentProducer.java License: Apache License 2.0 | 4 votes |
public TestWebhookEndpoint(String uri, Component component) { super(uri, component); }
Example #23
Source Project: camel-quarkus Author: apache File: CamelLifecycleEventBridge.java License: Apache License 2.0 | 4 votes |
@Override public void onComponentAdd(String name, Component component) { fireEvent(new ComponentAddEvent(component)); }
Example #24
Source Project: camel-quarkus Author: apache File: CamelLifecycleEventBridge.java License: Apache License 2.0 | 4 votes |
@Override public void onComponentRemove(String name, Component component) { fireEvent(new ComponentRemoveEvent(component)); }
Example #25
Source Project: camel-quarkus Author: apache File: ComponentAddEvent.java License: Apache License 2.0 | 4 votes |
public ComponentAddEvent(Component component) { super(component); }
Example #26
Source Project: camel-quarkus Author: apache File: ComponentEvent.java License: Apache License 2.0 | 4 votes |
public ComponentEvent(Component component) { this.component = component; }
Example #27
Source Project: camel-quarkus Author: apache File: ComponentEvent.java License: Apache License 2.0 | 4 votes |
public Component getComponent() { return this.component; }
Example #28
Source Project: camel-quarkus Author: apache File: ComponentEvent.java License: Apache License 2.0 | 4 votes |
public <T extends Component> T getComponent(Class<T> type) { return type.cast(this.component); }
Example #29
Source Project: camel-quarkus Author: apache File: ComponentRemoveEvent.java License: Apache License 2.0 | 4 votes |
public ComponentRemoveEvent(Component component) { super(component); }
Example #30
Source Project: camel-quarkus Author: apache File: TikaRecorder.java License: Apache License 2.0 | 4 votes |
public QuarkusTikaEndpoint(String endpointUri, Component component, TikaConfiguration tikaConfiguration, TikaParserProducer tikaParserProducer) { super(endpointUri, component, tikaConfiguration); this.tikaParserProducer = tikaParserProducer; }