consuming django json-rpc services

43 views
Skip to first unread message

lucrus

unread,
Mar 21, 2010, 7:10:35 AM3/21/10
to jabsorb-user
Hello *,

I'm new here, new to jabsorb, new to rpc, new to json, new to django
and quite new to webservices too, so please be patient if I post
trivial questions.

I have to write some unit tests for a number of json-rpc webservices
published by a Django setup. My customer wants the unit tests to be
done in Java (which is the only thing I've been using for 10 years
now).

Is there a snippet of sample code that shows how to consume such
webservices with jabsorb? Is jabsorb a viable solution at all? I've
looked at the API docs (Client class) but it's not clear to me how I'd
use it.

This is what I've written so far:

private HashMap createRPCMap(String method, String[] strparams)
{
ArrayList<String> al = new ArrayList<String>(strparams.length);
for (String s: strparams)
al.add(s);
HashMap params = new HashMap();
params.put("id", "djangorpc");
params.put("method", "resources." + method);
params.put("params", al);
return params;
}

@Test
public void addPoiCategory()
{
JSONObject jsonreq = new
JSONObject(createRPCMap("add_poi_category",
new String[]{"cat-1", "cat-1 desc", "icon 1",
"0"}));

URI uri = URI.create(host + context);
HTTPSession session = new HTTPSession(uri);
Client c = new Client(session);
}

...and then? How do I use my Client to consume the service?

Lucio Crusca

unread,
Mar 23, 2010, 4:39:28 AM3/23/10
to jabsor...@googlegroups.com
In data domenica 21 marzo 2010 12:10:35, lucrus ha scritto:

>
> ...and then? How do I use my Client to consume the service?
>

No replies in 2 days, this has to mean something...

1. Is there anyone out there consuming JSON services from Java?
2. Is Jabsorb dead?
3. Maybe "Django" in my question scared most of you, so let's put it another
way: how do I use Jabsorb to consume standard JSON services regardless of the
server software?

Arthur Blake

unread,
Mar 23, 2010, 10:03:06 AM3/23/10
to jabsorb-user
Sorry that nobody responded. I didn't personally respond because I
didn't think the question was specific enough.

I wasn't sure if you were referring to the Java client or the
JavaScript client. I think from the context you mean the Java client.
I haven't personally used the Java client, and it's not too well
documented. This page might help: http://jabsorb.org/JavaClient
The classic use case of jabsorb is to have the client running in the
browser, connecting to the server running on java, over http.
The all-java client is a relatively newer component that you can use
for direct java to java connection, or potentially java to some other
json-rpc service, which I think is what you need.

Hopefully, Sasha (the author of the all java client) could write a
more in depth tutorial on the wiki on how to use it.
(Sasha, feel free to jump in to this discussion at any time!)

Also, using jabsorb as a client to call another type of json-rpc
service is not normally what people want to do, because most of the
value of jabsorb is what it provides on the server.
This is not to say that it can't be done; it certainly can be used
that way.
Your best bet is to try things out and see if you can get it working.
If you get stuck at a certain point, ask more specific questions.

Reply all
Reply to author
Forward
0 new messages