* Move resourcestrings to single unit

This commit is contained in:
Michaël Van Canneyt 2021-12-28 16:07:40 +01:00
parent 036aea025d
commit 2f23239ebd
7 changed files with 70 additions and 62 deletions

View File

@ -302,8 +302,9 @@ begin
AddUnit('httpdefs');
AddUnit('fpextjs');
end;
T:=P.Targets.AddUnit('fpjsonrpc.pp');
T:=P.Targets.AddUnit('fprpcstrings.pp');
T.ResourceStrings:=true;
T:=P.Targets.AddUnit('fpjsonrpc.pp');
T:=P.Targets.AddUnit('webjsonrpc.pp');
With T.Dependencies do
begin
@ -314,9 +315,7 @@ begin
begin
AddUnit('fpjsonrpc');
end;
// T.ResourceStrings:=true;
T:=P.Targets.AddUnit('fprpcclient.pp');
T.ResourceStrings:=true;
T:=P.Targets.AddUnit('fprpccodegen.pp');
T:=P.Targets.AddUnit('fpdispextdirect.pp');
With T.Dependencies do
@ -324,7 +323,6 @@ begin
AddUnit('fpjsonrpc');
end;
T:=P.Targets.AddUnit('fpextdirect.pp');
T.ResourceStrings:=true;
With T.Dependencies do
begin
AddUnit('fpdispextdirect');

View File

@ -120,12 +120,10 @@ Type
implementation
{$ifdef extdebug}
uses dbugintf;
{$endif}
Resourcestring
SErrInvalidPath = 'Invalid path';
uses {$ifdef extdebug}dbugintf,{$endif} fprpcstrings;
{ TCustomExtDirectDispatcher }

View File

@ -446,47 +446,10 @@ Const
EJSONRPCInvalidParams = -32602;
EJSONRPCInternalError = -32603;
resourcestring
SErrDuplicateParam = 'Duplicate JSON-RPC Parameter name';
SErrUnknownParamDef = 'Unknown parameter definition: "%s"';
SErrParams = 'Error checking JSON-RPC parameters: "%s"';
SErrParamsMustBeArrayorObject = 'Parameters must be passed in an object or an array.';
SErrParamsMustBeObject = 'Parameters must be passed in an object.';
SErrParamsMustBeArray = 'Parameters must be passed in an array.';
SErrParamsRequiredParamNotFound = 'Required parameter "%s" not found.';
SErrParamsDataTypeMismatch = 'Expected parameter "%s" having type "%s", got "%s".';
SErrParamsNotAllowd = 'Parameter "%s" is not allowed.';
SErrParamsOnlyObjectsInArray = 'Array elements must be objects, got %s at position %d.';
SErrRequestMustBeObject = 'JSON-RPC Request must be an object.';
SErrNoIDProperty = 'No "id" property found in request.';
SErrInvalidIDProperty = 'Type of "id" property is not correct.';
SErrNoJSONRPCProperty = 'No "jsonrpc" property in request.';
SErrInvalidJSONRPCProperty = 'Type or value of "jsonrpc" property is not correct.';
SErrNoMethodName = 'Cannot determine method: No "%s" property found in request.';
SErrNoClassName = 'Cannot determine class: No "%s" property found in request.';
SErrNoParams = 'Cannot determine parameters: No "%s" property found in request.';
SErrInvalidMethodType = 'Type of "%s" property in request is not correct.';
SErrInvalidClassNameType = 'Type of "%s" property in request is not correct.';
SErrJSON2NotAllowed = 'JSON RPC 2 calls are not allowed.';
SErrJSON1NotAllowed = 'JSON RPC 1 calls are not allowed.';
SErrNoResponse = 'No response received from non-notification method "%s".';
SErrResponseFromNotification = 'A response was received from a notification method "%s".';
SErrInvalidMethodName = 'No method "%s" was found.';
SErrInvalidClassMethodName = 'No class "%s" with method "%s" was found.';
SErrDuplicateJSONRPCClassHandlerName = 'Duplicate JSON-RPC handler for class "%s" with method "%s".';
SErrDuplicateJSONRPCHandlerName = 'Duplicate JSON-RPC handler for method "%s".';
SErrUnknownJSONRPCClassMethodHandler = 'Unknown JSON-RPC handler for class "%s", method "%s".';
SErrUnknownJSONRPCMethodHandler = 'Unknown JSON-RPC handler for method "%s".';
SErrDuplicateRPCCLassMethodHandler = 'Duplicate JSON-RPC handler for class "%s", method "%s".';
SErrDuplicateRPCMethodHandler = 'Duplicate JSON-RPC handler for method "%s".';
SErrNoDispatcher = 'No method dispatcher available to handle request.';
implementation
uses {$IFDEF WMDEBUG}dbugintf, {$ENDIF} fprpccodegen;
uses {$IFDEF WMDEBUG}dbugintf, {$ENDIF} fprpccodegen, fprpcstrings;
function CreateJSONErrorObject(const AMessage: String; const ACode: Integer
): TJSONObject;

View File

@ -123,14 +123,10 @@ Type
Function RPCServiceRegistry : TFPRPCServiceRegistry;
Resourcestring
SErrUnknownServiceName = 'Unknown service name : "%s"';
SErrUnknownServiceGUID = 'Unknown service GUID : "%s"';
SErrSupportedServiceName = 'Interface does not support service: "%s"';
SErrExpectedReturnButNoServerReturn = 'Method "%s" expects return values, but no result was returned';
implementation
uses fprpcstrings;
function IsGUIDEqual(const guid1, guid2: tguid): boolean;
begin
IsGUIDEqual:=
@ -480,10 +476,10 @@ begin
Req:=aClient.CreateRequest;
try
S:=aRequest.AsJSON;
Writeln('Request : ',S);
// Writeln('Request : ',S);
Req.Content.WriteBuffer(S[1],Length(S));
Resp:=aClient.ExecuteRequest('POST',FBaseURL,Req);
Writeln('Response : ',Resp.GetContentAsString);
// Writeln('Response : ',Resp.GetContentAsString);
// For notification methods, there is no return !
if (resp.Content.Size>0) then
begin
@ -494,7 +490,7 @@ begin
else
begin
Res.Free;
Raise ERPCClient.Create('Invalid server response');
Raise ERPCClient.Create(SErrInvalidServerResponse);
end;
end;
finally

View File

@ -86,7 +86,7 @@ function RTTIJSONRPCRegistry : TRTTIJSONRPCRegistry;
implementation
uses fpjsonvalue;
uses fprpcstrings, fpjsonvalue;
function RTTIJSONRPCRegistry : TRTTIJSONRPCRegistry;
@ -194,7 +194,7 @@ begin
TRTTIJSONRPCRegistry.Instance.Get(FRPCClassName,FIntfType,FCreator);
FMethod:=FIntfType.GetMethod(aMethodName);
if FMethod=Nil then
Raise EJSONRPC.CreateFmt('unknown method name for class %s: %s',[aClassName,aMethodName]);
raise EJSONRPC.CreateFmt(SErrUnknownMethodForClass, [aClassName, aMethodName]);
end;
class function TRTTIJSONRPCHandler.ValueToJSON(const aValue: TValue; aType: TRttiType): TJSONData;
@ -253,7 +253,7 @@ begin
if (Intf.QueryInterface(IRPCCallContext,CC)=S_OK) then
CC.RPCCallContext:=aContext;
if Intf.QueryInterface(FIntfType.GUID,APIIntf)<>S_OK then
Raise EJSONRPC.CreateFmt('Creator does not support interface %s',[FIntfType.Name]);
raise EJSONRPC.CreateFmt(SErrCreatorDoesNotSupportInterface, [FIntfType.Name]);
TValue.Make(@APIIntf, PTypeInfo(FIntfType.Handle), instance);
res := method.Invoke(instance, args);

View File

@ -0,0 +1,53 @@
unit fprpcstrings;
{$mode ObjFPC}{$H+}
interface
Resourcestring
SErrInvalidPath = 'Invalid path';
SErrUnknownServiceName = 'Unknown service name : "%s"';
SErrUnknownServiceGUID = 'Unknown service GUID : "%s"';
SErrSupportedServiceName = 'Interface does not support service: "%s"';
SErrExpectedReturnButNoServerReturn = 'Method "%s" expects return values, but no result was returned';
SErrInvalidServerResponse = 'Invalid server response';
SErrDuplicateParam = 'Duplicate JSON-RPC Parameter name';
SErrUnknownParamDef = 'Unknown parameter definition: "%s"';
SErrParams = 'Error checking JSON-RPC parameters: "%s"';
SErrParamsMustBeArrayorObject = 'Parameters must be passed in an object or an array.';
SErrParamsMustBeObject = 'Parameters must be passed in an object.';
SErrParamsMustBeArray = 'Parameters must be passed in an array.';
SErrParamsRequiredParamNotFound = 'Required parameter "%s" not found.';
SErrParamsDataTypeMismatch = 'Expected parameter "%s" having type "%s", got "%s".';
SErrParamsNotAllowd = 'Parameter "%s" is not allowed.';
SErrParamsOnlyObjectsInArray = 'Array elements must be objects, got %s at position %d.';
SErrRequestMustBeObject = 'JSON-RPC Request must be an object.';
SErrNoIDProperty = 'No "id" property found in request.';
SErrInvalidIDProperty = 'Type of "id" property is not correct.';
SErrNoJSONRPCProperty = 'No "jsonrpc" property in request.';
SErrInvalidJSONRPCProperty = 'Type or value of "jsonrpc" property is not correct.';
SErrNoMethodName = 'Cannot determine method: No "%s" property found in request.';
SErrNoClassName = 'Cannot determine class: No "%s" property found in request.';
SErrNoParams = 'Cannot determine parameters: No "%s" property found in request.';
SErrInvalidMethodType = 'Type of "%s" property in request is not correct.';
SErrInvalidClassNameType = 'Type of "%s" property in request is not correct.';
SErrJSON2NotAllowed = 'JSON RPC 2 calls are not allowed.';
SErrJSON1NotAllowed = 'JSON RPC 1 calls are not allowed.';
SErrNoResponse = 'No response received from non-notification method "%s".';
SErrResponseFromNotification = 'A response was received from a notification method "%s".';
SErrInvalidMethodName = 'No method "%s" was found.';
SErrInvalidClassMethodName = 'No class "%s" with method "%s" was found.';
SErrDuplicateJSONRPCClassHandlerName = 'Duplicate JSON-RPC handler for class "%s" with method "%s".';
SErrDuplicateJSONRPCHandlerName = 'Duplicate JSON-RPC handler for method "%s".';
SErrUnknownJSONRPCClassMethodHandler = 'Unknown JSON-RPC handler for class "%s", method "%s".';
SErrUnknownJSONRPCMethodHandler = 'Unknown JSON-RPC handler for method "%s".';
SErrDuplicateRPCCLassMethodHandler = 'Duplicate JSON-RPC handler for class "%s", method "%s".';
SErrDuplicateRPCMethodHandler = 'Duplicate JSON-RPC handler for method "%s".';
SErrNoDispatcher = 'No method dispatcher available to handle request.';
SErrUnknownMethodForClass = 'unknown method name for class %s: %s';
SErrCreatorDoesNotSupportInterface = 'Creator does not support interface %s';
implementation
end.

View File

@ -147,9 +147,9 @@ type
implementation
{$ifdef debugjsonrpc}
uses dbugintf;
{$endif}
uses {$ifdef debugjsonrpc}dbugintf,{$endif} fprpcstrings;
Const
SApplicationJSON = 'application/json';