具体分析一下DataSanp App与Rest, WebBroker App的不同,先看TDSHTTPService。
***********************************************************************************************
TDSHTTPService = class(TCustomDSHTTPServerTransport)
继承体系:
TDSHTTPService -> TCustomDSHTTPServerTransport -> TCustomDSRESTServerTransport -> TDSServerTransport ...
************************************************************************************************
TDSHTTPWebDispatcher = class(TDSHTTPServerTransport, IWebDispatch)
继承体系:
TDSHTTPWebDispatcher -> TDSHTTPServerTransport -> TCustomDSHTTPServerTransport ...
************************************************************************************************
都是TCustomDSHTTPServerTransport的后代. 目前来看,如果没有意外,后续的请求处理方式应该是一样的。
那么DataSanp App的WEB请求又是从哪开始的呢?
1 TCustomDSHTTPServerTransport = class(TCustomDSRESTServerTransport) 2 strict protected 3 FHttpServer: TDSHTTPServer; 4 strict private 5 { Private declarations } 6 FCredentialsPassthrough: Boolean; 7 FDSAuthPassword: string; 8 FDSAuthUser: string; 9 FDSPort: Integer; 10 FDSHostName: string; 11 FDSCacheContext: string; 12 function IsCacheContextStored: Boolean; 13 private 14 function GetHttpServer: TDSHTTPServer; 15 function IsDSHostnameStored: Boolean; 16 procedure SetCacheContext(const Ctx: string); 17 function GetCacheContext: string; 18 protected 19 function CreateHttpServer: TDSHTTPServer; virtual; abstract;
上面是TCustomDSHTTPServerTransport类的部分定义,可以看到第19行处,有一个abstract的方法,意味着TCustomDSHTTPServerTransport的子类必须实现这个方法 。
1 function TDSHTTPService.CreateHttpServer: TDSHTTPServer; 2 var 3 LHTTPServer: TDSHTTPServerIndy; 4 begin 5 if Assigned(FCertFiles) then 6 LHTTPServer := TDSHTTPSServerIndy.Create(Self.Server, IPImplementationID) 7 else 8 LHTTPServer := TDSHTTPServerIndy.Create(Self.Server, IPImplementationID); 9 Result := LHTTPServer; 10 LHTTPServer.HTTPOtherContext := HTTPOtherContext; 11 end;
1 function TDSHTTPWebDispatcher.CreateHttpServer: TDSHTTPServer; 2 begin 3 Result := TDSHTTPServerWebBroker.Create; 4 end;
果然是不一样的,但都是一个父类继承下来的:
TDSHTTPServerIndy= class(TDSHTTPServer)
TDSHTTPServerWebBroker = class(TDSHTTPServer)
1 TDSHTTPServerIndy = class(TDSHTTPServer) 2 strict private 3 FHTTPOtherContext: TDSHTTPOtherContextEvent; 4 private 5 FServer: IIPHTTPServer; 6 FDefaultPort: Word; 7 FServerSoftware: string; 8 FIPImplementationID: string; 9 FPeerProcs: IIPPeerProcs; 10 function PeerProcs: IIPPeerProcs; 11 function GetActive: Boolean; 12 function GetDefaultPort: Word; 13 procedure SetActive(const Value: Boolean); 14 procedure SetDefaultPort(const Value: Word); 15 procedure DoIndyCommand(AContext: IIPContext; 16 ARequestInfo: IIPHTTPRequestInfo; AResponseInfo: IIPHTTPResponseInfo); 17 function GetServerSoftware: string; 18 procedure SetServerSoftware(const Value: string); 19 property HTTPOtherContext: TDSHTTPOtherContextEvent read FHTTPOtherContext write FHTTPOtherContext; 20 protected 21 function Decode(Data: string): string; override; 22 procedure DoCommandOtherContext(AContext: TDSHTTPContext; 23 ARequestInfo: TDSHTTPRequest; AResponseInfo: TDSHTTPResponse; 24 const ARequest: string); override; 25 procedure InitializeServer; virtual; 26 public 27 constructor Create(const ADSServer: TDSCustomServer; const AIPImplementationID: string = ''); override; 28 destructor Destroy; override; 29 property Server: IIPHTTPServer read FServer; 30 property DefaultPort: Word read GetDefaultPort write SetDefaultPort; 31 property Active: Boolean read GetActive write SetActive; 32 property ServerSoftware: string read GetServerSoftware write SetServerSoftware; 33 end;
1 procedure TDSHTTPServerIndy.SetActive(const Value: Boolean); 2 begin 3 if Value and (FServer = nil) then 4 begin 5 FServer := PeerFactory.CreatePeer(FIPImplementationID, IIPHTTPServer, nil) as IIPHTTPServer; 6 InitializeServer; 7 end; 8 if FServer <> nil then 9 FServer.Active := Value; 10 end;