TDSTCPServerTransport 的Filters
TDSTCPServerTransport 的Filters
TDSTCPServerTransport 的 Filter 属性,可以对传递的数据进行加密,压缩,再修改等,有
点注入的概念。默认情况下,Datasnap 自带的ZLIB, PC1,RSA 三个Filter。测试了一下,
RSA 只对KEY 加密,PC1 才对内容加密,ZLIB 来做压缩,ZLIB 压缩实在不咋的。并且,
Filter 的顺序,是依次执行的。我现在打算实现,服务器的一个Log 功能,记录下来进入的
数据,出去的数据,要求记录下来的数据是明文。
TTransportFilter 的 ProcessInput ,ProcessOutput 光看名字比较费解,可以这么理解
ProcessInput 为编码,ProcessOutput 可以理解为解码。
首先给DSTCPServerTransport1 的Fitlers 都加上默认的3 个Filter。
上一个完整的代码
unituLogFilter;
interface
uses
SysUtils, DBXPlatform, DBXTransport;
type
TLogHeadFilter =class(TTransportFilter)
public
constructorCreate;override;
destructorDestroy;override;
functionProcessInput(constData: TBytes): TBytes;override;
functionProcessOutput(constData: TBytes): TBytes;override;//do nothing
functionId: UnicodeString;override;
end;
TLogTailFilter =class(TTransportFilter)
public
constructorCreate;override;
destructorDestroy;override;
functionProcessInput(constData: TBytes): TBytes;override;//do nothing
functionProcessOutput(constData: TBytes): TBytes;override;
functionId: UnicodeString;override;
end;
procedureAddLogFilter(Filters: TTransportFilterCollection);
implementation
uses
CodeSiteLogging;
const
LogFilterName_Tail ='LogTail';
LogFilterName_Head ='LogHead';
procedureAddLogFilter(Filters: TTransportFilterCollection);
var
fs: TDBXStringArray;
i:Integer;
begin
fs := Filters.FilterIdList;
Filters.Clear;
Filters.AddFilter(LogFilterName_Head);
fori := Low(fs)toHigh(fs)do
begin
Filters.AddFilter(fs[i]);
end;
Filters.AddFilter(LogFilterName_Tail);
end;
constructorTLogTailFilter.Create;
begin
inheritedCreate;
//CodeSite.Send(csmBlue, 'TLogTailFilter.Create');
end;
destructorTLogTailFilter.Destroy;
begin
//CodeSite.Send(csmBlue, 'TLogTailFilter.Destroy');
inheritedDestroy;
end;
functionTLogTailFilter.ProcessInput(constData: TBytes): TBytes;
begin
Result := Data;
CodeSite.Send(csmOrange,'To Client: '+ IntToStr(Length(Data)));
end;
functionTLogTailFilter.ProcessOutput(constData: TBytes): TBytes;
begin
Result := Data;
CodeSite.Send(csmOrange,'From Client: '+ IntToStr(Length(Data)),
TEncoding.ASCII.GetString(Data));
end;
functionTLogTailFilter.Id: UnicodeString;
begin
Result := LogFilterName_Tail;
end;
{ TLogInputFilter }
constructorTLogHeadFilter.Create;
begin
inherited;
//CodeSite.Send(csmBlue, 'TLogHeadFilter.Create');
end;
destructorTLogHeadFilter.Destroy;
begin
//CodeSite.Send(csmBlue, 'TLogHeadFilter.Destroy');
inherited;
end;
functionTLogHeadFilter.Id: UnicodeString;
begin
Result := LogFilterName_Head;
end;
functionTLogHeadFilter.ProcessInput(constData: TBytes): TBytes;
begin
Result := Data;
CodeSite.Send(csmYellow,'To Client: '+ IntToStr(Length(Data)),
TEncoding.ASCII.GetString(Data));
end;
functionTLogHeadFilter.ProcessOutput(constData: TBytes): TBytes;
begin
Result := Data;
CodeSite.Send(csmYellow,'From Client: '+ IntToStr(Length(Data)));
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/5105857.html