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. Flask源码阅读-第三篇(flask\_compat.py)

    源码 # -*- coding: utf-8 -*-""" flask._compat ~~~~~~~~~~~~~ Some py2/py3 compatibility ...

  2. LVS原理详解(3种工作方式8种调度算法)

    一.集群简介 什么是集群 计算机集群简称集群是一种计算机系统,它通过一组松散集成的计算机软件和/或硬件连接起来高度紧密地协作完成计算工作.在某种意义上,他们可以被看作是一台计算机.集群系统中的单个计算 ...

  3. SpringSecurity入门例子及遇到的问题解决

    最近学习<Spring 实战>学习到了SpringSecurity,觉得书本上的例子过于复杂,而且不喜欢它基于java配置,更喜欢用xml文件进行配置 于是在极客学院网上学习,感觉挺不错的 ...

  4. python scrapy 数据处理时间格式转换

    def show(self,response): # print(response.url) title = response.xpath('//main/div/div/div/div/h1/tex ...

  5. 2019-03-06-day012-生成器与推导式

    01 昨日回顾 迭代器: 迭代器有iter方法 next方法就是迭代器 递归: 自己调用自己 明确的结束条件 递归的最大深度 官方 1000 实际测试:998/997 import sys sys.s ...

  6. 【一题多解】Python 字符串逆序

    https://blog.csdn.net/seetheworld518/article/details/46756639 https://blog.csdn.net/together_cz/arti ...

  7. C/C++内存泄漏检测 —— memleax

    memleax是个开源项目,原理是通过注入hook目标进程的malloc(new也是用的malloc)内存分配函数,在指定时间未释放则认为内存泄漏.优点是不需要重启,attach到目标进程. gith ...

  8. Putty CentOS SSH 总是自动断开连接

    /********************************************************************** * Putty CentOS SSH 总是自动断开连接 ...

  9. Python中的print、input函数以及Python中交换两个变量解析

    一.Python中的值交换操作 首先明确一点点,Python中的一切都是面向对象的,可以理解为Python的中一切都是对象. 我们知道Java也是面向对象的语言,但是在Java中定义一个值变量如下: ...

  10. [Data Structure] Stack Implementation in Python

    We can realize a Stack as an adaptation of a Python List. S.push(e)=L.append(e) S.pop()=L.pop() S.to ...