Hi
I use the rest full service and bpmn with inline scripting groovy or javascript
I get from response a file to download, I want to create a url and a result value
or I want download it as a pdf
How can I do it please help me
best Regards
Hi
I use the rest full service and bpmn with inline scripting groovy or javascript
I get from response a file to download, I want to create a url and a result value
or I want download it as a pdf
How can I do it please help me
best Regards
I get a response , my response is a pdf file
Hi @Abbas_Ulusoy,
You can download the value of a binary variable (such as byte or File) via the following resource: GET /process-instance/{id}/variables/{varName}/data
.
Cheers,
Thorben
I get a response from serviceTask It should be download it and i use groovy
import org.camunda.bpm.engine.variable.value.FileValue
import org.camunda.bpm.engine.variable.Variables
String filename = “testFile.pdf”;
InputStream stream = new ByteArrayInputStream(response.getBytes());
FileValue typedFileValue = Variables.fileValue(filename).file(stream).mimeType("application/pdf").create()
it is return empty pdf
@Abbas_Ulusoy see:
Looks like the same problem as i ran into. My solution was to use Jsoup as documented in the linked post
<camunda:outputParameter name="reportServiceResponse">
<camunda:script scriptFormat="javascript"><![CDATA[
var r = response
function downloadFile(fileUrl)
{
with (new JavaImporter(org.jsoup, java.io.BufferedInputStream))
{
var doc = Jsoup.connect(fileUrl)
.method(Java.type(‘org.jsoup.Connection.Method’).GET)
.timeout(30000)
.ignoreContentType(true)
.execute()
var bodyStream = doc.bodyStream()
return bodyStream
}
}
function saveFile(fileStream, fileName, mimeType)
{
var file = Java.type(‘org.camunda.bpm.engine.variable.Variables’)
.fileValue(fileName)
.file(fileStream)
.mimeType(mimeType)
.create()
}
function downloadAndSaveFile(fileUrl, fileName, mimeType)
{
var file = downloadFile(fileUrl)
saveFile(file, fileName, mimeType)
}
downloadAndSaveFile(‘http://www.pdf995.com/samples/pdf.pdf’, ‘download.pdf’, ‘application/pdf’)
]]></camunda:script>
</camunda:outputParameter>
How can I use my response my response is the bytes of files
How do you want to use your response? If you used my sample code, then the PDF will be saved as a Type “File” in the camunda DB as a process variable.
Can you also format your code using the code wrapper. Its 3 ` characters
edit: You have also omitted the execution.setVariable(fileName, file)
line in my code sample. So in your example the saveFile
function does not return anything.
if I put the file to a js file than I get this exception
First Problem
org.camunda.commons.logging.BaseLogger.logWarn ENGINE-14006 Exception while executing job 95efdaa1-dbe4-11e7-b746-28d244011131:
org.camunda.bpm.engine.exception.NotFoundException: ENGINE-09024 Unable to find resource at path deployment://downloadFile.js
Second Problem
How can I send my response from Rest-Service to this js file
mybpmn look like so
<?xml version="1.0" encoding="UTF-8"?><bpmn2:definitions xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:bpmn2=“http://www.omg.org/spec/BPMN/20100524/MODEL” xmlns:bpmndi=“http://www.omg.org/spec/BPMN/20100524/DI” xmlns:camunda=“http://camunda.org/schema/1.0/bpmn” xmlns:dc=“http://www.omg.org/spec/DD/20100524/DC” xmlns:di=“http://www.omg.org/spec/DD/20100524/DI” id="_B0ppIPFYEeOlke_H2tkzCA" targetNamespace=“http://camunda.org/examples” exporter=“Camunda Modeler” exporterVersion=“1.10.0” xsi:schemaLocation=“http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd”>
<bpmn2:process id=“twitter-service-bpmn” name=“Twitter Service BPMN” isExecutable=“true”>
<bpmn2:startEvent id=“InputTerms” name=“Input Terms” camunda:asyncBefore=“true”>
bpmn2:extensionElements
camunda:formData
<camunda:formField id=“term” label=“Term” type=“string”>
camunda:validation
<camunda:constraint name=“required” />
</camunda:validation>
</camunda:formField>
</camunda:formData>
<camunda:executionListener event=“end”>
<camunda:script scriptFormat=“groovy”></camunda:script>
</camunda:executionListener>
</bpmn2:extensionElements>
bpmn2:outgoingSequenceFlow_1p5licy</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:endEvent id=“End” name=“End”>
bpmn2:incomingSequenceFlow_toEnd</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:userTask id=“FileUpload” name=“File Download” camunda:formKey=“embedded:app:forms/download-report.html”>
bpmn2:incomingSequenceFlow_toFileDownload</bpmn2:incoming>
bpmn2:outgoingSequenceFlow_toEnd</bpmn2:outgoing>
</bpmn2:userTask>
<bpmn2:sequenceFlow id=“SequenceFlow_toEnd” sourceRef=“FileUpload” targetRef=“End” />
<bpmn2:serviceTask id=“ReportService” name=“Report Service” camunda:resultVariable=“pdffile”>
bpmn2:extensionElements
camunda:inputOutput
<camunda:inputParameter name=“reportServiceUrl”>http://localhost:5003</camunda:inputParameter>
</camunda:inputOutput>
camunda:connector
camunda:inputOutput
<camunda:inputParameter name=“url”>
<camunda:script scriptFormat=“groovy”></camunda:script>
</camunda:inputParameter>
<camunda:inputParameter name=“method”>POST</camunda:inputParameter>
<camunda:inputParameter name=“headers”>
camunda:map
<camunda:entry key=“Accept”>application/json</camunda:entry>
<camunda:entry key=“Content-Type”>application/json</camunda:entry>
</camunda:map>
</camunda:inputParameter>
<camunda:inputParameter name=“payload”>
<camunda:script scriptFormat=“groovy”></camunda:script>
</camunda:inputParameter>
<camunda:outputParameter name=“reportServiceResponse”>
<camunda:script scriptFormat=“javascript” resource=“deployment://downloadFile.js” />
</camunda:outputParameter>
</camunda:inputOutput>
camunda:connectorIdhttp-connector</camunda:connectorId>
</camunda:connector>
</bpmn2:extensionElements>
bpmn2:incomingSequenceFlow_1p5licy</bpmn2:incoming>
bpmn2:outgoingSequenceFlow_toFileDownload</bpmn2:outgoing>
</bpmn2:serviceTask>
<bpmn2:sequenceFlow id=“SequenceFlow_toFileDownload” sourceRef=“ReportService” targetRef=“FileUpload” />
<bpmn2:sequenceFlow id=“SequenceFlow_1p5licy” sourceRef=“InputTerms” targetRef=“ReportService” />
</bpmn2:process>
<bpmndi:BPMNDiagram id=“BPMNDiagram_1”>
<bpmndi:BPMNPlane id=“BPMNPlane_1” bpmnElement=“twitter-service-bpmn”>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_4" bpmnElement=“InputTerms”>
<dc:Bounds x=“82” y=“334” width=“36” height=“36” />
bpmndi:BPMNLabel
<dc:Bounds x=“71” y=“375” width=“59” height=“12” />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id=“EndEvent_0pmo85v_di” bpmnElement=“End”>
<dc:Bounds x=“1129” y=“334” width=“36” height=“36” />
bpmndi:BPMNLabel
<dc:Bounds x=“1137” y=“370” width=“20” height=“12” />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id=“UserTask_1xeoitw_di” bpmnElement=“FileUpload”>
<dc:Bounds x=“916” y=“312” width=“100” height=“80” />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id=“SequenceFlow_1fo8i4c_di” bpmnElement=“SequenceFlow_toEnd”>
<di:waypoint xsi:type=“dc:Point” x=“1016” y=“352” />
<di:waypoint xsi:type=“dc:Point” x=“1129” y=“352” />
bpmndi:BPMNLabel
<dc:Bounds x=“1028” y=“337” width=“90” height=“0” />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id=“ScriptTask_0lq65uf_di” bpmnElement=“ReportService”>
<dc:Bounds x=“746” y=“312” width=“100” height=“80” />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id=“SequenceFlow_02y7h07_di” bpmnElement=“SequenceFlow_toFileDownload”>
<di:waypoint xsi:type=“dc:Point” x=“846” y=“352” />
<di:waypoint xsi:type=“dc:Point” x=“916” y=“352” />
bpmndi:BPMNLabel
<dc:Bounds x=“881” y=“331” width=“0” height=“12” />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id=“SequenceFlow_1p5licy_di” bpmnElement=“SequenceFlow_1p5licy”>
<di:waypoint xsi:type=“dc:Point” x=“118” y=“352” />
<di:waypoint xsi:type=“dc:Point” x=“746” y=“352” />
bpmndi:BPMNLabel
<dc:Bounds x=“432” y=“331” width=“0” height=“12” />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
Please wrap your above code in code syntax.
Please review this post for learning how to use external js files. https://medium.com/@stephenrussett/deploying-external-scripts-with-camunda-rest-api-e06bd90a2931
ist resolve with byte[] dataBytes = Base64.getDecoder().decode(content.getBytes());
return from rest in Base64
next problem I can not add to form download it it empty Download Report