Exceptions - Java User Exceptions

Description:

The Java server throws a Java user exception within a remotely called method which is caught by the .NET client.

According to the standard (i.e. OMG's IDL-to-Java mapping) a CORBA user exception defined as OMG IDL is mapped to a Java exception derived from org.omg.CORBA.UserException. Java RMI user exceptions (derived from java.rmi.RemoteException), however, are mapped to an IDL valuetype (according to the OMG Java-to-IDL mapping).

To use the standard CORBA exception propagation mechanism these valuetypes have to be wrapped into a (generated) standard IDL exception with a derived name ending with 'Ex', e.g.:

          MyUserException  --> exception MyUserEx        (containing a MyUserException)
          MyUserProblem    --> exception MyUserProblemEx (containing a MyUserProblem)            
          MyUserEx         --> exception MyUserExEx      (containing a MyUserEx)

J-Integra® Espresso extends this mechanism to all Java user exceptions. Being a regular valuetype, though, the user exception requires an implentation on the client side.

The mechanism for propagating user exceptions from Java to .NET is essentially transferring an object by value (see also the Objects by value example.)

Source:

\DemoJava\Exceptions

Mapping:

java.lang.Exception <---> Ics.CORBA.UserException


Example

Step 1. Write the Java server:

  public class MyUserException extends java.lang.Exception   
  {
    public int iId;
    public MyUserException( int i)
    {
      super();
      iId = i;
    }
    public MyUserException()
    {
      super();
      iId = 0;
    }
  }

Step 2. Write the .NET client:

Exception Implementation: MyUserExceptionImpl.cs

  public class MyUserExceptionImpl: Exceptions.MyUserException  
  {
    public MyUserExceptionImpl()
    {
    }
    public MyUserExceptionImpl( int a_iValue)
    {
      this.iId = a_iValue;
    }
  }       

Retrieve the exception (main.cs):

  try
  {
    string strRet = oGreetings.hello( "Ics");
    ...
  }
  catch (Exceptions.MyUserEx ex)
  {
    Exceptions.MyUserException oMyUserException = (Exceptions.MyUserException)ex.value;  
    System.Console.WriteLine("ID:{0}", oMyUserException.iId);
    System.Console.WriteLine("Stacktrace:\n{0}", oMyUserException);
  }

Step 3. Run the example

a.) Start the sun name service on port 10050:

    > start orbd -ORBInitialPort 10050  

(could also use startNameService.bat located in the DemoJava directory to quick start the name service)

b.) Start the java server by using JNDI CosNaming and work with a name service running on 'localhost' at port '10050':

    > start java -cp .;Server.jar -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory -Djava.naming.provider.url=iiop://localhost:10050 Server  

(could also use buildServer.bat and startServer.bat located in the JavaServer directory to quick build and run the Java Server)

c.) Start the .NET Client.