Booking service

J2ME, JSP

Small booking service application using J2ME and JSP.

Before start this project I was using J2ME for a while but just for client mobile applications. I wanted to create some project combining together mobile applications and server side services so I got the opportunity to make this job for a project during my studies in Vitus Bering University College.

The result was the cachondo booking service (Cachondo means funny in spanish). I was the responsible of the major IT part and another friends took the marketing and business management part, which I'm not going to explain here.

The idea behind this project was to allow a user to access to the services provided by different companies. It was focus on leisure so mainly this kind of services include buy a ticket for a concert or cinema, book places in a restaurant, check special offers and featured parties in the clubs, etc.

The architecture is simple, a main server processing both inputs, from providers and from users. The communication between users and the server was made using custom xml messages managed by a servlet. In the other hand the providers access to their custom services page using simple website.

The server uses Tomcat to run the two servelts the project needed:

  • servlet_service: Building the website that will be show to the providers.
  • servlet_server: Communication with mobile phone.

Providers server-side

Once that the user has been validated, he can administrate the menus, offers or reservations.

Even if we can use the same template for each service option, we could also implement custom templates for each service and/or provider. Here we can see the available menus that users could choose from the mobile:

The provider could see as well the reservations from the clients, checking if they ask for some special service, and confirming the booking date.

Database

The database design is divided into two parts, one is the common for all the kind of services, and another one include the custom tables for each kind of service.

Mobile

The mobile uses custom messages in XML using the following syntax:

Mobile to Server

<cachondo version="1">
<message type="login">
<data login="userlogin" password="1234"/>
</message>
</cachondo>

Server to Mobile

<cachondo version="1">
<message type="login">
<data verified="true" user_id="1"/>
</message>
</cachondo>

These messages are generated and parsed using kXML, a small and simple xml library available for use in j2me.

State diagram

The following image shows the state diagram for a basic restaurant service:

Midlet connection

Maybe the most insteresting thing in the code was to create the asynchronous connection between the servlet and the midlet, instead of normal connection that freeze the mobile phone waiting for answer. Instead of that classic connection we create a thread and throw it in the connection section and when why finish the connection we close it. The following graph shows the normal workflow of our forms.

The login function is called in the main thread of the midlet, and it throws a thread that will entablish the connection needed for login.

private void login()
{
Thread t = new Thread()
{
public void run()
{
loginConnect();
}
};
t.start();
}

private boolean loginConnect()
{
HttpConnection hc = null;
InputStream is = null;
OutputStream os=null;

String url= URL.baseURL+"mobileserver";
try
{
hc = (HttpConnection)Connector.open(url);
hc.setRequestMethod(HttpConnection.POST);
hc.setRequestProperty("User-Agent","Profile/MIDP-2.0");
hc.setRequestProperty("Content-Language","es-ES");

// We send the petition
os = hc.openOutputStream();

// Send the XML petition for login
sendValidateRequest(os);

// Get the answer in XML form the server
midlet.login(userValidateResponse(hc));

hc.close();
}
catch (Exception ioe)
{
System.out.println(ioe.toString());
}
return true;
}