8.4.3 Creating Instances

To invoke the method of the synchronous reception (SessionBean), use the acquired stub to create an Enterprise Bean instance. The procedure for creating an Enterprise Bean instance is described below.

  1. Create a JNDI naming context to be used for retrieving an EJB home object reference.
    Example:

    javax.naming.Context ctx = new javax.naming.InitialContext();

  2. Using the created JNDI naming context, acquire an EJB home object reference.
    To acquire an EJB home object reference, use a user-specified name space or an EJB container name space for retrieval. For details about retrieving and acquiring an EJB home object reference, see the manual Cosminexus Application Server Function Guide - Basic Development for EJB Container.
    Example:

    Object objref
        = initial.lookup("HITACHI_EJB/SERVERS/" + "J2EE server-name"
          + "/EJB/CSCMsgSyncServiceDelivery/CSCMsgSyncServiceDeliveryEJB");

    CSCMsgSyncServiceDeliveryHome home
        = (CSCMsgSyncServiceDeliveryHome)PortableRemoteObject
           .narrow(objref, CSCMsgSyncServiceDeliveryHome.class);

  3. Use the create method of the EJB home object to create an Enterprise Bean instance. Using the created Enterprise Bean instance, invoke the method (Enterprise bean method) of the synchronous reception (SessionBean).
    Example: When the request message is in XML

    CSCMsgSyncServiceDelivery reception = home.create();
         // Enterprise Bean instance creation
    String result = reception .invokeXML(    // method invocation
                  serviceName,              // service name
                  clientID,                 // client correlation ID
                  requestFormatID,          // request format ID
                  responseFormatID,         // response format ID
                  operationName,            // operation name
                  userData);                // user message

    Example: When the request message is binary

    CSCMsgSyncServiceDelivery reception = home.create();
         // Enterprise Bean instance creation
    byte[] resultBinary = reception .invokeBinary(  // method invocation
                  serviceName,                 // service name
                  clientID,                    // client correlation ID
                  requestFormatID,             // request format ID
                  responseFormatID,            // response format ID
                  operationName,               // operation name
                  userDataBinary.length,       // message length
                  userDataBinary);             // user message

    Note
    A binary request message can be sent only when the message format used on the service component side is binary.