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_")
...
Note: 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 the proxy

When you need to pass additional parameters to a starting proxy, you can do it via environment variables that are then set in a ua or gdc proxy environment before the dispatcher starts it. Each parameter must be set in the HTTP header response when you specify the 307 HTTP return code. The HTTP header name must be of the form:
X-FourJs-Environment-envvar:value
Where envvar is the name of the variable to pass to the proxy and the HTTP header value is the value of the environment variable.
These headers are returned by the service to the proxy to be parsed and added in the environment of started DVMs for applications.
Note: 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
Then, with a call to the Genero function fgl_getenv(VARIABLENAME) (with the variable name in uppercase), you can retrieve them in your Genero program.

REST sample

Passing parameters to a proxy is not possible for Web services requests, as the proxy is already started. The only way to send the environment with a Web services request is through the HTTP header.

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_")
...
Genero program sample:
MAIN
...
DISPLAY fgl_getenv("HELLO")  -- Displays "World"
DISPLAY fgl_getenv("NAME")   -- Displays "Georges"
...