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
public Employee logEmployee(String usr, String pass) {
System.out.println("Username = "+ usr+" Password = "+pass);
Employee e = new Employee();
Connection conn = cm.getConnection();
if (conn != null) {
ResultSet rs = null;
PreparedStatement preparedStatement = null;
try {
String strQuery =
"SELECT employee_id, branch_id, password, firstName, lastName "
+ "FROM employee WHERE employee_id=? AND password=?";
preparedStatement = conn.prepareStatement(strQuery);
preparedStatement.setString(1, usr);
preparedStatement.setString(2, pass);
rs = preparedStatement.executeQuery();
while (rs.next()) {
e.setEmployeeID(rs.getString("employee_id"));
e.setBranchID(rs.getString("branch_id"));
e.setPassword(rs.getString("password"));
e.setFirstName(rs.getString("firstName"));
e.setLastName(rs.getString("lastName"));
}
}
catch (SQLException ex) {
ex.printStackTrace();
}
finally {
try {
rs.close();
preparedStatement.close();
}
catch (SQLException sqle) {
sqle.printStackTrace();
}
catch (NullPointerException npe) {
npe.printStackTrace();
}
cm.putConnection(conn);
}
}
return e;
}
public ArrayList<Employee> viewEmployees() {
ArrayList<Employee> employee = new ArrayList<Employee>();
Connection conn = cm.getConnection();
if (conn != null) {
ResultSet rs = null;
PreparedStatement preparedStatement = null;
Employee emp;
try {
String strQuery =
"SELECT employee_id, branch_id, firstName, lastName "
+ "FROM employee ORDER BY lastName,firstName";
preparedStatement = conn.prepareStatement(strQuery);
rs = preparedStatement.executeQuery();
while (rs.next()) {
emp = new Employee();
emp.setEmployeeID(rs.getString("employee_id"));
emp.setBranchID(rs.getString("branch_id"));
emp.setFirstName(rs.getString("firstName"));
emp.setLastName(rs.getString("lastName"));
employee.add(emp);
}
}
catch (SQLException ex) {
ex.printStackTrace();
}
finally {
try {
rs.close();
preparedStatement.close();
}
catch (SQLException sqle) {
sqle.printStackTrace();
}
catch (NullPointerException npe) {
npe.printStackTrace();
}
cm.putConnection(conn);
}
}
return employee;
}
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
try{
EmployeeQueriesServiceLocator locator = new EmployeeQueriesServiceLocator();
EmployeeQueries_PortType service = locator.getEmployeeQueries();
//execution of any service method here
}
catch(ServiceException ex){
ex.printStackTrace();
}
catch(RemoteException re){
re.printStackTrace();
}
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? :?: