Configure sticky web services

You create a sticky web service to ensure that requests from a specific user agent are always routed to the same DVM handling the web service by the Genero Application Server (GAS).

Sticky web services are set by HTTP cookies.

The first time a user agent connects to the Genero Application Server, the gwsproxy starts a new DVM to handle the sticky web service instance. The gwsproxy sets an HTTP cookie, called GWS_S_SESSION, in the first response to the user agent.

This cookie is then sent with any further requests from the user agent to the GAS. The gwsproxy can use the cookie to identify the DVM in charge of that cookie and dispatch the request to the correct DVM.

Important:

Genero web service DVMs are managed in a pool by the GAS. When sticky mode is used, the pool is disregarded. For instance, the MAX_AVAILABLE setting, limiting the number of DVMs available to the GWS, is no longer taken into account. Therefore, you must handle the stopping of the sticky Web service in your application code.

Configure a sticky web service

To enable sticky sessions in a web service, add the mode attribute to the application node in the web service application configuration, and set the value to "sticky". The KEEP_ALIVE element specifies the session lifetime, in seconds.

<APPLICATION Parent="ws.default" mode="sticky">
<EXECUTION>
  <PATH>$(res.path.app)/services/sticky-ws-service</PATH>
  <MODULE>sticky-main</MODULE>
</EXECUTION>
<TIMEOUT>
  <KEEP_ALIVE>60</KEEP_ALIVE>
</TIMEOUT>
</APPLICATION>
You can change the name of the cookie by setting the environment variable FGL_GWSPROXY_COOKIE_NAME in the application configuration with the value of the new cookie name.
<APPLICATION Parent="ws.default" mode="sticky">
<EXECUTION>
  <ENVIRONMENT_VARIABLE Id="FGL_GWSPROXY_COOKIE_NAME">new_name</ENVIRONMENT_VARIABLE>
  <PATH>$(res.path.app)/services/sticky-ws-service</PATH>
  <MODULE>sticky-main</MODULE>
</EXECUTION>
<TIMEOUT>
  <KEEP_ALIVE>60</KEEP_ALIVE>
</TIMEOUT>
</APPLICATION>

When does a session expire

The KEEP_ALIVE element specifies the session lifetime, in seconds. A DVM that does not get a request from the user agent it is servicing will stop after the time specified by KEEP_ALIVE has passed.

If a request comes from the user agent after the time specified by KEEP_ALIVE, and therefore after the DVM has stopped, it will return an HTTP 400 error.

Stop a sticky web service

To properly stop a sticky web service, have a dedicated method to be called by the user agent when it needs to close the session. The DVM can respond to the request, unset the cookie, and stop the Genero program properly.