1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
import java.net.URL;
import java.util.Vector;
import org.apache.log4j.Logger;
import java.io.*;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.util.ClientFactory;
import java.util.*;
import java.text.*;
public class ConnectToErp {
static Logger log = Logger.getLogger(ConnectToErp.class);
public int Connect(String host, int port, String Erpbd, String login, String password)
{
host = "127.0.0.1";
Erpbd = "OpenErp";
login = "postgres";
password = "postgres";
Object[] params = new Object[] {Erpbd,login,password};
setServer(host, port);
if (Erpbd != null)
{
log.info("Logging to " + Erpbd + " with user " + login + "("+ password +")");
params = new Object[] {Erpbd,login,password};
Object id = xmlrpcLogin.execute("login", params);
if (id instanceof Integer)
{
return (Integer)id;
}
else
{
log.info("Logging Cast Error : id is " + id.getClass() + " value =" + id);
return -5;
}
}
return 503;
}
private void setServer(String host, int port)
{
if (port<=0) port = 8080; //port par defaut
if (host == null || host.length()==0) host = "127.0.0.1"; //host par defaut
if (xmlrpcLogin.getConfig() != null &&
(host.equalsIgnoreCase(host)
|| port == port)) return;
XmlRpcClientConfigImpl xmlrpcConfigLogin = new XmlRpcClientConfigImpl();
xmlrpcConfigLogin.setEnabledForExtensions(true);
xmlrpcConfigLogin.setServerURL(new URL("http",host,port,"/xmlrpc/common"));
xmlrpcLogin.setConfig(xmlrpcConfigLogin);
xmlrpcConfigLogin = new XmlRpcClientConfigImpl();
xmlrpcConfigLogin.setEnabledForExtensions(true);
xmlrpcConfigLogin.setServerURL(new URL("http",host,port,"/xmlrpc/db"));
xmlrpcDb.setConfig(xmlrpcConfigLogin);
}
} |
Partager