Web Services - An XML-RPC Client for Android

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

Postby ducateg » Wed Sep 03, 2008 2:12 pm

:oops:

Holy kr4p I only had to add a permission:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <uses-permission xmlns:android = "http://schemas.android.com/apk/res/android" android:name = "android.permission.INTERNET"></uses-permission>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


And every thing is back to normal :shock: ... I cannot dare tell you how much time I have wasted for that...
User avatar
ducateg
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 07, 2008 10:32 am
Location: Ipswich UK

Top

zip file

Postby Txorl » Mon Sep 22, 2008 7:10 pm

@ducateg

you seem to got it work for beta 0.9. I got still plenty of errors :/
could you attach a zip file of your working application. Would be so useful.


Thanks in advance

Txorl
Txorl
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Sep 17, 2008 3:12 pm

Postby ducateg » Tue Sep 23, 2008 12:01 pm

There is the app. It contains the kxml-rpc modified as per the kickass guy. I had to rip it off my code and sanitise it too, so I do not guarantee it will run out of the box.

The crucial thing to bear in mind is that at the server side I have a xml-rpc servlet that can consume the xml-rpc messages. This is the first bit you will have to set up.

This requires a web server and the xml-rpc libraries. I got good info from here:
http://ws.apache.org/xmlrpc/index.html

xml-rpc can be a bit funny if it is the first time you look at it (it was for me). The thing to bear in mind is that it is about setting up a normal servlet that happen to have a property file with a single argument which is the name of the class you want to write that consumes the xml-rpc messages (long sentence I know).

Anyhow, I had to do a funny modification to the xmlrpc-common-3.1.jar which is explained in a previous post. and recompile. Before I did this, everything worked but the answer was not understood by android. I have a suspicion this is no longer necessary and the 0.9 sdk does not require this fix.

The Communication class that has the code itself is rather simple, hopefully it is self-explanatory. The hard bits were delivered to us at the start of this stream... :P

So, that's about it... Good luck

as a disclaimer, I would say do whatever you like with the code but if it melts your machine and create chaos on a global scale, don't come back to me... :wink:
Attachments
communication.zip
(68.61 KiB) Downloaded 653 times
User avatar
ducateg
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 07, 2008 10:32 am
Location: Ipswich UK

Postby ninor » Wed Sep 24, 2008 6:43 pm

A milion thanks for your time, ducateg.
Great submission

:wink:
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Help about server side plzzz

Postby Hans » Fri Oct 03, 2008 10:16 pm

Thanks ducateg for posting your project. I managed to get it running on SDK 0.9 but since most probably i do not have the right PHP on the server side i am not getting any reply. Would you please be able to explain what should i install on the serverside. I already have Apache and PHP. Any help would be greatly appreciated.

Thanks
Hans
Freshman
Freshman
 
Posts: 3
Joined: Fri Oct 03, 2008 8:24 am

Postby ducateg » Tue Oct 07, 2008 10:29 am

Try this:
.
Like I said this link XML-RPC tutorial:

has good details about the xml-rpc server side set up info.


Basically, you create a web based project (I use netbeans to do that)


you write a POJO, say "Relay.java" (a simple java class) with one method like so:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public String returnHello(String in)
  3.  
  4. {
  5.  
  6.     return "hello "+in;
  7.  
  8. }
  9.  
  10.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

You include all the xml-rpc libraries

You add the property file that points to the POJO Relay.java
It should be a one liner like so:

xmlrpc=your.path.to.Relay

You check the web.xml to include:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.     <servlet>
  3.  
  4.         <description>A test for XML-RPC connection</description>
  5.  
  6.         <servlet-name>XmlRpcServlet</servlet-name>
  7.  
  8.         <servlet-class>org.apache.xmlrpc.webserver.XmlRpcServlet</servlet-class>
  9.  
  10.         <init-param>
  11.  
  12.           <param-name>enabledForExtensions</param-name>
  13.  
  14.           <param-value>true</param-value>
  15.  
  16.         </init-param>
  17.  
  18.     </servlet>
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.     <servlet-mapping>
  27.  
  28.         <servlet-name>XmlRpcServlet</servlet-name>
  29.  
  30.         <url-pattern>/xmlrpc</url-pattern>
  31.  
  32.     </servlet-mapping>
  33.  
  34.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


If this still does not work you add the zip file content into your source code. I did not have the time to turn it into a jar. Feel free to do so. It contains one change I mentioned in the trail before, Good luck.
Attachments
xml-rpc_android.zip
(98.62 KiB) Downloaded 573 times
User avatar
ducateg
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 07, 2008 10:32 am
Location: Ipswich UK

Top

Postby Hans » Fri Oct 10, 2008 3:56 pm

Thanks for your help.
Do you have anything similar in PHP please?

Thanks
Hans
Freshman
Freshman
 
Posts: 3
Joined: Fri Oct 03, 2008 8:24 am

Postby ducateg » Fri Oct 10, 2008 4:39 pm

I'm afraid not. I am just as useful as Google when it comes to PHP.

Sorry, I seem to believe everyone programs in Java. :roll:

My advise is to get a simple xml-rpc server side going and to check that it is supported wherever you want your web site to be hosted.

When you manage, be sure to leave a little message here :wink:

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

Postby callingshotgun » Wed Nov 12, 2008 1:37 am

I tried downloading your source code for the android xmlrpc client, but I'm getting compiler errors- It can't seem to find any of the classes in android.net.http other than SslCertificate. The other ones, like RequestQueue, are gone.

I can't find *anything* in the docs about these classes having been moved, or having existed in the first place. Does this mean it's not safe (with regards to funtionality, not security) to use these classes on an actual G1?
callingshotgun
Freshman
Freshman
 
Posts: 4
Joined: Sun Nov 02, 2008 10:29 pm

Postby ducateg » Wed Nov 12, 2008 6:40 pm

You are right. It is funny because my app still runs (emulator not actual device). However, I extracted the old bits from previous Android sdk. I am pretty sure this is not a good idea regarding security, but using this might help compile.

I have my application working with this.
Attachments
android_xmlrpc_extra.zip
Select bits from 0.9 sdk. You can rename to .jar
(81.91 KiB) Downloaded 488 times
User avatar
ducateg
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Jul 07, 2008 10:32 am
Location: Ipswich UK

Postby mkorenba » Wed Nov 26, 2008 5:08 pm

Callingshotgun or Ducateg,

Have either of you found out what happened to the classes that have mysteriously disappeared from the android 1.0 SDK?

I guess specifically theses classes:

import android.net.http.EventHandler;
import android.net.http.Headers;
import android.net.http.RequestQueue;

Have you been able to get kxmlrpc to work with the 1.0 SDK without these classes?

Any help/ insight is much appreciated.
mkorenba
Freshman
Freshman
 
Posts: 4
Joined: Wed Nov 26, 2008 5:02 pm

Postby ducateg » Fri Nov 28, 2008 10:33 am

mkorenba
Check my previous post, it has libraries extracted from previous SDKs, I do not suppose it is a very secure way of doing things, but it works for me. Let us know...

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

Postby mkorenba » Fri Nov 28, 2008 7:44 pm

Yes I saw that, thank you. However, if they removed it from the most recent SDK I assume there was good reason for it. I was just wondering if anyone found out what happened to those specific classes in the most recent SDK (e.g. maybe they got moved to another package, or there is a comparable class with a different name).

Thanks
mkorenba
Freshman
Freshman
 
Posts: 4
Joined: Wed Nov 26, 2008 5:02 pm

working with web service in sdk 1.0

Postby discover_dileep » Tue Jan 06, 2009 2:56 pm

Hi all
I am trying to call a web service .For this i am following "daniel.kick.ass"tutorial. but error is comin in the org.kxmlrpc.java class on the line :
XmlRpcEventHandler eventHandler = new XmlRpcEventHandler();

// Create the connection and post the arguments
con = new RequestQueue(context);
con.queueRequest(url, "POST", headers, eventHandler, bis, request.length, false);
con.waitUntilComplete();
Error is appearing on the last line i.e. con.wait.untillComplete.error message is : "The method waitUntilComplete() is undefined for the type RequestQueue"

I am using sdk ver1.0 .Please help me out.
discover_dileep
Developer
Developer
 
Posts: 33
Joined: Tue Oct 21, 2008 2:19 pm

Postby mkorenba » Tue Jan 06, 2009 7:09 pm

discover_dileep,

Try this instead:

http://www.anddev.org/slim_xml-rpc-t3800.html


I've found it works without issue in SDK 1.0
mkorenba
Freshman
Freshman
 
Posts: 4
Joined: Wed Nov 26, 2008 5:02 pm

Top
PreviousNext

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests