Top
NetCOBOL V11.0 NetCOBOL Studio User's Guide
FUJITSU Software

11.2.2 Developing CORBA Server Applications

This section explains how to develop CORBA server applications.

Contents of Program Created

In this tutorial, you will create the following type of program:

Binary program

This program performs arithmetic operations with two parameters.

Developing procedure

This section explains how to develop CORBA server applications.

1. Starting the Interstage basis service

2. Creating a CORBA Server Project

3. Editing Programs

4. Building the Project

5. Running the Program

1. Starting the Interstage basis service

Before creating CORBA applications, it is necessary to start the J2EE execution environment service . Because the J2EE execution environment service is not started by default, use the Interstage basis service operation tool to start the service. Refer to "Checking the environment settings of Interstage Application Server".

2. Creating a CORBA Server Project

  1. Start the Interstage Studio Workbench.

  2. If the COBOL perspective is not displayed, then follow the procedure below to display it:

    1. Select "Window" > "Open Perspective" > "Other" from the menu bar. The "Open Perspective" dialog box is displayed.

    2. Select "COBOL", then click the "OK" button.

  3. Select "File" > "New" > "CORBA Server Project" from the workbench - a new CORBA Server project is displayed.

  4. Enter the project name and the save folder.

    Setting item

    Setting value

    Project name

    CALCSV

    Contents

    Select "Create new project in workspace"

    Click the "Next" button.

  5. You can specify the target information on this screen. Proceed without specifying any changes here.

    Click the "Next" button.

  6. You can specify the target information on this screen. Proceed without specifying any changes here.

    Click the "Next" button.

  7. You can select the option "Generate code". Make sure that "CORBA server application" is selected as the code generation wizard, and click the "Finish" button

    The "New CORBA Server Application Skeleton Code wizard" is started after the project is created.

  8. On this screen, specify the following settings. Click the "Next" button.

    Setting item

    Setting value

    Module name

    SAMPLE(any)

    Class name

    CALCSV(project name, fixed)

    Generate exceptions(*1)

    Check

    Generate default code (*2)

    Check

    Generate comments (*3)

    Check

    *1: For multiplication and division exception, check "Generate exceptions". If it is checked, the following exception declaration is generated in IDL.

    exception CDException{
        string CDExceptionMsg;
        long CDExceptionCode;
    };

    *2: If "Generate default code" is checked, a definition of a method to be implemented as a server application and the code for that method is generated. Otherwise, only a method declaration is generated.

    *3: If "Generate default code" is checked, a definition of a method to be implemented as a server application and the code for that method is generated. Otherwise, only a method declaration is generated. If "Generate comments" is checked, a comment is generated in the template source created.

  9. On this second screen, you can declare constants. In this tutorial, define two constants in such a way that exceptions are generated and error messages are thrown. Click the "Next" button.

    • Constant1

      Setting item

      Setting value

      Type

      string

      Constant name

      MSG1

      Initial value

      "item1 is zero"

    • Constant2

      Setting item

      Setting value

      Type

      string

      Constant name

      MSG2

      Initial value

      "item2 is zero"

  10. On this screen make a type declaration. Here, you can define repetition items, but no such definition is required in this tutorial.

    Proceed without making any changes on this screen. Click the "Next" button.

  11. Here, you can declare a structure. This sample program requires two input areas from a client and one area for results of operation. Declare these areas as one structure.

    On this screen, click the" Add" button to display the Structure Definition dialog, and declare the structure in this dialog.

  12. Here, declare the structure "S1", which consists of the following members.

    Variable name

    Type

    Usage

    item1

    long

    Item used for a binary operation (its value is specified by a client)

    item2

    long

    Item used for a binary operation (its value is specified by a client)

    result

    long

    Result of a binary operation (its value is set by the server)

    Click the "OK" button, "S1" is displayed on the "Structure Declaration" page.

    Click the "Next" button.

  13. Next, declare business methods. Here, declare the addop, subop, mltop, and divop methods described in "Contents of Program Created".

    On this screen, click the "Add" button to display the "User Method Definition" dialog, and declare the methods in this dialog.

  14. The addop method settings are specified in the dialog as shown below.

    The following are specified.

    • addop method

      Setting item

      Setting value

      Method name

      addop

      Return type

      none(void)

      Throws an exception

      Uncheck

      Parameters

      Variable Name : param1
      Type : S1 (*1)
      Parameter Ttype : inout (*2)

    • subop method

      Setting item

      Setting value

      Method name

      subop

      Return type

      none(void)

      Throws an exception

      Uncheck

      Parameters

      Variable Name : param1
      Type : S1
      Parameter Ttype : inout

    • mltop method

      Setting item

      Setting value

      Method name

      mltop

      Return type

      none(void)

      Throws an exception

      Check(*3)

      Parameters

      Variable Name : param1
      Type : S1
      Parameter Ttype : inout

    • divop method

      Setting item

      Setting value

      Method name

      divop

      Return type

      none(void)

      Throws an exception

      Check (*3)

      Parameters

      Variable Name : param1
      Type : S1
      Parameter Ttype : inout

    (*1) "S1" is the structure name declared in the structure definition.
    (*2) Specify "inout" as the parameter type for the "S1" structure as values are set by both server and client applications.
    (*3) Enable "Throws an exception" for multiplication and division methods.

  15. Click the "Finish" button. When "Finish" button is clicked, template sources are created in the source file folder. In this tutorial, the following files are generated.

    File name

    Description

    CALCSV.cob

    Main source program (server application framework)

    SAMPLE-CALCSV-IMPL.cob

    Business method program

    SAMPLE-CALCSV--INIT.cob

    Server application registration program

    USCALCSV.idl

    Interface file (IDL file)

    COBOL source file beginning with "SAMPLE"

    Skeleton file created by IDL compiler

3. Editing Programs

IDL file (USCALCSV.idl)
// Module declaration
module SAMPLE { 

  // Constant declaration
  const string MSG1 = "item1 is zero" ;
  const string MSG2 = "item2 is zero" ;

  // Type declaration
  
  // Structure declaration
  struct S1 {
    long item1;
    long item2;
    long result;
  };

  // Exception declaration
  exception CDException{
    string CDExceptionMsg;
    long CDExceptionCode;
  };
  // User interface declaration
  interface CALCSV { 
    void addop(inout S1 param1);
    void subop(inout S1 param1);
    void mltop(inout S1 param1)
      raises (CDException);
    void divop(inout S1 param1)
      raises (CDException);
  };

};

You can edit the IDL file as per requirement, but no such editing is required in this tutorial.

* If interface information is modified, be sure to also modify the business method program source so that they are consistent with each other.

Main source program (CALCSV.cob)
000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. CALCSV.
000030 ENVIRONMENT DIVISION.
000040 CONFIGURATION SECTION.
000050 REPOSITORY.
000060      COPY CORBA--REP.
000070      COPY USCALCSV--REP.
000080 .
000090 SPECIAL-NAMES.
000100      SYMBOLIC CONSTANT
000110      COPY CORBA--CONST.
000120  .
000130 DATA DIVISION.
000140 WORKING-STORAGE SECTION.
000150 COPY CORBA--COPY.
000160 COPY USCALCSV--COPY.
000170 01  API-NAME        PIC   X(50).
000180 01  APL-NAME        PIC   X(64)   VALUE     "CALCSV".
000190 01  ORB             USAGE OBJECT REFERENCE CORBA-ORB.
000200 01  BOA             USAGE OBJECT REFERENCE CORBA-BOA.
000210 01  IMPL-REP        USAGE OBJECT REFERENCE FJ-IMPLEMENTATIONREP.
000220 01  IMPL            USAGE OBJECT REFERENCE CORBA-IMPLEMENTATIONDEF.
000230 01  REP-ID          PIC   X(128) VALUE     "IDL:SAMPLE/CALCSV:1.0".(*1)
000240 01  OBJ             USAGE OBJECT REFERENCE CORBA-OBJECT.
000250 01  EXCEPT-ID       USAGE OBJECT REFERENCE CORBA-STRING.
000260 01  EXCEPT-ID-VALUE PIC   X(50).
000270 LINKAGE SECTION.
000280 PROCEDURE DIVISION
000290                   .
000300* 
000310*  ORB initialization
000320* 
000330      INVOKE CORBA "ORB_INIT" USING APL-NAME FJ-OM_ORBID RETURNING ORB.
000340* 
000350*  BOA initialization
000360* 
000370      INVOKE ORB "BOA_INIT" USING APL-NAME CORBA-BOA_OAID RETURNING BOA.
000380* 
000390*  Obtain the implementation object repository.
000400* 
000410      INVOKE ORB "RESOLVE_INITIAL_REFERENCES" USING
000411                    CORBA-OBJECTID_IMPLEMENTAT-001 RETURNING OBJ.
000420      INVOKE FJ-IMPLEMENTATIONREP "NARROW" USING OBJ RETURNING IMPL-REP.
000430* 
000440*  Obtain implementation information.
000450* 
000460      INVOKE IMPL-REP "LOOKUP_ID" USING REP-ID RETURNING OBJ.
000470      INVOKE CORBA-IMPLEMENTATIONDEF "NARROW" USING OBJ RETURNING IMPL.
000480* 
000490      SET OBJ TO NULL.
000500* 
000510*  Notify the OD of server activation.
000520* 
000530      MOVE "CORBA::BOA::IMPL_IS_READY" TO API-NAME.
000540      INVOKE BOA "IMPL_IS_READY" USING IMPL.
000550* 
000560      STOP RUN.
000570 END PROGRAM CALCSV. 

(*1) Repository ID
Each CORBA server application is determined by a unique repository ID. The default ID is "IDL:module-name/interface-name:1.0". For details, refer to the Interstage Application Server manuals.

Server application registration program (SAMPLE-CALCSV--INIT.cob)

This program registers the server application so that it can be used as a CORBA server. No modification is required.

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. SAMPLE-CALCSV--INIT.
000030 ENVIRONMENT DIVISION.
000040 CONFIGURATION SECTION.
000050 REPOSITORY.
000060      CLASS SAMPLE-CALCSV
000070      CLASS SAMPLE-CALCSV-IMPL
000080 .
000090 DATA DIVISION.
000100 WORKING-STORAGE SECTION.
000110 LINKAGE SECTION.
000120 01 RET USAGE OBJECT REFERENCE SAMPLE-CALCSV.
000130 PROCEDURE DIVISION
000140         RETURNING RET
000150                   .
000160      INVOKE SAMPLE-CALCSV-impl "new" RETURNING RET.
000170      EXIT PROGRAM.
000180 END PROGRAM SAMPLE-CALCSV--INIT.
Implementing business methods (SAMPLE-CALCSV-IMPL.cob)

The addop, subop, mltop, and divop methods entered in the wizard are declared. Implement their processes.

Add the statements shown in blue.

000010 CLASS-ID. SAMPLE-CALCSV-IMPL AS "SAMPLE-CALCSV-IMPL" INHERITS 
000020     SAMPLE-CALCSV
000030   .
000040 ENVIRONMENT DIVISION.
000050 CONFIGURATION SECTION.
000060 REPOSITORY.
000070      COPY CORBA--REP.
000080      COPY USCALCSV--REP.
000090 .
000100 SPECIAL-NAMES.
000110      SYMBOLIC CONSTANT
000120      COPY CORBA--CONST.
000121      COPY USCALCSV--CONST.
000130  .
000140 OBJECT.
000150 DATA DIVISION.
000160 WORKING-STORAGE SECTION.
000170 COPY CORBA--COPY.
000180 COPY USCALCSV--COPY.
000190 PROCEDURE DIVISION
000200                   .
000210 METHOD-ID. ADDOP AS "ADDOP" OVERRIDE.
000220* <IDL-INFO-START>
000230* void addop(inout S1 param1)
000240* <IDL-INFO-END>
000250 DATA DIVISION.
000260 WORKING-STORAGE SECTION.
000270 LINKAGE SECTION.
000280 01 PARAM1  TYPE SAMPLE-S1.
000290 PROCEDURE DIVISION
000300         USING 
000310                   PARAM1
000320                   .
000321      COMPUTE result OF param1 = item1 OF param1 + item2 OF param1.
000330 END METHOD ADDOP. 000340 METHOD-ID. SUBOP AS "SUBOP" OVERRIDE. 000350* <IDL-INFO-START> 000360* void subop(inout S1 param1) 000370* <IDL-INFO-END> 000380 DATA DIVISION. 000390 WORKING-STORAGE SECTION. 000400 LINKAGE SECTION. 000410 01 PARAM1 TYPE SAMPLE-S1. 000420 PROCEDURE DIVISION 000430 USING 000440 PARAM1 000450 . 000451 COMPUTE result OF param1 = item1 OF param1 - item2 OF param1. 000460 END METHOD SUBOP. 000470 METHOD-ID. MLTOP AS "MLTOP" OVERRIDE. 000480* <IDL-INFO-START> 000490* void mltop(inout S1 param1) 000500* <IDL-INFO-END> 000510 DATA DIVISION. 000520 WORKING-STORAGE SECTION. 000521 01 W-EXCEPTION OBJECT REFERENCE SAMPLE-CDException.
000522 01 W-STRING OBJECT REFERENCE CORBA-STRING.
000530 LINKAGE SECTION. 000540 01 PARAM1 TYPE SAMPLE-S1. 000550 PROCEDURE DIVISION 000560 USING 000570 PARAM1 000580 RAISING 000590 SAMPLE-CDEXCEPTION 000600 . 000601* Exception processing
000602 IF item1 OF param1 = 0
000603 THEN
000604 INVOKE SAMPLE-CDException "NEW" RETURNING W-EXCEPTION
000605 MOVE -1 TO CDEXCEPTIONCODE OF W-EXCEPTION
000606 INVOKE CORBA-STRING "NEW" RETURNING W-STRING
000607 INVOKE W-STRING "SET-VALUE" USING SAMPLE-MSG1
000608 SET CDEXCEPTIONMSG OF W-EXCEPTION TO W-STRING
000609 EXIT METHOD RAISING W-EXCEPTION
000610 END-IF
000611 IF item2 OF param1 = 0
000612 THEN
000613 INVOKE SAMPLE-CDException "NEW" RETURNING W-EXCEPTION
000614 MOVE -1 TO CDEXCEPTIONCODE OF W-EXCEPTION
000615 INVOKE CORBA-STRING "NEW" RETURNING W-STRING
000616 INVOKE W-STRING "SET-VALUE" USING SAMPLE-MSG2
000617 SET CDEXCEPTIONMSG OF W-EXCEPTION TO W-STRING
000618 EXIT METHOD RAISING W-EXCEPTION
000619 END-IF
000620 COMPUTE result OF param1 = item1 OF param1 * item2 OF param1.
000621 000622 END METHOD MLTOP. 000623 METHOD-ID. DIVOP AS "DIVOP" OVERRIDE. 000630* <IDL-INFO-START> 000640* void divop(inout S1 param1) 000650* <IDL-INFO-END> 000660 DATA DIVISION. 000670 WORKING-STORAGE SECTION. 000671 01 W-EXCEPTION OBJECT REFERENCE SAMPLE-CDException.
000672 01 W-STRING OBJECT REFERENCE CORBA-STRING.
000680 LINKAGE SECTION. 000690 01 PARAM1 TYPE SAMPLE-S1. 000700 PROCEDURE DIVISION 000710 USING 000720 PARAM1 000730 RAISING 000740 SAMPLE-CDEXCEPTION 000750 . 000751* Exception processing
000752 IF item1 OF param1 = 0
000753 THEN
000754 INVOKE SAMPLE-CDException "NEW" RETURNING W-EXCEPTION
000755 MOVE -1 TO CDEXCEPTIONCODE OF W-EXCEPTION
000756 INVOKE CORBA-STRING "NEW" RETURNING W-STRING
000757 INVOKE W-STRING "SET-VALUE" USING SAMPLE-MSG1
000758 SET CDEXCEPTIONMSG OF W-EXCEPTION TO W-STRING
000759 EXIT METHOD RAISING W-EXCEPTION
000760 END-IF
000761 IF item2 OF param1 = 0
000762 THEN
000763 INVOKE SAMPLE-CDException "NEW" RETURNING W-EXCEPTION
000764 MOVE -1 TO CDEXCEPTIONCODE OF W-EXCEPTION
000765 INVOKE CORBA-STRING "NEW" RETURNING W-STRING
000766 INVOKE W-STRING "SET-VALUE" USING SAMPLE-MSG2
000767 SET CDEXCEPTIONMSG OF W-EXCEPTION TO W-STRING
000768 EXIT METHOD RAISING W-EXCEPTION
000769 END-IF
000770 COMPUTE result OF param1 = item1 OF param1 / item2 OF param1.
000771 000772 END METHOD DIVOP. 000773 END OBJECT. 000780 END CLASS SAMPLE-CALCSV-IMPL.

Point

  • The "S1" structure is fixed in length and hence, is accompanied by a TYPE declaration.

  • Elements of the "S1" structure are defined as group items and therefore can be used as group items.

  • To report an exception, generate (new) an exception class instance, and specify a value in the member.

4. Building the Project

Select "Save" from the context menu of the edit window in USCALCSV.cob and the CORBA server application is built automatically.
However, if "Project" > "Build Automatically" was not previously selected (the "Build Automatically" menu item will have a check if it was selected), the application is not built.

Select the CORBA server project in the Dependency View or Structure View, and select "Project" > "Project Build" from the menu bar to build the CORBA server project.

5. Running the Program

The CORBA server application runs on a WorkUnit. This section explains the general procedure for verifying the operation of CORBA server application.

Point

Note on MyCORBADebug

In the initial state, a WorkUnit named MyCORBADebug is created for debugging. This created MyCORBADebug can be used as the deployment destination for functional tests. For details, see "11.5.1.4.3 Creating the CORBA work Unit".

  1. Copying runtime resources
    Copy the execution file and dynamic link library to the runtime environment, both of which have been generated during building.
    In this tutorial, copy the following files to the following destination:

    File: CALCSV.exe, USCALCSV.dll
    Copy destination folder: C:\Interstage\APS\var\CORBA_WU\MyCORBADebug

    The files can be copied to any folder. In this tutorial, however, they are copied to the default application folder of the WorkUnit to be created.

  2. Making of application operation current directory

    Create the application operation current directory that is needed because of the start of the work unit.
    Because the default value is used in this tutorial when the work unit is made, it is necessary to prepare the following directories.

    C:\Interstage\APS\var\CORBA_WU\MyCORBADebug\work
  3. Deploying the CORBA server application

    Click right button on IJServer view, select "Interstage Management Console". When it is not connected to the Interstage Application Server, select "Connect/Login" from the context menu of the Interstage Application Server, connect or log on to the Interstage Application Server and then select "Interstage Management Console". Select the deployment destination WorkUnit from the left tree of the Management Console, and select the "Deploy" tab in the right side of the window.

    Specify an implementation repository ID and executable program file name.

    Specify the implementation repository ID in the following format:

    IDL:module-name/interface-name:1.0

    For the executable program file name, specify the name of the EXE file that was copied.

    Click "Show" of the Show Details, then click "Show" of the CORBA application. The Detailed Settings window is displayed. Select "SYNC_END" from the "Operation Mode".

    Click "Show" of the Interface. Click the "Add Interface" button, and specify the interface repository ID, naming service registration name, and library name as shown below.

    Click the "Add" button, then click the "Deploy" button to execute deployment.

  4. Starting the WorkUnit

    If "Restart WorkUnit after deployment" was not selected as the initial setting during deployment, start the created WorkUnit as follows.

    Select the WorkUnit from the tree in the view on the left side of the Interstage Management Console, and click the "Status" tab in the right side of the window. Then, click the "Start" button.

    During the startup sequence, if there is no application operation current directory, an error occurs. You can check the application operation current directory by clicking the "Settings" tab of the WorkUnit.

  5. Running a client application

    Run a client application that accesses the CORBA server application.

    For details on how to create and run a client application, refer to "11.2.3 Developing CORBA Client Applications".