External Objects typed as "Java Session Beans" allow calling Java Session Beans hosted in a JEE server. The Java Session Bean EO will store all the necessary information to make the call to the Session EJB regarding context parameters, EJB interfaces etc. Once the EO has been defined we will be able to invoke the real EJB in the same way we use any other GeneXus object.
Name: name of the EO
Description: description of the EO
Type: EO type, Java Session Bean
EJB Version: EJB version being called (either 2.x or 3.x)
EJB Home Object: EJB home or local home interface (applies only when EJB Version = 2.x)
EJB Object: EJB component interface
EJB JNDI name: JNDI name to reference the EJB
Specify JNDI context properties: set to Yes if context properties for the EJB lookup must be specified, otherwise set to No.
When setting "Specify JNDI context properties = YES" the following properties are displayed:
INITIAL_CONTEXT_FACTORY: initial context factory class
PROVIDER_URL: provider URL where the EJB is located
SECURITY_PRINCIPAL: the principal to authenticate
SECURITY_CREDENTIALS: the credentials that will be used to authenticate the principal
Internal Name: internal name of the method
Type: data type of the returned value, if any
External Type: external data type of the returned value
External Name: external name of the method
Access Type: it indicates whether the parameter is an input only, output only, or input/output parameter.
Internal Name: internal name of the parameter
Description: description of the parameter
Type: data type that the parameter will have in GeneXus
External Type: external data type of the parameter
Suppose that we want to call a Session EJB located in another server. Basically, we will follow 2 steps:
Create the external object according to the Session EJB
Write the necessary GX code to invoke the EJB
For the first step, the Session EJB developer must provide us with the JAR package containing the EJB interfaces needed to make the call. Once we have the jar file we must place it in the model classpath and then create the EO according to the interfaces given in the jar file (of course it is also necessary to specify the JNDI name and probably its context properties). It will also be necessary to add a jar file with the standard classes needed when invoking EJBs (containing implementations of EJBLocalHome, EJBLocalObject etc.). This jar file may be different according to the version of the EJB being called (2.x or 3.x) and its name may be ejb.jar ejb3.jar o similar.
Once the EO has been defined we simply use it as any other GX object. E.g:
&first = "Hello "
&second = "Session Beans"
&concat = &externalObj.Concat(&first, &second)
msg(&concat) //prints "Hello Session Beans"
&externalObj is a variable based on the EO for the Session EJB, &concat-&first-&second are character variables and Concat is a method in the EO that matches a method in the EJB. As shown, the Concat being called returns the concatenation of two character variables.
When deploying the application through the GeneXus Deployment Wizard it is necessary to add the EJB provider jar file as an additional library.