External Java worker variable too large?

I have a Java Worker that I want to create a PDF and then feed the PDF to the process as a variable. The code is as follows:

    client.subscribe("tarkastuspoytakirja")
  .handler((externalTask, externalTaskService) -> {
    Map<String, Object> variables = new HashMap<>();
    try {
      PdfTarkastuspoytakirja pdf = new PdfTarkastuspoytakirja();
      ByteArrayOutputStream out = pdf.generatePdf();
      final byte[] pdfBytes = out.toByteArray();
      String pdfBase64 = Base64.getEncoder().encodeToString(pdfBytes);
      variables.put("pdfBase64", pdfBase64); // HERE! 
    } catch(Exception ioe) {
        ioe.printStackTrace();
    }
    externalTaskService.complete(externalTask, variables);
  })
  .open();

If I comment out variables.put("pdfBase64", pdfBase64) it works as expected, but if I leave that in, I get

[TopicSubscriptionManager] ERROR org.camunda.bpm.client - TASK/CLIENT-03004 Exception on external task service method invocation for topic 'tarkastuspoytakirja':

org.camunda.bpm.client.exception.NotResumedException: TASK/CLIENT-01009 Exception while completing the external task: The corresponding process instance could not be resumed. Reason: status code: 500, reason phrase: {"type":"ProcessEngineException","message":"ENGINE-03004 Exception while executing Database Operation 'INSERT HistoricVariableUpdateEventEntity[d810c95b-6f65-11ea-969f-4ee38f309fb9]' with message '\n### Error flushing statements.  Cause: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.HistoricDetailEntity.insertHistoricVariableUpdateEvent (batch index #2) failed. 1 prior sub executor(s) completed successfully, but will be rolled back. Cause: java.sql.BatchUpdateException: Data truncation: Data too long for column 'TEXT_' at row 1\n### Cause: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.HistoricDetailEntity.insertHistoricVariableUpdateEvent (batch index #2) failed. 1 prior sub executor(s) completed successfully, but will be rolled back. Cause: java.sql.BatchUpdateException: Data truncation: Data too long for column 'TEXT_' at row 1'. Flush summary: \n [\n  INSERT HistoricVariableInstanceEntity[d810c95a-6f65-11ea-969f-4ee38f309fb9]\n  INSERT HistoricVariableUpdateEventEntity[d810c959-6f65-11ea-969f-4ee38f309fb9]\n  INSERT HistoricVariableUpdateEventEntity[d810c95b-6f65-11ea-969f-4ee38f309fb9]\n  INSERT HistoricVariableUpdateEventEntity[d811177d-6f65-11ea-969f-4ee38f309fb9]\n  INSERT HistoricVariableUpdateEventEntity[d811177e-6f65-11ea-969f-4ee38f309fb9]\n  INSERT HistoricExternalTaskLogEntity[d810f06c-6f65-11ea-969f-4ee38f309fb9]\n  INSERT HistoricActivityInstanceEventEntity[Event_1m7ngrw:d811177f-6f65-11ea-969f-4ee38f309fb9]\n  DELETE ExternalTaskEntity[d7c0fba7-6f65-11ea-969f-4ee38f309fb9]\n  DELETE VariableInstanceEntity[d7c0ad82-6f65-11ea-969f-4ee38f309fb9]\n  DELETE ExecutionEntity[d7c0d495-6f65-11ea-969f-4ee38f309fb9]\n  DELETE ExecutionEntity[d7c0ad81-6f65-11ea-969f-4ee38f309fb9]\n  UPDATE HistoricActivityInstanceEventEntity[tarkastuspoytakirja:d7c0d496-6f65-11ea-969f-4ee38f309fb9]\n  UPDATE HistoricProcessInstanceEventEntity[d7c0ad81-6f65-11ea-969f-4ee38f309fb9]\n  DELETE_BULK deleteAuthorizationsForResourceId {resourceId=d7c0ad81-6f65-11ea-969f-4ee38f309fb9, resourceType=8}\n  UPDATE HistoricVariableInstanceEntity[d7c0ad82-6f65-11ea-969f-4ee38f309fb9]\n]"}
at org.camunda.bpm.client.impl.ExternalTaskClientLogger.externalTaskServiceException(ExternalTaskClientLogger.java:124)
at org.camunda.bpm.client.task.impl.ExternalTaskServiceImpl.complete(ExternalTaskServiceImpl.java:64)
at org.camunda.bpm.client.task.impl.ExternalTaskServiceImpl.complete(ExternalTaskServiceImpl.java:56)
at fi.test.bpm.Worker.lambda$0(Worker.java:44)
at org.camunda.bpm.client.topic.impl.TopicSubscriptionManager.handleExternalTask(TopicSubscriptionManager.java:152)
at org.camunda.bpm.client.topic.impl.TopicSubscriptionManager.lambda$acquire$0(TopicSubscriptionManager.java:108)
at java.util.Arrays$ArrayList.forEach(Arrays.java:3880)
at org.camunda.bpm.client.topic.impl.TopicSubscriptionManager.acquire(TopicSubscriptionManager.java:103)
at org.camunda.bpm.client.topic.impl.TopicSubscriptionManager.run(TopicSubscriptionManager.java:87)
at java.lang.Thread.run(Thread.java:748)

And the relevant part of that seems to be

java.sql.BatchUpdateException: Data truncation:
    Data too long for column 'TEXT_' at row 1

Is my variable really too large? It’s not a big PDF. What other way would I have of achieving this result?

I am currently running my worker in Eclipse, because I don’t know how to run directly from a jar, maybe that is the problem?

Hi @Joel,

you have to wrap your PDF as a Java Object before you complete the external task. Then the engine will put the variable into a blob to store large data.

Here is an example: https://github.com/camunda/camunda-external-task-client-java/blob/master/examples/loan-granting/src/main/java/org/camunda/bpm/App.java#L47-L53

And here are some background information about variable types in Camunda: https://docs.camunda.org/manual/7.12/user-guide/process-engine/variables/#supported-variable-values.

Hope this helps, Ingo