How to generate XSD that requires sending the contents of an XML element using JAX-WS

Asked

Viewed 162 times

2

I’m creating a web service with JAX-WS. In an operation, I receive an object that contains some attributes and I want these attributes to always come with value.

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class RequestConsultarMargem {

    @XmlElement(name = "usuario-webservice", required = true, nillable = false)
    public String usuarioWebservice;

}

In the annotation @XmlElement I specified required = true to validate whether the element came in XML, and nillable = false, to validate whether the content of the widget is not empty.

For the validation to be performed, I put the annotation @SchemaValidation in the service:

@WebService
@SchemaValidation
public class MargemWS {

    @WebMethod(operationName = "consultarMargem")
    @WebResult(name = "retorno-consulta-margem")
    public ResponseConsultarMargem consultarMargem(@WebParam(name = "consultar-margem")
                                                   @XmlElement(required = true, nillable = false) RequestConsultarMargem request) {
        ...
    }

}

However, when climbing the server and checking the generated XSD, the attribute nillable was not placed in the attribute:

<xs:complexType name="requestConsultarMargem">
    <xs:sequence>
        <xs:element name="usuario-webservice" type="xs:string"/>
    </xs:sequence>
</xs:complexType>

The nillable = false worked because the element in XSD did not come with the attribute minOccurs="0".

I’m using JAX-WS in version 2.2.10.

What could be wrong?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.