Skip to content

Commit

Permalink
Implement Camel custom component for Dirigible JavaScript/TypeScript …
Browse files Browse the repository at this point in the history
…execution (#4383)

* WIP: add dirigible javascript camel component

Signed-off-by: Iliyan Velichkov <[email protected]>

* configure component

Signed-off-by: Iliyan Velichkov <[email protected]>

* cleanup

Signed-off-by: Iliyan Velichkov <[email protected]>

* fix backward compatibility

Signed-off-by: Iliyan Velichkov <[email protected]>

* add integration tests for the new camel component and for the two steps invocation

Signed-off-by: Iliyan Velichkov <[email protected]>

* add integration tests for the new camel component and for the two steps invocation

Signed-off-by: Iliyan Velichkov <[email protected]>

* tests refactoring

Signed-off-by: Iliyan Velichkov <[email protected]>

* more tests refactoring

Signed-off-by: Iliyan Velichkov <[email protected]>

* simplify test projects creation

Signed-off-by: Iliyan Velichkov <[email protected]>

* cleanup

Signed-off-by: Iliyan Velichkov <[email protected]>

* move DirigibleCleaner.java to the framework project

Signed-off-by: Iliyan Velichkov <[email protected]>

* decouple custom Camel component from the Dirigible implementation

Signed-off-by: Iliyan Velichkov <[email protected]>

* cleanup

Signed-off-by: Iliyan Velichkov <[email protected]>

* delete empty line

Signed-off-by: Iliyan Velichkov <[email protected]>

* update ex message

Signed-off-by: Iliyan Velichkov <[email protected]>

* add java dsl test

Signed-off-by: Iliyan Velichkov <[email protected]>

---------

Signed-off-by: Iliyan Velichkov <[email protected]>
  • Loading branch information
iliyan-velichkov authored Oct 25, 2024
1 parent 6e54a13 commit 0c39750
Show file tree
Hide file tree
Showing 58 changed files with 1,205 additions and 275 deletions.
67 changes: 61 additions & 6 deletions components/engine/engine-camel/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand All @@ -14,6 +14,64 @@
<artifactId>dirigible-components-engine-camel</artifactId>
<packaging>jar</packaging>

<properties>
<license.header.location>../../../licensing-header.txt</license.header.location>
<parent.pom.folder>../../../</parent.pom.folder>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-component-maven-plugin</artifactId>
<version>${camel.version}</version>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>recompile</id>
<goals>
<goal>compile</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
<goal>add-resource</goal>
</goals>
<configuration>
<sources>
<source>src/generated/java</source>
</sources>
<resources>
<resource>
<directory>src/generated/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>

<!-- Core -->
Expand Down Expand Up @@ -94,9 +152,6 @@
</dependency>
</dependencies>

<properties>
<license.header.location>../../../licensing-header.txt</license.header.location>
<parent.pom.folder>../../../</parent.pom.folder>
</properties>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* Generated by camel build tools - do NOT edit this file! */
package org.eclipse.dirigible.components.engine.camel.components;

import javax.annotation.processing.Generated;
import java.util.Map;

import org.apache.camel.CamelContext;
import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
import org.apache.camel.spi.PropertyConfigurerGetter;
import org.apache.camel.spi.ConfigurerStrategy;
import org.apache.camel.spi.GeneratedPropertyConfigurer;
import org.apache.camel.util.CaseInsensitiveMap;
import org.apache.camel.support.component.PropertyConfigurerSupport;

/**
* Generated by camel build tools - do NOT edit this file!
*/
@Generated("org.apache.camel.maven.packaging.EndpointSchemaGeneratorMojo")
@SuppressWarnings("unchecked")
public class DirigibleJavaScriptComponentConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {

@Override
public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
DirigibleJavaScriptComponent target = (DirigibleJavaScriptComponent) obj;
switch (ignoreCase ? name.toLowerCase() : name) {
case "autowiredenabled":
case "autowiredEnabled": target.setAutowiredEnabled(property(camelContext, boolean.class, value)); return true;
case "lazystartproducer":
case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
default: return false;
}
}

@Override
public Class<?> getOptionType(String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase() : name) {
case "autowiredenabled":
case "autowiredEnabled": return boolean.class;
case "lazystartproducer":
case "lazyStartProducer": return boolean.class;
default: return null;
}
}

@Override
public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
DirigibleJavaScriptComponent target = (DirigibleJavaScriptComponent) obj;
switch (ignoreCase ? name.toLowerCase() : name) {
case "autowiredenabled":
case "autowiredEnabled": return target.isAutowiredEnabled();
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
default: return null;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Generated by camel build tools - do NOT edit this file! */
package org.eclipse.dirigible.components.engine.camel.components;

import javax.annotation.processing.Generated;
import java.util.Map;

import org.apache.camel.CamelContext;
import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
import org.apache.camel.spi.PropertyConfigurerGetter;
import org.apache.camel.spi.ConfigurerStrategy;
import org.apache.camel.spi.GeneratedPropertyConfigurer;
import org.apache.camel.util.CaseInsensitiveMap;
import org.apache.camel.support.component.PropertyConfigurerSupport;

/**
* Generated by camel build tools - do NOT edit this file!
*/
@Generated("org.apache.camel.maven.packaging.EndpointSchemaGeneratorMojo")
@SuppressWarnings("unchecked")
public class DirigibleJavaScriptEndpointConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {

@Override
public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
DirigibleJavaScriptEndpoint target = (DirigibleJavaScriptEndpoint) obj;
switch (ignoreCase ? name.toLowerCase() : name) {
case "lazystartproducer":
case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
default: return false;
}
}

@Override
public Class<?> getOptionType(String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase() : name) {
case "lazystartproducer":
case "lazyStartProducer": return boolean.class;
default: return null;
}
}

@Override
public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
DirigibleJavaScriptEndpoint target = (DirigibleJavaScriptEndpoint) obj;
switch (ignoreCase ? name.toLowerCase() : name) {
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
default: return null;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* Generated by camel build tools - do NOT edit this file! */
package org.eclipse.dirigible.components.engine.camel.components;

import javax.annotation.processing.Generated;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.camel.spi.EndpointUriFactory;

/**
* Generated by camel build tools - do NOT edit this file!
*/
@Generated("org.apache.camel.maven.packaging.GenerateEndpointUriFactoryMojo")
public class DirigibleJavaScriptEndpointUriFactory extends org.apache.camel.support.component.EndpointUriFactorySupport implements EndpointUriFactory {

private static final String BASE = ":javaScriptPath";

private static final Set<String> PROPERTY_NAMES;
private static final Set<String> SECRET_PROPERTY_NAMES;
private static final Set<String> MULTI_VALUE_PREFIXES;
static {
Set<String> props = new HashSet<>(2);
props.add("javaScriptPath");
props.add("lazyStartProducer");
PROPERTY_NAMES = Collections.unmodifiableSet(props);
SECRET_PROPERTY_NAMES = Collections.emptySet();
MULTI_VALUE_PREFIXES = Collections.emptySet();
}

@Override
public boolean isEnabled(String scheme) {
return "dirigible-java-script".equals(scheme);
}

@Override
public String buildUri(String scheme, Map<String, Object> properties, boolean encode) throws URISyntaxException {
String syntax = scheme + BASE;
String uri = syntax;

Map<String, Object> copy = new HashMap<>(properties);

uri = buildPathParameter(syntax, uri, "javaScriptPath", null, true, copy);
uri = buildQueryParameters(uri, copy, encode);
return uri;
}

@Override
public Set<String> propertyNames() {
return PROPERTY_NAMES;
}

@Override
public Set<String> secretPropertyNames() {
return SECRET_PROPERTY_NAMES;
}

@Override
public Set<String> multiValuePrefixes() {
return MULTI_VALUE_PREFIXES;
}

@Override
public boolean isLenientProperties() {
return false;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"component": {
"kind": "component",
"name": "dirigible-java-script",
"title": "Dirigible JavaScript",
"description": "Invoke JavaScript code.",
"deprecated": false,
"firstVersion": "1.0.0",
"label": "core,script",
"javaType": "org.eclipse.dirigible.components.engine.camel.components.DirigibleJavaScriptComponent",
"supportLevel": "Stable",
"groupId": "org.eclipse.dirigible",
"artifactId": "dirigible-components-engine-camel",
"version": "11.0.0-SNAPSHOT",
"scheme": "dirigible-java-script",
"extendsScheme": "",
"syntax": "dirigible-java-script:javaScriptPath",
"async": false,
"api": false,
"consumerOnly": false,
"producerOnly": true,
"lenientProperties": false,
"remote": false
},
"componentProperties": {
"lazyStartProducer": { "index": 0, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing." },
"autowiredEnabled": { "index": 1, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc." }
},
"properties": {
"javaScriptPath": { "index": 0, "kind": "path", "displayName": "Java Script Path", "group": "common", "label": "common", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Sets the path of the JavaScript file." },
"lazyStartProducer": { "index": 1, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing." }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by camel build tools - do NOT edit this file!
class=org.eclipse.dirigible.components.engine.camel.components.DirigibleJavaScriptComponent
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by camel build tools - do NOT edit this file!
class=org.eclipse.dirigible.components.engine.camel.components.DirigibleJavaScriptComponentConfigurer
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by camel build tools - do NOT edit this file!
class=org.eclipse.dirigible.components.engine.camel.components.DirigibleJavaScriptEndpointConfigurer
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by camel build tools - do NOT edit this file!
class=org.eclipse.dirigible.components.engine.camel.components.DirigibleJavaScriptEndpointUriFactory
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2010-2024 Eclipse Dirigible contributors
*
* All rights reserved. This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v2.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-FileCopyrightText: Eclipse Dirigible contributors SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.dirigible.components.engine.camel.components;

import org.apache.camel.Endpoint;
import org.apache.camel.support.DefaultComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

@org.apache.camel.spi.annotations.Component(DirigibleJavaScriptEndpoint.SCHEME)
public class DirigibleJavaScriptComponent extends DefaultComponent {

private static final Logger LOGGER = LoggerFactory.getLogger(DirigibleJavaScriptComponent.class);

public DirigibleJavaScriptComponent() {
LOGGER.debug("Creating [{}]", this);
}

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
DirigibleJavaScriptEndpoint endpoint = new DirigibleJavaScriptEndpoint(uri, this);
endpoint.setJavaScriptPath(remaining);
setProperties(endpoint, parameters);

return endpoint;
}

}
Loading

0 comments on commit 0c39750

Please sign in to comment.