From the REST service to the proxy

The delegation REST service must notify the dispatcher when it approves the start of an application or service.

Approve the proxy start

To approve the start of an application or a service proxy or the service forwarding (because if it is a Web service using delegation, the service may be already started), the Genero REST service must return the following HTTP code and description:
  • The HTTP return code must be 307
  • The description must be the string _GENERO_INTERNAL_DELEGATE_

Returning this HTTP code and description notifies the dispatcher to start the application or service proxy as the response to the current user-agent request.

IMPORT com
DEFINE req com.HTTPServiceRequest
...
CALL req.sendResponse(307,"_GENERO_INTERNAL_DELEGATE_")
...

You can return an HTTP message body from the REST service that is then transmitted to the proxy if the original incoming request was POST or PUT, otherwise body is skipped.

Passing parameters to Web applications or Web services

When you need to pass additional parameters or environment variables to a starting proxy, you do so through the HTTP header. The HTTP header name must be of the form:
X-FourJs-Environment-envvar:value
Where:
  • envvar is the name of the variable.
  • value is the value of the variable.
Each parameter must be set in the HTTP header response when you specify the 307 HTTP return code. For example:
IMPORT com
DEFINE req com.HTTPServiceRequest
...
CALL req.setResponseHeader("X-FourJs-Environment-Hello","World")
CALL req.setResponseHeader("X-FourJs-Environment-Name","Georges")
CALL req.sendResponse(307,"_GENERO_INTERNAL_DELEGATE_")
...

These headers are returned by the service to the proxy to be parsed and added in the environment of started DVMs.

Case sensitivity of environment variables are handled differently in different operating systems. For example, in Windows® they are case insensitive, and in UNIX® they are case sensitive. In addition some Web servers convert all header names to lowercase. In order to provide for these constraints, the proxy converts all environment variable names to uppercase. For example, the proxy may receive the header in the form:
  • X-FourJs-Environment-Hello:World
  • x-fourjs-environment-hello:World
It converts the environment variable to uppercase and sets it in the DVM environment as HELLO=World where it can be retrieved.

Retrieving parameters for Web application

The parameters set in the Passing parameters to Web applications or Web services are converted to environment variables and thus you can retrieve them in your Genero application with a call to the Genero function fgl_getenv(VARIABLENAME) (the variable name must be in uppercase)

Genero program sample:
MAIN
...
DISPLAY fgl_getenv("HELLO")  -- Displays "World"
DISPLAY fgl_getenv("NAME")   -- Displays "Georges"
...

Retrieving parameters for Web services

In the context of the Web service, the parameters set in the Passing parameters to Web applications or Web services can be retrieved in your delegation service or in another Web service with a call to the Genero getRequestHeader method of the com.HTTPServiceRequest class.

Genero program sample:
IMPORT com
 
  DEFINE resp com.HTTPServiceRequest

  LET h1 = resp.getRequestHeader("X-FourJs-Environment-Hello")
  DISPLAY h1  -- Displays "World" 

  LET h2 = resp.getRequestHeader("X-FourJs-Environment-Name")
  DISPLAY h2  -- Displays "Georges"
...