jangidipramod / android-xmlrpc

Automatically exported from code.google.com/p/android-xmlrpc
0 stars 0 forks source link

dateTime Error #32

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Attempt to connect to UPC database at (http://www.upcdatabase.com/xmlrpc) 
with android-xmlrpc on Button Click

What is the expected output? What do you see instead?
Returns expected error as seen in the Serialize file of: "java.io.IOException: 
Cannot deserialize dateTime". Is there any way to bypass this error so that I 
can retrieve the rest of the data in the xml file? 

I am successfully contacting the UPC database, but am unable to read the 
returned xml. 

What version of the product are you using? On what operating system?
r15, Windows 7

Please provide any additional information below.

I'm totally new to coding, so forgive me if this is a noob mistake!
Code Sample:
try {
        HashMap<String, String> params = new HashMap<String, String>();
            params.put("rpc_key", rpc_key);
            params.put("upc", "049000042566");
            HashMap result = (HashMap)client.call("lookup", params);

            resultSize = result.get("size").toString();
            resultDesc = result.get("description").toString();

            } catch (NullPointerException nl) {
                nl.printStackTrace();
                Log.d("It's returning null", "Lookup");
            } catch (XMLRPCException e) {
                e.printStackTrace();
                Log.d("It's failed", "Lookup");
            }
            text.setText("result description: " + resultDesc + "result size: " + resultSize);

Original issue reported on code.google.com by wusu...@gmail.com on 22 Nov 2011 at 11:57

GoogleCodeExporter commented 9 years ago
The android-xmlrpc code cannot decode the date that is received from the RPC 
call (at least in version r15).  In order to correct this change the TYPE_
DATE_TIME_ISO8601 handler within XMLRPCSerializer.deserialize to :

    if (typeNodeName.equals(TYPE_DATE_TIME_ISO8601)) {
        String value = parser.nextText();
        try {
            obj = dateFormat.parseObject(value);
        } catch (ParseException e) {

            try {
                SimpleDateFormat ISO8601Fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                obj = ISO8601Fmt.parse(value);
            } catch (ParseException e2) {
                throw new IOException("Cannot deserialize dateTime " + value);
            }
        }

This firstly tries the original check, then tries a variation if it fails.

Not elegant but it works :-)

Original comment by gunney.p...@gmail.com on 9 Dec 2011 at 6:09