RMI Remoting

This example is based on the simple object example.

Example Description

  • This example is based on the simple object example.
  • The RMI server project binds the exported service via the RMI-Registry. (see MainServer.java)
  • The RMI client project binds the service via the RMI-Registry for invoking it. (see RmiExampleRegistry.java)

Server Main Program

Java Class : MainServerFactoryApi.java
package application;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Properties;

import javax.sql.DataSource;

import factory.RmiServerRegistry;
import oracle.ucp.jdbc.PoolDataSource;
import oracle.ucp.jdbc.PoolDataSourceFactory;

public class MainServerFactoryApi {
  public static void main(String[] args) {
    try {
      Registry registry = LocateRegistry.createRegistry(1099);

      // call bindServices to register services and set data source
      RmiServerRegistry.bindServices(registry, 1098, getDataSource());
    catch (Exception e) {

  public static DataSource getDataSource() throws Exception {
    // TODO : set your individual connection parameter settings !
    PoolDataSource poolDataSource = PoolDataSourceFactory.getPoolDataSource();
    Properties properties = new Properties();
    return poolDataSource;

Client Setup

Set up the registry. This registry configuration is used by the factory.
Java Class : RmiClientRegistryFactoryApi.java
package factory;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class RmiClientRegistryFactoryApi {
  private static Registry registry;

  public static synchronized Registry getRegistry() throws RemoteException {
    if (registry == null) {
      registry = LocateRegistry.getRegistry();
    return registry;

Calling the Remote Services

Java Class : RmiServerInfoFactoryApi.java
package plsql_workbench_examples;

import factory.ExamplesRPCFactory;
import service.ServerInfoSimpleObjectService;
import transferobject.SimpleObject;

public class RmiServerInfoFactoryApi {
  public static void main(String[] args) {
    try {
      int diff = 10;

      // get the service
      ServerInfoSimpleObjectService service = ExamplesRPCFactory.getServerInfoSimpleObjectService();

      // calling the stored procedure, receiving a transfer object
      SimpleObject info = service.call(diff);

      // print server information
      System.out.println("database date(+" + diff + "):" + info.d);
      System.out.println("database timestamp(-" + diff + "):" + info.ts);
      System.out.println("database instance name:" + info.instance);
      System.out.println("database version:" + info.dbVersion + "." + info.dbRelease);
    catch (Exception e) {