View Single Post
Join Date: Dec 2004
Posts: 4,208
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 487
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Java and Web Services

 
0
  #1
Jan 12th, 2009
I know I should probably post this in Web Services of Web Development, but this may be beneficial to others that are trying to lean something about it too.

I'm getting lot of strange behaviour from this assignment that at this point I'm willing to throw it away and never work on it.
I have class that run various queries with database. With use of Axis2 plug-in I was able to generate WSDL (This has some red sections which I'm not able to work out). Here is small section of two methods out of it to demonstrate some errors I'm getting
  1. public Employee logEmployee(String usr, String pass) {
  2. System.out.println("Username = "+ usr+" Password = "+pass);
  3. Employee e = new Employee();
  4. Connection conn = cm.getConnection();
  5. if (conn != null) {
  6. ResultSet rs = null;
  7. PreparedStatement preparedStatement = null;
  8. try {
  9. String strQuery =
  10. "SELECT employee_id, branch_id, password, firstName, lastName "
  11. + "FROM employee WHERE employee_id=? AND password=?";
  12.  
  13. preparedStatement = conn.prepareStatement(strQuery);
  14. preparedStatement.setString(1, usr);
  15. preparedStatement.setString(2, pass);
  16. rs = preparedStatement.executeQuery();
  17.  
  18. while (rs.next()) {
  19. e.setEmployeeID(rs.getString("employee_id"));
  20. e.setBranchID(rs.getString("branch_id"));
  21. e.setPassword(rs.getString("password"));
  22. e.setFirstName(rs.getString("firstName"));
  23. e.setLastName(rs.getString("lastName"));
  24. }
  25. }
  26. catch (SQLException ex) {
  27. ex.printStackTrace();
  28. }
  29. finally {
  30. try {
  31. rs.close();
  32. preparedStatement.close();
  33. }
  34. catch (SQLException sqle) {
  35. sqle.printStackTrace();
  36. }
  37. catch (NullPointerException npe) {
  38. npe.printStackTrace();
  39. }
  40. cm.putConnection(conn);
  41. }
  42. }
  43. return e;
  44. }
  45.  
  46. public ArrayList<Employee> viewEmployees() {
  47. ArrayList<Employee> employee = new ArrayList<Employee>();
  48. Connection conn = cm.getConnection();
  49. if (conn != null) {
  50. ResultSet rs = null;
  51. PreparedStatement preparedStatement = null;
  52. Employee emp;
  53. try {
  54. String strQuery =
  55. "SELECT employee_id, branch_id, firstName, lastName "
  56. + "FROM employee ORDER BY lastName,firstName";
  57.  
  58. preparedStatement = conn.prepareStatement(strQuery);
  59. rs = preparedStatement.executeQuery();
  60.  
  61. while (rs.next()) {
  62. emp = new Employee();
  63. emp.setEmployeeID(rs.getString("employee_id"));
  64. emp.setBranchID(rs.getString("branch_id"));
  65. emp.setFirstName(rs.getString("firstName"));
  66. emp.setLastName(rs.getString("lastName"));
  67. employee.add(emp);
  68. }
  69. }
  70. catch (SQLException ex) {
  71. ex.printStackTrace();
  72. }
  73. finally {
  74. try {
  75. rs.close();
  76. preparedStatement.close();
  77. }
  78. catch (SQLException sqle) {
  79. sqle.printStackTrace();
  80. }
  81. catch (NullPointerException npe) {
  82. npe.printStackTrace();
  83. }
  84. cm.putConnection(conn);
  85. }
  86. }
  87. return employee;
  88. }

I was able to use this WSDL to create client side and get automated files Service, ServiceLocator, _PortType, SoapBindingStub.
To communicate with service I use following code
  1. try{
  2. EmployeeQueriesServiceLocator locator = new EmployeeQueriesServiceLocator();
  3. EmployeeQueries_PortType service = locator.getEmployeeQueries();
  4.  
  5. //execution of any service method here
  6. }
  7. catch(ServiceException ex){
  8. ex.printStackTrace();
  9. }
  10. catch(RemoteException re){
  11. re.printStackTrace();
  12. }
However for example when I'm trying to log in through logEmployee(String usr, String pass) method server side receive only user name string and password is lost. (I found solution to this in sending these strings in array)
Secondly when I tried to retrieve list of all employees through viewEmployees() method that is supposed to return ArrayList<Employee> I'm getting warning or error that found return is actually Object[].
Can somebody shed some light into this darkness?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote