0

AEM6.2 I have a Osgi Service where in org.apache.sling.event.jobs.JobManager referenced and job is added to it.

The code is something like:

Map dataSourceMap = new HashMap<String, DataSource>
dataSourceMap.put(fileName, new ByteArrayDataSource(byte[], mimeTypeOfFile))

final Map<String, Object> props = new HashMap<String, Object>();
props.put("item1", "/something");
props.put("count", 5);
props.put("files", dataSourceMap)

jobManager.addJob("my/special/jobtopic", props);

When this job gets executed it shows some error

org.apache.sling.api.resource.PersistenceException: Value can't be stored in the repository: {<<filename>>=org.apache.commons.mail.ByteArrayDataSource@3f0f234c}

Question: Is there any solution to this exception? Or am I doing something wrong? can we add a ByteArrayInputStream to the jobmanager?

Thank you !

Just a info, If I remove the line props.put("files", dataSourceMap), it works fine.

Please let me know if you need more info on it.

Jens
  • 20,533
  • 11
  • 60
  • 86
TAaL
  • 45
  • 3

2 Answers2

1

Sling will store the job as a node in the repository and it looks like it only supports the "standard" types like String, Boolean, Integer etc. and not files/blobs.

I can not think of a way to add a file to the job, but what you could do is to create temporary node in the repository yourself, which contains the files/blobs.

Sling stores jobs here:

/var/eventing/jobs

You might do something similar:

/var/<project-name>/jobs

And the payload of the Sling job then contains the path to this job node.

Jens
  • 20,533
  • 11
  • 60
  • 86
  • Thanks Jens ! That make sense , but some how I'm trying to store blob/files into an object and try to store that object in sling jobs. – TAaL May 23 '19 at 12:07
0

Further to Jens' comment, the job will indeed store data as node properties in the JCR. You could likely explore the possibility of storing data as Binary to the jcr:data property, but I have not tested this myself.

As a quick and likely not very optimized workaround, why not serialize your byte[] to a String or even encode it to a Base64 string?

Sample: Base64 Java encode and decode a string [duplicate]

GuillaumeCleme
  • 317
  • 1
  • 2
  • 10