Search code examples
javajavascriptbundleapache-cameljbossfuse

JBoss Fuse / Apache camel won't resolve language js (javascript) for bundle


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?


Solution

  • 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.