Customize the content of a Gen EJB/EJB Web Service ejb-jar.xml file
search cancel

Customize the content of a Gen EJB/EJB Web Service ejb-jar.xml file

book

Article ID: 387712

calendar_today

Updated On:

Products

Gen Gen - Run Time Distributed

Issue/Introduction

In a Gen EJB/EJB Web Service the Assemble step includes builds the .ear file which contains one or more SERVER_MANAGER.jar files.
Inside each SERVER_MANAGER.jar in the META-INF folder there is a file ejb-jar.xml.
By default it contains an empty assembly-descriptor section.

    <assembly-descriptor>
        
    </assembly-descriptor>


It is required to replace that with this:

    <assembly-descriptor>
        <security-role>
            <role-name>GenAcquisitionSecurityRole</role-name>
               </security-role>
               <method-permission>
            <role-name>GenAcquisitionSecurityRole</role-name>
            <method>
                <ejb-name>PSTEPNAME</ejb-name>
                <method-name>*</method-name>
            </method>
        </method-permission>
    </assembly-descriptor>

How can the Build Tool scripts be changed to enable this to be done automatically?

Environment

Gen 8.6 EJB/EJB Web Service

Resolution

This can only be achieved via a customization.
Gen Support developed the following solution.
NOTE: This solution assumes 1 Procedure Step (PStep) per SERVER MANAGER.

  1. The provided solution is based on the fact that the ejb-jar.xml file is first created at code generation time before the later BT Assemble step operates on it to any additional information for trace etc. The solution updates that copy of the file located in directory "model_name.ief\java\SERVER_NAME\META-INF".


  2. There are 2 PowerShell scripts attached to this article which should be placed into the directory "%GEN86%\Gen\bt\scripts":
    get_pstepname_from_ejb_jar_xml.ps1 receives the full path of the generated ejb-jar.xml file as an input argument and reads the pstepname from the ejb-name tag inside the session tag section. It passes the full path of the ejb-jar.xml file and pstepname to the 2nd script update_ejb_jar_xml.ps1 which updates the file with the required new assembly-descriptor block and pstepname.


  3. The existing file deploy_ear.scr in directory "%GEN86%\Gen\bt\scripts" also needs to be updated to run powershell.exe with the get_pstepname_from_ejb_jar_xml.ps1 to update the ejb-jar.xml file before the main Assemble processing starts. Only 1 line for the powershell.exe command is required but a comment line is also included below:
    *****
    {* I N I T I A L I Z A T I O N   A N D   H E A D E R S   *}
    echo.
    echo =====================EARFILE Assemble Information============
    {[FOREACH]} EARFILE AS earfile
    echo EAR File: {earfile.EARFILE}.ear
     {[IF]} EQUAL "{EJB_PRESENT}" "YES"
    echo    EJB Modules:
      {[FOREACH]} MODULE AS module
        {[FOREACH]} EXECDEF AS execdef
          {[FOREACH]} EXECUNIT AS execunit
    echo       {execunit.MEMBER}
    echo Updating ejb-jar.xml file
    powershell.exe -FILE "%GEN86%\Gen\bt\scripts\get_pstepname_from_ejb_jar_xml.ps1" "{LOC.CODE_OBJ}{execunit.MEMBER}/META-INF/ejb-jar.xml"
          {[ENDFOR]}
        {[ENDFOR]}
      {[ENDFOR]}
     {[ENDIF]}
    ...
    *****
    NOTE: Please take a backup copy of the existing deploy_ear.scr file before making any changes.


  4. The result at Assemble time will be an updated assemble.EAR.bat file e.g. for a simple model I tested with 2 server managers S1 and S2 each with a single PStep SVR1 and SVR2 respectively:
    *****
    @echo off
    setlocal
    REM
    REM  Copyright (C) 2016 CA. All rights reserved.
    REM
    set COPYCMD=/Y
    C:
    CD "C:\Users\Administrator\Documents\CA\Gen 8.6\Models\cstest99.ief\java\\."
    echo.
    echo =====================EARFILE Assemble Information============
    echo EAR File: cstest99.ear
    echo    EJB Modules:
    echo       S1
    echo Updating ejb-jar.xml file
    powershell.exe -FILE "%GEN86%\Gen\bt\scripts\get_pstepname_from_ejb_jar_xml.ps1" "C:\Users\Administrator\Documents\CA\Gen 8.6\Models\cstest99.ief\java\\S1/META-INF/ejb-jar.xml"
    echo       S2
    echo Updating ejb-jar.xml file
    powershell.exe -FILE "%GEN86%\Gen\bt\scripts\get_pstepname_from_ejb_jar_xml.ps1" "C:\Users\Administrator\Documents\CA\Gen 8.6\Models\cstest99.ief\java\\S2/META-INF/ejb-jar.xml"
    echo    Additional Files:
    echo       - EAR file:
    echo.
    echo ===========================================================
    ...
    *****


  5. For the above example the 2 files "...\cstest99.ief\java\\S1/META-INF/ejb-jar.xml" and "...\cstest99.ief\java\\S2/META-INF/ejb-jar.xml" were correctly updated. See attached file ejb-jar_xml_files_before_after.zip for comparison.
    Then after the main Assemble processing they are placed as normal into the respective SERVER_MANAGER.jar file within the .ear file (with any selected Assemble dialog options).

Attachments

ejb-jar_xml_files_before_after.zip get_app
update_ejb_jar_xml.ps1 get_app
get_pstepname_from_ejb_jar_xml.ps1 get_app