Sample Interceptor Example
This directory contains the sample interceptor example. The sample
interceptor example adds basic tracing to the Bank example through the interceptor API. The code from the
simple Bank example discussed earlier has not been modified, illustrating how the code for the interceptors can easily be added to existing applications.
This example illustrates how to:
-
Implement a simple ClientInterceptor, ServerInterceptor, and BindInterceptor
-
Implement factories for the ClientInterceptor and ServerInterceptor.
-
Add interceptor factories (or interceptors themselves) to the ORB's chaining
interceptor
Directory Contents
-
Init.java
Sample code for standard initialization for a interceptor package.
It shows how to install interceptors and interceptor factories.
-
SampleInterceptor.java
Super class for all the interceptors in this sample. It has some common code shared
by the sample interceptors.
-
SampleClientInterceptor.java
A sample client interceptor, which intercepts communication at client side.
-
SampleClientInterceptorFactory.java
A sample client interceptor factory, which creates client interceptors.
-
SampleServerInterceptor.java
A sample server intereptor, which intercepts communication at server side.
-
SampleInterceptorFactory.java
A sample server interceptor factory, which creates server interceptors.
-
SampleBindInterceptor.java
A sample bind interceptor, which intercepts bind process.
-
Bank.idl
IDL interface for the 'Bank' object.
-
Server.java
Server. Creates an instance of the Bank and calls org.omg.CORBA.BOA.impl_is_ready() to make this object available to client programs. The Bank Server implementation implements two methods: open(), which opens a bank account, and balance(), which returns the balance in a person's account whose name is provided as input. A random number is generated and returned as the balance.
-
Client.java
This is the bank client. It binds to an AccountManager object and invokes open() to open a bank account. It then invokes the balance() on the account object reference obtained to query the balance.
Building this example
cd .. to the interceptor directory (one level above) and type make all (vbmake on Windows) in the interceptor directory and not the current directory.
Compilation Errors and Warnings
You may see the following kind of compilation errors when you compile this example from the interceptor directory using either JDK1.0.2 or JDK1.1.1:
prompt>javac sample/Init.java
./sample/SampleBindInterceptor.java:5: Package
com.visigenic.vbroker.interceptor not found in import.
import com.visigenic.vbroker.interceptor.*;
^
The above error occurs because the javac compiler in JDK1.0.2 and JDK1.1.1 cannot locate packages imported from JAR files. The solution to this problem is to either:
- Unjar the vbj30.jar file found in the VisiBroker for Java 3.0 installation/lib directory using the following command:
prompt>jar xvf vbj30.jar
- Modify the example: delete the import statment and explicitly prefix each oc
currence of classes from the imported package with the complete package name.
- Upgrade to JDK1.1.2 or higher
Running the sample interceptor example
To run the example, read the instructions at the interceptor directory. You will have to switch your current working to the directory to the interceptor directory before running the sample interceptor example.
Here is the sample output from the server
Installing Sample Interceptors
BindINT: bind
BindINT: exception_occurred
AccountManager object is ready.
ServINT: locate
ServINT: locate_forwarded
ServINT: receive_request
ServINT: prepare_reply
ServINT: send_reply
ServINT: request_completed
ServINT: shutdown
Here is the sample output from the client
Installing Sample Interceptors
BindINT: bind
BindINT: bind_succeeded
ClntINT: prepare_request
ClntINT: send_request
ClntINT: send_request_succeeded
ClntINT: receive_reply
The balance in Jack B. Quick's account is $6.27.
Return to the Interceptor Examples Page.