HTTP and JSON

45 views
Skip to first unread message

Michal Panek

unread,
Mar 27, 2014, 7:24:15 PM3/27/14
to gama-p...@googlegroups.com
Hi,
I would like to know whether in Gama Platforrm I can use http to connect with some server to download some informations with GET?
I would like also to send them back in order to retrieve data which is processed by some distance engine.
Moreover is it possible to parse JSON which I would like to receive by HTTP protocol?

If not, what could the solution to do that? Write my own plugin and use it during simulation?

Michal

Patrick Taillandier

unread,
Mar 27, 2014, 11:24:37 PM3/27/14
to gama-p...@googlegroups.com
Hi Michal,

Concerning the http connection (and the database access), GAMA provides some tools: https://code.google.com/p/gama-platform/wiki/Ext_DB_SQL16. I think, other tools are currently under development (Viet ? )

I don't think someone has already developed a plug-in to parse JSON. You will maybe have to write your own plug-in (you will see if you follow the documentation that it is quite easy.... at least if you have some knowledge in Java - https://code.google.com/p/gama-platform/wiki/CreationPlugins15).

Cheers,

Patrick 


--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Robin Cura

unread,
Mar 28, 2014, 4:07:11 AM3/28/14
to gama-p...@googlegroups.com
Hi,

Or you can call R from GAMA, and use some of the many packages that are dedicated to web querying.

HTH,
Robin

Michal Panek

unread,
Mar 28, 2014, 5:53:06 AM3/28/14
to gama-p...@googlegroups.com, robin...@parisgeo.cnrs.fr
So to sum up:
What will the best (the easiest and the fastest) way to connect to a serwer by HTTP, send some information and the received back (and processed) and use it during simulation?

Thanks for your help, I am kind of a newbie.

Viet Truong Xuan

unread,
Mar 29, 2014, 2:44:28 PM3/29/14
to gama-p...@googlegroups.com
Hi Mr Michal,

Calling JSON from RESTful WebServices isn't committed yet because it isn't carefully verified. But in a simple way,  you can create a new operator as you want and add the code like:

//static String getGeocodingAPIOnline(String address, String sensor)
//    {
        String url = "https://maps.googleapis.com/maps/api/geocode";
        Client client = Client.create();
        client.setFollowRedirects(true);
        WebResource resource = client.resource(url);
        MultivaluedMap<String,String> params = new MultivaluedMapImpl();
        params.add("address", address);
        params.add("sensor", sensor);
       
        String res = resource.path("json").queryParams(params).get(String.class);

        // PARSING CODE IF NEEDED

        System.out.print(res);
        return res;
  //  }

Because the JSON data structure is so open, then a its parser to GAMA data structure is not really easy, so you can code it if needed.

The external library are as following:
(1) JERSEY: https://jax-rs-spec.java.net/
(2) Additional jar files:
activation.jar
jaxb-api.jar
jsr173_api.jar

Cheers,

Viet



--

Michal Panek

unread,
Mar 30, 2014, 3:48:55 AM3/30/14
to
Thank you very much, I was thinking that the easiest way to connect thorugh HTPP is to write some simple code as a GAMA function or something and you have showed me the way :)
I also will handle JSON parsing, that wouldn't be a problem so only as it would be JAVA programming :)
Reply all
Reply to author
Forward
0 new messages