2012-11-30 47 views
-2

我有一個grails(測試)項目,將通過肥皂訪問 您可以添加一本書等。 我想知道,是否有可能拋出一個所有添加圖書時發生錯誤。Webdefault jax-ws的自定義例外

下面的代碼是現在有這個工程,但我不能存儲所有的錯誤。 我已經嘗試在@webFault中創建一個bookExceptions列表,但這不起作用。 或者我必須返回@webresult中的所有錯誤。

@XmlRootElement(name="Book") 
@XmlAccessorType(XmlAccessType.NONE) 
class Book { 

    @XmlElement 
    String name; 

    @XmlElement 
    String author; 

    @XmlElement 
    String publisher; 

    @XmlElement 
    String isbn; 

    @XmlElement 
    Date release; 

    static constraints = { 
    name(nullable: false, blank: true, maxSize: 30); 
    author(nullable: false, blank: true, maxSize: 3); 
    publisher(nullable: true); 
    isbn(nullable: true); 
    release(nullable: true); 
    } 
} 

@WebService(serviceName="Service", endpointInterface="webservices.SimpleWebService", targetNamespace="http://pc158:7070/grailsSoap") 
class SimpleWebServiceImpl implements SimpleWebService { 

    public List<Book> getBooks() { 
    return Book.list(); 
    } 

    public void addBook(Book book) throws BookException { 
    if (book == null) 
     throw new BookException("Book is required.", new BookExceptionBean()); 

    // TODO : 
    /* 
    * if (! book.save(flush: true)) 
    * // get errors and throw the bookException that contains all errors. 
    */ 
    } 
} 

@XmlRootElement(name="BookException") 
@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name="BookError") 
public class BookExceptionBean extends Error { 

    public BookExceptionBean() { 
    super(); 
    } 

} 

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name="Error", propOrder= { 
    "field", 
    "value", 
    "i18Code", 
    "i18Message" 
    }) 
public class Error { 

    protected String field; 
    protected String value; 
    protected String i18Code; 
    protected String i18Message; 

    public Error() { 
    } 

    public void setField(String field) { 
    this.field = field; 
    } 

    public String getField() { 
    return this.field; 
    } 

    public void setValue(String value) { 
    this.value = value; 
    } 

    public String getValue() { 
    return this.value; 
    } 

    public void setI18Code(String code) { 
    this.i18Code = code; 
    } 

    public String getI18Code() { 
    return this.i18Code; 
    } 

    public void setI18Message(String message) { 
    this.i18Message = message; 
    } 

    public String getI18Message() { 
    return this.i18Message; 
    } 

} 

迎接縣,

+0

你在你的問題錯過的話。我不明白這個問題。請詳細解釋您的問題。可能有例子。 – sanders

回答

0

問題解決了:

@XmlRootElement(name="BookException") 
@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name="BookError") 
public class BookExceptionBean { 

    @XmlElementWrapper(name="errors") 
    @XmlElement(name="error") 
    private List<Error> errors = new ArrayList<Error>(); 

    public void setError(Error error) { 
    this.errors.add(error); 
    } 

    public List<Error> getErrors() { 
    return this.errors; 
    } 

}