Skip to content

Commit

Permalink
Added CreateRequest and CreateNotification methods on JSONRPCExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Jul 28, 2024
1 parent 7e55bfa commit d932857
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 73 deletions.
19 changes: 5 additions & 14 deletions samples/jsonrpc/async_client/MainClientFormU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,7 @@ procedure TMainForm.btnNotificationClick(Sender: TObject);
var
lNotification: IJSONRPCNotification;
begin
lNotification := TJSONRPCNotification.Create;
lNotification.Method := 'dosomething';
lNotification := FExecutor.CreateNotification('dosomething');
FExecutor.ExecuteNotificationAsync('/jsonrpc', lNotification);
end;

Expand Down Expand Up @@ -433,9 +432,7 @@ procedure TMainForm.btnReverseStringClick(Sender: TObject);
var
lReq: IJSONRPCRequest;
begin
lReq := TJSONRPCRequest.Create;
lReq.Method := 'reversestring';
lReq.RequestID := Random(1000);
lReq := FExecutor.CreateRequest('reversestring', Random(1000));
lReq.Params.AddByName('aString', edtReverseString.Text);
lReq.Params.AddByName('aUpperCase', CheckBox1.Checked);
FExecutor.ExecuteRequestAsync('/jsonrpc', lReq,
Expand Down Expand Up @@ -517,9 +514,7 @@ procedure TMainForm.btnSubtractClick(Sender: TObject);
lReq: IJSONRPCRequest;
begin
fExecutorAsync := TMVCJSONRPCExecutor.Create('http://localhost:8080');
lReq := TJSONRPCRequest.Create;
lReq.Method := 'subtract';
lReq.RequestID := Random(1000);
lReq := fExecutorAsync.CreateRequest('subtract', Random(1000));
lReq.Params.Add(StrToInt(edtValue1.Text));
lReq.Params.Add(StrToInt(edtValue2.Text));
fExecutorAsync
Expand All @@ -534,9 +529,7 @@ procedure TMainForm.btnSubtractWithNamedParamsClick(Sender: TObject);
var
lReq: IJSONRPCRequest;
begin
lReq := TJSONRPCRequest.Create;
lReq.Method := 'subtract';
lReq.RequestID := Random(1000);
lReq := fExecutor.CreateRequest('subtract', Random(1000));
lReq.Params.AddByName('Value1', StrToInt(Edit1.Text));
lReq.Params.AddByName('Value2', StrToInt(Edit2.Text));
FExecutor.ExecuteRequestAsync('/jsonrpc', lReq,
Expand All @@ -551,9 +544,7 @@ procedure TMainForm.btnWithJSONClick(Sender: TObject);
lPerson: TJsonObject;
lReq: IJSONRPCRequest;
begin
lReq := TJSONRPCRequest.Create;
lReq.Method := 'SaveObjectWithJSON';
lReq.RequestID := 1234;
lReq := FExecutor.CreateRequest('SaveObjectWithJSON', 1234);
lPerson := TJsonObject.Create;
lReq.Params.Add(lPerson, pdTJDOJsonObject);
lPerson.S['StringProp'] := 'Hello World';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
program jsonrpcclientwithobjects_async;
program jsonrpcclient_async;

uses
Vcl.Forms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>1</TargetedPlatforms>
<AppType>Application</AppType>
<MainSource>jsonrpcclientwithobjects_async.dpr</MainSource>
<ProjectName Condition="'$(ProjectName)'==''">jsonrpcclientwithobjects_async</ProjectName>
<MainSource>jsonrpcclient_async.dpr</MainSource>
<ProjectName Condition="'$(ProjectName)'==''">jsonrpcclient_async</ProjectName>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
Expand Down Expand Up @@ -58,7 +58,7 @@
<Icon_MainIcon>$(BDS)\bin\delphi_PROJECTICON.ico</Icon_MainIcon>
<UWP_DelphiLogo44>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png</UWP_DelphiLogo44>
<UWP_DelphiLogo150>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png</UWP_DelphiLogo150>
<SanitizedProjectName>jsonrpcclientwithobjects_async</SanitizedProjectName>
<SanitizedProjectName>jsonrpcclient_async</SanitizedProjectName>
<VerInfo_Locale>1040</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
</PropertyGroup>
Expand Down Expand Up @@ -132,17 +132,17 @@
<BorlandProject>
<Delphi.Personality>
<Source>
<Source Name="MainSource">jsonrpcclientwithobjects_async.dpr</Source>
<Source Name="MainSource">jsonrpcclient_async.dpr</Source>
</Source>
<Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k280.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dclofficexp280.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
</Excluded_Packages>
</Delphi.Personality>
<Deployment Version="4">
<DeployFile LocalName="Win32\Debug\jsonrpcclientwithobjects_async.exe" Configuration="Debug" Class="ProjectOutput">
<DeployFile LocalName="..\bin\jsonrpcclient_async.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>jsonrpcclientwithobjects_async.exe</RemoteName>
<RemoteName>jsonrpcclient_async.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
Expand Down
48 changes: 24 additions & 24 deletions samples/jsonrpc/jsonrpc_group.groupproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<ProjectGuid>{AFDF54C5-5184-4A5F-A230-FB7F37B3B2F0}</ProjectGuid>
</PropertyGroup>
<ItemGroup>
<Projects Include="jsonrpcserver\jsonrpcserverwithobjects.dproj">
<Projects Include="jsonrpcserver\jsonrpcserver.dproj">
<Dependencies/>
</Projects>
<Projects Include="sync_client\jsonrpcclientwithobjects_sync.dproj">
<Projects Include="sync_client\jsonrpcclient_sync.dproj">
<Dependencies/>
</Projects>
<Projects Include="async_client\jsonrpcclientwithobjects_async.dproj">
<Projects Include="async_client\jsonrpcclient_async.dproj">
<Dependencies/>
</Projects>
</ItemGroup>
Expand All @@ -20,41 +20,41 @@
<Default.Personality/>
</BorlandProject>
</ProjectExtensions>
<Target Name="jsonrpcserverwithobjects">
<MSBuild Projects="jsonrpcserver\jsonrpcserverwithobjects.dproj"/>
<Target Name="jsonrpcserver">
<MSBuild Projects="jsonrpcserver\jsonrpcserver.dproj"/>
</Target>
<Target Name="jsonrpcserverwithobjects:Clean">
<MSBuild Projects="jsonrpcserver\jsonrpcserverwithobjects.dproj" Targets="Clean"/>
<Target Name="jsonrpcserver:Clean">
<MSBuild Projects="jsonrpcserver\jsonrpcserver.dproj" Targets="Clean"/>
</Target>
<Target Name="jsonrpcserverwithobjects:Make">
<MSBuild Projects="jsonrpcserver\jsonrpcserverwithobjects.dproj" Targets="Make"/>
<Target Name="jsonrpcserver:Make">
<MSBuild Projects="jsonrpcserver\jsonrpcserver.dproj" Targets="Make"/>
</Target>
<Target Name="jsonrpcclientwithobjects_sync">
<MSBuild Projects="sync_client\jsonrpcclientwithobjects_sync.dproj"/>
<Target Name="jsonrpcclient_sync">
<MSBuild Projects="sync_client\jsonrpcclient_sync.dproj"/>
</Target>
<Target Name="jsonrpcclientwithobjects_sync:Clean">
<MSBuild Projects="sync_client\jsonrpcclientwithobjects_sync.dproj" Targets="Clean"/>
<Target Name="jsonrpcclient_sync:Clean">
<MSBuild Projects="sync_client\jsonrpcclient_sync.dproj" Targets="Clean"/>
</Target>
<Target Name="jsonrpcclientwithobjects_sync:Make">
<MSBuild Projects="sync_client\jsonrpcclientwithobjects_sync.dproj" Targets="Make"/>
<Target Name="jsonrpcclient_sync:Make">
<MSBuild Projects="sync_client\jsonrpcclient_sync.dproj" Targets="Make"/>
</Target>
<Target Name="jsonrpcclientwithobjects_async">
<MSBuild Projects="async_client\jsonrpcclientwithobjects_async.dproj"/>
<Target Name="jsonrpcclient_async">
<MSBuild Projects="async_client\jsonrpcclient_async.dproj"/>
</Target>
<Target Name="jsonrpcclientwithobjects_async:Clean">
<MSBuild Projects="async_client\jsonrpcclientwithobjects_async.dproj" Targets="Clean"/>
<Target Name="jsonrpcclient_async:Clean">
<MSBuild Projects="async_client\jsonrpcclient_async.dproj" Targets="Clean"/>
</Target>
<Target Name="jsonrpcclientwithobjects_async:Make">
<MSBuild Projects="async_client\jsonrpcclientwithobjects_async.dproj" Targets="Make"/>
<Target Name="jsonrpcclient_async:Make">
<MSBuild Projects="async_client\jsonrpcclient_async.dproj" Targets="Make"/>
</Target>
<Target Name="Build">
<CallTarget Targets="jsonrpcserverwithobjects;jsonrpcclientwithobjects_sync;jsonrpcclientwithobjects_async"/>
<CallTarget Targets="jsonrpcserver;jsonrpcclient_sync;jsonrpcclient_async"/>
</Target>
<Target Name="Clean">
<CallTarget Targets="jsonrpcserverwithobjects:Clean;jsonrpcclientwithobjects_sync:Clean;jsonrpcclientwithobjects_async:Clean"/>
<CallTarget Targets="jsonrpcserver:Clean;jsonrpcclient_sync:Clean;jsonrpcclient_async:Clean"/>
</Target>
<Target Name="Make">
<CallTarget Targets="jsonrpcserverwithobjects:Make;jsonrpcclientwithobjects_sync:Make;jsonrpcclientwithobjects_async:Make"/>
<CallTarget Targets="jsonrpcserver:Make;jsonrpcclient_sync:Make;jsonrpcclient_async:Make"/>
</Target>
<Import Project="$(BDS)\Bin\CodeGear.Group.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Group.Targets')"/>
</Project>
6 changes: 3 additions & 3 deletions samples/jsonrpc/jsonrpcserver/MyObjectU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -411,21 +411,21 @@ function TMyObject.Subtract(Value1, Value2: Integer): Integer;
procedure TMyObject.OnBeforeCallHook(const Context: TWebContext; const JSONRequest: TJDOJsonObject);
begin
Log.Info('TMyObjectWithHooks.OnBeforeCallHook >> ', 'jsonrpc');
Log.Info(JSONRequest.ToJSON(False), 'jsonrpc');
Log.Info(sLineBreak + JSONRequest.ToJSON(False), 'jsonrpc');
Log.Info('TMyObjectWithHooks.OnBeforeCallHook << ', 'jsonrpc');
end;

procedure TMyObject.OnBeforeRoutingHook(const Context: TWebContext; const JSON: TJDOJsonObject);
begin
Log.Info('TMyObjectWithHooks.OnBeforeRoutingHook >> ', 'jsonrpc');
Log.Info(JSON.ToJSON(False), 'jsonrpc');
Log.Info(sLineBreak + JSON.ToJSON(False), 'jsonrpc');
Log.Info('TMyObjectWithHooks.OnBeforeRoutingHook << ', 'jsonrpc');
end;

procedure TMyObject.OnAfterCallHook(const Context: TWebContext; const JSONResponse: TJDOJsonObject);
begin
Log.Info('TMyObjectWithHooks.OnAfterCallHook >> ', 'jsonrpc');
Log.Info(JSONResponse.ToJSON(False), 'jsonrpc');
Log.Info(sLineBreak + JSONResponse.ToJSON(False), 'jsonrpc');
Log.Info('TMyObjectWithHooks.OnAfterCallHook << ', 'jsonrpc');
end;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
program jsonrpcserverwithobjects;
program jsonrpcserver;

{$APPTYPE CONSOLE}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<ProjectGuid>{AF5FBC36-0D1D-4C07-B2E3-C2A2E688AC6F}</ProjectGuid>
<ProjectVersion>20.1</ProjectVersion>
<FrameworkType>VCL</FrameworkType>
<MainSource>jsonrpcserverwithobjects.dpr</MainSource>
<MainSource>jsonrpcserver.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>1</TargetedPlatforms>
<AppType>Console</AppType>
<ProjectName Condition="'$(ProjectName)'==''">jsonrpcserverwithobjects</ProjectName>
<ProjectName Condition="'$(ProjectName)'==''">jsonrpcserver</ProjectName>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
Expand Down Expand Up @@ -60,7 +60,7 @@
<Icns_MainIcns>$(BDS)\bin\delphi_PROJECTICNS.icns</Icns_MainIcns>
<DCC_UnitSearchPath>$(DMVC);$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<DCC_Framework>VCL;$(DCC_Framework)</DCC_Framework>
<SanitizedProjectName>jsonrpcserverwithobjects</SanitizedProjectName>
<SanitizedProjectName>jsonrpcserver</SanitizedProjectName>
<VerInfo_Locale>1040</VerInfo_Locale>
<DCC_ExeOutput>..\bin</DCC_ExeOutput>
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
Expand Down Expand Up @@ -136,7 +136,7 @@
<BorlandProject>
<Delphi.Personality>
<Source>
<Source Name="MainSource">jsonrpcserverwithobjects.dpr</Source>
<Source Name="MainSource">jsonrpcserver.dpr</Source>
</Source>
<Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k280.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
Expand All @@ -148,9 +148,9 @@
<DeployFile LocalName="$(BDS)\Redist\iossimulator\libcgunwind.1.0.dylib" Class="DependencyModule"/>
<DeployFile LocalName="$(BDS)\Redist\osx32\libcgsqlite3.dylib" Class="DependencyModule"/>
<DeployFile LocalName="$(BDS)\Redist\osx32\libcgunwind.1.0.dylib" Class="DependencyModule"/>
<DeployFile LocalName="..\bin\jsonrpcserverwithobjects.exe" Configuration="Debug" Class="ProjectOutput">
<DeployFile LocalName="..\bin\jsonrpcserver.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>jsonrpcserverwithobjects.exe</RemoteName>
<RemoteName>jsonrpcserver.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
Expand Down
5 changes: 2 additions & 3 deletions samples/jsonrpc/sync_client/MainClientFormU.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ object MainForm: TMainForm
ActivePage = TabSheet1
Align = alClient
TabOrder = 0
ExplicitWidth = 838
ExplicitHeight = 603
object TabSheet1: TTabSheet
Caption = 'Invoking Plain PODO'
object GroupBox1: TGroupBox
Expand Down Expand Up @@ -484,7 +482,7 @@ object MainForm: TMainForm
AlignWithMargins = True
Left = 3
Top = 3
Width = 808
Width = 828
Height = 69
Align = alTop
Caption =
Expand All @@ -499,6 +497,7 @@ object MainForm: TMainForm
Font.Style = []
ParentFont = False
WordWrap = True
ExplicitWidth = 808
end
object btnGenericExcWithCustomHandling: TButton
Left = 0
Expand Down
9 changes: 3 additions & 6 deletions samples/jsonrpc/sync_client/MainClientFormU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Delphi MVC Framework
//
// Copyright (c) 2010-2023 Daniele Teti and the DMVCFramework Team
// Copyright (c) 2010-2024 Daniele Teti and the DMVCFramework Team
//
// https://github.com/danieleteti/delphimvcframework
//
Expand Down Expand Up @@ -357,8 +357,7 @@ procedure TMainForm.btnNotificationClick(Sender: TObject);
var
lNotification: IJSONRPCNotification;
begin
lNotification := TJSONRPCNotification.Create;
lNotification.Method := 'dosomething';
lNotification := FExecutor.CreateNotification('dosomething');
FExecutor.ExecuteNotification('/jsonrpc', lNotification);
end;

Expand Down Expand Up @@ -500,9 +499,7 @@ procedure TMainForm.btnSubtractClick(Sender: TObject);
lExecutor: IMVCJSONRPCExecutor;
begin
lExecutor := TMVCJSONRPCExecutor.Create('http://localhost:8080');
lReq := TJSONRPCRequest.Create;
lReq.Method := 'subtract';
lReq.RequestID := Random(1000);
lReq := lExecutor.CreateRequest('subtract', Random(1000));
lReq.Params.Add(StrToInt(edtValue1.Text));
lReq.Params.Add(StrToInt(edtValue2.Text));
lResp := lExecutor.ExecuteRequest('/jsonrpc', lReq);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
program jsonrpcclientwithobjects_sync;
program jsonrpcclient_sync;

uses
Vcl.Forms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<ProjectGuid>{300F83FF-8F7B-43FD-B740-A3DFDF7238ED}</ProjectGuid>
<ProjectVersion>20.1</ProjectVersion>
<FrameworkType>VCL</FrameworkType>
<MainSource>jsonrpcclientwithobjects_sync.dpr</MainSource>
<MainSource>jsonrpcclient_sync.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>1</TargetedPlatforms>
<AppType>Application</AppType>
<ProjectName Condition="'$(ProjectName)'==''">jsonrpcclientwithobjects_sync</ProjectName>
<ProjectName Condition="'$(ProjectName)'==''">jsonrpcclient_sync</ProjectName>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
Expand Down Expand Up @@ -59,7 +59,7 @@
<Icon_MainIcon>$(BDS)\bin\delphi_PROJECTICON.ico</Icon_MainIcon>
<UWP_DelphiLogo44>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png</UWP_DelphiLogo44>
<UWP_DelphiLogo150>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png</UWP_DelphiLogo150>
<SanitizedProjectName>jsonrpcclientwithobjects_sync</SanitizedProjectName>
<SanitizedProjectName>jsonrpcclient_sync</SanitizedProjectName>
<VerInfo_Locale>1040</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
</PropertyGroup>
Expand Down Expand Up @@ -129,21 +129,21 @@
<BorlandProject>
<Delphi.Personality>
<Source>
<Source Name="MainSource">jsonrpcclientwithobjects_sync.dpr</Source>
<Source Name="MainSource">jsonrpcclient_sync.dpr</Source>
</Source>
<Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k280.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dclofficexp280.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
</Excluded_Packages>
</Delphi.Personality>
<Deployment Version="4">
<DeployFile LocalName="Win32\Debug\jsonrpcclientwithobjects.exe" Configuration="Debug" Class="ProjectOutput"/>
<DeployFile LocalName="bin\jsonrpcclientwithobjects_sync.exe" Configuration="Debug" Class="ProjectOutput">
<DeployFile LocalName="..\bin\jsonrpcclient_sync.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>jsonrpcclientwithobjects_sync.exe</RemoteName>
<RemoteName>jsonrpcclient_sync.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="Win32\Debug\jsonrpcclientwithobjects.exe" Configuration="Debug" Class="ProjectOutput"/>
<DeployClass Name="AdditionalDebugSymbols">
<Platform Name="iOSSimulator">
<Operation>1</Operation>
Expand Down
Loading

0 comments on commit d932857

Please sign in to comment.