Reputation: 501
I'm writing one of my very first web-service, as far as now it was more than ok, but when I'm trying to create sperate class:
public class Workers {
private String name;
private String surname;
private boolean type;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public boolean isType() {
return type;
}
public void setType(boolean type) {
this.type = type;
}
public Workers(String name, String surname, boolean type) {
this.name = name;
this.surname = surname;
this.type = type;
}
}
and than to use it in webservice like this:
@WebMethod(operationName = "SelectWorker")
public Pracownicy SelectWorker(@WebParam(name = "username") String username, @WebParam(name = "password") String password) {
ResultSet rs = null;
String name = null;
String surname = null;
boolean type = false;
PreparedStatement st = null;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("db_address", "login", "password");
System.out.println("connection status: " +con);
st = con.prepareStatement("select name, surname from clients where login = ? and passwd= ?");
st.setString(1, username);
st.setString(2, password);
rs = st.executeQuery();
if (rs.next()) {
name = rs.getString(2);
surname=rs.getString(3);
type = rs.getBoolean(5);
Workers pr = new Workers(name, surname, type);
return pr;
}
} catch (Exception e) {
System.out.println("error: " + e.toString());
}
return null;
}
the body of method can be empty or filled with code, it doesn't matter - I'm getting the same error:
Error occurred during deployment: Exception while loading the app
:java.lang.IllegalStateException: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: java.lang.RuntimeException: Servlet web
service endpoint '' failure.
Are the int, string, boolean etc only allowed as return type?
Upvotes: 0
Views: 2295
Reputation: 1760
I had this problem, the glassfish was on Linux environment. check your $JAVA_HOME it should be set in to jdk
export JAVA_HOME=/usr/java/jdk1.7.0_55
/opt/glassfish4/glassfish/bin # echo $JAVA_HOME
/usr/java/jdk1.7.0_55
then problem was solved..
Upvotes: 0
Reputation: 16062
For future googlers :
I've had the same error, and checked the server log and got the error :
Two classes have the same XML type name
Which I found wierd but adding this :
@XmlType(namespace="someName")
To my class I was trying to return ( I chose the same name of the class) fixed the problem.
Upvotes: 0
Reputation: 5399
there is by no means enough information given in your post... How are you creating the web service (I guess with an @WebService), your're telling it does not matter if method SelectWorker (which btw should be called selectWorker by proper naming conventions) is empty or not, but with an empty body your source would not even compile...
what I can tell you: int, String, boolean are not the only allowed return types. You can of course also return instances of your classes from a web service.
Upvotes: 1