Sticky Web services

A sticky Web service is instantiated to handle all requests coming from a specific user agent. The gwsproxy manages HTTP cookies to implement sessions with sticky Web services.

A sticky Web service is a Web service that uses an HTTP cookie 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.

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 ghe Genero Application Server. The gwsproxy can use the cookie to identify the DVM in charge of that cookie and dispatch the request to the correct DVM.

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, 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.