Jelajahi Sumber

* Rest module for in IDE

git-svn-id: trunk@41467 -
michael 6 tahun lalu
induk
melakukan
98a30de010

+ 1 - 0
.gitattributes

@@ -3469,6 +3469,7 @@ packages/fcl-web/src/restbridge/sqldbrestdata.pp svneol=native#text/plain
 packages/fcl-web/src/restbridge/sqldbrestini.pp svneol=native#text/plain
 packages/fcl-web/src/restbridge/sqldbrestio.pp svneol=native#text/plain
 packages/fcl-web/src/restbridge/sqldbrestjson.pp svneol=native#text/plain
+packages/fcl-web/src/restbridge/sqldbrestmodule.pp svneol=native#text/plain
 packages/fcl-web/src/restbridge/sqldbrestschema.pp svneol=native#text/plain
 packages/fcl-web/src/restbridge/sqldbrestxml.pp svneol=native#text/plain
 packages/fcl-web/src/webdata/Makefile svneol=native#text/plain

+ 6 - 0
packages/fcl-web/fpmake.pp

@@ -373,6 +373,12 @@ begin
       AddUnit('sqldbrestschema');
       AddUnit('sqldbrestconst');
       end;
+    T:=P.Targets.AddUnit('sqldbrestmodule.pp');
+    With T.Dependencies do  
+      begin
+      AddUnit('sqldbrestbridge');
+      AddUnit('sqldbrestconst');
+      end;
     
 {$ifndef ALLPACKAGES}
     Run;

+ 1 - 0
packages/fcl-web/src/restbridge/sqldbrestconst.pp

@@ -44,6 +44,7 @@ Resourcestring
   SErrMissingDocumentRoot = 'Missing document root';
   SErrInvalidCDSMissingElement = 'Invalid CDS Data packet: missing %s element';
   SErrNoResourceDataFound = 'Failed to find resource data in input';
+  SErrNoRESTDispatcher = 'No REST bridge dispatcher assigned to handle request!';
 
 Const
   DefaultAuthenticationRealm = 'REST API Server';

+ 78 - 0
packages/fcl-web/src/restbridge/sqldbrestmodule.pp

@@ -0,0 +1,78 @@
+unit sqldbrestmodule;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, httpdefs, fphttp, sqldbrestbridge;
+
+Type
+
+  { TSQLDBRestModule }
+
+  TSQLDBRestModule = Class (TSessionHTTPModule)
+  private
+    FDispatcher: TSQLDBRestDispatcher;
+    procedure SetDispatcher(AValue: TSQLDBRestDispatcher);
+  Protected
+    Procedure Notification(AComponent: TComponent; Operation: TOperation); override;
+    Function FindDispatcher : TSQLDBRestDispatcher; virtual;
+  Public
+    constructor Create(AOwner: TComponent); override;
+    Procedure HandleRequest(ARequest : TRequest; AResponse : TResponse); override;
+  Published
+    Property Dispatcher : TSQLDBRestDispatcher Read FDispatcher Write SetDispatcher;
+    Property Kind;
+  end;
+
+implementation
+
+uses sqldbrestconst;
+
+{ TSQLDBRestModule }
+
+procedure TSQLDBRestModule.SetDispatcher(AValue: TSQLDBRestDispatcher);
+begin
+  if FDispatcher=AValue then Exit;
+  if Assigned(Dispatcher) then
+    FDispatcher.RemoveFreeNotification(Self);
+  FDispatcher:=AValue;
+  if Assigned(Dispatcher) then
+    FDispatcher.FreeNotification(Self);
+end;
+
+procedure TSQLDBRestModule.Notification(AComponent: TComponent; Operation: TOperation);
+begin
+  inherited Notification(AComponent, Operation);
+  if Operation=opRemove then
+    if AComponent=FDispatcher then
+      FDispatcher:=Nil;
+end;
+
+function TSQLDBRestModule.FindDispatcher: TSQLDBRestDispatcher;
+begin
+  Result:=Dispatcher;
+end;
+
+constructor TSQLDBRestModule.Create(AOwner: TComponent);
+begin
+  Kind:=wkOneShot;
+  inherited Create(AOwner);
+end;
+
+procedure TSQLDBRestModule.HandleRequest(ARequest: TRequest; AResponse: TResponse);
+
+Var
+  Disp : TSQLDBRestDispatcher;
+
+begin
+  Disp:=FindDispatcher;
+  If assigned(Disp) then
+    Disp.HandleRequest(aRequest,aResponse)
+  else
+    Raise EHTTP.Create(SErrNoRESTDispatcher);
+end;
+
+end.
+