【问题标题】:How to tell SchemaValidation fatal and errors are ok and still get details of validation errors?如何告诉 SchemaValidation 致命并且错误正常,并且仍然获得验证错误的详细信息?
【发布时间】:2016-03-11 22:08:24
【问题描述】:

我有一个@Webservice,需要对输入进行 XSD 验证。 在我的 WSDL XSD 中,PingInput 中的 inputTime 和 userInput 都是必需的。

我用@SchemaValidation 装饰我的网络服务,并使用自定义SchemaValidationErrorHandler,如下所示。

因为我下面的SchemaValidationErrorHandler 方法只做一个packet.invocationProperties.put 并且不抛出异常,所以我期望当调用 ping 时,它仍然应该进入我的 ping 方法。

我需要做什么才能启用此行为?

网络服务:

@WebService
@Stateless
@SchemaValidation(handler = SchemaValidationErrorHandler.class)  
class MyWebservice {
  public PingResponse ping(PingInput input) throws PingFault{
    //never gets here when there is a XSD error
    Object errorException = messageContext.get(SchemaValidationErrorHandler.ERROR);  
...
  }
} 

SchemaValidationErrorHandler :

import org.xml.sax.SAXParseException;
import com.sun.xml.ws.developer.ValidationErrorHandler;  
public class SchemaValidationErrorHandler extends ValidationErrorHandler {  

  public static final String WARNING = "Warning";  
  public static final String ERROR = "Error";  
  public static final String FATAL_ERROR = "Fatal";  

  public void warning(SAXParseException exception) {  
    packet.invocationProperties.put(WARNING, exception);  
  }  

  public void error(SAXParseException exception) {  
    packet.invocationProperties.put(ERROR, exception);  
  }  

  public void fatalError(SAXParseException exception) {  
    packet.invocationProperties.put(FATAL_ERROR, exception);  
  } 

输入:

class PingInput {
  long inputTime;//required
  String userInput;//required
}

【问题讨论】:

  • 似乎这与我使用的 jaxws-rt 有关。 2.2.10 像魅力一样工作

标签: jakarta-ee xsd java-8 jax-ws xsd-validation


【解决方案1】:

我花了半天多的时间试图让它工作,所以我发布了一个答案。我希望它可以帮助别人。

看来是我的应用服务器捆绑的 JavaWS 出了问题。

在我的 WAR 中包含以下依赖项后,它就像一个魅力。 以前我将其标记为已提供。

<dependency>
  <groupId>com.sun.xml.ws</groupId>
  <artifactId>jaxws-rt</artifactId>
  version>2.2.10</version>
</dependency>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 2012-12-26
    • 1970-01-01
    相关资源
    最近更新 更多