使用 GlassFish v3、EJB 和 SOAPUI
我想创建一个网络服务。
我正在使用 Glassfish v3、Eclipse 动态 Web 项目和 SOAPUI 进行测试。
我在 eclipse 中有以下代码:
Class 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");
}
}
Class 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 + "]";
}
}
Class 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。
我将 WSDL 放入 SOAPUI 中并获取生成的请求:
<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”的答案。
I would like to create a web service.
I am using Glassfish v3, an Eclipse Dynamic Web Project, and SOAPUI to test.
I have the following code in eclipse:
Class 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");
}
}
Class 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 + "]";
}
}
Class 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 generates the WSDL.
I place the WSDL in SOAPUI and get this generated request:
<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>
and get the response:
<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>
What is going wrong please? I suspect there is something wrong with the request I am sending, but there may be something wrong with the annotations as this is my first attempt at EJB web services.
I would expect an answer containing the Strings "auth" and "token" as returned by the web method login in class MyLogin.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有看到
@WebParam
尝试像上面那样更改签名,然后尝试使用 SOAPUI
Update
测试它您还需要注释您的
AuthInfo
类喜欢,I don't see
@WebParam
Try changing the signature like above and then try testing it using SOAPUI
Update
You also need to annotate your
AuthInfo
class like,