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

Java External Task client unable to load value of local file variable #4523

Closed
3 of 4 tasks
venetrius opened this issue Aug 7, 2024 · 4 comments
Closed
3 of 4 tasks
Assignees
Labels
group:support All requests that are linked to a customer request. DRI: Tassilo type:bug Issues that describe a user-facing bug in the project. version:7.22.0

Comments

@venetrius
Copy link
Member

venetrius commented Aug 7, 2024

Environment (Required on creation)

Reported and reproduced on 7.21-ee

Description (Required on creation; please attach any relevant screenshots, stacktraces, log files, etc. to the ticket)

When trying to access the value of a local file Variable vars.getValueTyped("localFile") .getValue();, we get the following error message:

TASK/CLIENT-01008 Exception while loading deferred file: execution variable with name File does not exist

Steps to reproduce (Required on creation)

  • Create a BPMN process
  • In an earlier step create a file global variable for example from a inline script:
import org.camunda.bpm.engine.variable.Variables

def sampleContent = "someRandomFileContent";
def file = Variables.fileValue("sample.txt").file(sampleContent.getBytes()).mimeType("text/plain").create();

execution.setVariable('fileInProcess', file);
  • Create an external task that has a local input variable, lets call it localFile
${execution.getVariableTyped("fileInProcess")}
  • Attempt to load the localFile variable in the external client:
      client.subscribe("DEMO_TOPIC")
          .localVariables(true)
          .includeExtensionProperties(true)
          .handler((ExternalTask externalTask, ExternalTaskService externalTaskService) -> {
            VariableMap vars = externalTask.getAllVariablesTyped();
            vars.getValueTyped("localFile")
                .getValue();
           // same result if `externalTask.getVariableTyped("localFile").getValue()` is called (without `.localVariables(true)`)
            externalTaskService.complete(externalTask);
          })
          .open();
    }
  • observe error:
TASK/CLIENT-01008 Exception while loading deferred file: execution variable with name File does not exist

See example bpmn and process in JIRA

Observed Behavior (Required on creation)

When trying to access the value of a local file Variable vars.getValueTyped("localFile") .getValue();, we get the following error message:

TASK/CLIENT-01008 Exception while loading deferred file: execution variable with name File does not exist

Expected behavior (Required on creation)

The call to VariableMap::getValueTyped should return the actual value of the fileValue and don’t throw an error.

Root Cause (Required on prioritization)

In the class org.camunda.bpm.client.impl.EngineClient, the method getLocalBinaryVariable gets called from DeferredFileValueImpl::load with the processInstanceId instead of the executionId.
The request sent to the rest-api looks like: {{GET /execution/{processInstanceId}/localVariables/{name}/data}}
It tries to resolve a variable from the top level process instance execution instead of using the actual child execution where the local variable is set.

When executing the request (with the processInstanceId) in postman, i get the same error. When using the actual executionId of the externalTask {{GET /execution/{excecutionId}/localVariables/{name}/data}}, i get the correct variable value/file content.

Solution Ideas

Current attempt to retrieve content of a Variable:

 public byte[] getLocalBinaryVariable(String variableName, String processInstanceId) {
    String resourcePath = this.baseUrl + "/execution/{id}/localVariables/{name}/data".replace("{id}", processInstanceId).replace("{name}", variableName);
    return this.engineInteraction.getRequest(resourcePath);
  }

Using https://docs.camunda.org/rest/camunda-bpm-platform/7.21/#tag/Process-Instance/operation/getProcessInstanceVariableBinary with the executionId would work for both local and global variables:

 public byte[] getProcessInstanceVariableBinary(String variableName, String executionId) {
    String resourcePath = this.baseUrl + "/process-instance/{executionId}/variables/{name}/data".replace("{id}", executionId).replace("{name}", variableName);
    return this.engineInteraction.getRequest(resourcePath);
  }

The executionId can be set on the DeferredFileValueImpl instance when the instanceVariable is returned from ExternalTaskImpl.java getVariable, getAllVariablesTyped, getVariableTyped functions.

Hints

Links

Breakdown

Pull Requests

  1. ci:postgresql ci:tomcat
    venetrius
  2. venetrius
  3. venetrius

Follow ups

  1. type:bug version:7.23.0
    venetrius

Dev2QA handover

  • Does this ticket need a QA test and the testing goals are not clear from the description? Add a Dev2QA handover comment
@venetrius venetrius added type:bug Issues that describe a user-facing bug in the project. group:support All requests that are linked to a customer request. DRI: Tassilo labels Aug 7, 2024
@tasso94
Copy link
Member

tasso94 commented Aug 8, 2024

Let's try to fix it in the NodeJS XTaC as well or create a follow-up issue.

@venetrius
Copy link
Member Author

I still have to create a new task for External JavaScript Client or apply a fix in this ticket.

@mboskamp mboskamp assigned venetrius and unassigned mboskamp Sep 16, 2024
@venetrius venetrius assigned mboskamp and unassigned venetrius Sep 16, 2024
venetrius added a commit that referenced this issue Sep 16, 2024
@venetrius
Copy link
Member Author

@gbetances089 QA hand over note.
Scenarios to test:

  • external java client can load value for local file variable
  • external java client can load value for global file variable

Please see linked Jira issue for example BPMN.

@gbetances089
Copy link
Member

Tested on 7.22.0-alpha6 release candidate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
group:support All requests that are linked to a customer request. DRI: Tassilo type:bug Issues that describe a user-facing bug in the project. version:7.22.0
Projects
None yet
Development

No branches or pull requests

4 participants