Details

    • Type: Bug Bug
    • Status: Closed
    • Resolution: Won't Fix
    • Affects Version/s: 6.1.1 CE GA2, 6.1.20 EE GA2
    • Fix Version/s: 6.1.1 CE GA2, 6.1.20 EE GA2
    • Labels:
      None
    • Environment:
      Standalone REST client or Javascript client or Java client
    • Similar Issues:
      Show 3 results 

      Description

      When you invoke a JSON service, it is necessary to pass all data as application/x-www-form-urlencoded. It is not possible to pass JSON object in the post body using application/json.

      For example, if we have data like shown below,

      var data = {
        "serviceMethodName" : "createBar",
        "servletContextName" : "test-json-portlet",
        "serviceParameters" : ["userId","userName"],
        "userId" : 10194,
        "userName" : "test"
      };
      

      Then the following code does not work,

      var url = "http://localhost:8080/api/json";
      									
      $.ajax({
        type : "POST",
        url : url,
        contentType : "application/json; charset=utf-8",
        dataType : "json",
        headers : {
          "Authorization" : "Basic dGVzdEBsaWZlcmF5LmNvbTp0ZXN0"
        },
        data : JSON.stringify(data),
        success : function(results) {
          console.log(results);
        } 
      });
      

        Activity

        Hide
        Prashant Dighe added a comment -

        I have the fix and will send pull request soon.

        Show
        Prashant Dighe added a comment - I have the fix and will send pull request soon.
        Hide
        Igor Spasic added a comment - - edited

        Hey Prashant,
        thank you for submitting the issue!

        However, this seems to be a mixture of old and new json services The /api/json path is reserved for the new JSON WebServices and for those you don't need to send service parameters. In fact, the invocation model is now different as it uses REST-alike paths. Moreover, there are 3-4 different ways how you can invoke new web services, depending on what you prefer or need.

        To keep long story short, I suggest to visit our official documentation about JSONWebServices:

        https://github.com/liferay/liferay-docs/blob/master/devGuide/en/chapters/09-apis.markdown#json-web-services

        and see how it works now (documentation on this subject is quite updated).

        Also, visit http://localhost:8080/api/json in your browser, and you will see the API page and invocation call examples.

        Show
        Igor Spasic added a comment - - edited Hey Prashant, thank you for submitting the issue! However, this seems to be a mixture of old and new json services The /api/json path is reserved for the new JSON WebServices and for those you don't need to send service parameters. In fact, the invocation model is now different as it uses REST-alike paths. Moreover, there are 3-4 different ways how you can invoke new web services, depending on what you prefer or need. To keep long story short, I suggest to visit our official documentation about JSONWebServices: https://github.com/liferay/liferay-docs/blob/master/devGuide/en/chapters/09-apis.markdown#json-web-services and see how it works now (documentation on this subject is quite updated). Also, visit http://localhost:8080/api/json in your browser, and you will see the API page and invocation call examples.
        Hide
        Igor Spasic added a comment -

        I will close this LPS as described behavior is not how JSON WebServices work.

        Show
        Igor Spasic added a comment - I will close this LPS as described behavior is not how JSON WebServices work.
        Hide
        Prashant Dighe added a comment -

        Thanks Igor for taking a look at this.

        I agree that we can ignore the old way of invoking json services now that the new way is much more structured.
        I can confirm that the following works,

        curl http://localhost:8080/api/jsonws/test-json-portlet.bar\
          -H "Content-Type:application/json"\
          -H "Authorization:Basic dGVzdEBsaWZlcmF5LmNvbTp0ZXN0"\
          -X POST\
          -d '{"method":"create-bar","params":{"userId":10194, "userName":"test"},"id":123,"jsonrpc":"2.0"}'
        
        Show
        Prashant Dighe added a comment - Thanks Igor for taking a look at this. I agree that we can ignore the old way of invoking json services now that the new way is much more structured. I can confirm that the following works, curl http: //localhost:8080/api/jsonws/test-json-portlet.bar\ -H "Content-Type:application/json" \ -H "Authorization:Basic dGVzdEBsaWZlcmF5LmNvbTp0ZXN0" \ -X POST\ -d '{ "method" : "create-bar" , "params" :{ "userId" :10194, "userName" : "test" }, "id" :123, "jsonrpc" : "2.0" }'

          People

          • Assignee:
            Igor Spasic
            Reporter:
            Prashant Dighe
            Recent user:
            Randy Zhu
            Participants of an Issue:
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              2 years, 25 weeks, 6 days ago

              Development

                Structure Helper Panel