[MGNLRESTCL-99] It's not possible to process a request with body, but without parameters Created: 20/Nov/19  Updated: 03/Dec/19  Resolved: 03/Dec/19

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

Type: Bug Priority: Neutral
Reporter: Sergey Syrozhkin Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File Fix_for_case_when_empty_parameters_with_body.patch    
Template:
Patch included:
Yes
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)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

I've created a method which POST some data to the rest service. There's no any parameters there. It gets only JSON body.

@POST
@Path("/product")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
ResponseDto postMethod(SomeModel someModel);

When I try to execute it through Rest Client app. And because of no parameters I have to keep method parameters empty.

And there's a code in RestClientAppPresenter class which checks for empty parameters string and returns empty method parameters array and don't include body to it.

private Object[] parseParameters(Method method, String parametersAsString, String body) throws IOException {
    List<Object> parameters = new ArrayList<Object>();

    if (StringUtils.isNotEmpty(parametersAsString)) {
        Map<String, String> parametersMap = Splitter.on("\n").withKeyValueSeparator("=").split(StringUtils.trimToEmpty(parametersAsString));
        Class[] types = method.getParameterTypes();
        Annotation[][] annotations = method.getParameterAnnotations();
        if (types.length != parametersMap.size() + (this.getBodyClass(types, annotations) != null ? 1 : 0)) {
            throw new IllegalArgumentException("Wrong number of arguments");
        }
        for (int i = 0; i < types.length; i++) {
            if (annotations[i].length == 0) { //body param
                parameters.add(corvertValue(body, types[i]));
            } else {
                parameters.add(corvertValue(parametersMap.get(this.getAnnotationValue(annotations[i])), types[i]));
            }
        }
    }
    return parameters.toArray();
}
 

The decision is to remove this check.



 Comments   
Comment by Simon Lutz [ 21/Nov/19 ]

Hi syroezhkin,

thanks a lot for creating this ticket and providing a patch. We will review your findings and take next actions accordingly.

Best regards,
Simon

Comment by Simon Lutz [ 03/Dec/19 ]

HI syroezhkin,

this issue is fixed as of version 2.0 that will be available with Magnolia 6.2.

Thanks again & best regards,
Simon

Comment by Simon Lutz [ 03/Dec/19 ]

Fixed in version 2.0.

Comment by Sergey Syrozhkin [ 03/Dec/19 ]

Hi slutz
Glad to be helpful.

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