From 952fa6ce12e118f31441d9813bf468befe6f20c4 Mon Sep 17 00:00:00 2001 From: inoussa Date: Mon, 22 Oct 2007 12:44:00 +0000 Subject: [PATCH] Apache module extension to be a dll/so hosting env git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@278 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- wst/trunk/library_base_intf.pas | 86 +++- wst/trunk/library_imp_utils.pas | 94 ++-- wst/trunk/library_protocol.pas | 86 ---- wst/trunk/samples/apache_module/mod_wst.lpi | 448 ++++++++++++++++-- wst/trunk/samples/apache_module/mod_wst.lpr | 5 + .../apache_module/wst_apache_binding.pas | 253 +++++++++- .../user_client_console.lpi | 99 ++-- .../user_client_console.pas | 4 +- wst/trunk/samples/user_service_intf_imp.pas | 4 +- wst/trunk/tests/test_suite/test_utilities.pas | 167 ++++++- wst/trunk/tests/test_suite/wst_test_suite.lpi | 151 +++++- 11 files changed, 1125 insertions(+), 272 deletions(-) diff --git a/wst/trunk/library_base_intf.pas b/wst/trunk/library_base_intf.pas index 9c7223744..c64ae29fd 100644 --- a/wst/trunk/library_base_intf.pas +++ b/wst/trunk/library_base_intf.pas @@ -14,7 +14,7 @@ unit library_base_intf; interface -uses base_service_intf; +uses SysUtils, Classes, base_service_intf; {$INCLUDE wst.inc} {$INCLUDE wst_delphi.inc} @@ -51,6 +51,30 @@ type function SetPosition(const ANewPos : LongWord):LongInt; end; + { TwstStream } + + TwstStream = class(TInterfacedObject,IwstStream) + private + FStream : TStream; + protected + function Read( + ABuffer : Pointer; + const ALenToRead : LongWord; + out AReadedLen : LongWord + ):LongInt; + function Write( + ABuffer : Pointer; + const ALenToWrite : LongWord; + out AWrittenLen : LongWord + ):LongInt; + function GetSize(out ASize : LongWord):LongInt; + function SetSize(const ANewSize : LongWord):LongInt; + function GetPosition(out APos : LongWord):LongWord; + function SetPosition(const ANewPos : LongWord):LongInt; + public + constructor Create(AStream : TStream); + end; + TwstLibraryHandlerFunction = function( ARequestBuffer : IwstStream; @@ -85,5 +109,65 @@ begin end; end; +{ TwstStream } + +function TwstStream.Read( + ABuffer : Pointer; + const ALenToRead : LongWord; + out AReadedLen : LongWord +): LongInt; +begin + try + AReadedLen := FStream.Read(ABuffer^,ALenToRead); + Result := RET_OK; + except + Result := RET_FALSE; + end; +end; + +function TwstStream.Write( + ABuffer : Pointer; + const ALenToWrite : LongWord; + out AWrittenLen : LongWord +): LongInt; +begin + try + AWrittenLen := FStream.Write(ABuffer^,ALenToWrite); + Result := RET_OK; + except + Result := RET_FALSE; + end; +end; + +function TwstStream.GetSize(out ASize: LongWord): LongInt; +begin + ASize := FStream.Size; + Result := RET_OK; +end; + +function TwstStream.SetSize(const ANewSize: LongWord): LongInt; +begin + FStream.Size := ANewSize; + Result := RET_OK; +end; + +function TwstStream.GetPosition(out APos: LongWord): LongWord; +begin + APos := FStream.Position; + Result := RET_OK; +end; + +function TwstStream.SetPosition(const ANewPos: LongWord): LongInt; +begin + FStream.Position := ANewPos; + Result := RET_OK; +end; + +constructor TwstStream.Create(AStream: TStream); +begin + Assert(Assigned(AStream)); + FStream := AStream; +end; + end. diff --git a/wst/trunk/library_imp_utils.pas b/wst/trunk/library_imp_utils.pas index eaae419fa..1caf09dd4 100644 --- a/wst/trunk/library_imp_utils.pas +++ b/wst/trunk/library_imp_utils.pas @@ -16,13 +16,28 @@ unit library_imp_utils; interface uses - Classes, SysUtils; + Classes, SysUtils +{$IFDEF FPC} + , DynLibs +{$ELSE} + , Windows +{$ENDIF} +; {$INCLUDE wst.inc} {$INCLUDE wst_delphi.inc} +{$IFNDEF FPC} +const + NilHandle = 0; +{$ENDIF} + type +{$IFNDEF FPC} + TLibHandle = Longint; +{$ENDIF} + IwstModule = interface ['{A62A9A71-727E-47AD-9B84-0F7CA0AE51D5}'] function GetFileName():string; @@ -33,61 +48,57 @@ type ['{0A49D315-FF3E-40CD-BCA0-F958BCD5C57F}'] function Get(const AFileName : string):IwstModule; procedure Clear(); + function GetCount() : PtrInt; + function GetItem(const AIndex : PtrInt) : IwstModule; end; -var - LibraryManager : IwstModuleManager = nil; - -implementation -{$IFDEF FPC} - uses DynLibs; -{$ELSE} - uses Windows; - - type TLibHandle = THandle; - const NilHandle = 0; -{$ENDIF} - - -type - { TwstModule } TwstModule = class(TInterfacedObject,IwstModule) private FFileName : string; FHandle : TLibHandle; - private - procedure Load(const ADoLoad : Boolean); protected function GetFileName():string; function GetProc(const AProcName : string):Pointer; + procedure Load(const ADoLoad : Boolean);virtual; public - constructor Create(const AFileName : string); + constructor Create(const AFileName : string);virtual; destructor Destroy();override; end; + TwstModuleClass = class of TwstModule; { TwstModuleManager } TwstModuleManager = class(TInterfacedObject,IwstModuleManager) private FList : IInterfaceList; + FItemClass : TwstModuleClass; private function Load(const AFileName : string):IwstModule; - function GetItem(const AIndex : Integer):IwstModule; function IndexOf(const AFileName : string):Integer; protected function Get(const AFileName : string):IwstModule; procedure Clear(); + function GetCount() : PtrInt; + function GetItem(const AIndex : PtrInt) : IwstModule; public - constructor Create(); + constructor Create(AItemClass : TwstModuleClass); destructor Destroy();override; end; + +var + LibraryManager : IwstModuleManager = nil; + +implementation + procedure TwstModule.Load(const ADoLoad : Boolean); begin if ADoLoad then begin if ( FHandle = NilHandle ) then begin + if not FileExists(FFileName) then + raise Exception.CreateFmt('File not found : "%s".',[FFileName]); {$IFDEF FPC} FHandle := LoadLibrary(FFileName); {$ELSE} @@ -122,8 +133,6 @@ end; constructor TwstModule.Create(const AFileName: string); begin - if not FileExists(AFileName) then - raise Exception.CreateFmt('File not found : "%s".',[AFileName]); FHandle := NilHandle; FFileName := AFileName; Load(True); @@ -142,10 +151,22 @@ var i : Integer; begin i := IndexOf(AFileName); - if ( i < 0 ) then - Result := Load(AFileName) - else + if ( i < 0 ) then begin + FList.Lock(); + try + i := IndexOf(AFileName); + if ( i < 0 ) then begin + Result := Load(AFileName); + FList.Add(Result); + end else begin + Result := GetItem(i);; + end; + finally + FList.Unlock(); + end; + end else begin Result := GetItem(i); + end; end; procedure TwstModuleManager.Clear(); @@ -153,16 +174,21 @@ begin FList.Clear(); end; -function TwstModuleManager.Load(const AFileName: string): IwstModule; +function TwstModuleManager.GetCount(): PtrInt; begin - Result := TwstModule.Create(AFileName); + Result := FList.Count; end; -function TwstModuleManager.GetItem(const AIndex: Integer): IwstModule; +function TwstModuleManager.GetItem(const AIndex: PtrInt): IwstModule; begin Result := FList[AIndex] as IwstModule; end; +function TwstModuleManager.Load(const AFileName: string): IwstModule; +begin + Result := FItemClass.Create(AFileName); +end; + function TwstModuleManager.IndexOf(const AFileName: string): Integer; begin for Result := 0 to Pred(FList.Count) do begin @@ -172,9 +198,11 @@ begin Result := -1; end; -constructor TwstModuleManager.Create(); +constructor TwstModuleManager.Create(AItemClass : TwstModuleClass); begin - inherited; + Assert(Assigned(AItemClass)); + inherited Create(); + FItemClass := AItemClass; FList := TInterfaceList.Create(); end; @@ -186,7 +214,7 @@ end; procedure InitLibraryManager(); begin - LibraryManager := TwstModuleManager.Create(); + LibraryManager := TwstModuleManager.Create(TwstModule); end; initialization diff --git a/wst/trunk/library_protocol.pas b/wst/trunk/library_protocol.pas index f49a950cd..34db59c30 100644 --- a/wst/trunk/library_protocol.pas +++ b/wst/trunk/library_protocol.pas @@ -60,92 +60,6 @@ Type implementation uses binary_streamer; -type - - { TwstStream } - - TwstStream = class(TInterfacedObject,IwstStream) - private - FStream : TStream; - protected - function Read( - ABuffer : Pointer; - const ALenToRead : LongWord; - out AReadedLen : LongWord - ):LongInt; - function Write( - ABuffer : Pointer; - const ALenToWrite : LongWord; - out AWrittenLen : LongWord - ):LongInt; - function GetSize(out ASize : LongWord):LongInt; - function SetSize(const ANewSize : LongWord):LongInt; - function GetPosition(out APos : LongWord):LongWord; - function SetPosition(const ANewPos : LongWord):LongInt; - public - constructor Create(AStream : TStream); - end; - -{ TwstStream } - -function TwstStream.Read( - ABuffer : Pointer; - const ALenToRead : LongWord; - out AReadedLen : LongWord -): LongInt; -begin - try - AReadedLen := FStream.Read(ABuffer^,ALenToRead); - Result := RET_OK; - except - Result := RET_FALSE; - end; -end; - -function TwstStream.Write( - ABuffer : Pointer; - const ALenToWrite : LongWord; - out AWrittenLen : LongWord -): LongInt; -begin - try - AWrittenLen := FStream.Write(ABuffer^,ALenToWrite); - Result := RET_OK; - except - Result := RET_FALSE; - end; -end; - -function TwstStream.GetSize(out ASize: LongWord): LongInt; -begin - ASize := FStream.Size; - Result := RET_OK; -end; - -function TwstStream.SetSize(const ANewSize: LongWord): LongInt; -begin - FStream.Size := ANewSize; - Result := RET_OK; -end; - -function TwstStream.GetPosition(out APos: LongWord): LongWord; -begin - APos := FStream.Position; - Result := RET_OK; -end; - -function TwstStream.SetPosition(const ANewPos: LongWord): LongInt; -begin - FStream.Position := ANewPos; - Result := RET_OK; -end; - -constructor TwstStream.Create(AStream: TStream); -begin - Assert(Assigned(AStream)); - FStream := AStream; -end; - { TLIBTransport } procedure TLIBTransport.SetFileName(const AValue: string); diff --git a/wst/trunk/samples/apache_module/mod_wst.lpi b/wst/trunk/samples/apache_module/mod_wst.lpi index a4e06de39..63dadb6c7 100644 --- a/wst/trunk/samples/apache_module/mod_wst.lpi +++ b/wst/trunk/samples/apache_module/mod_wst.lpi @@ -7,7 +7,7 @@ - + @@ -24,121 +24,482 @@ - + - + - + - - - - + + + + - - - - - + + + - - - - - + + + - + - + - + - - - + - - - + - - - + - - - + - - - + - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -147,9 +508,10 @@ - + + - + diff --git a/wst/trunk/samples/apache_module/mod_wst.lpr b/wst/trunk/samples/apache_module/mod_wst.lpr index 9dfe8ac89..2b9672342 100644 --- a/wst/trunk/samples/apache_module/mod_wst.lpr +++ b/wst/trunk/samples/apache_module/mod_wst.lpr @@ -41,6 +41,7 @@ end; begin default_module_ptr := @wst_module; + wst_apache_binding.wst_module_ptr := default_module_ptr; FillChar(default_module_ptr^, SizeOf(default_module_ptr^), 0); STANDARD20_MODULE_STUFF(default_module_ptr^); with wst_module do @@ -48,5 +49,9 @@ begin name := MODULE_NAME; magic := MODULE_MAGIC_COOKIE; register_hooks := @RegisterHooks; + create_dir_config := @wst_create_dir_config; + cmds := WstCommandStructArray; end; + WstCommandStructArray[0].cmd_data := @WstConfigData^.BasePath; + FillChar(WstCommandStructArray[1],SizeOf(command_rec),#0); end. diff --git a/wst/trunk/samples/apache_module/wst_apache_binding.pas b/wst/trunk/samples/apache_module/wst_apache_binding.pas index 17d0788ef..2a42291c8 100644 --- a/wst/trunk/samples/apache_module/wst_apache_binding.pas +++ b/wst/trunk/samples/apache_module/wst_apache_binding.pas @@ -1,4 +1,27 @@ -{$DEFINE WST_DBG} +{$UNDEF WST_DBG} + +(*WST_BROKER enable the service brokering : + if enabled, this module just forwards the request to the + implementation libraries contained in the WstRootPath path. + WST load these libraries in the local file system folder + configured by the value of WstRootPath. + WstRootPath is a configuration directive which must be + in the wst "Location" scope. + Example : + + + SetHandler wst-handler + WstRootPath "C:/Programmes/lazarus/wst/trunk/samples/library_server/" + + + Services can then be invoked through the following addressing schema + http://127.0.0.1:8080/wst/services/lib_server/UserService + + lib_server : the library name ( without extension ) + UserService : the target service + wst/services : constant. +*) +{$DEFINE WST_BROKER} unit wst_apache_binding; @@ -17,25 +40,82 @@ const sWSDL = 'WSDL'; sHTTP_BINARY_CONTENT_TYPE = 'application/octet-stream'; sCONTENT_TYPE = 'Content-Type'; + + sWstRootPath = 'WstRootPath'; // The WST local file system path configure in apache + sWST_LIBRARY_EXTENSION = '.wml'; + +type + PWstConfigData = ^TWstConfigData; + TWstConfigData = record + Dir : PChar; + BasePath : PChar; + end; + +var + wst_module_ptr : Pmodule = nil; + WstConfigData : PWstConfigData = nil; + WstCommandStructArray : array[0..1] of command_rec = ( + ( name : sWstRootPath; + func : ( func_take1 : @ap_set_string_slot ); + cmd_data : ( nil {@WstConfigData^.BasePath} ); + req_override : OR_ALL; + args_how : TAKE1; + errmsg : 'usage : WstRootPath ' + LineEnding + ' path is the path to the WST root path.'; + ), + () + ); function wst_RequestHandler(r: Prequest_rec): Integer; + function wst_create_dir_config(p: Papr_pool_t; dir: PChar) : Pointer;cdecl; implementation uses base_service_intf, server_service_intf, server_service_imputils, - server_service_soap, server_binary_formatter, - metadata_repository, metadata_wsdl, DOM, XMLWrite, - - user_service_intf, user_service_intf_binder, user_service_intf_imp, + server_service_soap, server_binary_formatter, server_service_xmlrpc, + metadata_repository, metadata_wsdl, + imp_utils, binary_streamer, library_base_intf, library_imp_utils, + DOM, XMLWrite, metadata_service, metadata_service_binder, metadata_service_imp; +procedure wst_initialize(); +begin + RegisterStdTypes(); + Server_service_RegisterBinaryFormat(); + Server_service_RegisterSoapFormat(); + //Server_service_RegisterXmlRpcFormat(); + + RegisterWSTMetadataServiceImplementationFactory(); + Server_service_RegisterWSTMetadataServiceService(); +end; + +function wst_create_dir_config(p: Papr_pool_t; dir: PChar) : Pointer; cdecl; +begin + WstConfigData := PWstConfigData(apr_palloc(p,SizeOf(TWstConfigData))); + FillChar(WstConfigData^,SizeOf(TWstConfigData),#0); + WstConfigData^.Dir := apr_pstrdup(p,dir); + Result := WstConfigData; +end; + +function GetWstPath(): PChar;inline; +begin + Result := WstConfigData^.BasePath; +end; + type + PRequestArgument = ^TRequestArgument; + TRequestArgument = record + Name : shortstring; + Value : shortstring; + Next : PRequestArgument; + end; TRequestInfo = record - Root : string; - URI : string; - ContentType : string; - Buffer : string; - Argument : string; + InnerRequest : Pointer; + Root : string; + URI : string; + ContentType : string; + Buffer : string; + Arguments : string; + ArgList : PRequestArgument; end; TResponseInfo = record @@ -43,6 +123,52 @@ type ContentType : string; end; +function ParseArgs( + const APool : Papr_pool_t; + const AArgs : string; + const ASeparator : Char = '&' +) : PRequestArgument; +var + locBuffer, locArg : string; + locPrev, locTmpArg : PRequestArgument; +begin + Result := nil; + locBuffer := Trim(AArgs); + if not IsStrEmpty(locBuffer) then begin + locTmpArg := nil; + locPrev := nil; + while True do begin + locArg := GetToken(locBuffer,ASeparator); + if IsStrEmpty(locArg) then + Break; + locPrev := locTmpArg; + locTmpArg := PRequestArgument(apr_palloc(APool,SizeOf(TRequestArgument))); + FillChar(locTmpArg^,SizeOf(TRequestArgument),#0); + if ( Result = nil ) then begin + Result := locTmpArg; + end else begin + locPrev^.Next := locTmpArg; + end; + locTmpArg^.Name := GetToken(locArg,'='); + locTmpArg^.Value := locArg; + end; + end; +end; + +function FindArg(const AArgs : PRequestArgument; const AName : string) : PRequestArgument; +var + p : PRequestArgument; +begin + Result := nil; + p := AArgs; + while Assigned(p) do begin + if AnsiSameText(AName,AArgs^.Name) then begin + Result := p; + Break; + end; + p := p^.Next; + end; +end; procedure SaveStringToFile(const AStr,AFile:string;const AKeepExisting : Boolean); begin @@ -154,7 +280,7 @@ begin Result := '' + ''+ ''+ - 'The Web Service Toolkit generated Metadata table'+ + 'The Web Service Toolkit generated Metadata table XXXXX'+ ''+ '' + '

The following repositories has available. Click on the link to view the corresponding WSDL.

'+ @@ -233,7 +359,7 @@ begin AResponseInfo.ContentType := sHTTP_BINARY_CONTENT_TYPE else AResponseInfo.ContentType := ctntyp; - rqst := TRequestBuffer.Create(trgt,ctntyp,inStream,outStream,''); + rqst := TRequestBuffer.Create(trgt,ctntyp,inStream,outStream,ARequestInfo.ContentType); HandleServiceRequest(rqst); i := outStream.Size; if ( i > 0 ) then begin @@ -244,7 +370,7 @@ begin outStream.Free(); inStream.Free(); {$IFDEF WST_DBG} - SaveStringToFile('RequestInfo.ContentType=' + ARequestInfo.Argument + LineEnding,'c:\log.log',False); + SaveStringToFile('RequestInfo.ContentType=' + ARequestInfo.Arguments + LineEnding,'c:\log.log',False); {SaveStringToFile('RequestInfo.Buffer=' + ARequestInfo.Buffer + LineEnding,'E:\Inoussa\Sources\lazarus\wst\v0.3\tests\apache_module\log.log',True); SaveStringToFile('RequestInfo.URI=' + ARequestInfo.URI + LineEnding,'E:\Inoussa\Sources\lazarus\wst\v0.3\tests\apache_module\log.log',True); SaveStringToFile('ResponseInfo.ContentType=' + AResponseInfo.ContentType + LineEnding,'E:\Inoussa\Sources\lazarus\wst\v0.3\tests\apache_module\log.log',True); @@ -254,14 +380,94 @@ begin end; end; +const MAX_ERR_LEN = 500; +function ProcessServiceRequestLibrary( + const ARequestInfo : TRequestInfo; + out AResponseInfo : TResponseInfo +) : Boolean; +var + loc_path, ctntyp : string; + targetModuleName, targetFormat, targetService : string; + wrtr : IDataStore; + buffStream : TMemoryStream; + strBuff : string; + intfBuffer : IwstStream; + bl : LongInt; + targetModule : IwstModule; + handlerProc : TwstLibraryHandlerFunction; + pArg : PRequestArgument; + i : Integer; +begin + try + FillChar(AResponseInfo,SizeOf(TResponseInfo),#0); + loc_path := ARequestInfo.URI; + targetModuleName := ExtractNextPathElement(loc_path); + Result := False; + targetModule := LibraryManager.Get(GetWstPath() + targetModuleName + sWST_LIBRARY_EXTENSION); + handlerProc := TwstLibraryHandlerFunction(targetModule.GetProc(WST_LIB_HANDLER)); + if not Assigned(handlerProc) then + Exit; + targetService := ExtractNextPathElement(loc_path); + if AnsiSameText(sWSDL,targetService) then + Exit; + pArg := FindArg(ARequestInfo.ArgList,'format'); + if Assigned(pArg) then + targetFormat := pArg^.Value; + if IsStrEmpty(targetFormat) then + targetFormat := ARequestInfo.ContentType; + buffStream := TMemoryStream.Create(); + try + wrtr := CreateBinaryWriter(buffStream); + wrtr.WriteInt32S(0); + wrtr.WriteStr(targetService); + wrtr.WriteStr(ARequestInfo.ContentType); + wrtr.WriteStr(targetFormat); + wrtr.WriteStr(ARequestInfo.Buffer); + buffStream.Position := 0; + wrtr.WriteInt32S(buffStream.Size-4); + + buffStream.Position := 0; + intfBuffer := TwstStream.Create(buffStream); + bl := MAX_ERR_LEN; + strBuff := StringOfChar(#0,bl); + i := handlerProc(intfBuffer,Pointer(strBuff),bl); + if ( i <> RET_OK ) then + raise Exception.CreateFmt('Library server error :'#13'Code : %d'#13'Message : %s',[i,strBuff]); + + if AnsiSameText(sBINARY_CONTENT_TYPE,ARequestInfo.ContentType) then + AResponseInfo.ContentType := sHTTP_BINARY_CONTENT_TYPE + else + AResponseInfo.ContentType := ARequestInfo.ContentType; + buffStream.Position := 0; + if ( buffStream.Size > 0 ) then begin + SetLength(AResponseInfo.ContentText,buffStream.Size); + buffStream.Read(AResponseInfo.ContentText[1],Length(AResponseInfo.ContentText)); + end else begin + AResponseInfo.ContentText := ''; + end; + finally + buffStream.Free(); + end; + + Result := True; + except + on e : Exception do begin + Result := False; + ap_log_rerror(PCHAR('wst_apache_binding'),392,APLOG_ERR,0,Prequest_rec(ARequestInfo.InnerRequest),PCHAR(e.Message),[]); + end; + end; +end; + function wst_RequestHandler(r: Prequest_rec): Integer; function FillRequestInfo(var ARequestInfo : TRequestInfo):Integer; begin + ARequestInfo.InnerRequest := r; ARequestInfo.ContentType := apr_table_get(r^.headers_in,sCONTENT_TYPE); ARequestInfo.Root := ap_get_server_name(r) + sSEPARATOR + sWST_ROOT + sSEPARATOR; ARequestInfo.URI := r^.uri; - ARequestInfo.Argument := r^.args; + ARequestInfo.Arguments := r^.args; + ARequestInfo.ArgList := ParseArgs(r^.pool,ARequestInfo.Arguments); Result := ReadBuffer(r,ARequestInfo.Buffer); end; @@ -279,8 +485,14 @@ begin try if AnsiSameText(sSERVICES_PREFIXE,ExtractNextPathElement(loc_RequestInfo.URI)) then begin + +{$IFDEF WST_BROKER} + if not ProcessServiceRequestLibrary(loc_RequestInfo,loc_ResponseInfo) then + ProcessWSDLRequest(loc_RequestInfo,loc_ResponseInfo); +{$ELSE} if not ProcessServiceRequest(loc_RequestInfo,loc_ResponseInfo) then ProcessWSDLRequest(loc_RequestInfo,loc_ResponseInfo); +{$ENDIF} end else begin ProcessWSDLRequest(loc_RequestInfo,loc_ResponseInfo); end; @@ -294,7 +506,6 @@ begin ap_rputs(PCHAR(loc_ResponseInfo.ContentText), r); end; Result := OK; - Exit; except on e : Exception do begin ap_set_content_type(r, 'text/html'); @@ -307,14 +518,6 @@ begin end; initialization - RegisterStdTypes(); - Server_service_RegisterBinaryFormat(); - Server_service_RegisterSoapFormat(); - - RegisterUserServiceImplementationFactory(); - Server_service_RegisterUserServiceService(); - - RegisterWSTMetadataServiceImplementationFactory(); - Server_service_RegisterWSTMetadataServiceService(); - + wst_initialize(); + end. diff --git a/wst/trunk/samples/user_client_console/user_client_console.lpi b/wst/trunk/samples/user_client_console/user_client_console.lpi index b2cfee300..37eb02192 100644 --- a/wst/trunk/samples/user_client_console/user_client_console.lpi +++ b/wst/trunk/samples/user_client_console/user_client_console.lpi @@ -30,15 +30,15 @@ - + - - + + - + @@ -46,8 +46,8 @@ - - + + @@ -55,8 +55,8 @@ - - + + @@ -64,8 +64,8 @@ - - + + @@ -73,8 +73,8 @@ - - + + @@ -94,10 +94,10 @@ - - + + - + @@ -142,8 +142,8 @@ - - + + @@ -162,9 +162,11 @@ - - - + + + + + @@ -177,8 +179,8 @@ - - + + @@ -194,15 +196,15 @@ - + - - + + @@ -306,8 +308,8 @@ - - + + @@ -320,10 +322,10 @@ - - + + - + @@ -331,8 +333,8 @@ - - + + @@ -340,8 +342,8 @@ - - + + @@ -354,17 +356,26 @@ + + + + + + + + + + + + + + + + + + - - - - - - - - - - + diff --git a/wst/trunk/samples/user_client_console/user_client_console.pas b/wst/trunk/samples/user_client_console/user_client_console.pas index 1b1dc887c..e9dceb758 100644 --- a/wst/trunk/samples/user_client_console/user_client_console.pas +++ b/wst/trunk/samples/user_client_console/user_client_console.pas @@ -144,8 +144,8 @@ const ADDRESS_MAP : array[TTransportType] of string = ( 'LIB:FileName=..\library_server\lib_server.dll;target=UserService', //'TCP:Address=172.16.82.31;Port=1234;target=UserService', 'TCP:Address=127.0.0.1;Port=1234;target=UserService', - //'http:Address=http://127.0.0.1:8080/wst/services/UserService/?format=soap' - 'http:Address=http://127.0.0.1:8000/services/UserService' + 'http:Address=http://127.0.0.1:8888/wst/services/lib_server/UserService' + //'http:Address=http://127.0.0.1:8000/services/UserService' ); FORMAT_MAP : array[TFormatType] of string =( 'binary', 'soap', 'xmlrpc' ); var diff --git a/wst/trunk/samples/user_service_intf_imp.pas b/wst/trunk/samples/user_service_intf_imp.pas index 388f3b8c5..a5871f294 100644 --- a/wst/trunk/samples/user_service_intf_imp.pas +++ b/wst/trunk/samples/user_service_intf_imp.pas @@ -220,9 +220,9 @@ end; initialization FUserList := TObjectList.Create(True); FUserCursor := TObjectListCursor.Create(FUserList); - if FileExists(sDATA_FILE_NAME) then + {if FileExists(sDATA_FILE_NAME) then FillDataFromFile(sDATA_FILE_NAME) - else + else} FillSampleData(); finalization diff --git a/wst/trunk/tests/test_suite/test_utilities.pas b/wst/trunk/tests/test_suite/test_utilities.pas index ac969aaad..e78e05689 100644 --- a/wst/trunk/tests/test_suite/test_utilities.pas +++ b/wst/trunk/tests/test_suite/test_utilities.pas @@ -22,7 +22,8 @@ uses TestFrameWork, {$ENDIF} TypInfo, - base_service_intf, server_service_intf; + base_service_intf, server_service_intf, + library_imp_utils; type @@ -102,7 +103,24 @@ type published procedure POOLED_Discard(); end; + + { TwstModuleNotLoad } + TwstModuleNotLoad = class(TwstModule,IInterface,IwstModule) + protected + procedure Load(const ADoLoad : Boolean);override; + end; + + { TTest_TwstModuleManager } + + TTest_TwstModuleManager = class(TTestCase) + published + function Get(const AFileName : string):IwstModule; + procedure Clear(); + function GetCount() : PtrInt; + function GetItem(const AIndex : PtrInt) : IwstModule; + end; + implementation { TTestClass } @@ -585,19 +603,140 @@ begin CheckEquals(TSimpleFactoryItem_B,b.GetItemClass()); end; +{ TwstModuleNotLoad } + +procedure TwstModuleNotLoad.Load(const ADoLoad: Boolean); +begin + //; +end; + +{ TTest_TwstModuleManager } + +function TTest_TwstModuleManager.Get(const AFileName: string): IwstModule; +const C = 10; +var + locObj : IwstModuleManager; + locModule : IwstModule; + i, j, k: Integer; + ok : Boolean; + locName : string; +begin + locObj := TwstModuleManager.Create(TwstModuleNotLoad); + + for i := 0 to Pred(C) do begin + locObj.Get(Format('lib_%d',[i])); + end; + + for i := 0 to Pred(C) do begin + ok := False; + locName := Format('lib_%d',[i]); + for j := 0 to Pred(locObj.GetCount()) do begin + locModule := locObj.GetItem(j); + if AnsiSameText(locName, locModule.GetFileName()) then begin + ok := True; + k := j + 1; + Break; + end; + end; + Check(ok); + for j := k to Pred(locObj.GetCount()) do begin + locModule := locObj.GetItem(j); + if AnsiSameText(locName, locModule.GetFileName()) then begin + Check(False,'Duplicated items : ' + locName); + end; + end; + end; +end; + +procedure TTest_TwstModuleManager.Clear(); +const C = 12; +var + locObj : IwstModuleManager; + i : Integer; +begin + locObj := TwstModuleManager.Create(TwstModuleNotLoad); + locObj.Clear(); + CheckEquals(0,locObj.GetCount()); + for i := 0 to Pred(C) do begin + locObj.Get(Format('lib_%d',[i])); + end; + CheckEquals(C,locObj.GetCount()); + locObj.Clear(); + CheckEquals(0,locObj.GetCount()); +end; + +function TTest_TwstModuleManager.GetCount(): PtrInt; +const C = 10; +var + locObj : IwstModuleManager; + i : Integer; +begin + locObj := TwstModuleManager.Create(TwstModuleNotLoad); + CheckEquals(0,locObj.GetCount()); + CheckEquals(0,locObj.GetCount()); + for i := 0 to Pred(C) do begin + CheckEquals(i,locObj.GetCount(),'before Add'); + locObj.Get(Format('lib_%d',[i])); + CheckEquals(i + 1,locObj.GetCount(),'after Add'); + end; + CheckEquals(C,locObj.GetCount()); +end; + +function TTest_TwstModuleManager.GetItem(const AIndex: PtrInt): IwstModule; +const C = 10; +var + locObj : IwstModuleManager; + locModule : IwstModule; + i : Integer; + ok : Boolean; +begin + locObj := TwstModuleManager.Create(TwstModuleNotLoad); + ok := False; + try + locObj.GetItem(0); + except + on e : Exception do begin + ok := True; + end; + end; + Check(ok); + + ok := False; + try + locObj.GetItem(1); + except + on e : Exception do begin + ok := True; + end; + end; + Check(ok); + + for i := 0 to Pred(C) do begin + locObj.Get(Format('lib_%d',[i])); + end; + + for i := 0 to Pred(C) do begin + locModule := locObj.GetItem(i); + CheckEquals(Format('lib_%d',[i]), locModule.GetFileName()); + end; + + ok := False; + try + locObj.GetItem(C + 1); + except + on e : Exception do begin + ok := True; + end; + end; + Check(ok); +end; + initialization -{$IFDEF FPC} - RegisterTest(TTest_TIntfPool); - RegisterTest(TTest_TSimpleItemFactoryEx); - RegisterTest(TTest_TImplementationFactory); - RegisterTest(TTest_TIntfPoolItem); - RegisterTest(TTest_TImplementationFactory); -{$ELSE} - RegisterTest(TTest_TIntfPool.Suite); - RegisterTest(TTest_TSimpleItemFactoryEx.Suite); - RegisterTest(TTest_TImplementationFactory.Suite); - RegisterTest(TTest_TIntfPoolItem.Suite); - RegisterTest(TTest_TImplementationFactory.Suite); -{$ENDIF} + RegisterTest('Utilities',TTest_TIntfPool.Suite); + RegisterTest('Utilities',TTest_TSimpleItemFactoryEx.Suite); + RegisterTest('Utilities',TTest_TImplementationFactory.Suite); + RegisterTest('Utilities',TTest_TIntfPoolItem.Suite); + RegisterTest('Utilities',TTest_TImplementationFactory.Suite); + RegisterTest('Utilities',TTest_TwstModuleManager.Suite); end. diff --git a/wst/trunk/tests/test_suite/wst_test_suite.lpi b/wst/trunk/tests/test_suite/wst_test_suite.lpi index f2814f23a..3ae6b5d0d 100644 --- a/wst/trunk/tests/test_suite/wst_test_suite.lpi +++ b/wst/trunk/tests/test_suite/wst_test_suite.lpi @@ -7,7 +7,7 @@ - + @@ -27,7 +27,7 @@ - + @@ -251,7 +251,7 @@ - + @@ -318,10 +318,10 @@ - - + + - + @@ -414,7 +414,7 @@ - + @@ -450,7 +450,7 @@ - + @@ -459,7 +459,7 @@ - + @@ -468,7 +468,7 @@ - + @@ -504,7 +504,7 @@ - + @@ -519,7 +519,7 @@ - + @@ -548,7 +548,7 @@ - + @@ -557,7 +557,7 @@ - + @@ -566,7 +566,7 @@ - + @@ -576,7 +576,7 @@ - + @@ -585,7 +585,7 @@ - + @@ -608,16 +608,123 @@ + + + + + + + + + + + + + + + - + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +