A WS-BA Business Activity is a coordination context with relaxed constraints compared to WS-AT Atomic Transaction. The most important differences are:
When a web service client invites a business partner into a WS-Coordination transaction, they send them a WS-Coordination coordination context object that includes the address of the coordination service, the transaction's identifier and other data the coordination service requires.
The web service provider needs to allow a WS-Coordination Coordination Context object to be included with the business request:
<wsdl:definitions
xmlns:wscoor="http://schemas.xmlsoap.org/ws/2004/10/wscoor"
...
>
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="applicationRequest">
<!-- This element needs to be added -->
<xsd:element ref="wscoor:CoordinationContext" />
<!-- All other application elements need not be modified -->
<xsd:element name="flightNo" type="..." .../>
...
</xsd:element>
</xsd:schema>
</wsdl:definitions>
<!-- The rest of the definitions also need not be modified -->
</wsdl:types>
A WS-BA enabled web service needs to do only two things:
Apache Kandula provides two classes for registering participants with a coordination context:
this.tellCompleted()
when done.
Your participant implementation needs to extend one of those classes and implement the abstract methods. Thats it!
The following sections document what your implementation of kandula's abstract methods is required to do.
This method is only applicable for the Coordination Completion participant. When it is invoked, the
coordinator tells you to actually perform the requested work.
Return ParticipantCompleteResult.COMPLETED
when you were able to complete your work as requested, or
ParticipantCompleteResult.HANDLED_BY_APPLICATION
if you like not to report something back at the
moment. You need to call one of the tell...()
methods to send your response to the coordinator at any
time you wish.
When the coordinator sends Cancel, it asks you to cancel all outstanding work. If you were able
to successfully abort and cancel everything, return ParticipantCancelResult.CANCELED
. After the coordinator
acknowledges the receipt of Canceled, the participant is no longer needed.
If the service is unable to cancel, it should have reported Completed before.
After having reported Completed, either from onComplete
or by having invoked
tellCompleted()
, the business partner decided to go for it. Perform whatever it takes
to finalize your work and return ParticipantCloseResult.CLOSED
when done.
Please note that the service may not report any fault at this stage! You must successfully complete!
After having reported Completed, either from onComplete
or by having invoked
tellCompleted()
, the business partner decided to throw away your work. Perform whatever it takes
to compensate previous actions and return ParticipantCompensateResult.COMPENSATED
when done.
If compensation is not possible, you need to return ParticipantCompensateResult.FAULTED
and humans must investigate the issue. This should almost never happen.
To try out the samples provided with Kandula-1, you need the following prerequisites:
The WS-BA examples require you to have two Tomcat Servers running, one acting as the coordination service and one as the participants. The initiator will run independently as JUnit test cases or a Swing application.
Build Kandula as usual with "maven". Build the BusinessActivity-Testsuite and the Holiday example by running "ant" in the "samples/holiday" or "samples/ba-testsuite" directories.
Copy the jar-files from the respective "build" directories into the axis/lib folders of your Axis installation.
If you run Kandula from an IDE such as eclipse, you can typically manage multiple configurations there. The Eclipse Web Tools Projects, for example, offers to set different "base" directories with different axis installations.
The easiest way to have two Tomcat instances running is to copy the whole "Tomcat"-directory. This tutorial will refer to the "Coordination Server" and to the "Participant Server".
First, we configure the Coordination Server. It does not require the two JAR files from holiday and
ba-testsuite. Copy the "src/conf/server-only-config_with_WSBA.wsdd" to the axis/WEB-INF folder and
rename it to "server-config.wsdd". If the file already exists, replace it with that one.
Next, copy the kandula.properties and the client-config.wsdd files from src/conf/ to the
axis/WEB-INF/classes directory.
Now we have to make sure the correct ports are configured. Open the Tomcat/conf/server.xml file with
your favorite text editor, scan for the
<Connector ...>
line and make sure the port is set to 8280. If you don't want to use the TCP Monitor (which you only do
if you know what this is), set it to 8281.
Next, open the copy of the kandula.properties and make sure the following entries are set:
kandula.localService=http://localhost:8281/axis/services/The kandula.localService property shall point to the endpoint the coordination services are running, and be fully qualified. It is used to generate the endpoint addresses that is sent to the peers. The kandula.preferredCoordinationService property tells Kandula at which coordination service it shall create new coordination contexts; at the coordinator, this should point to itself.
kandula.preferredCoordinationService=http://localhost:8281/axis/services/
The Coordination Server is now ready!
Start it up by invoking the Tomcat/bin/startup script and verify that the Axis List Services page
shows the "coordinator", "kandula_BA_PC_coordinator" and some more services named like that.
Second, we configure the Participant Service. This server requires the Kandula, ba-testsuite and holiday
jar files in its axis/web-inf/lib directory. Copy the "server-participant-only-with-test-config_with_WSBA.wsdd"
from the src/conf directory to the axis/WEB-INF folder and
rename it to "server-config.wsdd". If the file already exists, replace it with that one.
Next, copy the kandula.properties and the client-config.wsdd files from src/conf/ to the
axis/WEB-INF/classes directory.
Now we have to make sure the correct ports are configured. Open the Tomcat/conf/server.xml file with
your favorite text editor, scan for the
<Connector ...>
line and make sure the port is set to 8180. If you don't want to use the TCP Monitor (which you only do
if you know what this is), set it to 8181.
Next, open the copy of the kandula.properties and make sure the following entries are set:
kandula.localService=http://localhost:8181/axis/services/The kandula.localService property shall point to the endpoint the participant services are running, and be fully qualified. It is used to generate the endpoint addresses that is sent to the peers. The kandula.preferredCoordinationService property tells Kandula at which coordination service it shall create new coordination contexts.
kandula.preferredCoordinationService=http://localhost:8281/axis/services/
The Participant Server is now ready!
Start it up by invoking the Tomcat/bin/startup script and verify that the Axis List Services page
shows the "participant", "kandula_BA_PC_participant" and some more services named like that.
Start up now the TCP Port Monitor, if you chose to use it.
After having started both servers, the port monitor if configured and verifying everything is OK, start the holiday demo by issuing "ant run" in the holiday folder.
The holiday example consists of two rental providers that offer cars and rooms for rent. When starting up the client, you must first chose whether you'd like atomic or mixed outcome.
Select "car" or "room" from the dropdown and hit the "Search for offers" button. The client now fetches offers from the remote web service on the participant web server. You may search for multiple different offers, also cars and rooms mixed. Choose some of the offers from the list, and hit the "add selected offer to basket" button to put the offer into the basket. The client now contacts the remote web service again, but this time provides the CoordinationContext to enrol a participant. The Rental Web Service immediatly enroles for the transaction.
To check the state of the business activity, switch to the "basket" tab and hit the "refresh basket" button. Depending on mixed or atomic outcome, the available buttons at the bottom change. With mixed outcome, select one or more participants from the basket and hit the "complete", "close", etc. buttons to send the corresponding messages to the participants. Refresh will always refresh the participant list. If you press buttons to send messages that are not applicable in the current state of the context or participant, there is no error message but the command is silently ignored.