2011-12-13 70 views
1

我想创建一个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”。

+0

我在最后添加了我的预期回复,谢谢。 – ET13

回答

2

我没有看到@WebParam

@WebMethod 
public AuthInfo login(@WebParam(name = "email") String email, @WebParam(name = "password") String password) throws IOException, CustomException { 

尝试更改签名像上面,然后尝试测试它使用SOAPUI

更新

您还需要来注释AuthInfo类像,

@XmlAccessorType(value = XmlAccessType.NONE) 
@Entity 
public class AuthInfo{ 
    @XmlElement 
    private String auth; 

    @XmlElement 
    private String token; 
} 
+0

谢谢你是一个问题,现在请求正在由肥皂生成,但我得到一个空的答复。请问我应该为响应对象AuthInfo做些什么? – ET13

+0

更新了答案,希望对您有所帮助 –

+0

非常感谢,现在一切正常。 – ET13