Forum » Development Discussion

Using Apache XML-RPC (written in Java)

 
  • Using Apache XML-RPC (written in Java)

    Hi everyone,

    What a great idea - I love last.fm and I just stumbled upon the Scrobbler!
    I can see that most of the people prefer using PHP or the java bindings - (sorry I haven't used any links), but I performed a search on xml-rpc, rpc, and xmlrpc and there was nothing on the Discussion board. I also noticed that some of the people have troubles with the encoding of the arguments sent to the scrobbler - mainly the "&" character. After a few days of unsuccessful attempts to query the scrobbler API using apache-xmlrpc-3.1.3.jar I have finally managed to get results. It is pretty simple at the end, but Web Services, XML-RPC is new to me, and the discussion board got me confused over the ampersand signs. The easiest way to do queries with the xmlrpc in java without the bindings is to use a

    Map<String, String> paramMap = new HashMap<String, String>();

    Add the <name><value> pairs needed for the query without any '&' or '=' as in:

    paramMap.put("artist", "tool");

    This is the only way to send 'named arguments' as
    and after that create an Object[] array - let's call it arguments - to hold the paramMap.
    This object is passed to the

    HttpClient(theScrobblerURL).execute("Artist.getTopTracks", arguments);

    and the resulting String containing the response will be displayed in the command prompt, or servlet, or in a JFrame - whenever you put it. I guess the logical next step would be to parse the results using DOM...

    But I felt I had to do this as there was no XML-RPC tread and I received a "Missing requested parameter" (or something similar) response far too many times.

    I hope this helps someone

Anonyma användare kan inte skriva inlägg. Vänligen logga in eller skapa ett konto för att göra inlägg i forumen.