【问题标题】:JAX-WS nillable schema validation for string does not seem to work字符串的 JAX-WS 可空模式验证似乎不起作用
【发布时间】:2013-03-13 10:31:35
【问题描述】:

我有 apache CXF wsdl2java 工具生成的 java 代码。我通过设置打开模式验证:

<jaxws:properties>
    <entry key="schema-validation-enabled" value="true" />
</jaxws:properties>

在 .wsdl 文件中我有这些元素:

<s:element minOccurs="1" maxOccurs="1" nillable="false" name="propertyName" type="s:string"/>

他们正在研究:

@XmlElement(name = "ServiceSeq", required = true, nillable = false)
protected String propertyName;

但是当我发送包含以下内容的 XML 时:

<abc:propertyName></abc:propertyName>

通过验证,映射为空字符串。我不希望有空字符串。我希望这种请求不要通过验证。 JAX-WS 是否提供这种验证?如果是 - 那么如何打开它?如果不是 - 编写我自己的代码以拒绝此类请求的最佳方法是什么?

【问题讨论】:

    标签: jakarta-ee jaxb jax-ws cxf wsdl2java


    【解决方案1】:

    唯一的办法就是定义类似如下的元素:

    <element minOccurs="1" maxOccurs="1" nillable="false" name="propertyName">
        <simpleType>
          <restriction base="string">
            <minLength value="1"/>
          </restriction>
        </simpleType>
    </element>
    

    将其标记为至少需要字符串中的 1 个字符。

    【讨论】:

      猜你喜欢
      • 2014-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多