Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to access ODOO 8 using Java xmlrpc?

By
IGAM Muliarsa
on 4/12/15, 4:01 AM 3,653 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();
          }
      } }

Yeah, not much happens here ;)

Dr Obx
on 4/15/15, 4:10 AM
1
IGAM Muliarsa
On 4/14/15, 10:48 PM

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;
}

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

Ashish Singh
on 5/26/15, 12:41 AM

Thx IGAM Muliarsa for sharing

xiaolong97427
on 4/25/16, 6:30 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/12/15, 4:01 AM
Seen: 3653 times
Last updated: 4/22/15, 5:03 AM