質問

I am deploying an osgi application to JBoss Fuse / Apache Camel and the javascript language doesn't want to resolve.

This error appears in the log:

ERROR | BluePrinntContainerImpl | Bundle my-service is waiting for dependencies
[(&(language=js)(objectClass=org.apache.camel.spi.LanguageResolver))]

I recently added a .javaScript() expression definition to a .choice() statement:

.choice()
    .when()
    .javaScript("request.body.updateSeq > exchange.getProperty('PrevUpdateSeq') + 1")
    .to("dosomething")

Maven:

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-script</artifactId>
        <version>${camel.version}</version>
    </dependency>

Where camel version is 2.10.0.redhat-60024.

Is there a way to fix this?

役に立ちましたか?

解決 2

The problem is due to the javascript language not being registered.

I modified some code I found on servicemix nabble to make sure the javascript engine is registered and has the key (language name) js instead of ECMAScript.

Same goes for groovy (instead of Groovy), although please note: this part is untested.

How to fix:

  1. Copy the Activator code from this page and add it as a new class in your project.

  2. Modify the register() method in BundleLanguageResolver as follows:

    public void register() {
        try
        {
            String language = factory.getLanguageName();
    
            // Hack to register languages correctly
            if ("ECMAScript".equals(language)) language = "js";
            if ("Groovy".equals(language)) language = "groovy";
    
            Hashtable<String, Object> properties =
                    new Hashtable<String, Object>();
    
            properties.put("language", language);
    
            reg = bundle.getBundleContext().registerService(
                    LanguageResolver.class,
                    new ScriptLanguageResolver(), properties);
    
            LOG.debug("Register LanguageResolver: " + language);
        } catch(Exception e)
        {
            LOG.warn("Cannot register LanguageResolver: " + e.getClass().getName(), e);
        }
    }
    
  3. Add the class you just created (e.g. com.my.Activator) to the manifest as a Bundle-Activator. The maven-bundle-plugin line can look like this:

    <Bundle-Activator>com.my.Activator</Bundle-Activator>
    

Perhaps there is another solution, but in the meantime this works for me.

他のヒント

And you have installed the features

features:install camel-script

And there may be a special for javascript named something along the lines of:

features:install camel-script-javascript

For the time being (I'm using Camel 2.16.5) adding google's scriptengine as a dependency does the trick:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-script</artifactId>
    <version>${camel.version}</version>
</dependency>
<dependency>
    <groupId>com.google.code.scriptengines</groupId>
    <artifactId>scriptengines-javascript</artifactId>
    <version>1.1.1</version>
</dependency>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top