Camunda-bpm-mail class loading problem

I am evaluating Camunda and the mail connector extension for possible usage in our projects
But we meet problem

Used Environment:
Adopt Open JDK 11
Camundas Pre-Packaged Distribution 7.15 for WildFly
Installing the mail connector camunda-bpm-mail-core:1.3.0 following the provided instructions.
Install the Extension for a Shared Process Engine on Wildfly

My experimental process flow (snipped) is as follows:

Connector: mail-poll ==> Service task: Process Mails

The good news is: The polled mails arrive correctly filled via the process variable “mails”
in the service task.
Also the received class name is correct.
Log output; “Class of mail is: org.camunda.bpm.extension.mail.dto.Mail”

But the further processing fails:

Here is my code snippet of the execute method of my service task:

public final class ServiceTaskProcessMails implements JavaDelegate {
    // Snipped
    
@Override
    public void execute(final DelegateExecution execution) {
        List mails = (ArrayList) execution.getVariable("mails");
        if (mails == null) {
            throw new IllegalStateException("Process variable \"mails\" not set");
        }
        LOGGER.info("Found {} mails in inbox", mails.size());
        if (mails.size() > 0) {
            // This works and shows correct data
            LOGGER.info("Mail: {}", mails.get(0).toString());
            // What kind of class we got?
            LOGGER.info("Class of mail is: {}", mails.get(0).getClass().getName());
            // This causes an exception
            Mail mail = (Mail) mails.get(0);
        }
    }

}

The line with the cast: “Mail mail = (Mail) mails.get(0)” causes the following exception:
many lines down:
Caused by: java.lang.NoClassDefFoundError: org/camunda/bpm/extension/mail/dto/Mail

Changing the dependency scope of “camunda-bpm-mail-core” from “provided” to “compile” within
the pom it becomes clearer what is going on here:
Now the exception says:
org.camunda.bpm.extension.mail.dto.Mail cannot be cast to
class org.camunda.bpm.extension.mail.dto.Mail

lines deleted

(org.camunda.bpm.extension.mail.dto.Mail is in unnamed module of loader
‘org.camunda.bpm.extension.camunda-bpm-mail-core@1.3.0’ @22d0c2d6;
org.camunda.bpm.extension.mail.dto.Mail is in unnamed module of loader
‘deployment.opvdemo.war’ @c86416e):

That means the Mail classes are loaded by different class loaders and cannot be castet eachother.

Also interesting in this context is:
A similar problem with class loading shows up when deploying the print-service example.
During deploy within the PostDeploy Method of class PrintServiceProcessApplication.java
the following exception is thrown, and the deployment fails:
lines deleted
Caused by: java.lang.NoClassDefFoundError:
org/camunda/bpm/extension/mail/config/MailConfigurationFactory

Any ideas?
Maybe adjusting WildFly config ???
Greetings from Munich
Stephan

Here is some extra Information:
First I think that the problem with the deployment of the
print-service example and the problem with my ServiceTask have
the same cause. So someone else can reproduce the problem easily.
What I have already done is:
Building the example and running WildFly with Jdk 8.
The problem remains

Here is some further Info
When setting mail.attachment.download=true
The following exception is thrown:
Caused by: java.lang.NoClassDefFoundError: javax/activation/DataHandler
at org.camunda.bpm.extension.camunda-bpm-mail-core@1.3.0//
org.camunda.bpm.extension.mail.dto.Attachment.download(Attachment.java:46)
at org.camunda.bpm.extension.camunda-bpm-mail-core@1.3.0//
org.camunda.bpm.extension.mail.dto.Mail.downloadAttachments(Mail.java:181)
at org.camunda.bpm.extension.camunda-bpm-mail-core@1.3.0//
org.camunda.bpm.extension.mail.poll.PollMailResponse.collectResponseParameters
(PollMailResponse.java:54)

It seems the dependencies for the connector would have to be adapted to the
new distro 7.15

Hello @StephanMuc81927 ,

this seems to be kind of an endless story :slight_smile:

What I basically did was importing the source code to my IDE and then searching the dependency tree for the class that went missing.
Then, I searched the modules for missing dependencies. And prefer system modules over our distro modules :wink:

Maybe this helps

Jonathan

Hello @StephanMuc81927 ,

I found out that Wildfly uses jakarta-mail instead of javax-mail now.

One difference is that jakarta-mail does not have javax-activation as dependency.

Please add this to the camunda-bpm-mail module.xml:

<module name="javax.activation.api"/>

I hope this takes you a step further.

If there are still problems, I would recommend to upgrade the connector and then create a pull request.

Jonathan

It didn’t help

But I think it is not nessecary, because jakarta.activation-1.2.2.jar
is already in the modules depenency chain

Here it is:

<module xmlns="urn:jboss:module:1.0" name="org.camunda.bpm.camunda-engine-plugin-connect">
    <dependencies>
        <module name="javax.api" />
        <module name="org.camunda.bpm.camunda-engine" />
        <module name="org.camunda.connect.camunda-connect-core" />
        <module name="org.camunda.connect.camunda-connect-http-client" services="import" />
        <module name="org.camunda.connect.camunda-connect-soap-http-client" services="import" />
        <module name="org.camunda.bpm.extension.camunda-bpm-mail-core" services="import" />
    </dependencies>
    <resources>
        <resource-root path="camunda-engine-plugin-connect-7.15.0.jar" />
    </resources>
</module>

<module xmlns="urn:jboss:module:1.0" name="org.camunda.bpm.extension.camunda-bpm-mail-core">
    <dependencies>
        <module name="javax.mail.api" />
        <module name="org.slf4j" />
        <module name="org.camunda.connect.camunda-connect-core" />
    </dependencies>
    <resources>
        <resource-root path="camunda-bpm-mail-core-1.3.0.jar" />
    </resources>
</module>

<module name="javax.mail.api" xmlns="urn:jboss:module:1.7">
    <dependencies>
        <module name="javax.activation.api" />
        <module name="javax.api" />
    </dependencies>
    <resources>
        <resource-root path="jakarta.mail-1.6.5.jar" />
    </resources>
</module>

<module name="javax.activation.api" xmlns="urn:jboss:module:1.5">
    <dependencies>
        <module name="javax.api" />
        <module name="javax.mail.api" optional="true">
            <imports>
                <include path="META-INF" />
            </imports>
        </module>
        <module name="com.sun.xml.messaging.saaj" optional="true" />
        <module name="org.jboss.ws.native.jbossws-native-core" optional="true" />
        <module name="org.apache.cxf" optional="true" />
    </dependencies>
    <resources>
        <resource-root path="jakarta.activation-1.2.2.jar" />
    </resources>
</module>

Hello @StephanMuc81927 ,

yes you are right. If you are still facing trouble, I would recommend you update the project and create a pull request. By doing this, you help the whole community :slight_smile:

Jonathan

This is really a never ending story
As another try I changed the dependencies within camunda-bpm-mail-core/pom.xml

From
Snippet:

  <properties>
    <version.javamail>1.5.5</version.javamail>
    <version.slf4j>1.7.21</version.slf4j>
  </properties>

  <dependencies>
    
    <dependency>
      <groupId>com.sun.mail</groupId>
      <artifactId>javax.mail</artifactId>
      <version>${version.javamail}</version>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${version.slf4j}</version>
    </dependency>
    
    <dependency>
      <groupId>org.camunda.connect</groupId>
      <artifactId>camunda-connect-core</artifactId>
    </dependency>

     <!-- rest snipped -->

To
Snippet:

  <properties>
    <version.jakartamail>1.6.5</version.jakartamail>
    <version.slf4j>1.7.26</version.slf4j>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.sun.mail</groupId>
      <artifactId>jakarta.mail</artifactId>
      <version>${version.jakartamail}</version>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${version.slf4j}</version>
    </dependency>

    <dependency>
      <groupId>org.camunda.connect</groupId>
      <artifactId>camunda-connect-core</artifactId>
    </dependency>
    
     <!-- rest snipped -->

     </dependencies>

This also didn’t help

I want to go back to what we want to do here in the project.
The use case is basically very simple:
An e-mail with an Excel sheet attachment starts a business process based on the data in the received Excel sheet.

So the Mail Connector Extension should work as soon as possible within the current WildFly Distro from Camunda.
I hope we get this resolved soon, or we need to search for an alternative to Camunda.

By the way, on the topic of Pull Request:
That could well become a reality because we need another
Connector Task:
Moving the received mail from the INBOX to another folder.
Stephan

Hello @StephanMuc81927 ,

as the connector is not the only approach to reach a mail server from wildfly, you could focus on the wildfly board tools to set up a connection from there to your mail server and handle the interaction of process and mail service via delegates.

Big Bonus:
You are free in using your wildfly environment and you can implement every required function from there.

I hope this takes you further to what you are willing to do.

Jonathan

1 Like

Hi Stephan! If you are interested in opening an issue in the repository regarding your need for another connection task, the community there might be able to help as well!

1 Like

Finally I got it.
The problems had to do with the introduction of modules in java 9.
See step 3 below.
Also included is a hint about slf4j logging by jonathan.lukas
Adjust the version numbers for your needs

Steps to install the Extension for a Shared Process Engine on Wildfly.

  1. Create a module for camunda-bpm-mail-core:

Copy the jar into \server\wildfly-22.0.1.Final.Final\modules\org\camunda\bpm\extension\camunda-bpm-mail-core\main and add a module.xml with following content:

  <module xmlns="urn:jboss:module:1.0" name="org.camunda.bpm.extension.camunda-bpm-mail-core">
    <dependencies>
      <module name="javax.mail.api" />
      <module name="org.slf4j" />
      <module name="org.camunda.connect.camunda-connect-core" />
    </dependencies>
    <resources>
      <resource-root path="camunda-bpm-mail-core-1.3.0.jar" />
    </resources>
  </module>
  1. Import the mail module in the connect-plugin:

Change the module.xml in \server\wildfly-22.0.1.Final\modules\org\camunda\bpm\camunda-engine-plugin-connect\main and add the line

  <module name="org.camunda.bpm.extension.camunda-bpm-mail-core" services="import" />
  1. Add a jboss-deployment-structure.xml to the WEB-INF directory of your web application with the following content:
 <jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="org.camunda.bpm.extension.camunda-bpm-mail-core" />
        </dependencies>
    </deployment>
</jboss-deployment-structure>
1 Like

Hello @StephanMuc81927 ,

this is one detail that I missed out. FYI, I came across the same thing when I used some SPIN serialization features (explicit serialization of Files I think).

And, this is very important knowledge. Thank you a lot for providing feedback. It would be great to have this additional step inside the github repo too. Can you add it there and create a Pull Request also?

Jonathan

1 Like