Skip to content

Commit

Permalink
feature: The demo 17.Parameters now shows how to get the exceptions g…
Browse files Browse the repository at this point in the history
…enerated before they are serialized and sent to the client
  • Loading branch information
paolo-rossi committed Feb 21, 2019
1 parent a303e33 commit 3aea797
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
1 change: 0 additions & 1 deletion Demos/17.Parameters/DemoParameters.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ uses
Forms,
Server.Forms.Main in 'Server.Forms.Main.pas' {MainForm},
Server.Resources in 'Server.Resources.pas',
WiRL.Schemas.Swagger in '..\..\Source\Extensions\WiRL.Schemas.Swagger.pas',
Server.Entities in 'Server.Entities.pas';

{$R *.res}
Expand Down
1 change: 0 additions & 1 deletion Demos/17.Parameters/DemoParameters.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
<Form>MainForm</Form>
</DCCReference>
<DCCReference Include="Server.Resources.pas"/>
<DCCReference Include="..\..\Source\Extensions\WiRL.Schemas.Swagger.pas"/>
<DCCReference Include="Server.Entities.pas"/>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
Expand Down
1 change: 1 addition & 0 deletions Demos/17.Parameters/Server.Entities.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ TRecordParam = record
end;

TArrayParam = TArray<TRecordParam>;
TArrayInt = TArray<Integer>;


implementation
Expand Down
17 changes: 17 additions & 0 deletions Demos/17.Parameters/Server.Forms.Main.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ object MainForm: TMainForm
OldCreateOrder = False
OnClose = FormClose
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 13
object TopPanel: TPanel
Expand Down Expand Up @@ -55,6 +56,22 @@ object MainForm: TMainForm
Text = '8080'
end
end
object memoLog: TMemo
Left = 0
Top = 73
Width = 554
Height = 216
Align = alClient
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Consolas'
Font.Style = []
ParentFont = False
TabOrder = 1
ExplicitTop = 79
ExplicitHeight = 210
end
object MainActionList: TActionList
Left = 104
Top = 96
Expand Down
43 changes: 34 additions & 9 deletions Demos/17.Parameters/Server.Forms.Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ interface
Vcl.StdCtrls, Vcl.ExtCtrls, System.Diagnostics, System.Actions, IdContext,

WiRL.Persistence.Types,
WiRL.Core.Application,
WiRL.Core.Engine,
WiRL.http.Server,
WiRL.http.Server.Indy;

type

TExceptionListener = class(TInterfacedObject, IWiRLHandleExceptionListener)
procedure HandleException(const ASender: TWiRLEngine; const AApplication: TWiRLApplication; E: Exception);
end;

TMainForm = class(TForm)
TopPanel: TPanel;
StartButton: TButton;
Expand All @@ -30,14 +36,17 @@ TMainForm = class(TForm)
StopServerAction: TAction;
PortNumberEdit: TEdit;
Label1: TLabel;
memoLog: TMemo;
procedure FormDestroy(Sender: TObject);
procedure StartServerActionExecute(Sender: TObject);
procedure StartServerActionUpdate(Sender: TObject);
procedure StopServerActionExecute(Sender: TObject);
procedure StopServerActionUpdate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
RESTServer: TWiRLServer;
FRESTServer: TWiRLServer;
FListener: IWiRLHandleExceptionListener;
public
{ Public declarations }
end;
Expand All @@ -49,17 +58,25 @@ implementation

{$R *.dfm}

procedure TMainForm.FormDestroy(Sender: TObject);
begin
FListener := nil;
FRESTServer.Free;
end;

procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
StopServerAction.Execute;
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
RESTServer := TWiRLServer.Create(Self);
FRESTServer := TWiRLServer.Create(Self);
FListener := TExceptionListener.Create;

RESTServer.AddEngine<TWiRLEngine>('/rest')
FRESTServer.AddEngine<TWiRLEngine>('/rest')
.SetEngineName('RESTEngine')
.AddSubscriber(FListener)
.AddApplication('/app')
.SetResources('*')
.SetFilters('*')
Expand All @@ -72,24 +89,32 @@ procedure TMainForm.FormCreate(Sender: TObject);

procedure TMainForm.StartServerActionExecute(Sender: TObject);
begin
RESTServer.Port := StrToIntDef(PortNumberEdit.Text, 8080);
if not RESTServer.Active then
RESTServer.Active := True;
FRESTServer.Port := StrToIntDef(PortNumberEdit.Text, 8080);
if not FRESTServer.Active then
FRESTServer.Active := True;
end;

procedure TMainForm.StartServerActionUpdate(Sender: TObject);
begin
StartServerAction.Enabled := not Assigned(RESTServer) or not RESTServer.Active;
StartServerAction.Enabled := not Assigned(FRESTServer) or not FRESTServer.Active;
end;

procedure TMainForm.StopServerActionExecute(Sender: TObject);
begin
RESTServer.Active := False;
FRESTServer.Active := False;
end;

procedure TMainForm.StopServerActionUpdate(Sender: TObject);
begin
StopServerAction.Enabled := Assigned(RESTServer) and RESTServer.Active;
StopServerAction.Enabled := Assigned(FRESTServer) and FRESTServer.Active;
end;

{ TExceptionListener }

procedure TExceptionListener.HandleException(const ASender: TWiRLEngine;
const AApplication: TWiRLApplication; E: Exception);
begin
MainForm.memoLog.Lines.Add(E.Message);
end;

end.

0 comments on commit 3aea797

Please sign in to comment.