Saad Farooq
Saad Farooq

Reputation: 13402

GAE - How to make an XML-RPC call?

I need to make a standard XML-RPC call to the UPC Database (www.upcdatabase.com) using my Google AppEngine Java application.

I found a lot of information on incorporating XML-RPC within GAE but couldn't find anything on how to make a call from GAE.

Any help or examples would be appreciated ?

Upvotes: 2

Views: 563

Answers (2)

Saad Farooq
Saad Farooq

Reputation: 13402

Well what do you know....

I did the following using the Redstone XMLRPC library and it works. Won't have figured that with all the focus on using URLFetch.

XmlRpcClient client = new XmlRpcClient("http://www.upcdatabase.com/xmlrpc", false);
    Map<String, String> params = new HashMap<String, String>();
    params.put("rpc_key", rpc_key);
    params.put("ean",upc);

    HashMap<?,?> token = null;
    try {
        token = (HashMap<?, ?>) client.invoke( "lookup", new Object[] { params } );
    } catch (XmlRpcException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (XmlRpcFault e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Don't quite know why it works and would love an explanation.

Upvotes: 1

Moishe Lettvin
Moishe Lettvin

Reputation: 8471

Here's a good article about how to do it: http://brizzled.clapper.org/blog/2008/08/25/making-xmlrpc-calls-from-a-google-app-engine-application/

EDIT: Sorry, I missed you were asking about Java specifically. The basic idea is the same in either language, though: make an UrlFetch request.

Here's another blog I found with some discussion: http://blog.techstacks.com/2010/01/xmlrpc-with-gae-java.html -- this one uses HTTPBuilder because at the time it was written UrlFetch wouldn't allow setting the User-Agent. That's been fixed (see http://googleappengine.blogspot.com/2009/04/sdk-version-121-released.html) though so implementing this should be much easier.

Upvotes: 0

Related Questions