Foros de discusión

way to use JSON?

Michael W., modificado hace 12 años.

way to use JSON?

New Member Mensajes: 2 Fecha de incorporación: 30/05/11 Mensajes recientes
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, modificado hace 10 años.

RE: way to use JSON?

New Member Mensajes: 4 Fecha de incorporación: 3/09/12 Mensajes recientes
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, modificado hace 10 años.

RE: way to use JSON?

Liferay Legend Mensajes: 1399 Fecha de incorporación: 17/09/10 Mensajes recientes
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();
    }
}