我有一个 grails (TEST) 项目,可以通过肥皂访问,您可以添加一本书等。我想知道,是否可以在添加书籍时抛出所有错误的列表。
下面的代码是现在可以使用的代码,但我无法存储所有错误。我已经尝试在@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;
}
}
问候肯,