Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使webservice架构验证将空标记视为丢失_Java_Validation_Jax Ws - Fatal编程技术网

Java 使webservice架构验证将空标记视为丢失

Java 使webservice架构验证将空标记视为丢失,java,validation,jax-ws,Java,Validation,Jax Ws,我有一个带有@SchemaValidation的jaxws Web服务 @SchemaValidation(handler = MySchemaValidationHandler.class) @WebService(portName = "MyService", serviceName = "MyService", targetNamespace = "urn:com.my.urn", wsdlLocation = "/wsdls/mywsdl.wsdl", endpointInterface

我有一个带有@SchemaValidation的jaxws Web服务

@SchemaValidation(handler = MySchemaValidationHandler.class)
@WebService(portName = "MyService", serviceName = "MyService", targetNamespace = "urn:com.my.urn", wsdlLocation = "/wsdls/mywsdl.wsdl", endpointInterface = "com.my.MyService")
@BindingType("http://schemas.xmlsoap.org/wsdl/soap/http")
public class MyServiceImpl
        implements MyService {
    @Resource
    WebServiceContext wsContext;
    public void myOperation(Holder<XMLGregorianCalendar> tag1, Holder<XMLGregorianCalendar> tag2, Holder<String> message) {
    ...
    }
}
@SchemaValidation(handler=MySchemaValidationHandler.class)
@WebService(portName=“MyService”,serviceName=“MyService”,targetNamespace=“urn:com.my.urn”,wsdlLocation=“/wsdls/mywsdl.wsdl”,endpointInterface=“com.my.MyService”)
@BindingType(“http://schemas.xmlsoap.org/wsdl/soap/http")
公共类MyServiceImpl
实现MyService{
@资源
webservicecontextwscontext;
公共无效myOperation(持有者tag1、持有者tag2、持有者消息){
...
}
}
在xsd中,我有以下示例:

<xsd:choice>
    <xsd:element name="tag1" type="xsd:dateTime" minOccurs="0"/>
    <xsd:element name="tag2" type="xsd:dateTime" minOccurs="0"/>
</xsd:choice>

当我发送带有空标记的请求时,我得到一个关于字段格式的错误(不符合日期格式的限制)


价值1
在请求描述中,我有强制标记和选择标记,并且必须在响应中返回正确的错误消息,所以我不能跳过处理程序中的此类错误。 我也不能修改xsd和wsdl

逻辑上为空的标记与缺少的标记的含义相同。如何使验证将空标记视为丢失,或者如何在验证之前删除空标记?
谢谢。

编辑:不要发送无效的XML。在您给出的示例中,您应该删除客户机代码中的
。不要试图滥用服务器的验证来处理无效的XML。

我想我忘了提到我不能修改模式,为了提供最棘手的示例,您应该用更具体的示例来更新问题,具体说明什么应该被允许,什么不应该被允许。这是一种最佳实践,但有时,当客户机代码不是您的,并且您无法真正保证它发送了有效的请求时,您需要通过一些自定义规则对其进行验证。发现这有助于我-HandlerChain.还发现了另一种方法,即使用HandlerChain并将请求直接作为xml处理。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:com.my.urn">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:myOperation>
         <Tag1>value1</Tag1>
         <Tag2></Tag2>
      </urn:myOperation> 
   </soapenv:Body>
</soapenv:Envelope>