function TWebRequestHandler.HandleRequest(Request: TWebRequest;
Response: TWebResponse): Boolean;
var
I: Integer;
LWebModule: TComponent;
LWebAppServices: IWebAppServices;
LGetWebAppServices: IGetWebAppServices;
LComponent: TComponent;
begin
Result := False;
11 LWebModule := ActivateWebModules;
if Assigned(LWebModule) then
try
try
if Supports(IInterface(LWebModule), IGetWebAppServices, LGetWebAppServices) then
LWebAppServices := LGetWebAppServices.GetWebAppServices;
if LWebAppServices = nil then
for I := to LWebModule.ComponentCount - do
begin
LComponent := LWebModule.Components[I];
if Supports(LComponent, IWebAppServices, LWebAppServices) then
if LWebAppServices.Active then
break
else
LWebAppServices := nil;
end;
if LWebAppServices = nil then
LWebAppServices := TDefaultWebAppServices.Create;
LWebAppServices.InitContext(LWebModule, Request, Response);
try
try
Result := LWebAppServices.HandleRequest;
except
ApplicationHandleException(LWebAppServices.ExceptionHandler);
end;
finally
LWebAppServices.FinishContext;
end;
if Result and not Response.Sent then
Response.SendResponse;
except
ApplicationHandleException(LWebAppServices.ExceptionHandler);
end;
finally
DeactivateWebModules(LWebModule);
end;
end;

第11行代码,先得到一个激活的WebModule,如何没有,就会创建一个再返回。

第14行到第26行代码,判断WebModule中是否实现了 IGetWebAppServices 接口的,具体做什么先略过。因为WebModule没有继承这个接口。

第27行,创建一个默认的WebAppServices

第32行,执行默认操作。

 function TDefaultWebAppServices.HandleRequest: Boolean;
begin
Result := InvokeDispatcher;
end; function TDefaultWebAppServices.InvokeDispatcher: Boolean;
begin
if RequestHandler <> nil then
begin
Result := RequestHandler.HandleRequest(Request, Response);
end
else
raise EWebBrokerException.CreateRes(@sNoDispatcherComponent);
end;

上面的RequestHandler是

property RequestHandler: IWebRequestHandler read GetRequestHandler;

function TDefaultWebAppServices.GetRequestHandler: IWebRequestHandler;
begin
if FRequestHandler = nil then
FRequestHandler := FindRequestHandler;
Result := FRequestHandler;
end; function TDefaultWebAppServices.FindRequestHandler: IWebRequestHandler;
var
Component: TComponent;
begin
Result := nil;
Component := FindWebDispatcher;
if Component <> nil then
if not Supports(Component, IWebRequestHandler, Result) then
Assert(False, 'Expect support for IWebRequestHandler'); { do not localize }
end; function TDefaultWebAppServices.FindWebDispatcher: TComponent;
var
  J: Integer;
begin
  Result := nil;
  if WebModule is TCustomWebDispatcher then
    Result := WebModule
  else
    for J := 0 to WebModule.ComponentCount - 1 do
      if WebModule.Components[J] is TCustomWebDispatcher then
      begin
        Result := WebModule.Components[J];
        break;
      end;
end;

上面红色标记的代码,最终会返回 WebModule.

TWebModule = class(TCustomWebDispatcher)

所以,上面绿色标记的代码,是调用TCustomWebDispatcher.HandleRequest方法, 内部代码如下:

function TCustomWebDispatcher.HandleRequest(
Request: TWebRequest; Response: TWebResponse): Boolean;
begin
FRequest := Request;
FResponse := Response;
Result := DispatchAction(Request, Response);
end;

读DataSnap源代码(三)的更多相关文章

  1. 读DataSnap源代码(五)

    function TDSHTTPWebDispatcher.DispatchRequest(Sender: TObject; Request: TWebRequest; Response: TWebR ...

  2. 读DataSnap源代码(一)

    Delphi的DataSnap用了一段时间了,但一直感觉有些地方还不够了解,所以花时间阅读了源代码,特作此烂笔头. Datasnap是在之前的WebBorker基础上搭建的,DataSnap向导自动生 ...

  3. 读DataSnap源代码(六)

    具体分析一下DataSanp App与Rest, WebBroker App的不同,先看TDSHTTPService. **************************************** ...

  4. 读DataSnap源代码(四)

    继续篇中的 function TCustomWebDispatcher.DispatchAction(Request: TWebRequest; Response: TWebResponse): Bo ...

  5. 读DataSnap源代码(二)

    program Project1; {$APPTYPE GUI} {$R *.dres} uses Vcl.Forms, Web.WebReq, IdHTTPWebBrokerBridge, Form ...

  6. session自己定义存储,怎样更好地进行session共享;读tomcat7源代码,org.apache.catalina.session.FileStore可知

    session自己定义存储.怎样更好地进行session共享: 读tomcat源代码,org.apache.catalina.session.FileStore可知 一.详见: 方法1 public ...

  7. 读Flask源代码学习Python--config原理

    读Flask源代码学习Python--config原理 个人学习笔记,水平有限.如果理解错误的地方,请大家指出来,谢谢!第一次写文章,发现好累--!. 起因   莫名其妙在第一份工作中使用了从来没有接 ...

  8. ReentrantReadWriteLock三个线程读数据,三个线程写数据

    /*** * 三个线程读数据,三个线程写数据 * */ public class ReadWriteLockTest { public static void main(String[] args) ...

  9. dotnet 读 WPF 源代码笔记 布局时 Arrange 如何影响元素渲染坐标

    大家是否好奇,在 WPF 里面,对 UIElement 重写 OnRender 方法进行渲染的内容,是如何受到上层容器控件的布局而进行坐标偏移.如有两个放入到 StackPanel 的自定义 UIEl ...

随机推荐

  1. apache ab 压力测试工具

    Apache的ab命令模拟多线程并发请求,测试服务器负载压力,也可以测试nginx.lighthttp.IIS等其它Web服务器的压力.Apache附带的ab工具(使用的PHP环境是WAMP集成环境, ...

  2. 2019-03-11-day009-函数定义

    什么是函数 函数就是将许多冗余的代码进行整合统一调用的内存地址 函数怎么定义 def make(): print('掏出手机') print('打开微信') print('摇一摇') print('聊 ...

  3. this是什么!

    this 1.js的关键字指定一个对象,然后去替代他 函数内的this    函数外的this 函数内的this指向行为发生的主体 函数外的this都指向window 2.函数内的this和函数在什么 ...

  4. ES6 声明变量的6种方法

    ES5 只有两种声明变量的方法:var命令和function命令. ES6除了添加let和const命令,后面章节还会提到,另外两种声明变量的方法:import命令和class命令.所以,ES6 一共 ...

  5. 单交换机划分VLAN配置

    实验要求:相同vlan的主机能够通信,不同vlan的主机不能通讯 拓扑如下: 涉及内容有: 1.端口trunk模式设置 2.VTP的创建和设置 3.vlan的划分 配置如下: A enable 进入特 ...

  6. web(三)html标签

    标签的层级特性 闭合的html标签内可以包含一个或多个子标签,因此html的标签是一个多叉树的数据结构,多叉树的根是html标签. 标签的属性描述 每个标签都具备一组公用或当前标签独有的属性,属性的作 ...

  7. LINUX7安装Oracle11g单实例小结

    LINUX7安装Oracle11g遇到问题如下,记录 添加组: groupadd -g 1000 oinstall #报错:提示组被占用 #useradd: group 'oinstall' does ...

  8. AI之路,第二篇:python数学知识2

    第二篇:python数学知识2 线性代数 导入相应的模块: >>> import numpy as np     (数值处理模块)>>> import scipy ...

  9. [转载] python必碰到的问题---encode与decode,中文乱码

    阅读来源: 字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unicod ...

  10. Light OJ 1199:Partitioning Game(SG函数模板)

    Alice and Bob are playing a strange game. The rules of the game are: 1.      Initially there are n p ...