This question has been flagged
2 Replies
14479 Views

i follow this documentation https://www.odoo.com/documentation/8.0/api_integration.html to connect java to odoo 8 web services.

I tried both online and localhost, but none are working.

  1. http://localhost:8069/start nor https://demo.odoo.com/start

  2. http://localhost:8069/xmlrpc nor https://demo.odoo.com/xmlrp 

  3. http://localhost:8069/xmlrpc/2/common nor https://demo.odoo.com/xmlrpc/2/common

the error said no url found/exist.

org.apache.xmlrpc.client.XmlRpcHttpTransportException: HTTP server returned unexpected status: NOT FOUND 

Sincerely

IGAM Muliarsa

Here is my source code:

import java.net.MalformedURLException;
import java.net.URL;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
public class TestOdoo {
      public static void main(String[] args) {
           //String url = "http://localhost:8069/xmlrpc/common";
           String url = "https://demo.odoo.com";
           //String url = "https://demo.odoo.com/start";
           XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
           try {
                 config.setServerURL(new URL(url+"/xmlrpc/2/common"));
           } catch (MalformedURLException e) {
                e.printStackTrace();
           }
           XmlRpcClient client = new XmlRpcClient();
          client.setConfig(config);
          Object[] params = new Object[]{"test", "admin", "admin"}; Object res;
          try {
              res = client.execute("login", params);
              System.out.print(res);
          } catch (XmlRpcException e) {
              e.printStackTrace();
          }
      } }

Avatar
Discard

Yeah, not much happens here ;)

Author Best Answer

Nobody is active on in these forum...... btw I found the solution. here is the source to whom concern or need the source code. don't forget to import library required to test this source... documentation on https://www.odoo.com/documentation/8.0/api_integration.html will not work at all.

 public static void main(String[] args) throws MalformedURLException, XmlRpcException {
      String url = "http://192.168.0.100:8069"; // work with odoo.com account!!
      String db = "test";
      String username = "admin";
      String password = "admin";
      System.out.println("Get database list");
      System.out.println("Login");
      System.out.println("--------------");
      int uid = login(url,db,username,password);
      if (uid >0) {
          System.out.println("Login Ok");
      } else {
           System.out.println("Login Fail");
      }
}
// login
static int login(String url, String db, String login, String password) throws XmlRpcException, MalformedURLException {
      XmlRpcClient client = new XmlRpcClient();
      XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
      config.setEnabledForExtensions(true);
      //config.setServerURL(new URL(url+"/xmlrpc/common"));
      config.setServerURL(new URL(url+"/xmlrpc/2/common"));
      client.setConfig(config);
      //Connect
      //Object[] empty = null; // Ok
      //Object[] params = new Object[] {db,login,password, empty}; // Ok
      Object[] params = new Object[] {db,login,password}; // Ok & simple
      Object uid = client.execute("login", params);
      if (uid instanceof Integer)
          return (int) uid;
      return -1;
}

Avatar
Discard

What jar file u had used for this, can u share a link also

Thx IGAM Muliarsa for sharing

Thank you IGAM Muliarsa very much! Finally I have a working Kotlin code to access OpenERP.

Author

you're welcome. nice to hear the code work :)