Foren

way to use JSON?

Michael W., geändert vor 12 Jahren.

way to use JSON?

New Member Beiträge: 2 Beitrittsdatum: 30.05.11 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: way to use JSON?

New Member Beiträge: 4 Beitrittsdatum: 03.09.12 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: way to use JSON?

Liferay Legend Beiträge: 1399 Beitrittsdatum: 17.09.10 Neueste Beiträge
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();
    }
}