Compile applications

Compile applications and services.

The goal of this quick start is to create an application and service for testing using the Genero Application Server for Java.

Steps

  1. Start the command line interface and set the environment for your Genero BDL using envcomp.
    • On Linux®/macOS™, change to your Genero BDL installation directory and run the script, for example:
      cd /opt/fourjs/fgl
      ./envcomp 
    • On Windows®, change to your Genero BDL installation directory and run the bat file, for example:
      cd "c:\program files\fourjs\fgl"
      envcomp.bat 
  2. With a text editor, create an application source file called helloapp.4gl.
    In it copy the code shown in the example and save:
    IMPORT FGL fgldialog
    
    MAIN
      OPEN FORM f FROM "helloapp"
      DISPLAY FORM f
    
      MENU "Exit"
        COMMAND "Hello"
          CALL fgl_winmessage("Hello", "Hello World!", "exclamation")
        COMMAND "exit"
          EXIT MENU
      END MENU
    END MAIN
  3. Create a per file (the application form) called helloapp.per
    Copy the code shown in the example and save:
    LAYOUT(TEXT="Hello World")
    GRID
    {
        Hello World!
    }
    END
  4. Create a file called helloservice.4gl
    Copy the code shown in the example and save:
    IMPORT XML
    IMPORT COM
    
    &define L(s) DISPLAY SFMT("(%1:%2) %3", __FILE__, __LINE__, s)
    &define LF(s) L(SFMT s)
    
    # Query string parameters
    TYPE QSParams DYNAMIC ARRAY OF RECORD
        name STRING,
        value STRING
      END RECORD
    
    MAIN
      DEFINE url,
             qs,
             requestUrl STRING
      DEFINE request com.HTTPServiceRequest
    
      CALL com.WebServiceEngine.Start()
    
      WHILE TRUE
        TRY
          #Retrieve the HTTPServiceRequest object to handle the HTTP request in various FUNCTIONs
          LET request = com.WebServiceEngine.GetHttpServiceRequest(-1)
    
          #Separate the incoming URL from query string
          LET requestUrl = request.readFormEncodedRequest(false)
          CALL splitUrl(requestUrl) RETURNING url, qs
          CALL processRequest(request, requestUrl)
        CATCH
          LF(("Exception %1 - %2", status, SQLCA.SQLERRM))
          L("Got an exception - Exiting")
          EXIT WHILE
        END TRY
      END WHILE
    END MAIN
    
    { Split a url and returns (path, query string) }
    FUNCTION splitUrl(url)
      DEFINE url STRING
      DEFINE i INTEGER
    
      IF url IS NULL THEN
        RETURN NULL, NULL
      END IF
    
      LET i = url.getIndexOf("?",1)
      IF i >= 1 THEN
        RETURN url.subString(1, i - 1), url.subString(i + 1, url.getLength())
      END IF
    
      RETURN url, NULL
    END FUNCTION
    
    FUNCTION processRequest(request, requestUrl)
      DEFINE request com.HTTPServiceRequest,
             requestUrl STRING
    
      LF(("processRequest: %1", requestUrl))
    
      CALL request.sendTextResponse(200, "OK", "Hello World!")
    END FUNCTION
    
  5. Compile the application and service source files (4gl and per).
    Run the commands shown at the command line:
    fglcomp -r -M helloapp.4gl
    fglform -M helloapp.per
    fglcomp -r -M helloservice.4gl
    
    The application and service 42m and 42f files are created.