[MGNLRESTCL-73] RestClient should not be modified by usages Created: 30/Sep/19  Updated: 20/Aug/21  Resolved: 19/Nov/19

Status: Closed
Project: REST Client
Component/s: None
Affects Version/s: None
Fix Version/s: 2.0

Type: Improvement Priority: Major
Reporter: Christopher Zimmermann Assignee: Dai Ha
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: 0d
Time Spent: 5.75d
Original Estimate: Not Specified

Issue Links:
causality
is causing MGNLRESTCL-102 DOC: Optional body param in restCallName Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:
Epic Link: Declarative REST clients
Sprint: Declarative REST 10, Declarative REST 11
Story Points: 3

 Description   

If a developer changes body of a request on a RestCall in a usage, it should not have an effect on the client itself, or other calls of the rest client - the changes to the body should only affect that specific one call, on that specific client.

(I have not tested, but the problem may apply to other aspects of a request such as headers, parameters)

 I have only tested this one example - but I am wondering how this relates to usages in different locations in java code or also in restfn in templates.

// code placeholder
//JS model
var restClient = restClientFactory.createClient(restClientRegistry.getProvider("posts").get());   var restCall = restClient.getRestClientDefinition().getRestCalls().get("create")

restCall.getHeaders().put("Content-Type", "application/json; charset=UTF-8")
restCall.setBody({   title: title,   body: body})

var result1 =  JSON.parse(restClient.invoke(restCall))  

// This call will have the body set above! Not good! 

var restCall2 = restClient.getRestClientDefinition().getRestCalls().get("create")
var result2 =  JSON.parse(restClient.invoke(restCall2))  

// This call will have the body set above! Not good! 

var restClient3 = restClientFactory.createClient(restClientRegistry.getProvider("posts").get());         

var restCall3 = restClient3.getRestClientDefinition().getRestCalls().get("create")var result3 =  JSON.parse(restClient3.invoke(restCall3))

Above example adopted from:  https://git.magnolia-cms.com/users/jfranco/repos/declarative-rest/browse/declarative-rest-demo/src/main/resources/declarative-rest-demo/templates/components/rest-model.js?at=refs%2Fheads%2Fjorge%2FduplicatePosts

 

 

 



 Comments   
Comment by Mikaël Geljić [ 04/Oct/19 ]

One first idea was to split concrete definitions vs. interfaces, so we don't expose getters; then jsimak pointed out it doesn't matter if you use if from JS models, you'll be able to use the setter anyways.

Now recommending to provide ImmutableWrappers for RestClientDefinitions and RestCalls that would bail with exception on all setters (and maybe make sure collections are returned with Unmodifiable wrappers); and wrap from the factory.

Generated at Mon Feb 12 10:42:57 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.