avinash_545 0 Junior Poster in Training

Dear All,
I am currently working on a small project whereby I want to use a SOAP client to insert Customer Values in a database.

The connection to database class is working, the only problem is that it seems that the Web Service wont communicate with this class. In the beginning I suspected that the SOAP thread does not wait long enough for the database thread to finish; for that I have made implemented the Callable interface in the database class. But this problem still persist.

I am actually reading a file, build up a string, send this string to SOAP client -->SOAP Server ---> Database Connection....all these return back a string...but in my case the string is empty...I have put lots of "System.out.println("In class DB operations"), but nothing is being printed. I made use of different projects and packages but in all cases I have imported them in their respective libraries...there is no referencing problem.

Grateful if anyone could please help me sort this out.

Source code for the different classes :

/*
                 * To change this template, choose Tools | Templates
                 * and open the template in the editor.
                 */
                package itshop_soapws_client;

                /**
                 *
                 * @author AVINASH
                 */
                public class ITSHOP_SOAPWS_Client {

                    public static String soapClient_login(String usn, String pwd, String dbname){
                        String resultLogin="";
                        try{
                            resultLogin=login(usn,pwd,dbname);
                            System.out.println("from soapClient, resultLogin = "+resultLogin);
                        }
                        catch(Exception e ){
                            System.out.println("openerp soap client error login >> "+e.getLocalizedMessage());
                             e.printStackTrace();
                        }
                        return resultLogin;
                    }
                          
                          
                    public static String soapClient_insert(String methodName,String partnerDetails){
                        String resultInsert=" ";
                        try{
                            resultInsert=insertPartner( methodName,partnerDetails);
                            System.out.println("from soapClient, resultInsert = "+resultInsert);
                            
                        }
                        catch(Exception e ){
                            System.out.println("openerp soap client error insert >> "+e.getLocalizedMessage());
                            e.printStackTrace();
                        }
                        return resultInsert;
                    }
                    
                    
                    private static String insertPartner(java.lang.String methodName, java.lang.String partnerDetails) {
                        openerpsoapws.OpenERPSOAPWS_Service service = new openerpsoapws.OpenERPSOAPWS_Service();
                        openerpsoapws.OpenERPSOAPWS port = service.getOpenERPSOAPWSPort();
                        return port.insertPartner(methodName, partnerDetails);
                    }

                    private static String login(java.lang.String username, java.lang.String password, java.lang.String databaseName) {
                        openerpsoapws.OpenERPSOAPWS_Service service = new openerpsoapws.OpenERPSOAPWS_Service();
                        openerpsoapws.OpenERPSOAPWS port = service.getOpenERPSOAPWSPort();
                        return port.login(username, password, databaseName);
                    }

                    private static Integer trivialADD(int num1, int num2) {
                        openerpsoapws.OpenERPSOAPWS_Service service = new openerpsoapws.OpenERPSOAPWS_Service();
                        openerpsoapws.OpenERPSOAPWS port = service.getOpenERPSOAPWSPort();
                        return port.trivialADD(num1, num2);
                    }

                    private static String hello(java.lang.String name) {
                        openerpsoapws.OpenERPSOAPWS_Service service = new openerpsoapws.OpenERPSOAPWS_Service();
                        openerpsoapws.OpenERPSOAPWS port = service.getOpenERPSOAPWSPort();
                        return port.hello(name);
                    }
                    
                    
                    
                //    public static void main(String[] args) {
                //         int n=12; int m=13;
                //        int sum= trivialADD(m,n);
                //        System.out.println("result from trivialADD = "+sum);
                //        
                //        String sayingHellow= "hi la vie ki dire...bug la encore laem\n";
                //        String resultHellow=hello(sayingHellow);
                //        System.out.println(">>>>>>hellow response = "+resultHellow);
                //        
                //       String ptner, ref, website, phone, fax, email, st1, st2, city, zip, mobile;
                //       ptner="manualDBClassSOAPCLIENT"; ref="manualDBSOAPCLIENT";website="manual.manual.com"; phone="000111";
                //       fax="111222"; email="a@a.com";st1=st2="street"; city="manualCIty"; zip="020"; mobile="222333";
                //       String pDetails=ptner+","+ref+","+website+","+phone+","+fax+","+email+","+st1+","+st2+","+city+","+zip+","+mobile;
                //       System.out.println("Going to send \n "+pDetails);
                //       try{
                //         String resultInsert=insertPartner(pDetails);
                //          System.out.println("inside opsoapclient... result Insert = "+resultInsert);
                //       }
                //       catch(Exception e ){
                //           System.out.println("soap client main error "+ e.getLocalizedMessage());
                //           e.getCause();
                //           e.printStackTrace();
                //           
                //       }
                //      
                //    }
                }
                /*
                 * To change this template, choose Tools | Templates
                 * and open the template in the editor.
                 */
                package OpenERPSOAPWS;

                import itshop_database_connection.ManualDBOperator;
                import javax.jws.WebService;
                import javax.jws.WebMethod;
                import javax.jws.WebParam;
                import itshop_database_connection.OpenERP_database_connections;
                /**
                 *
                 * @author AVINASH
                 */
                @WebService(serviceName = "OpenERPSOAPWS")
                public class OpenERPSOAPWS {

                    /**
                     * This is a sample web service operation
                     */
                    @WebMethod(operationName = "hello")
                    public String hello(@WebParam(name = "name") String txt) {
                        return "Hello " + txt + " !";
                    }

                    /**
                     * Web service operation
                     */
                //    @WebMethod(operationName = "insertPartner")
                //    public String insertPartner(@WebParam(name = "partnerDetails") String partnerDetails) {
                //        System.out.println("In SOAPWS...partnerDetails>> "+partnerDetails);
                //        String resultInsert= ManualDBOperator.doDBInsertOperation();
                //        if(resultInsert.equals(null)){
                //            resultInsert="EMPTY_RESPONSE";
                //        }
                //        return "hi method insert has been accessed";
                //    }
                    /**
                     * Web service operation
                     */
                    @WebMethod(operationName = "insertPartner")
                    public String insertPartner(@WebParam(name = "methodName") String methodName,@WebParam(name = "partnerDetails") String partnerDetails) {
                        System.out.println("In SOAPWS...partnerDetails>> "+partnerDetails);
                        String resultInsert= ManualDBOperator.doDBInsertOperation(methodName,partnerDetails);
                        if(resultInsert==null){
                            resultInsert="EMPTY_RESPONSE";
                        }
                        //used only when testing WS        
                //        return methodName+" , "+partnerDetails;
                        return resultInsert;
                    }    
                    /**
                     * Web service operation
                     */
                    @WebMethod(operationName = "login")
                    public String login(@WebParam(name = "username") String username, @WebParam(name = "password") String password, @WebParam(name = "databaseName") String databaseName) {
                        System.out.println("In SOAPWS...login details>>> "+ username+" "+password+" "+databaseName);
                        String resultLogin=OpenERP_database_connections.setDBConnections(databaseName, username, password);
                        return resultLogin;
                    }

                    /**
                     * Web service operation
                     */
                    @WebMethod(operationName = "trivialADD")
                    public Integer trivialADD(@WebParam(name = "num1") int num1, @WebParam(name = "num2") int num2) {
                        int sum=OpenERP_database_connections.trivialAdd(num1, num2);//num1+num2;
                        System.out.println("sum is "+sum);
                        return sum;
                    }
                }
                llll

                package itshop_database_connection;

                import java.util.concurrent.ExecutorService;
                import java.util.concurrent.Executors;
                import java.util.concurrent.FutureTask;

                /**
                 * @author AVINASH
                 */
                public class ManualDBOperator {
                   
                    
                //    public static String doDBLoginOperation(String methodName, String parameters){
                //        omdb.
                //        return " ";
                //    }
                    
                     public static String doDBInsertOperation(String methodName, String parameters){
                        OpenERP_Manual_DB omdb= new OpenERP_Manual_DB(methodName,parameters);
                        FutureTask<String> task = new FutureTask (omdb);
                        ExecutorService es = Executors.newSingleThreadExecutor ();
                        es.submit (task);
                        String result="";
                        try {
                            result =task.get();
                            System.out.println ("Result from task.get () = " + result);
                        }
                        catch (Exception e) {
                            System.err.println (e);
                        }
                        es.shutdown ();
                        return result;
                    }
                }
                /*



                 */


                package itshop_database_connection;

                /**
                 *
                 * @author AVINASH
                 */

                import java.sql.*;

                public class OpenERP_database_connections{
                    private static String dbname="itshop";//default value
                    private static String username="admin";//default value
                    private static String password="admin";//default value
                    private static Statement stmt;
                    private static int idPartner;
                    private static int idPartnerAddr;
                   /*Requirements : DBname, DBusername, DBpassword >> insert those in GUI*/
                    
                    public static String setDBConnections(String db, String usn, String pwd){
                        dbname=db;
                        username=usn;
                        password= pwd;
                        System.out.println("OpenERP Manual DB connections after setting them = " + dbname+" "+username+" "+password);
                        getLastID();//used to initialise the partner IDs...
                        return "Login parameters set using >> "+ username+","+password+", "+dbname;
                    }
                    
                    public static void trivialgetID(){
                        System.out.println("**********Getting last ids***********");
                        getLastID();
                    }
                    
                    public static String insert(String prtnerDetails){
                        getLastID();
                        String partnerName, ref, website, phoneOffice, phoneFax, email, billingStreet1, billingStreet2,city, zip,mobile;
                        System.out.println("In db connection, String insert  received = "+ prtnerDetails);
                        String[] partnerDetails=prtnerDetails.split(",");
                        partnerName=partnerDetails[0];
                        ref=partnerDetails[1];
                        website=partnerDetails[2];
                        phoneOffice=partnerDetails[3];
                        phoneFax=partnerDetails[4];
                        email=partnerDetails[5];
                        billingStreet1=partnerDetails[6];  
                        billingStreet2=partnerDetails[7];
                        city=partnerDetails[8];
                        zip=partnerDetails[9];
                        mobile=partnerDetails[10];
                        System.out.println("The assigned values in DB connection = \n partnerName= "+partnerName +"\nref = "+ ref
                        +"\nwebsite= "+website +"\n phoneOffice= "+phoneOffice+"\n phoneFax= "+phoneFax+"\nemail= "+email
                         +"\n billingStreet1= "+billingStreet1+"\n billingStreet2= "+billingStreet2+"\n city= "+city+
                                "\n zip= "+zip +"\n mobile= "+ mobile     );
                //        for(int p=0;p<partnerDetails.length;p++){
                //            System.out.println("Splitted String OpenERP_database_connections>>> "+ partnerDetails[p]);
                //        }
                        int country_id=1;
                        int company_id=1;
                        int state_id= 1;
                        
                // IDs to be used ...increment static field idPartner, idPartnerAddr
                        int incrIDPartner= ++idPartner; int incrIDPartnerAddr=++idPartnerAddr;
                        System.out.println("Updated IDs = "+ incrIDPartner+ ","+ incrIDPartnerAddr);
                        
                String insertPartner="INSERT INTO res_partner(id, active,lang, customer, name, company_id, website,employee, supplier, ref)"
                +"VALUES("+incrIDPartner+",TRUE,'en_US',TRUE,'"+partnerName+"',1,'"+website+"',FALSE, TRUE,'"+ref+"')";
                System.out.println("The build up insertPrtnerQuery= \n"+insertPartner);

                String insertPartnerAddr="INSERT INTO res_partner_address"
                + "(id,fax,street2,phone,street,active,partner_id,city,name,zip,mobile,type,country_id,company_id,birthdate,state_id,email)"
                + "VALUES("+incrIDPartnerAddr+",'"+phoneFax+"','"+ billingStreet2+"','"+phoneOffice+"','"+billingStreet1+"',TRUE,"+incrIDPartner+",'"+city+"','"+partnerName+"','"+zip+"','"+mobile+"','default',"+country_id+","+company_id+
                ",'birthdayEMPTY',"+ state_id+",'"+email+"')";
                System.out.println("The build up insertPrtnerQuery= \n"+insertPartnerAddr);

                        Connection con =db_connect();
                        try {
                            System.out.println("In DB connection..executing insert query");
                            stmt = con.createStatement();
                            stmt.executeUpdate(insertPartner);
                            stmt.executeUpdate(insertPartnerAddr);
                            //idPartner++; idPartnerAddr++;
                            //stmt.executeUpdate(insertString3);	
                            stmt.close();
                            con.close();
                        } catch(SQLException ex) {
                            System.err.println("SQLException: " + ex.getMessage());
                            ex.printStackTrace();
                        }
                        /*
                INSERT INTO res_partner
                (id, active,lang, customer, name, company_id, website, employee, supplier, ref)
                VALUES(44,TRUE,'en_US', TRUE,'manualINSERTION2', 1, 'aila@aila.aila', FALSE, TRUE, 'hihahahoo' );
                INSERT INTO res_partner_address
                * (id,fax,street2,phone,street,active,partner_id,city,"name",zip,title,mobile,"type",
                * country_id,company_id,birthdate,state_id,email)
                VALUES(39,'en_US', TRUE,'manualINSERTION2', 1, 'aila@aila.aila', FALSE, TRUE, 'hihahahoo' );         
                */
                        
                        
                        return "operation insertion occured";
                    }
                //    public static String create(){}
                //    public static String search(){}

                    //getLastID() selected is used to retrieve to last id inserted in both res_partner and res_partner_address
                    public static void getLastID(){

                        String queryIDpartners="SELECT res_partner.id as idPartner, res_partner_address.id as idPartnerAddr "
                                + "FROM res_partner, res_partner_address where res_partner.id=res_partner_address.partner_id "
                                + "ORDER BY  res_partner.id DESC LIMIT 1;";
                        //format of result is [idPartner, idPartnerAddr]
                       Connection con = db_connect();
                       try {
                            Statement stmtID = con.createStatement();
                            ResultSet rs = stmtID.executeQuery(queryIDpartners);
                            while (rs.next()) {
                                idPartner = rs.getInt("idPartner");
                                idPartnerAddr=rs.getInt("idPartnerAddr");
                                System.out.println("ID retrieved from last row >> "+ idPartner +" , "+ idPartnerAddr+"\n--------------------------------------------------------\n");
                            }
                            stmtID.close();
                            con.close();

                       } 
                       catch(SQLException ex) {
                            System.err.println("SQLException: " + ex.getMessage());
                        } 
                }
                    
                    public  static Connection db_connect(){
                        System.out.println("\n\n\n-------- PostgreSQL "+ "JDBC Connection Testing ------------");
                        try {Class.forName("org.postgresql.Driver");	} 
                        catch(ClassNotFoundException e) {
                            System.out.println("Where is your PostgreSQL JDBC Driver? "+ "Include in your library path!");
                            e.printStackTrace();
                            //return;
                        }
                        System.out.println("PostgreSQL JDBC Driver Registered!");
                        Connection connection = null;
                        //String url = "jdbc:postgresql://localhost/test?user=postgres&password=&ssl=true";
                        try{
                            connection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/itshop","admin","admin");//+dbname,username,password);
                        } //("jdbc:postgresql://127.0.0.1:5432/GUI","avinash","avi");
                        catch (SQLException e) {
                            System.out.println("Connection Failed! Check output console");
                            e.printStackTrace();
                            //return;
                        }
                        if (connection != null) {
                            System.out.println("You made it, take control your database now!");
                        } 
                        else{
                            System.out.println("Failed to make connection!");
                        }
                        return connection;
                    }//end of db_connect
                    public static int trivialAdd(int a, int b){
                        System.out.println("method trivial add in db conenction class has been accessed");
                        return a+b+100;
                    }
                    
                    
                    public static void main(String[] args) {
                       System.out.println("lalalala");
                      // Connection con=db_connect();
                       String ptner, ref, website, phone, fax, email, st1, st2, city, zip, mobile;
                       ptner="manualDBClass"; ref="manualDB";website="manual.manual.com"; phone="000111";
                       fax="111222"; email="a@a.com";st1=st2="street"; city="manualCIty"; zip="020"; mobile="222333";
                       String partnerDetails=ptner+","+ref+","+website+","+phone+","+fax+","+email+","+st1+","+st2+","+city+","+zip+","+mobile;
                      //trivialgetID();
                       insert(partnerDetails);
                    }
                }