0

I am working in an Android app with Eclipse which connects with an OpenERP server using XML-RPC protocol. My question is how to do a logout to the server or if it is not necessary.

I have tried to do it in the same way as the "login" method but it does not work. I catch a

java.lang.ClassCastException (java.lang.String cannot be cast to java.lang.Integer)

at client.execute() line.

Here is the full stack:

07-17 10:18:42.271: E/Conector OpenERP(19595):  Error while logging out
07-17 10:18:42.271: E/Conector OpenERP(19595):  java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.xmlrpc.parser.XmlRpcResponseParser.addResult(XmlRpcResponseParser.java:55)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.endValueTag(RecursiveTypeParserImpl.java:71)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.xmlrpc.parser.XmlRpcResponseParser.endElement(XmlRpcResponseParser.java:164)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.harmony.xml.ExpatParser.endElement(ExpatParser.java:156)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.harmony.xml.ExpatParser.appendBytes(Native Method)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:513)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:474)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:316)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:172)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:149)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:95)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:39)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:136)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:125)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at com.example.nfcreader.JavaOpenerpConnector.disconnect(JavaOpenerpConnector.java:459)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at com.example.nfcreader.MainActivity$ReadDBTask.doInBackground(MainActivity.java:1198)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at com.example.nfcreader.MainActivity$ReadDBTask.doInBackground(MainActivity.java:1)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
07-17 10:18:42.271: E/Conector OpenERP(19595):  at java.lang.Thread.run(Thread.java:841)  

I have searched in the web but I do not find anything about how to implement this "logout" method. I think the problem is the parameters to send at client.execute() method.

Here is my code:

public void disconnect() {

    try{
        XmlRpcClient client = new XmlRpcClient();
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();

        config.setServerURL(new URL("http",host,port,"/xmlrpc/common"));
        client.setConfig(config);

        Object result = client.execute("logout", new Object[] {database,user,password});

    }catch(MalformedURLException ex){
        Log.e(TAG, "Wrong URL", ex);

    }catch (XmlRpcException ex){
        Log.e(TAG, "Error XML-RPC", ex);

    }catch (Exception ex) {
        Log.e(TAG, "Error while logging out", ex);          
    }
    return;
}

The code for "login" method runs successfully and it is the same like the above one, just changes the word "logout" by "login".

Thanks for your suggestions!

jelogar
  • 25
  • 5
  • I assume the line `execute` produces the error? Please post the full stacktrace and the "login" method. – Christian St. Jul 15 '14 at 18:02
  • @Christian St. Yes, error is at line `execute`. I have reviewed my question and I have added the full stack trace. – jelogar Jul 17 '14 at 08:36
  • It seems, that an Integer is needed, instead of the string `logout`. Are you sure, that you have to explicitly perform a "logout" to kill the session? Where are your examples from? – Christian St. Jul 17 '14 at 10:12

1 Answers1

2

I'm using XML-RPC with PHP, and the login() method authenticates the user credentials and returns a user ID.

Each call to subsequent methods needs the user ID and password - it seems there is no need to actually log in - it is just there to validate the user credentials. I cannot find any documentation on this, but it appears that the XML-RPC API is stateless - there is no need to log in and log out.

However, there is a session interface available through the API, but it is unclear whether that is of any use with XML-RPC. It could be possible that logout() interacts with the session to connect/remove an authenticated user to the session. The session ID is a UUID string.

Sorry if that is a bit fuzzy; most of what I've found out is trial-and-error, as the documentation unfortunately skips over any of the important points.

Jason
  • 4,411
  • 7
  • 40
  • 53
  • I agree with you @Jason. After looking for information, I have come to the conclusion that the login method just returns the user-id, eg for the administrator is '1'. For other OpenERP users it would be another positive integer number. Therefore it is **not necessary to logout** since OpenERP server does not execute it (and throws a ClassCastException). The login method is only used to find the user-id of the current OpenERP user since it is necessary to then use it in other XML-RPC methods (read, write, exec_workflow, etc.). Thank you very much for helping to clarify. – jelogar Jul 30 '14 at 06:53