Icon Web Server Native Modules

The web server includes a native server module manager that allows authenticated users to make requests to native server modules. Web server requests are routed to native server modules using the following architecture:

Image

Please see the Web Server Request Handling topic for more information on how requests are structured and routed by the web server.

Native Module Format
A native server module is a library that can handle incoming web server requests. When a native server module is required by the web server, the server module is loaded before being executed.

For information on creating native server modules, please refer to the product-specific manual that accompanies the Elevate Web Builder 3 Modules product installation. You can download and install the Elevate Web Builder 3 Modules installation for your specific product using the following link:

Elevate Web Builder Downloads

Modules can only be created and built using Embarcadero RAD Studio and Delphi XE2 or higher.

Native Module Deployment
Native server modules can be deployed using the administration API in the web server. The IDE uses this API to deploy server modules to a specified path within the Modules virtual resource on the web server. Please see the Using the Server Manager and Web Server Administration API - Files topics for more information.

Native Module Installation
Native server module deployment is insufficient for allowing a server module to be accessible to authenticated users, and a server module must first be installed before incoming web server requests can be routed to the module. The IDE allows the user to install a native server module using the server manager.

Information Native server modules, like all server objects in the web server, are versioned. However, once a native server module has been installed, the underlying library cannot be reliably updated while the web server is running because, at any given moment in time, the server module library could be loaded in the web server process and, therefore, cannot be overwritten. For this reason, you should consider using a versioning scheme with native server module file names and increment the version and/or build number in the native server module file name. You will then need to upload the new native server module to the web server and re-install the server module using the new file name. This will cause the web server to create a new version of the native server module and remove the older version once all instances of the server module are unloaded by any executing threads in the web server.

Please see the Using the Server Manager topic for more information on using the server manager in the IDE and the Web Server Administration API - Modules topic for more information on installing and uninstalling native server modules.

Native Module Execution
When an incoming request is routed to a particular native server module and the library code is executed, an execution environment is obtained. These execution environments are cached for each server module in order to minimize module startup times.

The native server module memory is initialized once when the library is loaded and finalized when the library is unloaded. If any global initialization is required for a database engine or other support code, it should be placed in the initialization section of a source unit in the Delphi native server module project. Similarly, any global teardown code should be place in the finalization section of a source unit in the Delphi native server module project.

A global TEWBModule component instance is created for every incoming request to the web server. The incoming web server TEWBWebServerRequest instance is then routed to the TEWBModule instance's OnExecute event handler, if one is defined. The event handler code can then handle the request and send a response to the request using one of the following TEWBWebServerRequest methods:

MethodDescription
SendContentHeaderSends a response for a HEAD request.
SendCustomContentHeaderSends a custom content response for a HEAD request.
SendContentSends a UTF-8-encoded text response with a Content-Type header of "text/html; charset=utf-8" along with an optional status code and message.
SendCustomContentSends a UTF-8-encoded text response with a custom content type, encoding, and disposition.
SendRedirectSends a redirect response to a new URL along with an optional UTF-8-encoded text response with a Content-Type header of "text/html; charset=utf-8". By default, the redirect HTTP status code is 302, but you can specify a different status code.
SendErrorSends a status code and message along with an optional UTF-8-encoded text response with a Content-Type header of "text/plain; charset=utf-8".
SendContentStreamSends a UTF-8-encoded text stream response with a Content-Type header of "text/html; charset=utf-8" along with an optional status code and message.
SendCustomContentStreamSends a binary stream response with a custom content type, encoding, and disposition.

Warning If none of the above methods are called by the native server module and execution of the module terminates, the web server will not automatically send a response. This can cause the client application to hang and, eventually, time out waiting on a response that will never arrive.
Image