|
Overview
The Net Caboodle mobile gateway allows
you to connect your mobile clients to your existing business
systems. In this article we look at how to write a simple
mobile booking client that using transactions.
To use the example booking system source/binary
distribution we are going to
- Install the sample Seat Reservation
(RMI) service
- Use the Net Caboodle plugin
to create a new MIDP project
- Use the Net Caboodle stub generator
to create the mobile stubs
- Write a simple MIDlet that
uses transactions
Create a new MIDP project
The next step is to create a new MIDP
project for the mobile client application -- please refer
to the NetBeans
or Eclipse plugin's
documentation for information about creating new projects.
Having created a new project the first
thing to do is to add the following JAR file to the project's
classpath
transactionmanager.jar
Generating the mobile stubs
Before the Net Caboodle plugins can generate the mobile
stubs you must first start the Net Caboodle gateway.
- Eclipse plugin
Right-click on your MIDP project and select "Start Gateway" from
the "Caboodle" Menu.
- NetBeans plugin
Use the "Tools->Net Caboodle Gateway->Start Gateway" option.
Once the gateway is up and running we can generate the
mobile stubs and then get on to the fun stuff -- writing the mobile client application.
- Eclipse plugin
Right-click on your MIDP project and select "New RMI
connector" from the "Caboodle" Menu.
- NetBeans plugin
Use the "Tools->Net Caboodle Business 2 Mobile->New
Connector " option and then select the "RMI Connector"
tab.
Next enter the default gateway
port of 6060 and the lookup name
example.SeatReservationImpl
Click the "Connect" button
and then select the interface name
example.SeatReservation
Finally click the OK button and the
Net Caboodle plugin will generate the mobile stubs.
- Eclipse plugin
Net Caboodle will have added the mobile stubs JAR to your project.
- NetBeans plugin
You will be prompted where you want to save the generated stubs JAR file to.
Save the JAR and then add it to your project.
The stub generator will have created classes that map
directly to those used by the connector bean, plus an additional factory class
that allows the mobile client to obtain a 'shadow' proxy to the connector bean.
In the supplied example code these are
- com.nc.txn.Transaction
- example.SeatReservationFactory
- example.SeatReservation
We should now be ready to implement the mobile client
code.
Writing the mobile transaction client
Here's the basic code to create and
use transactions with the generated stubs and the MIDP transaction
pack.
//MIDP transaction pack
import com.nc.txn.TransactionManager;
import com.nc.txn.TransactionManagerFactory;
//Example booking service imports
import example.SeatReservation;
import example.SeatReservationFactory;
//get the transaction manager proxy
TransactionManager txnMgr = TransactionManagerFactory.getService();
//create a five minute lease length for the Transaction
long lease=60*1000*5;
Transaction txn==txnMgr.create( lease );
//get the SeatReservation proxy
SeatReservation service=SeatReservationFactory.getService();
//register the transaction with the SeatReservation service
service.newTransaction(txn);
//perform some UI code and then reserve the selected seat
service.reserve(txn,seatID);
//finally having prompted the user, commit the transaction
txnMgr.commit(txn);
As you can see writing the mobile client
looks virtually identical to the type of code you would use
in your business services to access the Transaction Manager
and other services.
Watching the interactions occur
When the above code is executed you
will be out from both the Transaction Manager and Seat Reservation
service appear in the Net Caboodle console, as shown below.
13-Jul-2005 09:43:07 com.nc.txn.SimpleTransactionConnector create
INFO: Transaction created ID=1121244140766
Reserving seat 12b Txn ID=1121244140766
13-Jul-2005 09:43:07 com.nc.txn.SimpleTransactionConnector commit
INFO: Transaction commiting number of participants=1
prepare
Commit
Example MIDlet
The screenshots below show the example MIDlet you can
download along with the above resources to help you get started
You will see the following output in the Net Caboodle
console after the "Buy" button has been selected

Summary
In this article we have shown how to
use the Net Caboodle Transaction Manager and how to pass transactions
between a mobile client and a business service.
The mobile stubs generated by the Net Caboodle plugin
remove the need to write any of your own code for a mobile business application
to communicate with existing business services.
All communication between the mobile stubs and the Net
Caboodle Gateway are encrypted.
By using the Net Caboodle gateway
authentication it is possible to stop any mobile client accessing business
service with having first b een authenticated by the gateway.
Downloads
Support and Feedback
If you have any questions relating to this article please
contact us
|