Application environment

When the Genero Application Server starts an application process, it sets environment variables from various sources. Understanding how variables are defined by the various front-ends, is helpful to you when configuring applications.

The application process can be started as a DVM (fglrun), as an intermediate script, or whatever is specified in the application configuration file.

Environment inheritance

Environment variable settings are inherited by the DVM in the following order:

  1. The environment of the dispatcher that starts the proxy.
  2. The environment variables defined in the application configuration file (ENVIRONMENT_VARIABLE elements).
  3. Additionally, some specific environment variables can be defined by the front-end; whether this is Genero Desktop Client (GDC) and Genero Browser Client Genero (GBC), or web service. See:

How to get the URL of the application

The FGL_VMPROXY_START_URL environment variable stores the real URL of an application. The real URL refers to the URL that the user clicked to start the application. Use the Genero fgl_getenv() function in your application to retrieve the value of the environment variable.
LET startUrl = fgl_getenv( "FGL_VMPROXY_START_URL" )

The variable name must be in uppercase.

There are environment variables that are internal to the GAS, to include variables with the FGL_VMPROXY_ prefix. As the name suggests, these environment variables are set by the dispatcher starting the proxy. In general, you do not have access to these environment variables; however, an exception was made for the FGL_VMPROXY_START_URL environment variable.

How to use environment variables in GDC and GBC

The GAS gets environment at the start of web applications from these sources:
  • Standard HTTP request header fields
  • Web server Common Gateway Interface (CGI) environment variables
It handles these in different ways by converting them to environment variables you can use at runtime.
HTTP request headers converted to FGL_WEBSERVER_HTTP_*

The uaproxy converts HTTP headers, such as the User-Agent, to environment variables by adding the FGL_WEBSERVER_HTTP_ prefix.

The GAS replaces the dash (or minus "-") characters with underscore (_) characters. For example, it converts the header "User-Agent" to the FGL_WEBSERVER_HTTP_USER_AGENT environment variable.

If you need to use these variables in your application, use the Genero fgl_getenv() function to retrieve their value. For example to identify the client browser, you add a statement like this:
LET user_agent = fgl_getenv( "FGL_WEBSERVER_HTTP_USER_AGENT" )
Web server CGI environment converted to FGL_WEBSERVER_*

The uaproxy converts some CGI variables (see Table 1) transmitted by the web server (Apache, IIS, and so on) by adding them to the GAS environment with FGL_WEBSERVER_ as prefix. For more information on the standard specification, see rfc3875, or see your web server's documentation.

Table 1. Web server environment variables
Web server variables GAS converted variables Description
REMOTE_ADDR FGL_WEBSERVER_REMOTE_ADDR Returns the network address of the client sending the request to the server.
REMOTE_USER FGL_WEBSERVER_REMOTE_USER Returns the user name supplied by the client as part of user authentication.
SERVER_NAME FGL_WEBSERVER_SERVER_NAME Returns the name of the server host to which the client request is directed.
HTTPS FGL_WEBSERVER_HTTPS Returns "ON" if the request came in through a secure channel (for example, SSL); or it returns "OFF", if the request is for an insecure channel.
Use the Genero fgl_getenv() function in your application to retrieve their values. For example, to find out if the web server supports the HTTPS protocol, add this statement in your application:
LET httpsOn = fgl_getenv( "FGL_WEBSERVER_HTTPS" )

How to retrieve web server information in a web service

With Genero web services applications, environment variables cannot be used to pass HTTP request headers because the gwsproxy has already started. The only way to send the environment is through the HTTP header. Header names set by the GAS have the following form:
X-FourJs-Environment-Variable-MyHeaderName
Where MyHeaderName is the header name.

Some variables transmitted by the web server (Apache, IIS, and so on) are also available to the environment:

  • X-FourJs-Environment-Variable-REMOTE_ADDR
  • X-FourJs-Environment-Variable-REMOTE_USER
  • X-FourJs-Environment-Variable-SERVER_NAME
  • X-FourJs-Environment-Variable-HTTPS
There are options available to retrieve headers depending on whether you are working with GWS RESTful high-level APIs or using low-level APIs:
RESTful high-level APIs
  • Set a WSHeader attribute as part of a function parameter. For example,
    ip_addr STRING ATTRIBUTE(WSHeader, WSOptional, WSName="X-FourJs-Environment-Variable-REMOTE_ADDR")
    Or:
  • Set a context dictionary variable (for example context) at the modular level with the WSContext attribute. This allows you to retrieve all X-FourJs-Environment-xxx set by the GAS by referencing a dictionary key value, for example, DISPLAY context["Variable-REMOTE_ADDR"].
Low-level APIs
With low-level APIs you use the com.HTTPServiceRequest.getRequestHeader() method. For example:
LET param = req.getRequestHeader("X-FourJs-Environment-Variable-REMOTE_ADDR")

For more information on RESTful high-level API and low-level API methods, see the Web services section in the Genero Business Development Language User Guide.