Really off topic but interesting, here is how you could
launch Tomcat from RPG via JNI on recent AS/400.

I'm sure Pier and JF will love it :)

PS: My company is proud to offer it to ASF, but RPG compiler
    editing limitation, prevent us to use the standard 80....

---- CLP, a kind of tomcat.sh ----

   /***************************************************************************/
   /* Start of an embbeded TOMCAT with RPGV                                   */
   /* this tips allow to avoid using the QSH or RUNJAVA command which         */
   /* spawn a BCI (Batch Immediate Job) disallowing the identification of the */
   /* Task in the OS/400 with the job Name.                                   */
   /*                                                                         */
   /* This CL programme is used to :                                          */
   /* - First Create a DATAQ for the send of command to the main module       */
   /*  the command can be the standart command of the TOMCAT : stop, estart.. */
   /*  eg: for stopping the process and the job.                              */
   /* call QSNDDTAQ ('TCEMBED''*LIBL' X'00005F' 'stop ')                      */
   /* - Intialisation of the CLASSPATH and TOMCAT_HOME                        */
   /*                                                                         */
   /* Paremeter :                                                             */
   /*           Allow to add an option to the 'start' action as -noout        */
   /*           to get the log in a file prefered to the stdout QSYSPRT       */
   /*                                                                         */
   /* CAUTION :                                                               */
   /* this module should not run in an interactive session, since the JVM or  */
   /* the system don't close and freed and  the socket on the port            */
   /* (eg : 8080 standart ), when the program end , disallowing a second call */
   /* until the end of the job. So use SBMJOB                                 */
   /***************************************************************************/
             Pgm        Parm(&Action )

             Dcl        Var(&Action)            Type(*char) Len(256)
             Dcl        Var(&ClassPath)         Type(*char) Len(2000)
             Dcl        Var(&TomcatHome)        Type(*char) Len(2000) +
                                                value('/var/tomcat3')
             Dcl        Var(&Dataq)             Type(*char) Len(10) +
                                                value('TCEMBED')
             Dcl        Var(&DataqLib)          Type(*char) Len(10)  +
                                                Value('QGPL')


   /***************************************************************************/
   /* Create the DtaQ ,                                                       */
   /* if exist no error then Clear it to avoid previous command               */
   /***************************************************************************/

             CrtDtaq Dtaq(&DataqLib/&Dataq) Type(*Std) MaxLen(256)
                Monmsg Cpf9870

             Call QclrDtaq (&Dataq &DataqLib)

   /***************************************************************************/
   /* Setup the TOMCAT_HOME for the WEB-APP     if envvar exist no error      */
   /***************************************************************************/
/*           ChgVar     Var(&TomcatHome) VALUE( +
                        '/var/tomcat3')                                       */
             AddEnvVar  EnvVAr(TOMCAT_HOME ) Value(&TomcatHome)
                        Monmsg CpfA980 exec(Do)

                        ChgEnvVar  EnvVAr(TOMCAT_HOME ) Value(&TOMCATHOME)

                        EndDo

   /***************************************************************************/
   /* Setup the classpath for the JVM                                         */
   /***************************************************************************/

             ChgVar     Var(&ClassPath) +
                          Value(&TomcatHome !< '/lib/tomcat.jar+
                          :/QIBM/ProdData/Java400/jdk12/lib/tools.jar')

             ChgEnvVar  EnvVar(CLASSPATH) Value(&ClassPath)


   /***************************************************************************/
   /* Call the Module                                                         */
   /***************************************************************************/

             Call       Pgm(TcEmbedG) Parm(&action &Dataq &DataqLib)

             EndPgm


---- RPG side of the force ----



      ****************************************************************************
      * Start of an embbeded TOMCAT with RPGV                                    *
      * this tips allow to avoid using the QSH or RUNJAVA command which          *
      * This programme :                                                         *
      * - start a TOMCAT using the external optionnal parameters                 *
      * Wait on DTAQ until receive the stop command                              *
      * transmit all the command receive to the TOMCAT                           *
      *CAUTION :                                                                 *
      * this module should not run in an interactive session, since the JVM or   *
      * the system don't close and freed and  the socket on the communication port*
      * (eg : 8080 standart ), when the program end , disallowing a second call  *
      * until the end of the job. So use SBMJOB                                  *
      ****************************************************************************

      * Prototype for create a string object from RPG string.
      * String method of Java class String.
      * return a string java Objet
      * Input parameter is a string with varying
     Dmakestring       PR              O   EXTPROC(*JAVA:
     D                                     'java.lang.String':
     D                                     *CONSTRUCTOR)
     D                                      CLASS(*JAVA:'java.lang.String')
     D str                          256A    varying
      * Prototype for String method of Java class String.
      * return void so the method is static
      * Input parameter is string array java Object
     Dstart            PR                  EXTPROC(*JAVA:
     D                                      'org.apache.tomcat.startup.Main':
     D                                     'main' ) static
     D arg                             O    CLASS(*JAVA:'java.lang.String')
     D                                      DIM(10)
      * Prototype for Receive the Command from the Dataq
     Drcvdtaq          PR                  EXTPGM('QRCVDTAQ')
     D dtaqname                      10    const
     D dtaqlib                       10    const
     D dtaqsz                         5P 0 const
     D dtaqval                       10
     D dtaqwait                       5p 0 const

      * To store the command and the attributes to the tomcat
      * string array java Object
     d Lstr            S               O   CLASS(*JAVA:'java.lang.String')
     d                                      DIM(10)
      * to store the string command as the java class need a varying format type
     d zstr            S            256a    varying
      * to receive the command from the dataq
     D signal          S            256
      * to wait without limit on the dataq
     d wait            s              5p 0  inz(-1)
      *
      * Main
      *
     c     *Entry        Plist
     c                   Parm                    pStr            256
     c                   Parm                    pDataq           10
     c                   Parm                    pDataqLib        10
      /FREE

           zStr= %trim('start');
           lStr(1)=makestring(zStr);
           // if a Option is requested  add it to the
           if (pStr <> ' ');
                zStr= %trim(pStr);
                lStr(2)=makestring(zStr);
           endif;
           // start of the TomCat
            start(lStr);
           //  run Until receive the command stop.
           dou signal = 'stop';
            // Now the Tomcat is start wait, Wait Until receive a command.
                callp  rcvdtaq(pDataq : pDataqLib : X'00256F' : Signal : wait);
                if  signal <> '         ';
                         zstr= %trim(signal);
                        lStr(1)=makestring(zstr);
                        start(lStr);
                endif;
            enddo;
            *inlr = *on;
      /END-FREE


-
Henri Gomez                 ___[_]____
EMAIL : [EMAIL PROTECTED]        (. .)                     
PGP KEY : 697ECEDD    ...oOOo..(_)..oOOo...
PGP Fingerprint : 9DF8 1EA8 ED53 2F39 DC9B 904A 364F 80E6 


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to