Monday, April 22, 2024

Custom Mediator cannot be found by synapse-core

 Caused by: java.lang.ClassNotFoundException: com.chandana.test.CustomMediator cannot be found by synapse-core_4.0.0.wso2v20_43
        at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:512)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:423)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:415)
        at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:155)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
        at org.apache.synapse.config.xml.ClassMediatorFactory.createSpecificMediator(ClassMediatorFactory.java:100)


 If you try to build a WSO2 Custom mediator for Micro Integrator 4.2.0 using Maven, you might encounter above exception in the logs. Based on my understanding, there are two ways to overcome this issue. The first option is to use Integration Studio to export the custom mediator JAR file. However, in my use case, it’s not feasible. After going through the WSO2 Integration Studio source code, I found that it uses different Maven-bundle-plugin instructions than what’s available in the pom.xml file.

I have overcome this issue by adding <_removeheaders>Import-Package,Private-Package</_removeheaders> to the Maven-bundle-plugin instructions.

<plugin>

        <groupId>org.apache.felix</groupId>

        <artifactId>maven-bundle-plugin</artifactId>

        <version>2.3.4</version>

        <extensions>true</extensions>

        <configuration>

          <instructions>

            <Bundle-SymbolicName>CustomClassMediator</Bundle-SymbolicName>

            <Bundle-Name>CustomClassMediator</Bundle-Name>

            <Export-Package>com.chandana.test</Export-Package>

            <DynamicImport-Package>*</DynamicImport-Package>

            <_removeheaders>Import-Package,Private-Package</_removeheaders>

          </instructions>

        </configuration>

      </plugin>

1 comment:

  1. Hi Chandana, thanks for your post. I'm struggling with a similar issue, whenever I try to use the deployed custom mediator jar, I'm getting class not found. I tried compiling using maven following your advice, and also tried generating the jar from Integration Studio, both ways gave me the same error when trying to use the mediator in a sequence.

    I tried deploying to /lib, also tried deploying to /dropins, no success so far.

    Could you please give me a hand with this? Any advice would be greatly appreciated.

    Thanks

    ReplyDelete


View Counts


Followers