-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Camel custom component for Dirigible JavaScript/TypeScript …
…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
1 parent
6e54a13
commit 0c39750
Showing
58 changed files
with
1,205 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
.../dirigible/components/engine/camel/components/DirigibleJavaScriptComponentConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
|
51 changes: 51 additions & 0 deletions
51
...e/dirigible/components/engine/camel/components/DirigibleJavaScriptEndpointConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
|
71 changes: 71 additions & 0 deletions
71
...e/dirigible/components/engine/camel/components/DirigibleJavaScriptEndpointUriFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
33 changes: 33 additions & 0 deletions
33
...A-INF/org/eclipse/dirigible/components/engine/camel/components/dirigible-java-script.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." } | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...rc/generated/resources/META-INF/services/org/apache/camel/component/dirigible-java-script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 2 additions & 0 deletions
2
...d/resources/META-INF/services/org/apache/camel/configurer/dirigible-java-script-component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 2 additions & 0 deletions
2
...ed/resources/META-INF/services/org/apache/camel/configurer/dirigible-java-script-endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 2 additions & 0 deletions
2
...ed/resources/META-INF/services/org/apache/camel/urifactory/dirigible-java-script-endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
37 changes: 37 additions & 0 deletions
37
...rg/eclipse/dirigible/components/engine/camel/components/DirigibleJavaScriptComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Oops, something went wrong.