Uploaded image for project: 'REST Client'
  1. REST Client
  2. MGNLRESTCL-99

It's not possible to process a request with body, but without parameters

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Neutral Neutral
    • None
    • 1.5.3
    • app
    • None
    • Yes

      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.

        Acceptance criteria

              Unassigned Unassigned
              syroezhkin Sergey Syrozhkin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: