【问题标题】:sending list of validation failed messaged to client?向客户端发送验证失败消息列表?
【发布时间】:2013-11-06 11:56:22
【问题描述】:

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

@WebService
public interface MySoapService {

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

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

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

谢谢!

谢谢!

【问题讨论】:

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


    【解决方案1】:

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

    @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 关于架构验证的内容很棒。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-07
      • 2019-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-18
      相关资源
      最近更新 更多