Web Services - An XML-RPC Client for Android

Tutorials with advanced 'difficulty' and more Lines of Code.

Web Services - An XML-RPC Client for Android

Postby daniel.kick.ass » Wed Jan 23, 2008 7:02 pm

[align=center]Web Services - An XML-RPC Client for Android [/align]

Difficulty: 3 of 5

Description:
I was looking for a way to implement a lightweight web service communication.
First I saw this post by Lex ( :src: Calling a web service from Android) about kSOAP. It drew my attention. But I did some reading and decided that this implementation is too heavy for the Android platform. I wanted my code to go easy on the resources. So I did some further research and decided to go with the kXML-RPC which is a lightweight implementation of the XML-RPC protocol.

It wasn't all strait forward though since this library is actually meant to work with the J2ME SDK and it is not 100% compatible with the Android SDK.
Using some docs a debugger and the tutorial plusminus posted here (:src: Doing HTTP Post with Android) I managed to make this library work on Android.
Here is a small guide on how to make it all work together.

1. Download the kXML-RPC sources (http://sourceforge.net/projects/kxmlrpc).

2. Download the kXML2 sources
(http://sourceforge.net/project/showfile ... e_id=58653). You need it since the kXML-RPC lib depends on it to do the XML parsing.


3. Add those packages to your project.

4. Now to make it work with android you need to modify the "execute" method at the org.kxmlrpc.XmlRpcClient class.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     /**
  2.  
  3.      * An Android specific implementation of the "execute" method
  4.  
  5.      */
  6.  
  7.     public Object execute(String method, Vector params, Context context) throws Exception {
  8.  
  9.                 KXmlSerializer                  xw = null;
  10.  
  11.                 XmlRpcWriter                    writer = null;
  12.  
  13.                 XmlRpcParser                    parser = null;
  14.  
  15.                 RequestQueue                    con = null;
  16.  
  17.                 ByteArrayOutputStream   bos = null;
  18.  
  19.                 ByteArrayInputStream    bis = null;
  20.  
  21.  
  22.  
  23.                 try {
  24.  
  25.                         // Prepare the arguments for posting
  26.  
  27.                         bos = new ByteArrayOutputStream();
  28.  
  29.                         xw = new KXmlSerializer();
  30.  
  31.                         xw.setOutput(new OutputStreamWriter(bos));
  32.  
  33.                         writer = new XmlRpcWriter(xw);
  34.  
  35.                         writer.writeCall(method, params);
  36.  
  37.                         xw.flush();
  38.  
  39.                        
  40.  
  41.                         if (debug)
  42.  
  43.                                 Log.d(DEBUG_TAG, bos.toString());
  44.  
  45.                        
  46.  
  47.                         byte[] request = bos.toByteArray();
  48.  
  49.                         bis = new ByteArrayInputStream(request);
  50.  
  51.  
  52.  
  53.                         Map<String, String> headers = new HashMap<String, String>();
  54.  
  55.                         headers.put("Content-Type", "text/xml");
  56.  
  57.                        
  58.  
  59.                         XmlRpcEventHandler eventHandler = new XmlRpcEventHandler();
  60.  
  61.  
  62.  
  63.                         // Create the connection and post the arguments
  64.  
  65.                         con = new RequestQueue(context);
  66.  
  67.                         con.queueRequest(url, "POST", headers, eventHandler, bis, request.length, false);
  68.  
  69.                         con.waitUntilComplete();
  70.  
  71.                        
  72.  
  73.                         ByteArrayInputStream in = new ByteArrayInputStream(eventHandler.getBytes());
  74.  
  75.                        
  76.  
  77.                         // Parse response from server
  78.  
  79.                         KXmlParser xp = new KXmlParser();
  80.  
  81.                         xp.setInput(new InputStreamReader(in));
  82.  
  83.                         parser = new XmlRpcParser(xp);
  84.  
  85.                         result = parser.parseResponse();
  86.  
  87.  
  88.  
  89.                 } catch (Exception x) {
  90.  
  91.                         Log.e(DEBUG_TAG + ".error", x.getMessage());
  92.  
  93.                 }//end try/catch/finally
  94.  
  95.  
  96.  
  97.                 if (result instanceof Exception)
  98.  
  99.                         throw (Exception) result;
  100.  
  101.  
  102.  
  103.                 return result;
  104.  
  105.         }//end execute( String, Vector )
  106.  
  107.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


5. And here is the event handler class that will get for the server response. (This is based on the code posted by plusminus).

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     /**
  2.  
  3.      * This class receives the server response
  4.  
  5.      */
  6.  
  7.     private class XmlRpcEventHandler implements EventHandler {
  8.  
  9.                 private final String DEBUG_TAG = "XmlRpcEventHandler";
  10.  
  11.                 private ByteArrayBuffer m_byteArray = new ByteArrayBuffer(20);
  12.  
  13.  
  14.  
  15.                 XmlRpcEventHandler() {
  16.  
  17.                 }
  18.  
  19.  
  20.  
  21.                 public void data(byte[] bytes, int len) {
  22.  
  23.                         m_byteArray.append(bytes, 0, len);
  24.  
  25.                 }
  26.  
  27.  
  28.  
  29.                 public void endData() {
  30.  
  31.                         Log.d(DEBUG_TAG + ".endData", new String(m_byteArray.toByteArray()));
  32.  
  33.                 }
  34.  
  35.  
  36.  
  37.                 public void status(int arg0, int arg1, int arg2, String s) {
  38.  
  39.                         Log.d(DEBUG_TAG + ".status", "status [" + s + "]");
  40.  
  41.                 }
  42.  
  43.  
  44.  
  45.                 public void error(int i, String s) {
  46.  
  47.                         Log.d(DEBUG_TAG + ".error", "error [" + s + "]");
  48.  
  49.                 }
  50.  
  51.  
  52.  
  53.                 public void handleSslErrorRequest(int arg0, String arg1, SslCertificate arg2) {
  54.  
  55.                 }
  56.  
  57.  
  58.  
  59.                 public void headers(Iterator arg0) {
  60.  
  61.                 }
  62.  
  63.  
  64.  
  65.                 public void headers(Headers arg0) {
  66.  
  67.                 }
  68.  
  69.                
  70.  
  71.                 public byte[] getBytes() {
  72.  
  73.                         return m_byteArray.toByteArray();
  74.  
  75.                 }
  76.  
  77.         }    
  78.  
  79.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


6. Now you are almost done. Except there is a problem with the kXML-RPC library. It throws an exception while parsing the return values.
I believe it is a bug in the library. And here is the fix.
Open the "parseValue" method at the org.kxmlrpc.XmlRpcParser class and replace it with this one.


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         Object parseValue() throws XmlPullParserException, IOException {
  2.  
  3.                 Object      result = null;
  4.  
  5.                 parser.require(XmlPullParser.START_TAG, null, "value");
  6.  
  7.                 parser.nextTag();
  8.  
  9.  
  10.  
  11.                 parser.require( XmlPullParser.START_TAG, null, null );
  12.  
  13.                 String name = parser.getName();
  14.  
  15.                 if( name.equals("string") )
  16.  
  17.                         result = parser.nextText();
  18.  
  19.                 else if( name.equals("i4") || name.equals("int") )
  20.  
  21.                         result = new Integer
  22.  
  23.                         ( Integer.parseInt( parser.nextText().trim() ) );
  24.  
  25.                 else if( name.equals("boolean") )
  26.  
  27.                         result = new Boolean( parser.nextText().trim().equals("1") );
  28.  
  29.                 else if( name.equals("dateTime.iso8601") )
  30.  
  31.                         result = IsoDate.stringToDate  
  32.  
  33.                         ( parser.nextText() );
  34.  
  35.                 else if( name.equals("base64") )
  36.  
  37.                         result = Base64.decode( parser.nextText() );
  38.  
  39.                 else if( name.equals("struct") )
  40.  
  41.                         result = parseStruct();
  42.  
  43.                 else if( name.equals("array") )
  44.  
  45.                         result = parseArray();
  46.  
  47.                 // kxmlrpc does not currently support the XML-RPC double data type
  48.  
  49.                 //  the temporary workaround is to process double values as strings
  50.  
  51.                 else if( name.equals("double") )
  52.  
  53.                         result = parser.nextText();
  54.  
  55.                     // return as text if the tag is not part of XML-RPC grammar
  56.  
  57.                     // this is a temporary workaround as we need to be able to return
  58.  
  59.                     // XML and HTML as a whole long String without terminating with </value>
  60.  
  61.                     else result = parser.nextText();
  62.  
  63.  
  64.  
  65.                 parser.require( XmlPullParser.END_TAG, null, name );
  66.  
  67.                 parser.nextTag();
  68.  
  69.  
  70.  
  71.                 parser.require( XmlPullParser.END_TAG, "", "value" );
  72.  
  73.                 return result;
  74.  
  75.         }//end parseValue()
  76.  
  77.  
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


7. Now you have an XML-RPC client on your Android platform.
If you want to test this code you can call it using a method similar to this one.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         public void ping(Context context) {
  2.  
  3.                 XmlRpcClient client = new XmlRpcClient("192.168.1.104/rpctest/server.php");
  4.  
  5.                 Object res = null;
  6.  
  7.                 try {
  8.  
  9.                         res = client.execute("getResponse", new Vector(), context);
  10.  
  11.                 } catch (Exception e) {
  12.  
  13.                         new ExceptionNotification(m_context, e.getMessage());
  14.  
  15.                 }
  16.  
  17.                 Log.d(DEBUG_TAG + ".ping", res.toString());
  18.  
  19.         }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

8. And that's a wrap.

Last final note. To test it all in action I used Keith Devens PHP library for the server. You can grab it here: (http://keithdevens.com/software/xmlrpc)
The logcat output of my test was:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         D/XmlRpcEventHandler.status(11544): status [OK]
  2.  
  3.         D/XmlRpcEventHandler.endData(11544): <?xml version="1.0" ?>
  4.  
  5.         D/XmlRpcEventHandler.endData(11544): <methodResponse>
  6.  
  7.         D/XmlRpcEventHandler.endData(11544):    <params>
  8.  
  9.         D/XmlRpcEventHandler.endData(11544):            <param>
  10.  
  11.         D/XmlRpcEventHandler.endData(11544):                    <value>
  12.  
  13.         D/XmlRpcEventHandler.endData(11544):                            <string>Hello World</string>
  14.  
  15.         D/XmlRpcEventHandler.endData(11544):                    </value>
  16.  
  17.         D/XmlRpcEventHandler.endData(11544):            </param>
  18.  
  19.         D/XmlRpcEventHandler.endData(11544):    </params>
  20.  
  21.         D/XmlRpcEventHandler.endData(11544): </methodResponse>
  22.  
  23.         D/WebServiceClient.ping(14583): Hello World
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


Hope it helped you to gain some understanding on how to implement XML-RPC with web services.

Regards,
Daniel
daniel.kick.ass
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Dec 22, 2007 9:54 pm

Top

Postby res » Thu Jan 24, 2008 5:53 am

Nice tutorial :)
res
Senior Developer
Senior Developer
 
Posts: 146
Joined: Tue Nov 20, 2007 8:14 pm
Location: United States

XML-RPC Client

Postby gvkreddyvamsi » Thu Jan 31, 2008 11:36 am

I studied this application. Very well.

Where i can get full source code.

Can any body send me zip file for this application.


by
vamsi
gvkreddyvamsi
Developer
Developer
 
Posts: 43
Joined: Mon Jan 21, 2008 5:10 am
Location: INDIA

Postby chris » Sat Feb 02, 2008 10:55 pm

Tips:
If you want to use long , you have to get the latest Version from CSV (or SVN , i don't remember) as kxml-rpc is intended for javaMe where no float type is implemented.therefore , no float type is handeled by the default version that is designed to work on all version of JRE

And by the Way , the kxml library is included in Android , so there's no need yet to include the source of this library in your project.


I'm having some problem when getting the result : the parser is looking for data after the tag <value> and is finding a \n which caus him to look for the </value> tag and make it crash.
Anyone know how to deal with that? (i'm thinking of modifying the parser but ther must be a good reason that exqplin the way it has been coded and i'm not a XML-RPC Expert (and i have other things to do)

Has anyone else tried others implementations of XML-RPC (the one from apache is needing some java.xml library that have been included in Android) ?

Chris

PS I just modified my PHP serveur script to remove the \n and now it's working.
Thince kxmlrpc is using 'undocumented' api from android , i don't think i'll go any further.Let's see what's coming soon with the new development kit next week
chris
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sat Feb 02, 2008 4:39 pm

please attach ksoap2 SOAP client example application

Postby gvkreddyvamsi » Thu Feb 21, 2008 8:42 am

hi,

I was tried to get through KSOAP2 . But i got lot errors while doing. please attach zip file for example application.


Thanks in advance.



by
vamsi
gvkreddyvamsi
Developer
Developer
 
Posts: 43
Joined: Mon Jan 21, 2008 5:10 am
Location: INDIA

Postby daniel.kick.ass » Thu Feb 21, 2008 10:34 pm

Hey Vasmi,

First of all, just to clarify, this tutorial is about kXML-RPC not kSOAP.

The code above should work ok if you follow the steps.
If you still getting errors, send me your code to daniel.kick.ass@gmail.com and I will take a look at it when I get a spare moment.

Just a note for everybody, like Chris mentioned, you don't need to add the kXML2 lib to your project since it's a part of the SDK.
Also, there is a problem when the parser gets an XML with no actual data (like string, double etc). You should either modify your server to send default empty values, or change your client parser (XmlRpcParser.parseValue) to take care of that situation.

The client can look like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         Object parseValue() throws XmlPullParserException, IOException {
  3.  
  4.                 Object      result = null;
  5.  
  6.                 parser.require(XmlPullParser.START_TAG, null, "value");
  7.  
  8.                 int tagType = parser.nextTag();
  9.  
  10.  
  11.  
  12.                 if (tagType != XmlPullParser.END_TAG) {
  13.  
  14.  
  15.  
  16.                         // Same as before
  17.  
  18.  
  19.  
  20.                 } else {
  21.  
  22.                         // If there is no value, return an empty string object
  23.  
  24.                         result = new String();
  25.  
  26.                 }
  27.  
  28.                
  29.  
  30.                 parser.require( XmlPullParser.END_TAG, "", "value" );
  31.  
  32.                 return result;
  33.  
  34.         }//end parseValue()
  35.  
  36.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4



Daniel
daniel.kick.ass
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Dec 22, 2007 9:54 pm

Top

kXML-RPC source

Postby daniel.kick.ass » Sat Feb 23, 2008 4:46 am

Hey guys,

I got a bunch of questions and requests for the source so I'd better just post it all.
The attached zip file contains a sample project that utilizes kXML-RPC on Android.
The server implementation is totally up to you.
For testing purposes I used this code for my server:

Syntax: [ Download ] [ Hide ]
Using php Syntax Highlighting
  1. <?php
  2.  
  3.  
  4.  
  5. $xmlrpc_methods = array();
  6.  
  7. $xmlrpc_methods['server.getResponse'] = 'callbuddy_getgetResponse';
  8.  
  9.  
  10.  
  11. function callbuddy_getgetResponse($params) {   
  12.  
  13.         $response = array();
  14.  
  15.  
  16.  
  17.         $response[] = "server: val 1";
  18.  
  19.         $response[] = "server: val 2";
  20.  
  21.         $response[] = "server: val 3";
  22.  
  23.         $response[] = "server: val 4";
  24.  
  25.                        
  26.  
  27.         # Send a response to the client
  28.  
  29.         XMLRPC_response(XMLRPC_prepare($response), $this_server);
  30.  
  31. }
  32.  
  33.  
  34.  
  35. ?>
Parsed in 0.066 seconds, using GeSHi 1.0.8.4


Please note that you should provide the correct IP or the app will hang trying to connect to an invalid IP.
Your IP might change after you restart your machine.
Also, as it was mentioned numerous times before, do not put "localhost" as your IP address. This will only make Android to ping itself instead of the host.

Daniel
Attachments
WebService.zip
Web service client source.
(22.58 KiB) Downloaded 2123 times
daniel.kick.ass
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Dec 22, 2007 9:54 pm

Postby Mohamed Mo3ty » Sat Feb 23, 2008 2:00 pm

thanks daniel :D
Mohamed Mo3ty
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Feb 22, 2008 3:14 pm

Postby ksiomelo » Sat Mar 01, 2008 10:10 pm

Can you attach source code of php file, So that it's useful to me to test your program... :)
ksiomelo
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Mar 01, 2008 8:09 pm

Postby oho » Wed Apr 16, 2008 3:09 pm

Hello,

I have extended the example by authentication.

In class XmlRpcClient I have added:

The variable:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. /**
  2.  
  3.   * Stores the authentication string
  4.  
  5. */
  6.  
  7. private String auth = null;
Parsed in 0.037 seconds, using GeSHi 1.0.8.4



The method:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.   /**
  2.  
  3.      * Sets Authentication for this client. This will be sent as Basic
  4.  
  5.      * Authentication header to the server as described in
  6.  
  7.      * <a href="http://www.ietf.org/rfc/rfc2617.txt">
  8.  
  9.      * http://www.ietf.org/rfc/rfc2617.txt</a>.
  10.  
  11.      */
  12.  
  13.     public void setBasicAuthentication(String user, String password) {
  14.  
  15.         if (user == null || password == null) {
  16.  
  17.                 auth = null;
  18.  
  19.         } else {
  20.  
  21.                 auth = new String(Base64.encode((user + ':' + password).getBytes())).trim();
  22.  
  23.         }
  24.  
  25.     }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


and in the method:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public Object execute(String method, Vector params, Context context) throws Exception {
  2.  
  3. *
  4.  
  5. *
  6.  
  7. *
  8.  
  9. if (auth != null) {
  10.  
  11.     headers.put("Authorization", "Basic " + auth);
  12.  
  13. }
  14.  
  15.  
  16.  
  17.  
  18.  
  19. *
  20.  
  21. *
  22.  
  23. *
  24.  
  25.  
  26.  
  27.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


This can be set by:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. client.setBasicAuthentication(username, pwd);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


I have only tried it with basic authentication so far.

Hth.
Cheers,
Oho
oho
Freshman
Freshman
 
Posts: 4
Joined: Thu Mar 27, 2008 3:05 pm

Can't make it work...

Postby ducateg » Mon Jul 07, 2008 11:17 am

First thanks for this tutorial, it is fan-ta-stic.

Now, however, it fails to return an answer to me. So, I have a XML RPC server that works fine. I use kxml to call a service which now works. However, my android app cannot process the answer coming back to my Android app.

I can debug up to the XmlRpcClient: con.queueRequest(url, "POST", headers, eventHandler, bis, request.length, false)

then, debugging becomes a bit messy (because step by step debug does not pass this point). However, using Log.d statements, I can track the code down to line (so it seems to run fine until the following line) :
result = parser.parseResponse()

At this point I get an error that says:
unexpected type (position:END_DOCUMENT null@1:0 in sent java.io.InputStreamReader@4003fad0)

However, inspecting objects in debug mode, the answer - has made it - to the android app, I can see the following answer when I inspect the eventHandler object):
<?xml version="1.0" encoding="UTF-8"?><methodResponse xmlns:ex="htt;://ws.apache.org/xmlrpc/namespaces/externsions"><params><param><value>sent</value></param</params></methodResponse>

The response is actually coming back, so, I am not sure what is wrong, my guesses so far are:
- The byte stream is not closed propertly (whatever that means)
- The XML-RPC return format is not as expected in kxml

I do not rule out an external cause such as a connection badly closed down which would mislead the diagnostic...

I would very much appreciate if anyone can shed light on this problem.

PS: The main cause of all the bugs I see normally come down to me coding things in the wrong way, so, I would not be surprised to find out I am just doing something silly...
User avatar
ducateg
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 07, 2008 10:32 am
Location: Ipswich UK

Postby daniel.kick.ass » Mon Jul 07, 2008 11:40 am

Hi,

The server response should contain the <type></type> tags between the <value></value> tags. This is how the variables get parsed. Your server response doesn't have those, thus the code can't determine the type of your variables.
Also, the response snapshot that you posted here is buggy. If it's due to "copy-pasting" than in doesn't matter, but if this is how it look in reality then it's a problem:

<?xml version="1.0" encoding="UTF-8"?>
<methodResponse xmlns:ex="htt;://ws.apache.org/xmlrpc/namespaces/externsions">
<params>
<param>
<value>sent</value>
</param
</params>
</methodResponse>

This should be something like this:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <methodResponse xmlns:ex="http://ws.apache.org/xmlrpc/namespaces/externsions">
  4.  
  5. <params>
  6.  
  7.         <param>
  8.  
  9.                 <value>
  10.  
  11.                         <string>sent</string>
  12.  
  13.                 </value>
  14.  
  15.         </param>
  16.  
  17. </params>
  18.  
  19. </methodResponse>
  20.  
  21.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Daniel
daniel.kick.ass
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Dec 22, 2007 9:54 pm

Postby ducateg » Tue Jul 08, 2008 2:51 pm

Thanks for the fast answer and the enlightning insight.
I have been spending some time trying to figure out why the <string> tag did not appear.

It turns out the source code for the org.apache.xmlrpc.serializer.StringSerializer did not put it. It had been deliberately excluded. Anyway, I put it back in. Unfortunately but the error has not changed. So, I now have the following data going back:
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse xmlns:ex="http://ws.apache.org/xmlrpc/namespaces/extensions">
<params>
<param>
<value>
<string>sent</string>
</value>
</param>
</params>
</methodResponse>

but, the error is the same

E/[XmlRpcClient].error( 783): unexpected type (position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@401679e0)

So, the parser object seems to have the correct data now but throws an END_DOCUMENT null error. What should the last character of the byte stream be? I have a printed the byte stream and the last byte is 62 which is the > character. Is this ok? Should I see some sort of EOL or END_OF_DOCUMENT character of some sort instead?

Any info on the issue greatly appreciated.
User avatar
ducateg
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 07, 2008 10:32 am
Location: Ipswich UK

Postby ducateg » Tue Jul 08, 2008 4:57 pm

Everybody stop thinking about my problem I got it sorted :o and :lol:

daniel did kick ass because he had it covered in his last post. Stupidly, I was looking up the byte stream object (for debug purposes) which is why I was getting the END_DOCUMENT error the second time round.

:oops:

Now, I got it working.

So, in the end, the problem was only that the <string> tag did not appear in the XML RPC answer. I did try a lot of different XML RPC versions (2.0, 3.0a1, 3.0b1, 3.0rc1, 3.1...).

The way to fix this was to go to the:
org.apache.xmlrpc.serializer.StringSerializer class

and replace the single line, in the write method (that class only has one line of code anyway):

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. write(pHandler, null, pObject.toString());
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


with the line:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. write(pHandler, STRING_TAG, pObject.toString());
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


So, you see, the second argument had been left to null which, for the parser class in kxml seems to be wrong.

Perharps this solution can come handy to someone else, I am surprised other people did not face this issue, is it only me?

Anyhow, I really like this way of calling and XML RPC server. For what it's worth, my XML RPC server then bridges to a WS web service. In effect, I simply wanted to bridge Android to proper Web Services. XML RPC does kick ass for that purpose. My XML RPC is hosted on a Glassfish server. What was difficult for me during this exercise was to understand how to get the server side organised. Most places/tutorials assume that people have that sorted. However, there exists quite a few ways to publish web services, and Android cannot access most of them. So, I recommend people who are trying to go from Android to web services to understand XML RPC, or whatever web service solution they're thinking of before they try this from Android (I know I had to).

At least, this problem has given me a chance to thank Daniel.kick.ass for this solution.

Thanks again.
User avatar
ducateg
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 07, 2008 10:32 am
Location: Ipswich UK

Postby ducateg » Tue Sep 02, 2008 3:50 pm

:x The app does not run since beta 0.9. Has anyone found a solution. The class it is not happy about is the RequestQueue.queueRequest method.

Many thanks in advance.
User avatar
ducateg
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 07, 2008 10:32 am
Location: Ipswich UK

Top
Next

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 7 guests