2016-07-19 11 views
1

可変マップを渡してjbpmからcamelまでのプロセスを開始します。 jbpmでは、変数(ここでは「名前」)の値を変更していますが、変数をラクダに戻すことができません。ここでプロセス変数をjbpmからcamelを使用して取得する方法は?

 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

jbpmのどのバージョンを使用していますか? jbpmはルールフロー実装か適切なbpmですか? –

+0

jbpmバージョン6.2。 jbpmでは、1つのスクリプトタスクを使用して変数値を取得し、それを印刷します。ここで、 "name"は変数で、 "SAntanu"はラクダを通る値です。グローバルではないプロセス・レベル変数です。 @raphaëλ – Santanu

+0

とCamel?のバージョンは2.16+なら、http://camel.apache.org/jbpm.html –

答えて

0

は一例です(コードはScalaであるが、私はあなたのアイデアを得るでしょう確信している)

それは取得するプロセスを開始するcamel-jbpmを使用し、カスタムコード用:コードを以下に示しますプロセス変数(純粋なkie)。

このデモでは、標準camel-jbpmコンポーネントを使用してプロセスを開始しています。値を取得するには、2番目の残りのリクエストが必要です。この執筆時点(2016年7月)には、まだcamel-jbpmコンポーネントではサポートされていません。私はカスタムプロセッサを使用してnameプロセス変数のためにFindVariableInstancesCommandリクエストを送信しています。 私はまた、あなたが思っているかもしれないと、彼らは明らかなようではないかもしれないとして、import文をリストした

私はのjBPMワークベンチから雇用プロセスを使用しています(気づくそれはすべてのKIEです) *

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 
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")) 

} 

を使用)を使用すると、すぐにそれをテストしたい場合は、以下のドッキングウィンドウコンテナ

0を実行します
docker run -Pd -p 8080:8080 -p 8001:8001 --name jbpm-workbench docker.io/jboss/jbpm-workbench-showcase 
+0

ありがとうございました。 @raphaëλ – Santanu

関連する問題