[MGNLREST-62] Add possibility to put context attributes to the rest response in command endpoint Created: 16/Feb/15  Updated: 21/Nov/17  Resolved: 23/Feb/15

Status: Closed
Project: Magnolia REST Framework
Component/s: None
Affects Version/s: None
Fix Version/s: 1.1

Type: Improvement Priority: Neutral
Reporter: Jaroslav Simak Assignee: Jaroslav Simak
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Screen Shot 2015-02-20 at 08.35.36.png    
Issue Links:
Relates
relates to MGNLBACKUP-105 Invoking backup via REST might be log... 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)
Documentation update required:
Yes
Date of First Response:

 Description   

ilgun -> As far as I could grasp when I was working on MGNLBACKUP-105, the behaviour is as follows;

  • Command itself it returning false ->{ Success : true }
  • Command returning true -> no effect I'd expect to have success : false but no it will still return{ Success : true }
  • Command throwing exceptions -> Finally we get a { Success : false } with exception message in the response entity.

Therefore the success message relies on the command throwing exceptions or not.



 Comments   
Comment by Jan Haderka [ 20/Feb/15 ]

allowing caller to configure what params he wants to suck out of context seems like very insecure option opening door to exploits. It should be configured on the server not decided by caller.

Comment by Jaroslav Simak [ 20/Feb/15 ]

Attached configuration example.

Comment by Jan Haderka [ 20/Feb/15 ]

exposedContextParams or returnedContextParams or responseContextParams or something like that to make it obvious what happens with params listed in there?

Comment by Philip Mundt [ 31/Oct/16 ]

jsimak could you please update the description of this issue? We need to know:

  1. Why was this update done? (There is no description whatsoever and no linked tickets)
  2. Why do we always return true (in contrast to what is documented here https://wiki.magnolia-cms.com/pages/viewpage.action?pageId=100926374 ; it says we always return false + potential params)? Figured it out, it relies on the exception being thrown by the command executing. Wondering why we do nothing with the return of the info.magnolia.commands.CommandsManager#executeCommand(info.magnolia.commands.chain.Command, java.util.Map<java.lang.String,java.lang.Object>) result?
  3. Why are context parameters fetched from MgnlContext? (I wonder what's up with info.magnolia.commands.chain.Context which seems more appropriate)
  4. What was the initial intent of doing this? I guess being able to handle exceptions thrown by the command during execution...
Comment by Philip Mundt [ 01/Nov/16 ]

Actually we just figured this is not usable. The interface specifies info.magnolia.rest.service.command.definition.CommandDefinition#getResponseContextParameters() which is correctly implemented by info.magnolia.rest.service.command.definition.ConfiguredCommandDefinition#getResponseContextParameters() however, the setter is called info.magnolia.rest.service.command.definition.ConfiguredCommandDefinition#setContextParameters() (notice the missing Response), therefore N2B will most likely have difficulties setting those I guess.

@Override
public Collection<String> getResponseContextParameters() {
    return responseContextParameters;
}

public void setContextParameters(Collection<String> responseContextParameters) {
    this.responseContextParameters = responseContextParameters;
}
Comment by Antti Hietala [ 02/Mar/17 ]

Requires a documentation update. Commands endpoint v2 allows you to configure context parameters which are then sent back in the response if the command is executed successfully. This feature is not documented in the REST API docs and it is difficult to discover on your own because the example commands that ship with the REST Service module (/modules/rest-services/rest-endpoints/commands) don't have any context attributes. Please document and provide an example.

Generated at Mon Feb 12 06:56:12 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.