Forums de discussion

JSON web service -POST

gary b, modifié il y a 8 années.

JSON web service -POST

Junior Member Publications: 81 Date d'inscription: 02/02/13 Publications récentes
Hi All,

I am facing problems while calling JSON web service using POST
So far I've used GET without any problem, but as per requirement i need to convert same method to POST.
So i have added below annotation before my method and change the input parameter as jsonobject:

@JSONWebService(value = "service-details", method = "POST")
public JSONObject myServiceDetails(JSONObject detailJsonObject){

But getting below exception while consuming this services :
{"exception":"No JSON web service action associated with path /myextension/service-details and method POST for //my-service-builder-portlet"}

previously while using GET my method was like this:
public JSONObject getMyServiceDetails(String name,
			String reminder, String webId, String loginId)

And from browser it is creating below URL:
http://localhost:8080/api/jsonws?contextPath=/my-service-builder-portlet&signature=%2Fmy-service-builder-portlet%2Fmyextension%2Fservice-details-1-detailJsonObject


I want my method to be accessed by POST request without passing parameter in url.

Your help would be very much appreciated.

Thanks
thumbnail
David H Nebinger, modifié il y a 8 années.

RE: JSON web service -POST

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
I usually check http://localhost:8080/api/jsonws directly to find the method. It can help identify where things might be named differently than what you think (has happened to me more times than I care to share emoticon).
gary b, modifié il y a 8 années.

RE: JSON web service -POST

Junior Member Publications: 81 Date d'inscription: 02/02/13 Publications récentes
Hi David,

I am also checking using below url,
http://localhost:8080/api/jsonws?contextPath=/my-service-builder-portlet&signature=%2Fmy-service-builder-portlet%2Fmyextension%2Fservice-details-1-detailJsonObject


It is working perfectly for GET as well as for POST when we pass the parameter(detailJsonObject) in url but we need to access method without passing parameter in url because it has confidential info like user's credentials.

I need help to achieve that.

Regards,
Garima
thumbnail
David H Nebinger, modifié il y a 8 années.

RE: JSON web service -POST

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
Hmm, when you try the request using /api/jsonws, along with the results there's a JSON tab where I believe you see the invocation using a JSON body, not parameters...
gary b, modifié il y a 8 années.

RE: JSON web service -POST

Junior Member Publications: 81 Date d'inscription: 02/02/13 Publications récentes
Hi David,

I can't see any JSON tab, attached the screenshot

Pièces jointes:

thumbnail
David H Nebinger, modifié il y a 8 années.

RE: JSON web service -POST

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
Sorry, been awhile since I looked at it, it's the JavaScript Example tab.
gary b, modifié il y a 8 années.

RE: JSON web service -POST (Réponse)

Junior Member Publications: 81 Date d'inscription: 02/02/13 Publications récentes
Hi All,

Finally I achieved this using "Invoker Call".
We can access invoker using below address
http://localhost:8080/api/jsonws/invoke

and then can send details in request body like this:
{
    "/my-service-builder-portlet.my-extension/service-details": {
        "param1": abc,
        "param2": 123,
        "param3": test
        }
}



Thanks.