Forums

Home » Liferay Portal » English » Liferay Legacy

Combination View Flat View Tree View
Threads [ Previous | Next ]
Sebastián Gurin
REST-style JSON Web Services
September 3, 2007 11:52 AM
Answer

Sebastián Gurin

Rank: Junior Member

Posts: 75

Join Date: June 13, 2007

Recent Posts

Hi all. I'm trying to access portal's REST-style JSON Web Services from javascript.

First of all, looking in liferay 4.3.1 sourcecode (com.liferay.portal.action.JSONServiceAction.java, com.liferay.portlet.documentlibrary.service.http.*JSON.java, struts-config.xml) and I was able to figure out the url syntax for invoking the services. For example, for invoking DLFolderService.getFolder(311) I have to send an xmlhttprequest to http://localhost:8080/c/portal/json_service?serviceClassName=com.liferay.portlet.documentlibrary.service.http.DLFolderServiceJSON&serviceMethodName=getFolder&serviceParameters=311

in the case of methods that accept multiple parameters, they must be passed comma separated.

Question 1: Is this correct?

Question 2: in the case of String parameters, how can I pass a string that contains a comma character?

Question 3: I see jsonrpc-java (jsonrpc.jar) is used for implementing this kind of web service access. Where is the endpoint so I can use a json JSONRpcClient object for accessing the service as explained in http://oss.metaparadigm.com/jsonrpc-svn-trunk/manual.html#javascript-client ?

thanks in advance
Jorge Ferrer
RE: REST-style JSON Web Services
September 19, 2007 12:53 PM
Answer

Jorge Ferrer

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2768

Join Date: August 31, 2006

Recent Posts

Hi Sebastián,

I'm also a newbie on this, but as nobody has answered in a few days, I'll try to help.

I would recommend you to take a look at the service.js file. It contains a set of js APIs to access the JSON services and abstract the details that you are going to find out. If your client uses JavaScript that will be much easier. If not, you can still look at the code to learn how to build something similar for yourself. In particular to learn how the parameters are joined together take a look at the following code:

 1    getParameters: function(params) {
 2        var serviceParameters = "";
 3
 4        for (var key in params) {
 5            if ((key != "serviceClassName") && (key != "serviceMethodName")) {
 6                serviceParameters += key + ",";
 7            }
 8        }
 9
10        if (Liferay.Util.endsWith(serviceParameters, ",")) {
11            serviceParameters = serviceParameters.substring(0, serviceParameters.length - 1);
12        }
13
14        return serviceParameters;
15    }
Alex Wallace
RE: REST-style JSON Web Services
April 22, 2008 3:11 PM
Answer

Alex Wallace

Rank: Liferay Master

Posts: 640

Join Date: November 4, 2007

Recent Posts

Is it possible to authenticate in the url, kind of how it is done when using SOAP / axis ? I tried simple auth but that doesn't cut it... Only if i login in the portal can i use the REST / Json style web services... Is that the only way to do it?


UPS this is legacy... sorry about the post!
Sebastián Gurin
RE: REST-style JSON Web Services
April 24, 2008 10:30 AM
Answer

Sebastián Gurin

Rank: Junior Member

Posts: 75

Join Date: June 13, 2007

Recent Posts

accesing liferay api via rest

shows a complete test case of how to access liferay services via rest/json. hope it is useful.