RSS Forums RSS

Java and Web Services

Please support our Java advertiser: Programming Forums
Reply
Posts: 3,465
Reputation: peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold 
Solved Threads: 412
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Java and Web Services

  #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, JAVAWUG (Java Web User Group), The London Android Group
AddThis Social Bookmark Button
Reply With Quote  
Posts: 644
Reputation: sillyboy is on a distinguished road 
Solved Threads: 54
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: Java and Web Services

  #2  
Jan 12th, 2009
first issue sounds really strange, the system out doesn't print pass?
with the second, are you importing Employee?
Reply With Quote  
Posts: 3,465
Reputation: peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold 
Solved Threads: 412
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Java and Web Services

  #3  
Jan 13th, 2009
Yes of course I do import Employee
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote  
Posts: 7,398
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 439
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Java and Web Services

  #4  
Jan 13th, 2009
A piece of advice: use a debugger, given that we have no way of reproducing the scenario and the code posted so far looks OK.

BTW, why are you catching a NullPointerException ? Catching unchecked exceptions without any kind of processing is *always* a bad practice and screams of a pre-condition check. Instead put null checks before closing the database resources [like result sets and statements].
Connection conn = null;
Statement stmt = null;
try {
  try {
    // do something
  } finally {
    if(stmt != null) stmt.close();
    if(conn != null) conn.close();
  }
} catch(Exception e) {
  e.printStackTrace();
}
I don't accept change; I don't deserve to live.

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.

-- Eric Naggum RIP :-(
Reply With Quote  
Posts: 3,465
Reputation: peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold 
Solved Threads: 412
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Java and Web Services

  #5  
Jan 13th, 2009
Yeah NullPointerException is one of many small things I need to battle through as many of the things I pick up either from IDE suggestions (which is not always best to do) or following other people code and often miss the reason of the use. Hopefully with all this technical reading I'm doing I will loose some bad habits

Right now I'm "cracking" through Service-Oriented Architecture with Java Web Services by Mark Hansen and found nice quote
Unfortunately, if you are like me, you may have found the Java Web Services learning curve a little steep. It seems that lots of powerful and complex machinery is required just to deploy a Java class as a Web service or create a simple client to consume such services. Sure, you can get the simple "Hello World" application from the Java EE 5 tutorial to work. However, when you need to deploy your purchase ordering system, things suddenly seem to get much more complicated. Either the WSDL you start with gets compiled into myriad bizarre classes that have to be manually wrapped and mapped into your real purchasing system, or, if you start from your Java classes, the WSDL that gets produced doesn't turn out the way you need it to. If you have been frustrated by problems like these, I sympathize with you.
This assignment is already submitted, it is only my stubbornness that push now to find out why it did not worked in first place and in doing so learn something new and maybe help somebody in the future with insufficient resources and support from tutor/teacher
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 474 | Replies: 4 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:13 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC