TDAJavaScriptHttpDispatcher
Overview
Adding DAJavaScriptHttpDispatcher to the form turns RemObjects server into simple web server that can serve static html files along with Data Abstract files. Inherits most properties and functionality from TROHTTPFileDispatcher.
Location
- Unit: uDAJavaScriptHttpDispatcher.pas
- Ancestry: TComponent | TROComponent | TROExtendedHttpDispatcher | TROHTTPFileDispatcher | TROJavaScriptHttpDispatcher | TDAJavaScriptHttpDispatcher
constructor Create override
Standard component constructor
constructor Create(AOwner: TComponent)
Parameters:
- AOwner: Owner
Activate virtual (declared in TROExtendedHttpDispatcher)
procedure Activate
Assign (TPersistent) override
Copies data from a given source.
procedure Assign(aSource: TPersistent)
Parameters:
- aSource: Source
Assign (TPersistent) override (declared in TROJavaScriptHttpDispatcher)
Copies the contents of another, similar object.
procedure Assign(Source: TPersistent)
Parameters:
- Source: Instance whose properties will be copied
CanHandlePath (declared in TROExtendedHttpDispatcher)
Return true if the given path can be handled by the dispatcher. The function compares the Path property content with the given path and chacks if the given path starts with the Path subpath.
function CanHandlePath(aPath: string): Boolean
Parameters:
- aPath: The request path to check.
Deactivate virtual (declared in TROExtendedHttpDispatcher)
procedure Deactivate
DefaultFile (declared in TROHTTPFileDispatcher)
The name of the file that will be served for directory request.
Example: assume we have configured the server to serve for /js/ virtual folder. The request to get http://example.org/js will serve the file specified with this property. Note: the request without trailing slash (http://example.org/js) will be redirected to the location with the trailing slash (http://example.org/js/) using 302 HTTP response code. The user's browser will get the new location and display it to the user seamlessly.
The default value is index.html
property DefaultFile: string read write
FireOnRequest protected virtual (declared in TROHTTPFileDispatcher)
Fires the OnRequest event.
procedure FireOnRequest(Path: string; Data: TStream; out ContentType: string; out ResultCode: Integer; out Status: string)
Parameters:
- Path: The request path.
- Data: The response data - output parameter.
- ContentType: The response content type - output parameter.
- ResultCode: The response HTTP result code - output parameter.
- Status: The response HTTP status message - output parameter.
Folder (declared in TROHTTPFileDispatcher)
The local path that will correspond to the virtual folder from the Path property. If relative path is specified then the path to the program main module will be used as base path.
property Folder: string read write
Notification protected override (declared in TROComponent)
Forwards notification messages to all owned components.
procedure Notification(aComponent: TComponent; Operation: TOperation)
Parameters:
- aComponent: component
- Operation: operation
NotifyDispose (declared in TROExtendedHttpDispatcher)
This procedure is called when the server HTTP channel is about to be freed.
procedure NotifyDispose
OnRequest (declared in TROHTTPFileDispatcher)
Allows full customization of serving files by the user.
NOTICE: when this event is handled user's code takes full responsibility of the request processing, no other processing actions are performed except request validity check before the event is fired.
property OnRequest: TROHTTPFileDispatcherEvent read write
delegate: procedure OnRequest(Sender: TObject; Path: string; Data: TStream; out ContentType: string; out ResultCode: Integer; out Status: string)
Path (declared in TROExtendedHttpDispatcher)
The request path the dispatcher will be activated for. For example, if this property contains /js then the dispatcher will be activated by the server channel to process such requests as http://example.org:8099/js/* (the asterisk means zero or more characters to continue the request path).
property Path: string read write
Process override (declared in TROHTTPFileDispatcher)
The main method to perform the request processing ant to form the response. Called every time to process incoming requests if the dispatcher is suitable to process it (determined by CanHandlePath result).
procedure Process(aTransport: IROHTTPTransport; aRequest: IROHTTPRequest; aResponse: IROHTTPResponse; aRequestData: TStream; aResponseData: TStream)
Parameters:
- aTransport: Http transport.
- aRequest: Contains object implementing IROHTTPRequest interface that describes the request.
- aResponse: Contains initialized object implementing IROHTTPResponse interface that should describe the response.
- aRequestData: The data stream (TStream) that contains the raw HTTP request data except the header part.
- aResponseData: Contais initialized and empty data stream (TStream) that shpuld be filled with the raw reponse data except the header part.
ReplyWithMessage protected (declared in TROHTTPFileDispatcher)
Internal utility method - prepares response with specified parameters and puts it into the response object and response stream.
procedure ReplyWithMessage(aCode: Integer; aStatus: string; aMessage: string; aResponse: IROHTTPResponse; aResponseData: TStream)
Parameters:
- aCode: The HTTP response code.
- aStatus: The HTTP response status message.
- aMessage: The user understandable response message.
- aResponse: The reference to the object describing the HTTP response.
- aResponseData: The stream that will contain the response data.
ResolveContentType (declared in TROHTTPFileDispatcher)
Resolves and returns content type based on the file extension. Contains the content type table for the most often used extensions, others are resolved using registry (Windows platforms only).
function ResolveContentType(aExtension: string): string
Parameters:
- aExtension: The file extension to resolve.
ROFreeNotification (declared in TROComponent)
Forwards notification messages to all owned components.
procedure ROFreeNotification(aComponent: TComponent)
Parameters:
- aComponent: component
RORemoveFreeNotification (declared in TROComponent)
Forwards notification messages to all owned components.
procedure RORemoveFreeNotification(aComponent: TComponent)
Parameters:
- aComponent: component
SendRemoveNotification protected (declared in TROComponent)
Forwards notification messages to all owned components.
procedure SendRemoveNotification(aComponent: TComponent)
Parameters:
- aComponent: component
ServeCustom protected override
To add more flexibility this method allows the user process request on his own.
procedure ServeCustom(aFilePath: string; aRequest: IROHTTPRequest; aResponse: IROHTTPResponse; aResponseData: TStream)
Parameters:
- aFilePath: The requested file path.
- aRequest: The reference to the object describing the HTTP request.
- aResponse: The reference to the object describing the HTTP response.
- aResponseData: The stream that will contain the response data.
ServeDAJavaScript
Set this property to true to enable serving DataAbstract.js and DataAbstract4_intf.js from embedded resource.
property ServeDAJavaScript: Boolean read write
ServeFilesFromFolder (declared in TROHTTPFileDispatcher)
Enables or disables serving files from the Folder. When this property has false value then the only option to serve files remains the OnRequest event handler. The default is true.
property ServeFilesFromFolder: Boolean read write
ServeFromFolder protected virtual (declared in TROHTTPFileDispatcher)
Locates file in the disk folder and forms the proper response.
procedure ServeFromFolder(aFilePath: string; aResponse: IROHTTPResponse; aResponseData: TStream)
Parameters:
- aFilePath: The requested file path.
- aResponse: The reference to the object describing the HTTP response.
- aResponseData: The stream that will contain the response data.
Server (declared in TROExtendedHttpDispatcher)
Points to the HTTP server channel which the dispatcher works with.
property Server: IROHTTPServer read write
ServeROJavaScript (declared in TROJavaScriptHttpDispatcher)
Enables or disables RemObjectsSDK.js script serving. If set to false the component will function exactly like it's superclass TROHTTPFileDispatcher.
property ServeROJavaScript: Boolean read write
ServeWithEvent protected virtual (declared in TROHTTPFileDispatcher)
Performs event based serving, fires OnRequest event.
procedure ServeWithEvent(aRequest: IROHTTPRequest; aResponse: IROHTTPResponse; aResponseData: TStream)
Parameters:
- aRequest: The reference to the object describing the HTTP request.
- aResponse: The reference to the object describing the HTTP response.
- aResponseData: The stream that will contain the response data.
DefaultFile (declared in TROHTTPFileDispatcher)
The name of the file that will be served for directory request.
Example: assume we have configured the server to serve for /js/ virtual folder. The request to get http://example.org/js will serve the file specified with this property. Note: the request without trailing slash (http://example.org/js) will be redirected to the location with the trailing slash (http://example.org/js/) using 302 HTTP response code. The user's browser will get the new location and display it to the user seamlessly.
The default value is index.html
property DefaultFile: string read write
Folder (declared in TROHTTPFileDispatcher)
The local path that will correspond to the virtual folder from the Path property. If relative path is specified then the path to the program main module will be used as base path.
property Folder: string read write
Path (declared in TROExtendedHttpDispatcher)
The request path the dispatcher will be activated for. For example, if this property contains /js then the dispatcher will be activated by the server channel to process such requests as http://example.org:8099/js/* (the asterisk means zero or more characters to continue the request path).
property Path: string read write
ServeDAJavaScript
Set this property to true to enable serving DataAbstract.js and DataAbstract4_intf.js from embedded resource.
property ServeDAJavaScript: Boolean read write
ServeFilesFromFolder (declared in TROHTTPFileDispatcher)
Enables or disables serving files from the Folder. When this property has false value then the only option to serve files remains the OnRequest event handler. The default is true.
property ServeFilesFromFolder: Boolean read write
Server (declared in TROExtendedHttpDispatcher)
Points to the HTTP server channel which the dispatcher works with.
property Server: IROHTTPServer read write
ServeROJavaScript (declared in TROJavaScriptHttpDispatcher)
Enables or disables RemObjectsSDK.js script serving. If set to false the component will function exactly like it's superclass TROHTTPFileDispatcher.
property ServeROJavaScript: Boolean read write
constructor Create override
Standard component constructor
constructor Create(AOwner: TComponent)
Parameters:
- AOwner: Owner
Activate virtual (declared in TROExtendedHttpDispatcher)
procedure Activate
Assign (TPersistent) override
Copies data from a given source.
procedure Assign(aSource: TPersistent)
Parameters:
- aSource: Source
Assign (TPersistent) override (declared in TROJavaScriptHttpDispatcher)
Copies the contents of another, similar object.
procedure Assign(Source: TPersistent)
Parameters:
- Source: Instance whose properties will be copied
CanHandlePath (declared in TROExtendedHttpDispatcher)
Return true if the given path can be handled by the dispatcher. The function compares the Path property content with the given path and chacks if the given path starts with the Path subpath.
function CanHandlePath(aPath: string): Boolean
Parameters:
- aPath: The request path to check.
Deactivate virtual (declared in TROExtendedHttpDispatcher)
procedure Deactivate
FireOnRequest protected virtual (declared in TROHTTPFileDispatcher)
Fires the OnRequest event.
procedure FireOnRequest(Path: string; Data: TStream; out ContentType: string; out ResultCode: Integer; out Status: string)
Parameters:
- Path: The request path.
- Data: The response data - output parameter.
- ContentType: The response content type - output parameter.
- ResultCode: The response HTTP result code - output parameter.
- Status: The response HTTP status message - output parameter.
Notification protected override (declared in TROComponent)
Forwards notification messages to all owned components.
procedure Notification(aComponent: TComponent; Operation: TOperation)
Parameters:
- aComponent: component
- Operation: operation
NotifyDispose (declared in TROExtendedHttpDispatcher)
This procedure is called when the server HTTP channel is about to be freed.
procedure NotifyDispose
Process override (declared in TROHTTPFileDispatcher)
The main method to perform the request processing ant to form the response. Called every time to process incoming requests if the dispatcher is suitable to process it (determined by CanHandlePath result).
procedure Process(aTransport: IROHTTPTransport; aRequest: IROHTTPRequest; aResponse: IROHTTPResponse; aRequestData: TStream; aResponseData: TStream)
Parameters:
- aTransport: Http transport.
- aRequest: Contains object implementing IROHTTPRequest interface that describes the request.
- aResponse: Contains initialized object implementing IROHTTPResponse interface that should describe the response.
- aRequestData: The data stream (TStream) that contains the raw HTTP request data except the header part.
- aResponseData: Contais initialized and empty data stream (TStream) that shpuld be filled with the raw reponse data except the header part.
ReplyWithMessage protected (declared in TROHTTPFileDispatcher)
Internal utility method - prepares response with specified parameters and puts it into the response object and response stream.
procedure ReplyWithMessage(aCode: Integer; aStatus: string; aMessage: string; aResponse: IROHTTPResponse; aResponseData: TStream)
Parameters:
- aCode: The HTTP response code.
- aStatus: The HTTP response status message.
- aMessage: The user understandable response message.
- aResponse: The reference to the object describing the HTTP response.
- aResponseData: The stream that will contain the response data.
ResolveContentType (declared in TROHTTPFileDispatcher)
Resolves and returns content type based on the file extension. Contains the content type table for the most often used extensions, others are resolved using registry (Windows platforms only).
function ResolveContentType(aExtension: string): string
Parameters:
- aExtension: The file extension to resolve.
ROFreeNotification (declared in TROComponent)
Forwards notification messages to all owned components.
procedure ROFreeNotification(aComponent: TComponent)
Parameters:
- aComponent: component
RORemoveFreeNotification (declared in TROComponent)
Forwards notification messages to all owned components.
procedure RORemoveFreeNotification(aComponent: TComponent)
Parameters:
- aComponent: component
SendRemoveNotification protected (declared in TROComponent)
Forwards notification messages to all owned components.
procedure SendRemoveNotification(aComponent: TComponent)
Parameters:
- aComponent: component
ServeCustom protected override
To add more flexibility this method allows the user process request on his own.
procedure ServeCustom(aFilePath: string; aRequest: IROHTTPRequest; aResponse: IROHTTPResponse; aResponseData: TStream)
Parameters:
- aFilePath: The requested file path.
- aRequest: The reference to the object describing the HTTP request.
- aResponse: The reference to the object describing the HTTP response.
- aResponseData: The stream that will contain the response data.
ServeFromFolder protected virtual (declared in TROHTTPFileDispatcher)
Locates file in the disk folder and forms the proper response.
procedure ServeFromFolder(aFilePath: string; aResponse: IROHTTPResponse; aResponseData: TStream)
Parameters:
- aFilePath: The requested file path.
- aResponse: The reference to the object describing the HTTP response.
- aResponseData: The stream that will contain the response data.
ServeWithEvent protected virtual (declared in TROHTTPFileDispatcher)
Performs event based serving, fires OnRequest event.
procedure ServeWithEvent(aRequest: IROHTTPRequest; aResponse: IROHTTPResponse; aResponseData: TStream)
Parameters:
- aRequest: The reference to the object describing the HTTP request.
- aResponse: The reference to the object describing the HTTP response.
- aResponseData: The stream that will contain the response data.
OnRequest (declared in TROHTTPFileDispatcher)
Allows full customization of serving files by the user.
NOTICE: when this event is handled user's code takes full responsibility of the request processing, no other processing actions are performed except request validity check before the event is fired.
property OnRequest: TROHTTPFileDispatcherEvent read write
delegate: procedure OnRequest(Sender: TObject; Path: string; Data: TStream; out ContentType: string; out ResultCode: Integer; out Status: string)
- Calling Data Abstract Servers from JavaScript