读DataSnap源代码(四)

继续篇中的

 1 function TCustomWebDispatcher.DispatchAction(Request: TWebRequest;
 2   Response: TWebResponse): Boolean;
 3 var
 4   I: Integer;
 5   Action, Default: TWebActionItem;
 6   Dispatch: IWebDispatch;
 7 begin
 8   FRequest := Request;
 9   FResponse := Response;
10   I := 0;
11   Default := nil;
12   if Response.Sent then
13   begin
14     Result := True;
15     { Note that WebSnapSvr enabled apps have no way to mark response as sent }
16     Exit;
17   end;
18   Result := DoBeforeDispatch(Request, Response) or Response.Sent;
19   while not Result and (I < FActions.Count) do
20   begin
21     Action := FActions[I];
22     Result := Action.DispatchAction(Request, Response, False);
23     if Action.Default then Default := Action;
24     Inc(I);
25   end;
26   // Dispatch to self registering components
27   I := 0;
28   while not Result and (I < FDispatchList.Count) do
29   begin
30     if Supports(IInterface(FDispatchList.Items[I]), IWebDispatch, Dispatch) then
31     begin
32       Result := DispatchHandler(Self, Dispatch,
33         Request, Response, False);
34     end;
35     Inc(I);
36   end;
37
38   if not Result and Assigned(Default) then
39     Result := Default.DispatchAction(Request, Response, True);
40   if Result and not Response.Sent then
41     Result := DoAfterDispatch(Request, Response);
42
43 end;

在第26行代码之前,是执行WebModule中的Action, 然后是遍例WebModule上的Component, 只要支持IWebDispatch,都有机会处理WEB请求。

当然就包括了   TDSHTTPWebDispatcher = class(TDSHTTPServerTransport, IWebDispatch)。 继续代码:

 1 function DispatchHandler(Sender: TObject; Dispatch: IWebDispatch; Request: TWebRequest; Response: TWebResponse;
 2   DoDefault: Boolean): Boolean;
 3 begin
 4   Result := False;
 5   if (Dispatch.Enabled and ((Dispatch.MethodType = mtAny) or
 6     (Request.MethodType = Dispatch.MethodType)) and
 7     Dispatch.Mask.Matches(string(Request.InternalPathInfo))) then
 8   begin
 9     Result := Dispatch.DispatchRequest(Sender, Request, Response);
10   end;
11 end;
function TDSHTTPWebDispatcher.DispatchRequest(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse): Boolean;
begin
  try
    if Owner is TWebModule then
      DataSnapWebModule := TWebModule(Owner);
    try
      try
        RequiresServer;
        TDSHTTPServerWebBroker(Self.FHttpServer).DispatchDataSnap(Request, Response);
        Result := True;
      except
        on E: Exception do
        begin
          { Default to 500, like web services. }
          Response.StatusCode := 500;
          Result := True;
        end;
      end;
    except
      { Swallow any unexpected exception, it will bring down some web servers }
      Result := False;
    end;
  finally
    { Reset current DataSnapWebModule }
    DataSnapWebModule := nil;
  end;
end;

至此,WEB请求转入到WebModule中的TDSHTTPWebDispatcher来处理了。

时间: 2024-12-11 13:38:39

读DataSnap源代码(四)的相关文章

读DataSnap源代码(一)

Delphi的DataSnap用了一段时间了,但一直感觉有些地方还不够了解,所以花时间阅读了源代码,特作此烂笔头. Datasnap是在之前的WebBorker基础上搭建的,DataSnap向导自动生成了基础的代码,所以就以基础代码为起点来看看DataSnap的内部机制. 首选创建一个 Stand-alone 的REST App,  向导至少会为我们生成一个Form1和一个WebModule1, FormUnit1单元如下: unit FormUnit1; interface uses Wina

读DataSnap源代码(五)

1 function TDSHTTPWebDispatcher.DispatchRequest(Sender: TObject; 2 Request: TWebRequest; Response: TWebResponse): Boolean; 3 begin 4 try 5 if Owner is TWebModule then 6 DataSnapWebModule := TWebModule(Owner); 7 try 8 try 9 RequiresServer; 10 TDSHTTPS

读DataSnap源代码(二)

program Project1; {$APPTYPE GUI} {$R *.dres} uses Vcl.Forms, Web.WebReq, IdHTTPWebBrokerBridge, FormUnit1 in 'FormUnit1.pas' {Form1}, ServerMethodsUnit1 in 'ServerMethodsUnit1.pas', WebModuleUnit1 in 'WebModuleUnit1.pas' {WebModule1: TWebModule}; {$R

读DataSnap源代码(三)

1 function TWebRequestHandler.HandleRequest(Request: TWebRequest; 2 Response: TWebResponse): Boolean; 3 var 4 I: Integer; 5 LWebModule: TComponent; 6 LWebAppServices: IWebAppServices; 7 LGetWebAppServices: IGetWebAppServices; 8 LComponent: TComponent

30秒读懂mysql四种事务隔离级别

一.事务的基本要素(ACID) 1.原子性(Atomicity):事务开始后所有操作,要么全部做完,要么全部不做,不可能停滞在中间环节.事务执行过程中出错,会回滚到事务开始前的状态,所有的操作就像没有发生一样.也就是说事务是一个不可分割的整体,就像化学中学过的原子,是物质构成的基本单位.  2.一致性(Consistency):事务开始前和结束后,数据库的完整性约束没有被破坏 .比如A向B转账,不可能A扣了钱,B却没收到. 3.隔离性(Isolation):同一时间,只允许一个事务请求同一数据,

最近读cocoaui源代码有感

上半年为了做一个ios的应用,引入了cocoaui库,主要是用来布局ios界面,发现简化了不少代码和工作量.因为在写第一个ios应用的时候,用的代码布局,在适配4s和6的机型时候,几乎被搞死,大量的约束定义充斥在代码中,惨不忍睹. cocoaui的作者是ssdb的作者ideawu,在微博里面比较活跃,有问题at他一般很快就会有回应.ssdb是一个类似于redis的nosql数据库:像这样一个在客户端和服务器领域都有建树的人还是很少的.我等普普通通的程序员,距离这种大神还是有一些距离,不过不能气馁

linux 读写锁应用实例

转自:http://blog.csdn.net/dsg333/article/details/22113489 /*使用读写锁实现四个线程读写一段程序的实例,共创建了四个新的线程,其中两个线程用来读取数据,另外两个线程用来写入数据.在任意时刻,如果有一个线程在写数据,将阻塞所有其他线程的任何操作.*/#include <errno.h>#include <pthread.h>#include <stdio.h>#include <stdlib.h>#incl

MYSQL 源代码 编译原理 AST和解析树 代码语法解析

MYSQL 源代码 编译原理 AST和解析树 代码语法解析 http://blog.csdn.net/wfp458113181wfp/article/details/17082355 使用AST树 分类:             antlr              2013-12-02 22:39     255人阅读     评论(0)     收藏     举报 目录(?)[+] 第五章使用AST树中间结果来计算表达式值 创建ASTS 第五章.使用AST树中间结果来计算表达式值 现在我们已

【JUnit4.10源代码分析】6.1 排序和过滤

abstract class ParentRunner<T> extends Runner implements Filterable,Sortable 本节介绍排序和过滤.(虽然JUnit4.8.2源代码分析-6.1 排序和过滤中演示了客户使用排序和过滤的方式,也有些不明白其设计意图,但是,先读懂源代码为妙.说不定看着看着就明白了.) org.junit.runner.manipulation包 排序和过滤的相关类型,在org.junit.runner.manipulation包中. 1.例