Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(classloader): always reset current classloader after an API call #104

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
SONAR_TOKEN: ${{secrets.SONAR_TOKEN}}
run: ./mvnw -B sonar:sonar -Dsonar.login=${{ secrets.SONAR_TOKEN }}
run: ./mvnw -B sonar:sonar

- name: Copy artifacts for staging
run: |
Expand Down
21 changes: 12 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
<jakarta.mail.version>1.6.7</jakarta.mail.version>

<!-- Bonita -->
<bonita-runtime.version>7.13.0</bonita-runtime.version>
<bonita-runtime.version>8.0.0</bonita-runtime.version>

<!-- Test -->
<junit-jupiter-engine.version>5.11.3</junit-jupiter-engine.version>
<greenmail.version>1.6.11</greenmail.version>
<jacoco-maven-plugin.version>0.8.11</jacoco-maven-plugin.version>
<sonar-maven-plugin.version>3.10.0.2594</sonar-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>
<sonar-maven-plugin.version>5.0.0.4389</sonar-maven-plugin.version>
<mockito-core.version>5.8.0</mockito-core.version>
<assertj-core.version>3.24.2</assertj-core.version>
<logback-classic.version>1.2.13</logback-classic.version>
Expand Down Expand Up @@ -312,7 +312,7 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>3.0.19</version>
<version>3.0.23</version>
</dependency>
</dependencies>
</plugin>
Expand All @@ -335,6 +335,9 @@
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco.exec</destFile>
</configuration>
</execution>
<execution>
<id>jacoco-site</id>
Expand Down Expand Up @@ -432,24 +435,24 @@
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>integration-tests-7.13</id>
<id>integration-tests-8.0</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<systemProperties>
<bonita.version>7.13.0</bonita.version>
<bonita.version>8.0.0</bonita.version>
</systemProperties>
</configuration>
</execution>
<execution>
<id>integration-tests-7.14</id>
<id>integration-test-10.2</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<systemProperties>
<bonita.version>7.14.0</bonita.version>
<bonita.version>10.2</bonita.version>
</systemProperties>
</configuration>
</execution>
Expand All @@ -474,7 +477,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.7</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/org/bonitasoft/connectors/email/EmailConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,14 @@ private void handleAttachment(boolean html, StringBuilder messageBody, ProcessAP
private void addBodyPart(ProcessAPI processAPI, List<MimeBodyPart> bodyParts, Document document)
throws DocumentNotFoundException, MessagingException {
String fileName = document.getContentFileName();
byte[] docContent = processAPI.getDocumentContent(document.getContentStorageId());
byte[] docContent = null;
// Workaround RUNTIME-1919
ClassLoader currentClassloader = Thread.currentThread().getContextClassLoader();
try {
docContent = processAPI.getDocumentContent(document.getContentStorageId());
}finally {
Thread.currentThread().setContextClassLoader(currentClassloader);
}
if (docContent != null) {
String mimeType = document.getContentMimeType();
var bodyPart = new MimeBodyPart();
Expand All @@ -487,7 +494,14 @@ private Document getDocument(Object attachment, ProcessAPI processAPI)
if (attachment instanceof String && !((String) attachment).trim().isEmpty()) {
String docName = (String) attachment;
long processInstanceId = getExecutionContext().getProcessInstanceId();
return processAPI.getLastDocument(processInstanceId, docName);
// Workaround RUNTIME-1919
ClassLoader currentClassloader = Thread.currentThread().getContextClassLoader();
try{
return processAPI.getLastDocument(processInstanceId, docName);
}finally {
Thread.currentThread().setContextClassLoader(currentClassloader);
}

} else if (attachment instanceof Document) {
return (Document) attachment;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import java.util.Map;

import javax.mail.internet.MimeMessage;
Expand Down Expand Up @@ -61,6 +62,7 @@ void test0(ConnectorExecutor executor) throws Exception {
.addInput(EmailConnector.TO, Expression.stringValue("receiver@bonitasoft.com"))
.addInput(EmailConnector.SUBJECT, Expression.stringValue("Testing Subject"))
.addInput(EmailConnector.MESSAGE, Expression.stringValue("Hello World"))
.addInput(EmailConnector.ATTACHMENTS, Expression.groovyScript("['myDoc']", List.class.getName()))
.build();

Map<String, String> result = executor.execute(configuration);
Expand All @@ -74,7 +76,7 @@ void test0(ConnectorExecutor executor) throws Exception {
assertThat(message.getFrom()[0]).hasToString("romain.bioteau@bonitasoft.com");
assertThat(message.getRecipients(RecipientType.TO)[0]).hasToString("receiver@bonitasoft.com");
assertThat(message.getSubject()).isEqualTo("Testing Subject");
assertThat(GreenMailUtil.getBody(message)).isEqualTo("Hello World");
assertThat(GreenMailUtil.getBody(message)).contains("Hello World");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class BonitaContainer extends GenericContainer<BonitaContainer> {
private User user;

public BonitaContainer() {
this(System.getProperty("bonita.version", "7.13"));
this(System.getProperty("bonita.version", "10.2"));
}

public BonitaContainer(String version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.Predicate;
Expand All @@ -52,6 +53,8 @@
import org.bonitasoft.engine.bpm.process.impl.ProcessDefinitionBuilder;
import org.bonitasoft.engine.expression.Expression;
import org.bonitasoft.engine.expression.ExpressionBuilder;
import org.bonitasoft.engine.expression.ExpressionInterpreter;
import org.bonitasoft.engine.expression.ExpressionType;
import org.bonitasoft.engine.expression.InvalidExpressionException;
import org.bonitasoft.engine.operation.OperationBuilder;

Expand Down Expand Up @@ -167,6 +170,9 @@ private DesignProcessDefinition buildConnectorInProcess(Configuration configurat
var processBuilder = new ProcessDefinitionBuilder();
processBuilder.createNewInstance("PROCESS_UNDER_TEST", "1.0");
processBuilder.addActor("system");
processBuilder.addDocumentDefinition("myDoc")
.addFile("myDoc.docx")
.addContentFileName("myDoc.docx");
var expConverter = expressionConverter();
var connectorBuilder = processBuilder.addConnector("connector-under-test",
configuration.getDefinitionId(),
Expand Down Expand Up @@ -197,8 +203,11 @@ private static Function<Configuration.Expression, Expression> expressionConverte
try {
return expBuilder.createExpression(UUID.randomUUID().toString(),
exp.getContent(),
exp.getType(),
exp.getReturnType(),
exp.getType());
Objects.equals(exp.getType(), ExpressionType.TYPE_READ_ONLY_SCRIPT) ? ExpressionInterpreter.GROOVY.name(): null,
List.of()
);
} catch (InvalidExpressionException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -243,6 +252,10 @@ private BusinessArchive buildBusinessArchive(DesignProcessDefinition process,
actorMapping.addActor(systemActor);
barBuilder.setActorMapping(actorMapping);

try(var is = ConnectorExecutorImpl.class.getResourceAsStream("/myDoc.docx")){
barBuilder.addDocumentResource(new BarResource("myDoc.docx", is.readAllBytes()));
}

return barBuilder.done();
}

Expand Down
Binary file added src/test/resources/myDoc.docx
Binary file not shown.