0
我有簡單的cxf 3.1.1 soap web服務。Apache CXF如何響應自定義驗證錯誤
@WebService
public interface MyService {
@WebMethod
public MyResponse addSomeModel(MyRequest req) throws SoapValidationException;
}
和實現:
@Component
@WebService(endpointInterface = "com...MyService", serviceName="Myservice")
public class MyServiceImpl implements MyService {
@Override
public MyResponse addSomeModel(MyRequest req) throws SoapValidationException {
Errors errors = new BeanPropertyBindingResult(req, "myReq");
addCampaignValidator.validate(req, errors);
if(errors.hasErrors()){
throw new SoapValidationException("Validation error.", errors);
}
//... save it the DB
return ...;
}
}
的SoapValidationException是:
@WebFault
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
public class SoapValidationException extends Exception implements Serializable{
private static final long serialVersionUID = 1L;
private Errors errors;
public SoapValidationException(String message, Errors errors, Throwable cause) {
super(message, cause);
this.errors = errors;
}
public SoapValidationException(String message, Errors errors) {
super(message);
this.errors = errors;
}
public List<FieldError> getErrors() { // Here I have to use some complex type
return errors.getFieldErrors();
}
public String getTargetObject(){
return errors.getObjectName();
}
public int getErrorCount(){
return errors.getErrorCount();
}
}
當我用一個簡單的類型如int或字符串爲一個公共的getter它的工作原理確定的對象序列化並以xml形式返回。 但我想使用一些複雜的類型,就像我使用Spring驗證中的FieldError
一樣。
我要做什麼,所以我可以使用複雜類型作爲SoapValidationException
的字段?
不需要使用FieldError
,我也可以用我自己的包裝和映射proeprties。