2016-07-19 18 views
1

Ich beginne einen Prozess in jbpm durch Kamel, indem ich die variable Karte übergebe. In jbpm ändere ich den Wert dieser Variablen (hier "Name") und ich bin nicht in der Lage, die Variable zurück zu Kamel zu bekommen. Es folgt der Code:Wie bekomme ich die Prozessvariable von jbpm mit Kamel zurück?

 final Map map = new HashMap(); 
     JBPMConfiguration bPMConfiguration = new JBPMConfiguration(); 
     bPMConfiguration.setUserName("admin"); 
     bPMConfiguration.setPassword("***"); 
     bPMConfiguration.setProcessId("HelloWorld.helloworldBusinessProcess"); 
     bPMConfiguration.setDeploymentId("SAN:HelloWorld:1.0"); 

     bPMConfiguration.setConnectionURL(new URL("http://127.0.0.1:8080/kie-wb62")); 
     JBPMEndpoint bPMEndpoint = new JBPMEndpoint("jbpm:http", new JBPMComponent(), bPMConfiguration); 
     JBPMProducer bPMProducer=(JBPMProducer) bPMEndpoint.createProducer(); 
     if (bPMProducer instanceof JBPMProducer) { 
     Exchange exchange = ((JBPMProducer) bPMProducer).createExchange(); 
      map.put("name", "SAntanu"); 
      bPMConfiguration.setParameters(map); 
      exchange.setPattern(ExchangePattern.OutIn); 
      exchange.getOut().setHeader("CamelJBPMParameters",map); 
      bPMProducer.start(); 
      bPMProducer.process(exchange); 

      } 
+0

Welche Version von jbpm verwenden Sie? Ist die jbpm eine Ruleflow-Implementierung oder eine ordnungsgemäße BPM? –

+0

jbpm Version 6.2. In jbpm mit einer Skriptaufgabe, um den Variablenwert zu erhalten und auszudrucken. Hier ist "Name" die Variable und "SAntanu" ist der Wert, der durch das Kamel geht. Es ist eine Variable auf Prozessebene, die nicht global ist. @ raphaëλ – Santanu

+0

und welche Version von Camel ?, wenn 2.16+ könnten Sie einfach http://camel.apache.org/jbpm.html verwenden –

Antwort

0

Hier ist ein Beispiel (Code ist in scala, aber ich bin sicher, dass Sie auf die Idee kommen)

Es nutzt camel-jbpm den Prozess zu starten und für benutzerdefinierten Code zu erhalten eine Prozessvariable (rein kie).

In dieser Demo verwende ich die Standard camel-jbpm Komponente, um den Prozess zu starten. Um Werte zu erhalten, benötigen Sie eine zweite Ruheanforderung. Zum Zeitpunkt des Schreibens (Juli 2016) wurde dies noch nicht von der Komponente camel-jbpm unterstützt. Ich verwende einen benutzerdefinierten Prozessor, um die FindVariableInstancesCommand Anfrage für die name Prozessvariable zu senden. Ich habe aufgelistet auch die Import-Anweisungen, da sie nicht so offensichtlich sein könnten, wie Sie vielleicht gedacht haben (es zu bemerken ist alles kie)

ich den Einstellung Prozess von jbpm-Werkbank bin mit *

package demo.http 

import java.net.URL 

import org.apache.camel.Exchange 
import org.apache.camel.component.jbpm.JBPMConstants 
import org.apache.camel.scala.dsl.builder.RouteBuilder 
import org.kie.api.runtime.manager.RuntimeEngine 
import org.kie.api.runtime.process.ProcessInstance 
import org.kie.remote.client.api.RemoteRuntimeEngineFactory 
import org.kie.remote.jaxb.gen.FindVariableInstancesCommand 
import org.kie.services.client.serialization.jaxb.impl.audit.JaxbVariableInstanceLog 

import scala.collection.JavaConverters._ 

/** 
    * todo 
    */ 
class JBpmnRoute extends RouteBuilder { 

    "direct:jbpmRoute" ==> { 
     // set the process id 
     setHeader(JBPMConstants.PROCESS_ID, constant("hiring")) 

     // in this example: copy map from in.body to header[JBPMConstants.PARAMETERS] 
     process((e: Exchange) => { 
     e.getIn().setHeader(JBPMConstants.PARAMETERS, e.in[Map[String, AnyRef]].asJava) 
     }) 

     // Start the process 
     to("jbpm:http://localhost:8080/jbpm-console?userName=admin&password=admin" 
     + "&deploymentId=org.jbpm:HR:1.0&operation=startProcess") 

     // obtain process variable (in this example "name") 
     process((e: Exchange) => { 
     val rte: RuntimeEngine = RemoteRuntimeEngineFactory.newRestBuilder() 
      .addUrl(new URL("http://localhost:8080/jbpm-console/")).addUserName("admin").addPassword("admin") 
      .addDeploymentId("org.jbpm:HR:1.0").build() 

     val cmd: FindVariableInstancesCommand = new FindVariableInstancesCommand() 
     cmd.setProcessInstanceId(e.in[ProcessInstance].getId) 
     cmd.setVariableId("name") 
     val result = rte.getKieSession.execute(cmd).asInstanceOf[java.util.List[AnyRef]].asScala 
     e.in = result.head.asInstanceOf[JaxbVariableInstanceLog].getValue 
     }) 
     log("value of name ${body}") 
    } 

} 

test~~POS=TRUNC verwendet

@Test 
def exampleTest(): Unit = { 
    val param: Map[String, AnyRef] = Map("name" -> "Mike Wheeler") 
    val response = template.requestBody("direct:jbpmRoute", 
    param, classOf[String]) 
    org.junit.Assert.assertThat(response, Is.is("Mike Wheeler")) 

} 

*) Wenn Sie es schnell testen möchten, führen Sie den folgenden docker Behälter

docker run -Pd -p 8080:8080 -p 8001:8001 --name jbpm-workbench docker.io/jboss/jbpm-workbench-showcase 
+0

Vielen Dank. @ Raphaëλ – Santanu