M314
M314

Reputation: 955

JAX-WS nillable schema validation for string does not seem to work

I have java code generated by apache CXF wsdl2java tool. I turn on schema validation by setting:

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

In .wsdl file I have those kind of elements:

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

They are mappnig on:

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

But when I am sending XML containing:

<abc:propertyName></abc:propertyName>

It pass the validation, and mapped is empty string. I do not want there empty string. I want those kind of request not to passing validation. Is JAX-WS provide those kind of validation? If yes - then how to turn it on? If not - what is the best way to write my own code that will reject those kind of request?

Upvotes: 0

Views: 1140

Answers (1)

Daniel Kulp
Daniel Kulp

Reputation: 14607

The only way is to define the element similar to:

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

to mark it as requiring at least 1 character in the string.

Upvotes: 1

Related Questions