I’m writing a groovy builder to generate simple bpmn processes. My builder class provides a method ‘exportAsInputStream’, which takes the formatted process and generates an InputStream from the toString() internally. the generated xml from builder looks like this
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="hardcodedname" id="def_1"
targetNamespace="com.softwood"
xmlns="http://www.omg.org.spec/BPMN/20100524/MODEL"
xmlns:flowable="http://flowable.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:di="http://www.omg.org/spec/20100524/DI"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
typeLanguage="http://www.w3.org/2001/XMLSchema">
<!-- Structures and Messages -->
<import importType="http://www.w3.org/2001/XMLSchema" location="DataDefinitions.xsd" namespace="http://www.example.org/Messages"/>
<import importType="http://schemas.xmlsoap.org/wsdl/" location="Interfaces.wsdl" namespace="http://www.example.org/Messages"/>
<!-- process definition -->
<process id="p_1" name="builderScriptProcess">
<startEvent id="e_1" name="startProc" />
<sequenceFlow id="f_2" name="transition" sourceRef="e_1" targetRef="e-2" />
<endEvent id="e_2" name="endproc" />
</process>
</definitions>
i then created a test to try and deploy the content
@Test
void GroovyBPMBuilderSimpleTest() {
BpmnProcessBuilder bpmn = new BpmnProcessBuilder()
bpmn.process("builderScriptProcess", id:"p_1") {
start("startProc", id:"e_1")
flow ('transition', source:"e_1", target:"e-2")
end ("endproc", id: "e_2")
}
DeploymentBuilder depBldr = repositoryService.createDeployment()
depBldr.name"named deployment"
//resourcename is name of process, stream is actual defn
InputStream ins = bpmn.exportAsInputStream()
depBldr.addInputStream("builderScriptProcess", ins)
//depBldr.addClasspathResource("com/softwood/spring/junit4/BpmnBuilderSimpleTest.bpmn20.xml")
Deployment myDeployment = depBldr.deploy()
assert myDeployment.id == "1"
as you can see ive got the ‘addInputStream’ method in this and the ‘addClasspathResource’ commented out
when i look at these in the debugger they are very different. I get a deployment (id=1), but the deployment.deployedArtifacts field is null, and i cant query for a process
If i re run the test and comment out loading from stream, and load a file classPathResource, I do get deployedArtifacts and i can query the process.
All the examples i can find all seem to use the addClasspathResource method and not an input stream.
i had a peek at the master source tree for v6.2 which has following. where addClasspathResource reflects for file and then passes to addInputStream. The only difference is that my resourceName attribute parameter is a ‘made-up name’ as i have no real file - just a string exposed as an InputStream as the second parameter.
@Override
public DeploymentBuilder addInputStream(String resourceName, InputStream inputStream) {
if (inputStream == null) {
throw new ActivitiIllegalArgumentException("inputStream for resource '" + resourceName + "' is null");
}
byte[] bytes = IoUtil.readInputStream(inputStream, resourceName);
ResourceEntity resource = new ResourceEntity();
resource.setName(resourceName);
resource.setBytes(bytes);
deployment.addResource(resource);
return this;
}
@Override
public DeploymentBuilder addClasspathResource(String resource) {
InputStream inputStream = ReflectUtil.getResourceAsStream(resource);
if (inputStream == null) {
throw new ActivitiIllegalArgumentException("resource '" + resource + "' not found");
}
return addInputStream(resource, inputStream);
}
so why does a real file work - where my generated xml string exposed as InputStream does not.
Perplexed and stuck at the moment. Appreciate if anyone can get me over my hurdle
my project in dev on github is here https://github.com/woodmawa/flowable