{ This file is part of the Web Service Toolkit Copyright (c) 2006 by Inoussa OUEDRAOGO This file is provide under modified LGPL licence ( the files COPYING.modifiedLGPL and COPYING.LGPL). This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. } unit app_object; {$mode objfpc}{$H+} interface uses Classes, SysUtils, IdCustomHTTPServer, IdHTTPServer, IdContext, IdSocketHandle; type { TwstWebApplication } TwstWebApplication = class(TObject) private FHTTPServerObject: TIdHTTPServer; FRootAddress : string; private function GenerateWSDLTable():string; procedure ProcessWSDLRequest( AContext : TIdContext; ARequestInfo : TIdHTTPRequestInfo; AResponseInfo : TIdHTTPResponseInfo; var APath : string ); procedure ProcessServiceRequest( AContext : TIdContext; ARequestInfo : TIdHTTPRequestInfo; AResponseInfo : TIdHTTPResponseInfo; var APath : string ); private procedure Handler_CommandGet( AContext : TIdContext; ARequestInfo : TIdHTTPRequestInfo; AResponseInfo : TIdHTTPResponseInfo ); public constructor Create(); destructor Destroy(); override; procedure Display(const AMsg : string); end; implementation uses base_service_intf, server_service_intf, server_service_imputils, server_service_soap, server_binary_formatter, metadata_repository, metadata_wsdl, DOM, XMLWrite, calculator, calculator_binder, calculator_imp, metadata_service, metadata_service_binder, metadata_service_imp; const sSEPARATOR = '/'; sSERVICES_PREFIXE = 'services'; sWSDL = 'WSDL'; function ExtractNextPathElement(var AFullPath : string):string; var i : SizeInt; begin Result := ''; if ( Length(AFullPath) > 0 ) then begin while ( Length(AFullPath) > 0 ) and ( AFullPath[1] = sSEPARATOR ) do begin Delete(AFullPath,1,1); end; i := Pos(sSEPARATOR,AFullPath); if ( i < 1 ) then begin Result := AFullPath; AFullPath := ''; end else begin Result := Copy(AFullPath,1,Pred(i)); Delete(AFullPath,1,i); end; end; end; function GetWSDL(const ARepName, ARootAddress: shortstring):string; var strm : TMemoryStream; rep : PServiceRepository; doc :TXMLDocument; i : SizeInt; s : string; begin Result := ''; rep := nil; doc := Nil; i := GetModuleMetadataMngr().IndexOfName(ARepName); if ( i < 0 ) then Exit; strm := TMemoryStream.Create(); try s := GetModuleMetadataMngr().GetRepositoryName(i); GetModuleMetadataMngr().LoadRepositoryName(s,ARootAddress,rep); //if ( GetModuleMetadataMngr().LoadRepositoryName(s,rep) > 0 ) then //rep^.namespace := 'urn:wst'; strm.Clear(); doc := TXMLDocument.Create(); GenerateWSDL(rep,doc); WriteXMLFile(doc,strm); i := strm.Size; if ( i > 0 ) then begin SetLength(Result,i); Move(strm.memory^,Result[1],i); end; finally doc.Free(); strm.Free(); GetModuleMetadataMngr().ClearRepository(rep); end; end; { TwstWebApplication } function TwstWebApplication.GenerateWSDLTable(): string; var r : IModuleMetadataMngr; i : Integer; begin r := GetModuleMetadataMngr(); Result := '' + '
'+ 'The following repositories has available. Click on the link to view the corresponding WSDL.
'+ '' + Format('',[sSEPARATOR+sSERVICES_PREFIXE+sSEPARATOR+sWSDL+sSEPARATOR+r.GetRepositoryName(i)])+ r.GetRepositoryName(i) + ''+ ' | '; Result := Result + '