Using different middleware

Same problem, different middleware

The client-half object pattern has been given as a means of abstracting away from particular middleware solutions, so that code not directly involved in networking is not affected by changes of middleware.

In this section, we look at the "simple ftp" problem considered earlier, and give a variety of solutions using different middleware systems

Service specification

We specify the service using a Java interface.

There is a concession to lessons from RMI being adopted by a number of middleware systems: in recognition that network errors can occur in calling remote services, the interface extends Remote and all methods throw RemoteException. This exception should not be visible "on the wire" since it is not a cross-platform solution - for example, .NET remoting has its different equivalent System.Runtime.Remoting.RemotingException However, these exceptions are normally generated in the client HOPP and do not appear on the wire. Web Services don't conform to this and the WSDL lists remote exceptions even though they are not generated on the service side.

Service Implementation

Client view

Client UI

The client UI is independent of the network code. It just needs to know that the client half-object implements the common interface common.FileTransfer. To avoid hard-coding the actual half-object into the UI, a call is made to a factory object.

Factory

A factory object is used to generate specific client half-objects. It uses command line parameters passed from the UI object to determine which half-object to return. All half-objects implement the FileTransfer interface

Sockets

The socket-based solution requires a client half-object and a server talking across an ordinary socket

Socket constants

This just defines strings that are common to both client and server

Socket client

Socket server

Running

To run the server,

java socket.FileTransferServer
To run the client
java client.FileTransferClientUI socket localhost

Web services

Instant deployment using Axis

Steps:


Instant deployment Service HOPP

Client HOPP

There are several ways of building a client HOPP. One way is to generate the WSDL and from there generate a set of client-side classes. This is the technically simpler but more laborious way based on constructing each function call by hand. Note that call.invoke() will throw a RemoteException if an error occurs.

Running

Download Axis from Apache.org. Copy the FileTransferClientHOPP.java to the axis subdirectory with the .jws extension. Start Axis

To run the client, the classpath needs to include the Axis libraries and also the Xerces XML parser library. Then

java -classpath ... client.FileTransferClientUI webservice localhost

CORBA

IDL

The file ftp.idl contains

Generate files by


idlj -fall ftp.idl
See http://java.sun.com/j2se/1.5.0/docs/guide/rmi-iiop/toJavaPortableUG.html

Generated files are

CORBA generates its own interfaces and classes. By specifying the module as corba, it generates the corba.FileTransfer, not common.FileTransfer. It also introduces classes such as FileTransferPOA which have to be used. So introduce a "wrapper" class to translate between CORBA and our implementation.

CORBA Server

CORBA Server HOPP

CORBA Client HOPP

CORBA IDL allows the application-defined exceptions. However, any remote method call can also throw an exception. These exceptions are unchecked, that is, they do not form part of the method signature and do not need to be caught. However, if an unchecked exception is thrown and not caught, then it will terminate the application. So it is better to catch them. They are all subclasses of org.omg.CORBA.SystemException.

Running

A name server needs to run

tnameserv -ORBInitialPort 9876

Then you can run the server

java corba.FileTransferServer \
	  -ORBInitialHost localhost \
	  -ORBInitialPort 9876

The client is

java client.FileTransferClientU corba \
	  -ORBInitialHost localhost \
	  -ORBInitialPort 9876

RMI

RMI client

RMI server

Running

Run an RMI name server

rmiregistry

Run the server


java -classpath classes \
     -Djava.rmi.server.codebase=http://localhost/classes/ \
     -Djava.security.policy=policy.all \
     rmi.FileTransferServer

Run the client


java -classpath classes \
     -Djava.security.policy=policy.all \
     client.FileTransferClientUI \
     rmi \
     localhost

Alternative clients

The HOPP model shows that we can change the middleware without too many problems for a decent middleware system. But we can also change the UI for any given system in the same way!

Here is a GUI based client that uses Swing and exactly the same HOPP objects

Session state


Jan Newmarch <jan@newmarch.name>
Last modified: Tue Sep 19 16:42:24 EST 2006