refactor: split the ServerRpcHandler#handleRpc method#24533
Conversation
The ServerRpcHandler#handleRpc method parses the json and produces RpcRequest object which is then internally passed as parameter to handleInvocations() method, but discarded afterwards. Adjust the handleRpc() API so the RpcRequest is not discarded at the end of method invocation, but is returned as method result. Motivation: there are situations when customers extend the ServerRpcHandler logic and since the RpcRequest is lost, it needs to be re-parsed from json once again. (Specific scenario - "UNLOAD" beacon requests are ignored when @PreserveOnRefresh is used, but that request needs to be specially processed anyway).
|
|
|
Thanks for the contribution. This reveals that API could be easier to customize, but we are also talking about internal API here. Adding return value is breaking change for extenders. Even though it's in internal API, knowing that it will break someone's project makes one think some alternatives. Since there is already a workaround of creating your own RpcRequest instance, this change feels like the last effort. Another option that wouldn't break extenders code is to make RpcRequest available via new method: public void handleRpc(UI ui, String message, VaadinRequest request, RpcRequest rpcRequest)
throws InvalidUIDLSecurityKeyException, MessageIdSyncException {
// most of the code in handleRpc goes here
...and existing method would call that: public void handleRpc(UI ui, String message, VaadinRequest request)
throws InvalidUIDLSecurityKeyException, MessageIdSyncException {
ui.getSession().setLastRequestTimestamp(System.currentTimeMillis());
if (message == null || message.isEmpty()) {
// The client sometimes sends empty messages, this is probably a bug
return;
}
RpcRequest rpcRequest = new RpcRequest(message, request.getService()
.getDeploymentConfiguration().isSyncIdCheckEnabled());
handleRpc(ui, message, request, rpcRequest);
} |
This reverts commit 70b2ae8.
The ServerRpcHandler#handleRpc method parses the json and produces RpcRequest object which is then internally passed as parameter to handleInvocations() method, but discarded afterwards. Split the handleRpc() method, separating parsing of RpcRequest and its processing. Motivation: there are situations when customers extend the ServerRpcHandler logic and since the RpcRequest is lost, it needs to be re-parsed from json once again. Extract the UnloadBeaconRequest to separate method. (Specific scenario - "UNLOAD" beacon requests are ignored when @PreserveOnRefresh is used, but that request needs to be specially processed anyway). Change-Id: I45f3fa102aa0b1c179a8fd7e232399694c9cbc18
|
I understand and agree it is a breaking change and I also understand it is internal method. |
|



Description
The ServerRpcHandler#handleRpc method parses the json and produces RpcRequest object which is then internally passed as parameter to handleInvocations() method, but discarded afterwards.
Adjust the handleRpc() API so the RpcRequest is not discarded at the end of method invocation, but is returned as method result.
Motivation: there are situations when customers extend the ServerRpcHandler logic and since the RpcRequest is lost, it needs to be re-parsed from json once again.
(Specific scenario - "UNLOAD" beacon requests are ignored when @PreserveOnRefresh is used, but that request needs to be specially processed anyway).
Type of change
Checklist
Additional for
Featuretype of change