留言板

way to use JSON?

Michael W.,修改在12 年前。

way to use JSON?

New Member 帖子: 2 加入日期: 11-5-30 最近的帖子
Hello,

I try to figure out how I can use JSON in Liferay with JAVA. Is it possible to send an JSON RPC Request to Liferay ? Because I've read that Liferay only supports SOAP-based WebServices (wikilink) and in that case I wonder why then there are so much JSONSerializer classes if it doesn't support json-requests....
Did someone have experiences/knowledges/information about JSON in Liferay using Java? Or is it true that I only can use SOAP to use an WebService in Liferay?

If so I'd be gradeful for every information!

Regards,

Michael
Thanasis Iliopoulos,修改在10 年前。

RE: way to use JSON?

New Member 帖子: 4 加入日期: 12-9-3 最近的帖子
Michael W:
Hello,

I try to figure out how I can use JSON in Liferay with JAVA. Is it possible to send an JSON RPC Request to Liferay ? Because I've read that Liferay only supports SOAP-based WebServices (wikilink) and in that case I wonder why then there are so much JSONSerializer classes if it doesn't support json-requests....
Did someone have experiences/knowledges/information about JSON in Liferay using Java? Or is it true that I only can use SOAP to use an WebService in Liferay?

If so I'd be gradeful for every information!

Regards,

Michael


Searching exactly the same! Have you found any solutions?
thumbnail
James Falkner,修改在10 年前。

RE: way to use JSON?

Liferay Legend 帖子: 1399 加入日期: 10-9-17 最近的帖子
Thanasis Iliopoulos:
Michael W:
Hello,

I try to figure out how I can use JSON in Liferay with JAVA. Is it possible to send an JSON RPC Request to Liferay ? Because I've read that Liferay only supports SOAP-based WebServices (wikilink) and in that case I wonder why then there are so much JSONSerializer classes if it doesn't support json-requests....
Did someone have experiences/knowledges/information about JSON in Liferay using Java? Or is it true that I only can use SOAP to use an WebService in Liferay?

If so I'd be gradeful for every information!

Regards,

Michael


Searching exactly the same! Have you found any solutions?


Yes, it is possible to send JSON requests to Liferay from Java code. Liferay's JSON services do not know about or care about the language in which a program is written which access the JSON services. So you can make a JSON "call" to Liferay using any programming language in the universe emoticon

Here's an example Java program which makes a JSON services call. It uses Apache HTTPClient 4.2.x to implement the HTTP protocol:
import net.sf.json.JSONArray;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.net.URI;

public class Foo {

    public static void main(String[] args) throws Exception {

        DefaultHttpClient httpclient = new DefaultHttpClient();

        URIBuilder builder = new URIBuilder();
        builder.setScheme("http").setHost("localhost").setPort(8080).setPath
                ("/api/jsonws/country/get-countries")
                .setParameter("format", "json").setUserInfo("bruno", "bruno");
        URI uri = builder.build();

        HttpGet httpget = new HttpGet(uri);
        HttpResponse resp = httpclient.execute(httpget);

        JSONArray countries = JSONArray.fromObject(EntityUtils.toString(resp
                .getEntity()));
        System.out.println("countries: " + countries);
        httpget.releaseConnection();
    }
}