// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package client

import java.lang.reflect.*

import com.googlecode.jsonrpc4j.*

import common.*

def test(String urlstr) {
	println(urlstr)
	client = new JsonRpcHttpClient(new URL(urlstr))
	v = client.invoke("getInt", new Object[0], Integer.class)
	println(v)
	s = client.invoke("getString", new Object[0], String.class)
	println(s)
	d = client.invoke("getData", new Object[0], Data.class)
	println(d)
	lstv = client.invoke("getListOfInts", new Object[0], List.class)
	println(lstv)
	lsts = client.invoke("getListOfStrings", new Object[0], List.class)
	println(lsts)
	lstdata = new ParameterizedType() {
		@Override
		public Type[] getActualTypeArguments() {
			return [ Data.class ]
		}
		@Override
		public Type getRawType() {
			return List.class
		}
		@Override
		public Type getOwnerType() {
			return null
		}
	}
	lstd = (List<Data>)client.invoke("getListOfData", new Object[0], lstdata)
	println(lstd)
	v1 = 123
	v2 = 456
	v3 = client.invoke("add", [ v1,  v2 ], Integer.class)
	println(v3)
	s1 = "ABC"
	s2 = "DEF"
	s3 = client.invoke("concat", [ s1, s2 ], String.class)
	println(s3)
	d1 = new Data(ival: 123, sval: "ABC")
	d2 = client.invoke("modify", [ d1 ], Data.class)
	println(d2)
}

test("http://localhost:8001/test")
test("http://localhost:8002/test")
test("http://localhost:8003/test")
test("http://localhost:8004/test")
test("http://localhost:8005/test")
test("http://localhost:8006/server.php")
test("http://localhost:8007/server.php")
