Example: Executing a Transaction Using the OSMW
In this example, the server hosting the OSM for the Web is called shark. The Apache Tomcat application host is serving at port 8080. The servlet that is processing the requests is called osmint. The URL to which the message should be posted is http://shark:8080/workflow/osmint to create a new transaction. This is the CreateProcessInstance (request) message:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE WfMessage SYSTEM "http://shark:8080/workflow/Wf-XML-1_0.dtd"><WfMessage Version="1.0"><WfTransport><CorrelationData>OSMINTTEST _-1830803183 </CorrelationData></WfTransport><WfMessageHeader><Request ResponseRequired="Yes"/><Key>http://shark:8080/workflow/osmint</Key></WfMessageHeader><WfMessageBody><CreateProcessInstance.Request StartImmediately="true"><ObserverKey>http://10.227.1.113:8000/osmintclient</ObserverKey><ContextData><TransactionID>REQ000123</TransactionID><Action>subscribe_initial</Action><TargetObject>uniqueid=paulo,ou=ottawa,retailername=default,o=users,o=umc</ TargetObject></ContextData></CreateProcessInstance.Request></WfMessageBody></WfMessage>The host replies with a CreateProcessInstance (response) message, stating it was able to start a transaction, and returns the ProcessInstanceKey as http://shark:8080/workflow/osmint?procid=REQ000123&target=uniqueid%3Dpaulo%2Cou%3Dottawa%2Cretailername%3Ddefault%2Co%3Dusers%2Co%3Dumc.
<?xml version="1.0" encoding="UTF-8"?><WfMessage Version="1.0"><WfTransport><CorrelationData>OSMINTTEST_-1830803183</CorrelationData></WfTransport><WfMessageHeader><Response/><Key>http://shark:8080/workflow/osmint</Key></WfMessageHeader><WfMessageBody><CreateProcessInstance.Response> <ProcessInstanceKey>http://shark:8080/workflow/osmint?procid=REQ000123& amp;target=uniqueid%3Dpaulo%2Cou%3Dottawa%2Cretailername%3Ddefault%2C o%3Dusers%2Co%3Dumc</ProcessInstanceKey></CreateProcessInstance.Response></WfMessageBody></WfMessage>This completes the transaction preparation cycle. At this point the transaction is created but not yet executing. The target object is backed up, and any changes made to it can be reverted if the transaction aborts. This is point where the object can be safely updated before a workflow is triggered, which is done by the next message. In this example, the target object is left intact.
The message that executes the transaction is the ChangeProcessInstanceState. It changes the state of the process from open.notrunning to open.running.
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE WfMessage SYSTEM "http://shark:8080/workflow/Wf-XML-1_0.dtd"><WfMessage Version="1.0"><WfTransport><CorrelationData>OSMINTTEST_2090215924</CorrelationData></WfTransport><WfMessageHeader><Request ResponseRequired="Yes"/> <Key>http://shark:8080/workflow/osmint?procid=REQ000123&target=uniq ueid%3Dpaulo%2Cou%3Dottawa%2Cretailername%3Ddefault%2Co%3Dusers%2Co %3Dumc</Key></WfMessageHeader><WfMessageBody><ChangeProcessInstanceState.Request><State><open.running/></State></ChangeProcessInstanceState.Request></WfMessageBody></WfMessage>The response to this message acknowledges the state change, which means that the transaction is executing and possibly also a workflow.
<?xml version="1.0" encoding="UTF-8"?><WfMessage Version="1.0"><WfTransport><CorrelationData>OSMINTTEST_2090215924</CorrelationData></WfTransport><WfMessageHeader><Response/> <Key>http://shark:8080/workflow/osmint?procid=REQ000123&target=uniq ueid%3Dpaulo%2Cou%3Dottawa%2Cretailername%3Ddefault%2Co%3Dusers%2Co %3Dumc</Key></WfMessageHeader><WfMessageBody><ChangeProcessInstanceState.Response><State><open.running/></State></ChangeProcessInstanceState.Response></WfMessageBody></WfMessage>The client is now waiting for the transaction completion, which is notified by a ProcessInstanceStateChanged message sent to the Observer URL as specified in the CreateProcessInstance message by the ObserverKey tag. It includes the ProcessInstanceKey, when the process changed its state (LastModified tag), to which state and an optional ResultData, which in this case indicates the transaction was successful.
<?xml version="1.0" encoding="UTF-8"?><WfMessage Version="1.0"><WfTransport><CorrelationData>REPORT_REQ000123</CorrelationData></WfTransport><WfMessageHeader><Request ResponseRequired="Yes"/><Key>http://10.227.1.113:8000/osmintclient</Key></WfMessageHeader><WfMessageBody><ProcessInstanceStateChanged.Request><ProcessInstanceKey>http://shark:8080/workflow/osmint?procid=REQ000123&target=uniqueid%3Dpaulo%2Cou%3Dottawa%2Cretailername%3Ddefault %2Co%3Dusers%2Co%3Dumc</ProcessInstanceKey><State><closed.completed/></State><ResultData><SUCCEEDED/></ResultData><LastModified>2002-06-164 11:45:34EDT</LastModified></ProcessInstanceStateChanged.Request></WfMessageBody></WfMessage>Because the above message requires a response as specified by the ResponseRequired attribute of the Request tag, the client sends this message:
<?xml version="1.0" encoding="UTF-8"?><WfMessage Version="1.0"><WfMessageHeader><Response/><Key>http:// 10.227.1.113:8000/osmintclient</Key></WfMessageHeader><WfMessageBody><ProcessInstanceStateChanged.Response/></WfMessageBody></WfMessage>This completes the transaction execution cycle. The target object is properly updated in the directory to reflect its new state, and the backup copy and the lock in the object are removed, leaving it ready for another transaction.