1 Reply Latest reply on Aug 26, 2012 7:34 AM by ramy Hassan

    @XMLElement(required = true) Validation

    Vincenzo Esposito Newbie

      Dear Community,

      before anything thanks for all support.



      JBoss 4.2.3.GA

      JBossWS Native 3.1.0.GA


      I'm just developing a simple test usingWebService. I have some constraints to be applied to service’s parameters. In particular I’m looking for away to assure that the service provider receives only requests with valid input parameters.



      This is the service code:


      TestService Interface

      import javax.jws.WebMethod;
      import javax.jws.WebService;
      import javax.jws.soap.SOAPBinding;
      import javax.jws.soap.SOAPBinding.ParameterStyle;
      import javax.jws.soap.SOAPBinding.Style;
      import org.jboss.wsf.spi.annotation.WebContext;
      @SOAPBinding(style= Style.DOCUMENT, parameterStyle = ParameterStyle.WRAPPED)
      public interface TestService {
                public void sendInfo(TestObject to);



      import javax.ejb.Stateless;
      import javax.jws.WebMethod;
      import javax.jws.WebService;
      import org.jboss.wsf.spi.annotation.WebContext;
      @WebService(serviceName="TestService", endpointInterface="testing.TestService")
      public class TestServiceBean implements TestService {
                public void sendInfo(TestObject to) {


      TestObject Class

      import javax.xml.bind.annotation.XmlElement;
      public class TestObject {
                private String _data;
                private int _key;
                @XmlElement(name = "_data", required = true)
                public String get_data() {
                     return _data;
                public void set_data(String _data) {
                     this._data = _data;
                public int get_key() {
                     return _key;
                public void set_key(int _key) {
                     this._key = _key;


      As you can see by code, analyzing TestObject class, Idecided that the "_data" attribute should be necessarly required and it must be not “nillable”. Once deployed, the generated WSDL is this one:




      <definitions name="TestService" targetNamespace="http://testing/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://testing/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xs:schema targetNamespace="http://testing/" version="1.0" xmlns:tns="http://testing/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
         <xs:element name="sendInfo" type="tns:sendInfo"/>
         <xs:element name="sendInfoResponse" type="tns:sendInfoResponse"/>
         <xs:complexType name="sendInfo">
           <xs:element minOccurs="0" name="arg0" type="tns:testObject"/>
         <xs:complexType name="testObject">
           <xs:element name="_data" type="xs:string"/>
           <xs:element name="_key" type="xs:int"/>
         <xs:complexType name="sendInfoResponse">
       <message name="TestService_sendInfoResponse">
        <part element="tns:sendInfoResponse" name="sendInfoResponse"/>
       <message name="TestService_sendInfo">
        <part element="tns:sendInfo" name="sendInfo"/>
       <portType name="TestService">
        <operation name="sendInfo" parameterOrder="sendInfo">
         <input message="tns:TestService_sendInfo"/>
         <output message="tns:TestService_sendInfoResponse"/>
       <binding name="TestServiceBinding" type="tns:TestService">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="sendInfo">
         <soap:operation soapAction=""/>
          <soap:body use="literal"/>
          <soap:body use="literal"/>
       <service name="TestService">
        <port binding="tns:TestServiceBinding" name="TestServiceBeanPort">
         <soap:address location=""/>


      Just analyzing the WSDL, I don't see anything about the "required" element, but using "wsconsume" tool I can obtain stubs to use client side. In detail, this is the generated TestObject stub


      Generated TestObject Stub detail

      @XmlType(name = "testObject", propOrder = {
      public class TestObject {
          @XmlElement(name = "_data", required = true)
          protected String data;
          @XmlElement(name = "_key")
          protected int key;


      The generated Stub contains the"required" constraint over the "_data" attribute.


      In order to be consistent, I think that if Itry to use the TestObject omitting the "_data" value, JBossWS should not allow the service request. This is the client main method using to request the service.


      Main class

      public static void main(String[] args) {
                TestService_Service srv = new TestService_Service();
                TestService test_srv = srv.getTestServiceBeanPort();
                TestObject to = new TestObject();


      Running the client, it will perform the request without any Exception on its side and the "null" value for the "_data"attribute is received by service implementation.


      Now, what's wrong with the code? Is there anyexplaination about this issue? Why the WSDL do not contains the contraints over the "_data" value? Is there any validation before the SOAPMessage send?


      Thank you for support again.