向客户端发送验证失败消息列表?

时间:2013-11-06 11:56:23

标签: java web-services jaxb xsd jax-ws

我正在使用jax-ws来开发基于肥皂的网络服务。我有下面的终点,它有一个网络方法如下。

@WebService
public interface MySoapService {

    @WebMethod
    public List<Result> getResult(TestRequest request);
}

这里使用jaxb从xsd生成TestRequest。我想验证对xsd的请求。

如果验证失败,那么我需要将所有验证错误保留在列表中并发送给客户。我怎样才能做到这一点?请帮帮我。

谢谢!

谢谢!

1 个答案:

答案 0 :(得分:0)

选项A:性能方面不是最佳解决方案,也不是最优雅的解决方案,但是因为您需要列出所有错误 - 实现ValidationEventHandler,在JAX-WS逻辑处理程序中处理模式验证并抛出SOAP错误,接缝是最合适的解决方案 选项B:如果使用逻辑处理程序不是有吸引力的解决方案,可以在SIB中处理SOAP有效负载:

@Resource
WebServiceContext wsContext;

@WebMethod
public void test(String test) throws ValidationException {
    MessageContext messageContext = wsContext.getMessageContext();
    DOMSource source = (DOMSource) messageContext.getRequest().getPayloadSource();
    ...//Unmarshling and validating SOAP payload. Same as described in option A
}

选项C:在较低级别运行,增加了SOAP消息将被解组一次的好处:

@WebServiceProvider
@ServiceMode(value=Service.Mode.MESSAGE)
public class TestProvider implements Provider<SOAPMessage>
{
    public SOAPMessage invoke(SOAPMessage request) 
    {
        SOAPBody requestBody = request.getSOAPBody();
        Document document = requestBody.extractContentAsDocument();
        ...//Unmarshling and validating SOAP payload. Same as described in option A
    }
}

验证和其他不相关的内容已经描述here,并且关于架构验证的内容非常documentation

相关问题