org.apache.camel.Component Java Examples

The following examples show how to use org.apache.camel.Component. 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: ComponentVerifier.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: InjectionPointsRecorder.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: ActiveMQConnector.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: ComponentProxyWithCustomComponentTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: CoreMainResource.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@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 File: BoxConnector.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@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 #7
Source File: EMailComponent.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@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 #8
Source File: ComponentMetadataRetrieval.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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 #9
Source File: HandlerCustomizer.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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 #10
Source File: HandlerCustomizer.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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 #11
Source File: ComponentProxyComponent.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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 #12
Source File: ActiveMQConnector.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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 #13
Source File: Components.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
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 #14
Source File: Components.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
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 #15
Source File: ArdulinkEndpoint.java    From Ardulink-2 with Apache License 2.0 5 votes vote down vote up
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 #16
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 #17
Source File: CamelRegistryTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@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 #18
Source File: ComponentResolverAssociationHandler.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@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 #19
Source File: UndertowSubsystemExtension.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@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 File: ActiveMQComponentResolver.java    From servicemix with Apache License 2.0 5 votes vote down vote up
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 #21
Source File: PropagateEndpoint.java    From syncope with Apache License 2.0 4 votes vote down vote up
public PropagateEndpoint(final String endpointUri, final Component component) {
    super(endpointUri, component);
}
 
Example #22
Source File: JBatchEndpoint.java    From incubator-batchee with Apache License 2.0 4 votes vote down vote up
public JBatchEndpoint(final String uri, final String remaining, final Component jBatchComponent, final JobOperator operator) {
    super(uri, jBatchComponent);
    this.operator = operator;
    this.job = remaining;
}
 
Example #23
Source File: CoreMainResource.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@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 #24
Source File: CamelSubsytemExtension.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
public default Component resolveComponent(String name, SubsystemState subsystemState) {
    return null;
}
 
Example #25
Source File: ERPEndpoint.java    From camelinaction2 with Apache License 2.0 4 votes vote down vote up
public ERPEndpoint(String endpointUri, Component component) {
    super(endpointUri, component);
}
 
Example #26
Source File: ERPEndpoint.java    From camelinaction with Apache License 2.0 4 votes vote down vote up
public ERPEndpoint(String endpointUri, Component component) {
    super(endpointUri, component);
}
 
Example #27
Source File: ErpEndpoint.java    From camelinaction with Apache License 2.0 4 votes vote down vote up
public ErpEndpoint(String uri, Component component) {
    super(uri, component);
}
 
Example #28
Source File: AMQPConnector.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private AMQPComponent lookupComponent() {
    final CamelContext context = getCamelContext();
    final List<String> names = context.getComponentNames();

    if (ObjectHelper.isEmpty(names)) {
        return null;
    }

    // lookup existing component with same configuration
    for (String name: names) {

        Component cmp = context.getComponent(name, false, false);
        if (cmp instanceof AMQPComponent) {

            final ConnectionFactory factory;
            try {
                factory = ((AMQPComponent)cmp).getConfiguration().getConnectionFactory();
            } catch (IllegalArgumentException e) {
                // ignore components without a connection factory
                continue;
            }

            if (factory instanceof JmsConnectionFactory) {
                JmsConnectionFactory jmsConnectionFactory = (JmsConnectionFactory)factory;

                if (!Objects.equals(connectionUri, jmsConnectionFactory.getRemoteURI())) {
                    continue;
                }
                if (!Objects.equals(username, jmsConnectionFactory.getUsername())) {
                    continue;
                }
                if (!Objects.equals(password, jmsConnectionFactory.getPassword())) {
                    continue;
                }
                if (!Objects.equals(clientId, jmsConnectionFactory.getClientID())) {
                    continue;
                }

                return (AMQPComponent) cmp;
            }
        }
    }

    return null;
}
 
Example #29
Source File: ODataComponent.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
protected Optional<Component> createDelegateComponent(ComponentDefinition definition, Map<String, Object> options) {
    Olingo4AppEndpointConfiguration configuration = new Olingo4AppEndpointConfiguration();

    Map<String, String> httpHeaders = new HashMap<>();
    configuration.setHttpHeaders(httpHeaders);

    Methods method = ConnectorOptions.extractOptionAndMap(options, METHOD_NAME, Methods::getValueOf);
    if (ObjectHelper.isEmpty(method)) {
        throw new IllegalStateException("No method specified for odata component");
    }

    configuration.setMethodName(method.id());

    //
    // Ensure at least a blank map exists for this property
    //
    Map<String, String> endPointHttpHeaders = new HashMap<>();
    configuration.setEndpointHttpHeaders(endPointHttpHeaders);

    Map<String, Object> resolvedOptions = bundleOptions(options);
    HttpClientBuilder httpClientBuilder = ODataUtil.createHttpClientBuilder(resolvedOptions);
    configuration.setHttpClientBuilder(httpClientBuilder);

    HttpAsyncClientBuilder httpAsyncClientBuilder = ODataUtil.createHttpAsyncClientBuilder(resolvedOptions);
    configuration.setHttpAsyncClientBuilder(httpAsyncClientBuilder);

    if (getServiceUri() != null) {
        configuration.setServiceUri(getServiceUri());
    }

    configureResourcePath(configuration, options);

    if (Methods.READ.equals(method)) {
        //
        // Modify the query parameters into the expected map
        //
        Map<String, String> queryParams = new HashMap<>();
        if (getQueryParams() != null) {
            String queryString = getQueryParams();
            String[] clauses = queryString.split(AMPERSAND, -1);
            if (clauses.length >= 1) {
                for (String clause : clauses) {
                    String[] parts = clause.split(EQUALS, -1);
                    if (parts.length == 2) {
                        queryParams.put(parts[0], parts[1]);
                    } else if (parts.length < 2) {
                        queryParams.put(parts[0], EMPTY_STRING);
                    }
                    // A clause with more than 1 '=' would be invalid
                }
            }
        }

        configuration.setQueryParams(queryParams);
        configuration.setFilterAlreadySeen(isFilterAlreadySeen());
        configuration.setSplitResult(isSplitResult());
    }

    Olingo4Component component = new Olingo4Component(getCamelContext());
    component.setConfiguration(configuration);
    return Optional.of(component);
}
 
Example #30
Source File: CbSailEndpoint.java    From rya with Apache License 2.0 4 votes vote down vote up
public CbSailEndpoint(String endpointUri, Component component, Repository sailRepository, String remaining) {
    super(endpointUri, component);
    this.sailRepository = sailRepository;
}