我想創建一個web服務。使用GlassFish v3,EJB和SOAPUI
我正在使用Glassfish v3,Eclipse動態Web項目和SOAPUI進行測試。
我已經在eclipse以下代碼:
類MyLogin
package packageTest;
import java.io.IOException;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public class MyLogin {
@WebMethod
public AuthInfo login(@WebParam(name = "email") String email,@WebParam(name = "password")String password) throws IOException, CustomException {
if(email == null || email.isEmpty()){
throw new CustomException("Email cannot be empty.");
}
if(password == null || password.isEmpty()){
throw new CustomException("Password cannot be empty.");
}
return new AuthInfo("auth","token");
}
}
類AUTHINFO
package packageTest;
import javax.persistence.Entity;
@Entity
public class AuthInfo {
private String token;
private String auth;
public AuthInfo(){}
public AuthInfo(String auth,String token) {
super();
this.token = token;
this.auth = auth;
}
public String getToken() {
return token;
}
public String getAuth() {
return auth;
}
@Override
public String toString() {
return "AuthInfo [auth=" + auth + ", token=" + token + "]";
}
}
類CustomException
package packageTest;
public class CustomException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
public CustomException() {
}
public CustomException(String msg) {
super(msg);
}
public CustomException(String msg,
Throwable cause){
super(msg,cause);
}
}
Glassfish的生成WSDL。
我放在SOAPUI WSDL和得到這個生成的請求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pac="http://packageTest/">
<soapenv:Header/>
<soapenv:Body>
<pac:login>
<!--Optional:-->
<email>email</email>
<!--Optional:-->
<password>password</password>
</pac:login>
</soapenv:Body>
</soapenv:Envelope>
,並獲得響應:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:loginResponse xmlns:ns2="http://packageTest/">
<return/>
</ns2:loginResponse>
</S:Body>
</S:Envelope>
到底哪裏出問題了嗎?我懷疑我發送的請求有問題,但註釋可能有問題,因爲這是我第一次嘗試EJB Web服務。
我希望得到一個答案,其中包含類MyLogin中Web方法登錄所返回的字符串「auth」和「token」。
我在最後添加了我的預期回覆,謝謝。 – ET13