当前位置: 首页 > ai >正文

Delphi DataSnap 流程分析(二)

Delphi DataSnap 流程分析(一)_看那山瞧那水的博客-CSDN博客

粗略分析了 创建传统DataSnap的流程,现在再分析下创建现在更常用的 方式:

DataSnap REST Application

这种方式只支持HTTP(普通HTTP和REST HTTP)通信,不支持TCP通信。

 这种方式包含有WebModule,HTTP服务器也是TIdHTTPWebBrokerBridge

 因此其HTTP Server的启动流程和 Delphi Web Server 流程分析_看那山瞧那水的博客-CSDN博客

里分析的一样,只是到了最后,也就是方法TCustomWebDispatcher.DispatchAction(),接着进行后续处理。

代码: 


constructor TCustomWebDispatcher.Create(AOwner: TComponent);
varI: Integer;Component: TComponent;SetAppDispatcher: ISetAppDispatcher;
begin
{$IFDEF MSWINDOWS}
{$ENDIF}FDispatchList := TObjectList<TComponent>.Create;//TComponentList.Create;FDispatchList.OwnsObjects := False;FOnException := nil;if AOwner <> nil thenif AOwner is TCustomWebDispatcher thenraise EWebBrokerException.Create(sOnlyOneDispatcher)elsefor I := 0 to AOwner.ComponentCount - 1 doif AOwner.Components[I] is TCustomWebDispatcher thenraise EWebBrokerException.Create(sOnlyOneDispatcher);inherited CreateNew(AOwner, -1);FActions := TWebActionItems.Create(Self, TWebActionItem);if Owner <> nil thenfor I := 0 to Owner.ComponentCount - 1 dobeginComponent := Owner.Components[I];if Supports(IInterface(Component), ISetAppDispatcher, SetAppDispatcher) thenSetAppDispatcher.SetAppDispatcher(Self)else if Supports(IInterface(Component), IWebDispatch) thenFDispatchList.Add(Component);end;
end;

TCustomWebDispatcher类创建的时候,会加载支持接口IWebDispatch的组件,TDSHTTPWebDispatcher是支持IWebDispatch接口的:

TDSHTTPWebDispatcher = class(TDSHTTPServerTransport, IWebDispatch) 

所以FDispatchList列表包含了WebModule的组件DSHTTPWebDispatcher1。

 
function TCustomWebDispatcher.DispatchAction(Request: TWebRequest;Response: TWebResponse): Boolean;
varI: Integer;Action, Default: TWebActionItem;Dispatch: IWebDispatch;
beginFRequest := Request;FResponse := Response;I := 0;Default := nil;if Response.Sent thenbeginResult := True;{ Note that WebSnapSvr enabled apps have no way to mark response as sent }Exit;end;Result := DoBeforeDispatch(Request, Response) or Response.Sent;while not Result and (I < FActions.Count) dobeginAction := FActions[I];Result := Action.DispatchAction(Request, Response, False);if Action.Default then Default := Action;Inc(I);end;// Dispatch to self registering componentsI := 0;while not Result and (I < FDispatchList.Count) dobeginif Supports(IInterface(FDispatchList.Items[I]), IWebDispatch, Dispatch) thenbeginResult := DispatchHandler(Self, Dispatch,Request, Response, False);end;Inc(I);end;if not Result and Assigned(Default) thenResult := Default.DispatchAction(Request, Response, True);if Result and not Response.Sent thenResult := DoAfterDispatch(Request, Response);end;

如果前面没有中断,则执行下面的代码:

  // Dispatch to self registering components
  I := 0;
  while not Result and (I < FDispatchList.Count) do
  begin
    if Supports(IInterface(FDispatchList.Items[I]), IWebDispatch, Dispatch) then
    begin
      Result := DispatchHandler(Self, Dispatch,
        Request, Response, False);
    end;
    Inc(I);
  end;

因而执行Dispatch := DSHTTPWebDispatcher1(TDSHTTPWebDispatcher类),

DispatchHandler(): 这是一个局部方法


function DispatchHandler(Sender: TObject; Dispatch: IWebDispatch; Request: TWebRequest; Response: TWebResponse;DoDefault: Boolean): Boolean;
beginRes
http://www.xdnf.cn/news/11177.html

相关文章:

  • robots.txt的语法和写法详解
  • 视频CDN概念和特点
  • 软件开发文档模板(全套)(规格说明书;详细设计;测试计划;验收报告)
  • SD新插件,AI生成视频,动画和模特换装
  • 经典前端框架,一个时代的落幕:如何看待layui 官网将于 2021年10月13日 进行下线?
  • 简单的base64转pdf
  • 网页设计必学:CSS四种样式引入方式及常用样式
  • 什么是SDH
  • 制作一个简单HTML电影网页设计(HTML+CSS)
  • 转载:国内从事机器视觉领域的公司
  • android_基础_editText字符过滤
  • SoftICE出现Error Code 31无法启动的解决办法
  • HTML汉字编码简明对照表
  • 常见的10种网络安全攻击类型
  • 硬件知识:USB3.0和USB2.0的区别
  • 浅谈UDP(数据包长度,收包能力,丢包及进程结构选择)
  • 面试趣事,我遇到的一个极品老女人
  • 转载-万维网是如何工作的
  • 入手ZeroNet,我的站吼吼
  • 好奇!滴滴在 GitHub 开源了哪些有意思的项目?
  • 12 个超好用的免费在线工具建议收藏!(非常详细)从零基础入门到精通,看完这一篇就够了
  • 国内无法访问Android开发网站的解决方法
  • 蝶阀质量标准执行标准
  • platform_device与platform_driver
  • 【解决】AlertDialog和AlertDialog.Builder的区别是什么?
  • 使用 Microsoft SQL Server 2000 各种版本或组件而必须安装的操作系统
  • QQ卡丁车:腾讯自主研发的联网对战赛车游戏
  • 收藏!一个详细完整的公司局域网搭建案例
  • WinBuilder使用与配置详解
  • 正则表达式30分钟入门教程