この章の内容は次のとおりです。
Javaクライアント・アプリケーションを作成して、ヒューマン・ワークフロー・サービスをコールする場合、JRFがJavaクライアント・アプリケーションと同じ環境で実行されている必要があります。次に、簡単なワークリスト・アプリケーションを作成する際の典型的なコール順序を示します。
簡単なワークリスト・アプリケーションを作成する手順は、次のとおりです。
IWorklistServiceClientへのハンドルをWorkflowServiceClientFactoryから取得します。ITaskQueryServiceへのハンドルをIWorklistServiceClientから取得します。ITaskQueryServiceの認証メソッドに渡して、ユーザーを認証します。IWorkflowContextへのハンドルを取得します。ITaskQueryServiceを使用してタスク・リストを問い合せます。ITaskServiceへのハンドルをIWorklistServiceClientから取得します。ITaskServiceを使用してタスクに対するアクションを実行します。次のコード・サンプルは、ワークフロー・サービスのクライアントの作成方法を示しています。jsteinに割り当てられている全タスクのリストに対して問合せが実行されます。結果が設定されていないタスクが承認されます。
try
{
//Create JAVA WorflowServiceClient
IWorkflowServiceClient wfSvcClient = WorkflowServiceClientFactory.getWorkflowServiceClient(
WorkflowServiceClientFactory.REMOTE_CLIENT);
//Get the task query service
ITaskQueryService querySvc = wfSvcClient.getTaskQueryService();
//Login as jstein
IWorkflowContext ctx = querySvc.authenticate("jstein","welcome1".toCharArry(),null);
//Set up list of columns to query
List queryColumns = new ArrayList();
queryColumns.add("TASKID");
queryColumns.add("TASKNUMBER");
queryColumns.add("TITLE");
queryColumns.add("OUTCOME");
//Query a list of tasks assigned to jstein
List tasks = querySvc.queryTasks(ctx,
queryColumns,
null, //Do not query additional info
ITaskQueryService.AssignmentFilter.MY,
null, //No keywords
null, //No custom predicate
null, //No special ordering
0, //Do not page the query result
0);
//Get the task service
ITaskService taskSvc = wfSvcClient.getTaskService();
//Loop over the tasks, outputting task information, and approving any
//tasks whose outcome has not been set...
for(int i = 0 ; i < tasks.size() ; i ++)
{
Task task = (Task)tasks.get(i);
int taskNumber = task.getSystemAttributes().getTaskNumber();
String title = task.getTitle();
String taskId = task.getSystemAttributes().getTaskId();
String outcome = task.getSystemAttributes().getOutcome();
if(outcome == null)
{
outcome = "APPROVE";
taskSvc.updateTaskOutcome(ctx,taskId,outcome);
}
System.out.println("Task #"+taskNumber+" ("+title+") is "+outcome);
}
}
catch (Exception e)
{
//Handle any exceptions raised here...
System.out.println("Caught workflow exception: "+e.getMessage());
}
クライアントの作成には、次のパッケージとクラスを使用します。
oracle.bpel.services.workflow.metadata.config.model
このパッケージ内の各クラスには、タスク定義ファイル内のワークフロー構成用のオブジェクト・モデルが含まれています。オブジェクトの作成には、ObjectFactoryクラスを使用できます。
oracle.bpel.services.workflow.metadata.routingslip.model
このパッケージ内の各クラスには、ルーティング・スリップ用のオブジェクト・モデルが含まれています。オブジェクトの作成には、ObjectFactoryクラスを使用できます。
oracle.bpel.services.workflow.metadata.taskdisplay.model
このパッケージ内の各クラスには、タスク表示用のオブジェクト・モデルが含まれています。オブジェクトの作成には、ObjectFactoryクラスを使用できます。
oracle.bpel.services.workflow.metadata.taskdefinition.model
このパッケージ内の各クラスには、タスク定義ファイル用のオブジェクト・モデルが含まれています。オブジェクトの作成には、ObjectFactoryクラスを使用できます。
oracle.bpel.services.workflow.client.IWorkflowServiceClient
ワークフロー・サービス・クライアントのインタフェースです。
oracle.bpel.services.workflow.client.WorkflowServiceClientFactory
ワークフロー・サービス・クライアントを作成するためのファクトリです。
oracle.bpel.services.workflow.metadata.ITaskMetadataService
タスク・メタデータ・サービスのインタフェースです。
oracle.bpel.services.workflow.task.ITaskService
タスク・サービスのインタフェースです。
oracle.bpel.services.workflow.task.IRoutingSlipCallback
タスク処理中にコールバックを受信するコールバック・クラスのインタフェースです。
oracle.bpel.services.workflow.task.IAssignmentService
割当てサービスのインタフェースです。
ワークリスト・アプリケーションは、ワークフロー・サービス・クライアントを介して様々なワークフロー・サービスにアクセスします。ワークフロー・サービス・クライアントのコードは、様々なローカル・プロトコルとリモート・プロトコルを使用したワークフロー・サービスとの通信に必要なロジックをすべてカプセル化します。ワークリスト・アプリケーションにワークフロー・サービス・クライアントのインスタンスがある場合は、クライアントとワークフロー・サービスとの通信方法を考慮する必要はありません。
クライアントを使用するメリットは、次のとおりです。
SOAP/HTTPやEnterprise JavaBeansなどの基礎となる接続メカニズムの複雑さが軽減されます。
使用する起動メカニズムの変更(SOAP/HTTPからリモートEnterprise JavaBeansへの変更など)が容易になります。
IWorkflowServiceClientインタフェースのインスタンス作成には、次のクラスが使用されます。
oracle.bpel.services.workflow.client.WorkflowServiceClientFactory
WorkflowServiceClientFactoryには、ワークフロー・クライアントを作成する複数のメソッドがあります。getWorkflowServiceClientは最も単純なメソッドで、パラメータとしてクライアント・タイプのみをとります。クライアント・タイプは次のいずれかです。
WorkflowServiceClientFactory.REMOTE_CLIENT: クライアントはリモートEnterprise JavaBeansインタフェースを使用してリモートのワークフロー・サービスを起動します。
WorkflowServiceClientFactory.SOAP_CLIENT: クライアントはSOAPを使用して、リモートのワークフロー・サービスへのWebサービス・インタフェースを起動します。
他のファクトリ・メソッドを使用すると、接続プロパティを直接指定し(ファクトリで接続プロパティをwf_client_config.xml fileからロードする必要はありません)、クライアント・アクティビティを記録するロガーを指定できます。
このリリースには、ワークフロー・サービス・クライアントの次の拡張機能が含まれています。
次の例1および2に示すように、ワークフロー・クライアント構成は、JAXBオブジェクトまたはマップのいずれかを使用して指定できます。
例1
WorkflowServicesClientConfigurationType wscct = new WorkflowServicesClientConfigurationType();
List<ServerType> servers = wscct.getServer();
ServerType server = new ServerType();
server.setDefault(true);
server.setName(serverName);
servers.add(server);
RemoteClientType rct = new RemoteClientType();
rct.setServerURL("t3://stapj73:7001");
rct.setUserName("weblogic");
rct.setPassword("weblogic"));
rct.setInitialContextFactory("weblogic.jndi.WLInitialContextFactory");
rct.setParticipateInClientTransaction(false);
server.setRemoteClient(rct);
IWorkflowServiceClient wfSvcClient = WorkflowServiceClientFactory.getWorkflowServiceClient(
WorkflowServiceClientFactory.REMOTE_CLIENT, wscct, logger);
例2
Map<IWorkflowServiceClientConstants.CONNECTION_PROPERTY,java.lang.String> properties = new HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY,java.lang.String>(); properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.MODE, IWorkflowServiceClientConstants.MODE_DYNAMIC); properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.SOAP_END_POINT_ROOT, "http://localhost:8888"); IWorkflowServiceClient client = WorkflowServiceClientFactory.getWorkflowServiceClient(WorkflowServiceClientFactory.SOAP_CLIENT, properties, null);
クライアントでは、クライアントがメッセージを記録するjava.util.logging.Loggerを必要に応じて渡すことができます。ロガーが指定されていない場合、ワークフロー・サービスのクライアント・コードは何も記録しません。次のコード・サンプルは、ロガーをワークフロー・サービス・クライアントに渡す方法を示しています。
java.util.logging.Logger logger = ....; IWorkflowServiceClient client = WorkflowServiceClientFactory.getWorkflowServiceClient(WorkflowServiceClientFactory.REMOTE_CLIENT, properties, logger);
すべてのワークフロー・サービスのクライアント・ライブラリは、ファクトリを介して取得できます。表34-1で、各サービスに使用可能なクライアントを確認してください。
BPMIdentityServiceおよびBPMIdentityConfigServiceのインスタンスは、WorkflowServiceClientFactoryでgetSOAPIdentityServiceClientメソッドおよびgetSOAPIdentityConfigServiceClientメソッドをコールして取得できます。その他のすべてのサービスは、IWorkflowServiceClientのインスタンスを介して取得できます。
クライアント・クラスは、サービスのエンドポイントにwf_client_config.xml構成ファイルを使用します。クライアントのクラスパスでは、このファイルはクラスパス直下にあります。つまり、このファイルが格納されているディレクトリはクラスパス内にあります。wf_client_config.xmlファイルには、次の内容が含まれています。
次のコード・サンプルに示すリモート・クライアント用のセクション:
<remoteClient>
<serverURL>t3://hostname.domain_name:7001</serverURL>
<userName>weblogic</userName>
<password>weblogic</password>
<initialContextFactory>weblogic.jndi.WLInitialContextFactory
</initialContextFactory>
<participateInClientTransaction>false</participateInClientTransaction>
</remoteClient>
次のコード・サンプルに示す各サービスのSOAPエンドポイント用のセクション:
<soapClient>
<rootEndPointURL>http://hostname.domain_name:7001</rootEndPointURL>
<identityPropagation mode="dynamic" type="saml">
<policy-references>
<policy-reference enabled="true" category="security"
uri="oracle/wss10_saml_token_client_policy"/>
</policy-references>
</identityPropagation>
</soapClient>
ワークフロー・クライアント構成のXMLスキーマ定義は、wf_client_config.xsdファイルに格納されています。
IWorkflowServiceClientインタフェースは、各種ワークフロー・サービス・インタフェースへのハンドルを取得できるように、表33-1に示すメソッドを提供します。
表33-1 IWorkflowServiceClientのメソッド
| メソッド | インタフェース |
|---|---|
getTaskService |
oracle.bpel.services.workflow.task.ITaskService |
getTaskQueryService |
oracle.bpel.services.workflow.query.ITaskQueryService |
getTaskReportService |
oracle.bpel.services.workflow.report.ITaskReportService |
getTaskMetadataService |
oracle.bpel.services.workflow.metadata.ITaskMetadataService |
getUserMetadataService |
oracle.bpel.services.workflow.user.IUserMetadataService |
getRuntimeConfigService |
oracle.bpel.services.workflow.runtimeconfig.IRuntimeConfigService |
getTaskEvidenceService |
oracle.bpel.services.workflow.metadata.ITaskMetadataService |
SOAPクライアントのクラスパスには、次のJARファイルが必要です。
$SOA_HOME/soa/modules/oracle.bpm.client_11.1.1/
oracle.bpm.bpm-services.client.jar
oracle.bpm.bpm-services.interface.jar
oracle.bpm.client.jar
oracle.bpm.web-resources.jar
$SOA_HOME/soa/modules/oracle.bpm.project_11.1.1/
oracle.bpm.project.catalog.jar
oracle.bpm.project.draw.jar
oracle.bpm.project.jar
oracle.bpm.project.model.jar
$SOA_HOME/soa/modules/oracle.bpm.runtime_11.1.1/
oracle.bpm.bpm-services.implementation.jar
oracle.bpm.bpm-services.internal.jar
oracle.bpm.core.jar
oracle.bpm.lib.jar
oracle.bpm.metadata.jar
oracle.bpm.metadata-interface.jar
oracle.bpm.papi.jar
oracle.bpm.xml.jar
$SOA_HOME/soa/modules/oracle.soa.fabric_11.1.1/
fabric-runtime.jar
bpm-infra.jar
$SOA_HOME/soa/modules/oracle.soa.workflow_11.1.1/
bpm-services.jar
bpm-workflow-datacontrol.jar
$SOA_HOME/soa/modules/
soa-startup.jar
$MW_HOME/oracle_common/modules/oracle.webservices_11.1.1/
wsclient.jar
$MW_HOME/oracle_common/modules/oracle.jrf_11.1.1/
jrf-api.jar
$MW_HOME/wlserver_10.3/server/lib/
wlthint3client.jar
${bea.home}/wlserver/server/lib/
wlfullclient.jar
$ORACLE_HOME/soa/plugins/jdeveloper/external/
oracle.external.soa.jrf-wsclient-extended.jar
${bea.home}/oracle_common/module/clients/
com.oracle.webservices.wls.jaxws-owsm-client_12.1.3.jar
wlfullclient.jarファイルは、次のコード・サンプルに示すコマンドを使用して生成できます。
cd ${bea.home}/wlserver/server/lib
java -jar ../../../modules/com.bea.core.jarbuilder_2.2.0.0.jar
注意:
クライアント・アプリケーションは、クラスパス内のsystem\services\configまたはsystem\services\schemaディレクトリを使用しません。
リモートEJBを使用するクライアントのクラスパスには、次のJARファイルが必要です。
wlfullclient.jar
oracle.external.soa.jrf-wsclient-extended.jar
wlclient.jar
xmlparserv2.jar
xml.jar
bpm-infra.jar
bpm-services.jar
fabric-runtime.jar
注意:
クライアント・アプリケーションは、クラスパス内のsystem\services\configまたはsystem\services\schemaディレクトリを使用しません。
タスクはプログラムによって開始できます。その場合は、次のタスク属性を設定する必要があります。
taskDefinitionId
title
payload
priority
次のタスク属性はオプションですが、通常はクライアントによって設定されます。
creator
ownerUser: 空の場合はbpeladminにデフォルト設定されます。
processInfo
identificationKey: タスクは、TaskQueryServiceからの識別キーに基づいて問い合せることができます。
タスクのオブジェクト・モデルは、次のパッケージで使用できます。
oracle.bpel.services.workflow.task.model
このモデル内でオブジェクトを作成するには、ObjectFactoryクラスを使用します。
タスク・ペイロードには、複数のペイロード・メッセージ属性を含めることができます。ペイロードはタスクが定義されるまで詳細に定義されないため、タスクのJavaオブジェクト・モデルには、クライアント・ペイロード用の強い型指定のオブジェクトが含まれません。タスク・ペイロードはAnyType Javaオブジェクトで表されます。AnyType Javaオブジェクトは、ネームスペース内のpayloadをルートとして持つXML要素を使用して作成されます。
http://xmlns.oracle.com/bpel/workflow/task
ペイロードのXML要素には、他のすべてのXML要素が含まれます。各XML要素では、メッセージ属性を定義します。
次のコード・サンプルは、タスク・ペイロードの設定方法を示しています。
import oracle.bpel.services.workflow.task.model.AnyType;
import oracle.bpel.services.workflow.task.model.ObjectFactory;
import oracle.bpel.services.workflow.task.model.Task;
..........
Document document = //createXMLDocument
Element payloadElem = document.createElementNS("http://xmlns.oracle.com/bpel/workflow/
task", "payload");
Element orderElem = document.createElementNS("http://xmlns.oracle.com/pcbpel/test/order", "order");
Element child = document.createElementNS("http://xmlns.oracle.com/pcbpel/test/order", "id");
child.appendChild(document.createTextNode("1234567"));
orderElem.appendChild(child);
payloadElem.appendChild(orderElem);
document.appendChild(payloadElem);
task.setPayloadAsElement(payloadElem);
注意:
AnyType.getContent()要素は、変更不可のXML要素リストを返します。このリストには他のメッセージ属性を追加できません。
次のコード・サンプルは、休暇申請タスクをプログラムによって開始する方法を示しています。
// create task object
ObjectFactory objectFactory = new ObjectFactory();
Task task = objectFactory.createTask();
// set title
task.setTitle("Vacation request for jcooper");
// set creator
task.setCreator("jcooper");
// set taskDefinitionId. taskDefinitionId is the target
// namespace of the task
// If namespace is used, the active version of the composite corresponding
// to that of the namespace will be used.
task.setTaskDefinitionId("http://xmlns.oracle.com/VacationRequest/
Project1/Humantask1"); (Your task definition ID will be different.)
// create and set payload
Document document = XMLUtil.createDocument();
Element payloadElem = document.createElementNS(TASK_NS, "payload");
Element vacationRequestElem = document.createElementNS(VACATION_REQUEST_NS,
"VacationRequestProcessRequest");
Element creatorChild = document.createElementNS(VACATION_REQUEST_NS, "creator");
creatorChild.appendChild(document.createTextNode("jcooper"));
vacationRequestElem.appendChild(creatorChild);
Element fromDateChild = document.createElementNS(VACATION_REQUEST_NS, "fromDate");
fromDateChild.appendChild(document.createTextNode("2006-08-05T12:00:00"));
vacationRequestElem.appendChild(fromDateChild);
Element toDateChild = document.createElementNS(VACATION_REQUEST_NS, "toDate");
toDateChild.appendChild(document.createTextNode("2006-08-08T12:00:00"));
vacationRequestElem.appendChild(toDateChild);
Element reasonChild = document.createElementNS(VACATION_REQUEST_NS, "reason");
reasonChild.appendChild(document.createTextNode("Hunting"));
vacationRequestElem.appendChild(reasonChild);
payloadElem.appendChild(vacationRequestElem);
document.appendChild(payloadElem);
task.setPayloadAsElement(payloadElem);
IWorkflowServiceClient workflowServiceClient =
WorkflowServiceClientFactory.getWorkflowServiceClient
(WorkflowServiceClientFactory.SOAP_CLIENT);
ITaskService taskService = workflowServiceClient.getTaskService();
IInitiateTaskResponse iInitiateTaskResponse = taskService.initiateTask(task);
Task retTask = iInitiateTaskResponse.getTask();
System.out.println("Initiated: " + retTask.getSystemAttributes().getTaskNumber() + " - " +
retTask.getSystemAttributes().getTaskId());
return retTask;
ワークリスト・アプリケーションおよびUserMetadataService APIは、標準ビューの作成、更新および削除に使用できるメソッドを提供します。詳細は、「ユーザー・メタデータ・サービス」を参照してください。