9.4.2 Procedure for creating an application for ORB clients other than TPBroker V5
The following figure shows a method whereby EJBs of an EJB application (Cosminexus) are invoked via CORBA communication from an ORB client other than TPBroker V5 (CORBA client compliant with CORBA 2.1; TMS-4V/SP Object Access; or TPBroker V3).
|
With this method, only the following data types and data definitions can be used in IDL:
long, unsigned long, string, sequence<octet>, struct
- Organization of this subsection
(1) Interface design procedure
The communication interface on the Application Server side must be defined as a remote interface of EJB. The communication interface on the ORB client must be defined as an IDL definition of CORBA.
The following shows an overview of the procedure for designing the remote interface and IDL definition:
-
Create the IDL definition on which the interface will be based.
-
Create a remote interface of EJB according to the IDL definition.
-
Correct the order of the structure members in the IDL definition based on the information output by the ctmjava2idl command.
-
Change the IDL definitions for the string, sequence<octet>, and struct members.
The following describes each step of the preceding procedure.
(a) Creating an IDL definition on which the interface will be based
Note the following when creating an IDL definition on which the interface will be based:
-
The out and inout arguments cannot be used. Use a return value as the data to be returned. If multiple pieces of data must be returned, put them into a struct.
-
Do not use user exceptions.
-
For struct, you can use only the long, unsigned long, string, and sequence<octet> members.
-
Do not use #pragma.
(b) Creating a remote interface
After you have created a base IDL definition, create a remote interface of EJB based on the IDL definition.
At this time, make sure that the corresponding members between the IDL definition and remote interface have the same names.
Note that modules in IDL correspond to packages in Java.
The following table shows the mapping of supported data types.
Data Type |
IDL |
Remote interface |
---|---|---|
Integer |
long |
int |
unsigned long#1 |
||
String |
string#3 |
byte[]#2 |
Binary |
sequence<octet>#3 |
byte[] |
Structure |
struct |
class (Serializable implemented) |
- #1
-
Java does not provide a data type that corresponds to unsigned. Therefore, unsigned long in IDL is handled as long.
- #2
-
String in Java corresponds to Wstring in IDL. Therefore, in the remote interface, use byte[] instead of String.
- #3
-
In IDL, maximum lengths can be set for string and sequence<octet>. In Java, however, values of those types are handled as variable-length data.
Coding example in IDL:
struct AAA { long longData; string<4> strData; unsigned long ulongData; sequence<octet> octseqData; };
Coding example in the remote interface:
public class AAA implements java.io.Serializable { public int longData; public byte[] strData; public int ulongData; public byte[] octSeqData; };
(c) Correcting the order of structure members in IDL based on the information output by the ctmjava2idl command
To enable CORBA communication with EJB, the members of struct in IDL must be sorted according to the specifications of Serializable in Java. Use the ctmjava2idl command to check the correct order of the members of struct in IDL.
The ctmjava2idl command converts a remote interface of EJB into an IDL definition.
- The following shows an example procedure in a case where the AAA structure shown in the example for Table 9-9 is used:
-
-
Compile AAA.java, which is the Java source program for AAA.
% javac AAA.java
-
Using the generated class file (AAA.class) as the input, execute the ctmjava2idl command:
% ctmjava2idl AAA.class
-
Correct the base IDL definition by referring to the IDL definition that has been output to the standard output.
The following figure shows an example of changing the order of structure members in IDL based on the information output by the ctmjava2idl command.
Figure 9‒5: Example of changing the order of structure members in IDL based on the information output by the ctmjava2idl command - Reference note
-
The rules on the order of struct members are as follows:
The order of members is determined based on the data type and member name in the remote interface.
-
Members of type int come before members of type byte[].
-
Members of type int are sorted by name in character code order.
-
Members of type byte[] are sorted by name in character code order.
-
Sort the members of type int and the members type byte[] separately based on the order of struct members in the IDL definition output by the ctmjava2idl command.
-
-
(d) Changing the IDL definitions of string, sequence<octet>, and struct
In EJB invocation from an ORB client, the data of types string, sequence<octet>, and struct cannot be directly handled. The data of these types must be changed to structures in a specific format. The data of types long and unsigned long can be directly handled.
- Format of send data on the ORB client side:
-
The format of the data to be sent from the ORB client to EJB must be changed to the following format.
Note that the following is an example applicable to the in arguments StringValue, OctSeqValue, and AAARequest of the invoke method in Figure 9-6 Conversion example of an IDL definition for EJB.
struct user-defined-structure-name { long VALUE_TAG; string REPOSITORY_ID; data-body; }
For the string and sequence<octet> members of struct, do not use the preceding structure. Instead, prefix the following structure to each data item.
Note that the following is an example applicable to the tag1 and tag2 members of AAARequest in Figure 9-6 Conversion example of an IDL definition for EJB.
struct ValueTag { long VALUE_TAG; string REPOSITORY_ID; }
For program implementations on the ORB client, values must be set for VALUE_TAG and REPOSITORY_ID.
- Format of receive data on the ORB client side:
-
For struct itself as the return value, change its format in the same way as for send data.
Note that the following is an example applicable to AAAReply in Figure 9-6 Conversion example of an IDL definition for EJB.
struct user-defined-structure-name { long VALUE_TAG; string REPOSITORY_ID; data-body; }
For the first occurrences of string and sequence<octet> members among all members of struct, prefix the following structure to their data.
Note that the following is an example applicable to the tag1 member of AAAReply in Figure 9-6 Conversion example of an IDL definition for EJB.
struct ValueTag { long VALUE_TAG; string REPOSITORY_ID; }
For the second and subsequent occurrences of the string and sequence<octet> members, prefix the following structure to their data.
Note that the following is an example applicable to the tag2 member of AAAReply in Figure 9-6 Conversion example of an IDL definition for EJB. In this case, ReplyTag is used instead of ValueTag because an occurrence of the sequence<octet> member exists before the tag2 member.
struct ReplyTag { long VALUE_TAG; long INDIRECTION_TAG; long INDIRECTION; }
For receive data, ignore the values of VALUE_TAG, REPOSITORY_ID, INDIRECTION_TAG, and INDIRECTION.
- Example of changing an IDL definition:
-
The following figure shows an example of changing an IDL definition (including the corresponding remote interface).
Figure 9‒6: Conversion example of an IDL definition for EJB
(2) Program implementations related to communication processing
This section describes the processing to be added as program implementations.
(a) VALUE_TAG and REPOSITORY_ID settings in the send data on the ORB client
For string, sequence<octet>, and struct, if you send data from the ORB client to EJB, beforehand, set values also for VALUE_TAG and REPOSITORY_ID in addition to the data body.
- VALUE_TAG
-
Always set the fixed value 0x7fffff02.
- REPOSITORY_ID
-
- For string and sequence<octet>:
-
Set the fixed value "RMI:[B:0000000000000000".
- For struct:
-
Because the repository ID differs depending on the name and structure of the struct member, obtain the repository ID from the output results of the ctmjava2idl command. In the output results, under the #pragma ID class-name line, the "RMI:xxxxx" portion is the repository ID. For example, in the following figure, the repository ID of AAA is "RMI:AAA:D7A0D1FA6D5A19A3:86B2BC1FA4F5362A".
Figure 9‒7: Example of the repository ID
If you specify the length of the REPOSITORY_ID section in the COBOL map file, specify the following value:
- For string or sequence<octet>:
-
23 or more characters
(Numeric value equal to or larger than the length of the fixed value "RMI:[B:0000000000000000")
- For struct:
-
Numeric value equal to or larger than the number of characters in the repository ID obtained from the output results of the ctmjava2idl command
For the receive data on the ORB client side, ignore all information (including VALUE_TAG) except the data body.
The following figure shows an example of specifying the VALUE_TAG and REPOSITORY_ID settings applicable to XXX::invoke() in Figure 9-6 Conversion example of an IDL definition for EJB.
|
|
|
(b) Handling of IDL string data in EJB
On the EJB side, strings being sent or received are handled as data of type byte[]. Therefore, perform conversion from or to String in Java if necessary.
If received byte[] data is directly converted into String in Java, the code \0 is suffixed. Therefore, if you retrieve the string length, the length one character longer than the actual string length will be returned. If necessary, delete the code \0 at the end of the string.
Conversely, when you set a string in byte[], make sure that the program explicitly suffixes the code \0 to the string. If data not terminated by \0 is returned as an IDL string, an error might occur on the receiving side.
If the maximum string length is specified in IDL, because the length of the termination code \0 is not included in the maximum length, secure the byte[] size that is one larger than the maximum length.
(c) Null in EJB
Do not use a null object for class/byte[] in the return value returned from Java.
(3) Generating a reference to a stringified object
This section describes the procedure for obtaining an IOR string file for connection from an ORB client to an ORB gateway.
-
Start an ORB gateway by executing the ctmstartgw command with the -CTMIDLConnect option specified.
-
Deploy and then start the J2EE application that is to be invoked from the ORB client.
-
Execute the ctmgetior command to obtain an IOR string file.
If you re-generate a file that contains IOR strings, note the following:
- If you do not change the EJB remote interface, the name registered in the CORBA Naming Service, the server IP address, or the receive port number of the ORB gateway:
-
You do not need to re-generate the file.
If you start the ORB gateway by executing the ctmstartgw command with -CTMIDLConnect 0 specified, although you cannot obtain IOR strings by using the ctmgetior command, you can shorten the times required to start the application and ORB gateway.
- If you change the EJB remote interface, the name registered in the CORBA Naming Service, the server IP address, or the receive port number of the ORB gateway:
-
Re-perform the procedure for generating a reference to a stringified object from step 1.