So i'm traying to connect my application with an odoo database in android studion with an odoo External API "XML-RPC" to get data from the database, I was able to connect and i get the user Id successfuly, i was also able to search and create normaly, but when i'm trayin to read any thing from the database, this exception keep showing. and i can't find any thing that he can help me. So please is there any one who can tell me where i am mestaking ?
This is my code:
public class MainActivity extends AppCompatActivity {
final String db = "BTP_p",
username = "admin",
password = "_chantier";
final String url ="http://sogesi.hopto.org";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new DemoTask().execute(url);
}
class DemoTask extends AsyncTask<String, Void, Integer> {
@Override
protected Integer doInBackground(final String... url) {
final XmlRpcClient client = new XmlRpcClient();
final XmlRpcClientConfigImpl common_config = new XmlRpcClientConfigImpl();
try {
//Testé l'authentification
common_config.setServerURL(
new URL(String.format("%s/xmlrpc/2/common", url)));
int uid = (int)client.execute(
common_config, "authenticate", asList(
db, username, password, emptyMap()));
Log.d("result", "*******************************************************************");
Log.d("uid = ", Integer.toString(uid));
//Testé la liste des recordes d'une table
final XmlRpcClient models = new XmlRpcClient() {{
setConfig(new XmlRpcClientConfigImpl() {{
setServerURL(new URL(String.format("%s/xmlrpc/2/object",url)));
}});
}};
final List id = asList((Object[])models.execute(
"execute_kw", asList(
db, uid, password,
"project.chantier", "search",
asList(asList(
asList("state", "=", "en_cour"))),
new HashMap() {{
put("limit", 1);
}}
)));
//this is the ligne where the exception is rising
final Map record = (Map)((Object[])models.execute(
"execute_kw", asList(
db, uid, password,
"project.chantier", "read",
asList(id)
)
))[0];
return (Integer) uid;
} catch (MalformedURLException e) {
Log.d("MalformedURLException", "*********************************************************");
Log.d("MalformedURLException", e.toString());
} catch (XmlRpcException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void result) {
// TODO: do something with the feed
}
}
}
In my case I had to download and import this three libraries :
exist-dependency-ws-commons-util-1.0.2.jar
xmlrpc-client-3.1.jar
xmlrpc-common-3.1.jar