<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
@XMLElement(required = true) Validation
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/vesposito">Vincenzo Esposito</a> in <i>JBoss Web Services</i> - <a href="http://community.jboss.org/message/600002#600002">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Dear Community,</p><p>before anything thanks for all support. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Configuration:</p><p>JBoss 4.2.3.GA</p><p>JBossWS Native 3.1.0.GA</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="margin-bottom: 0.0001pt;"><span style="color: #333333;"><em><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">I'm just developing a </span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">simple </span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">test </span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">using</span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">WebService</span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">.</span> <span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">I have </span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">some constraints</span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;"> 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.</span></em></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>This is the service code:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>TestService Interface</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>import</b></font> javax.jws.WebMethod;
<font color="navy"><b>import</b></font> javax.jws.WebService;
<font color="navy"><b>import</b></font> javax.jws.soap.SOAPBinding;
<font color="navy"><b>import</b></font> javax.jws.soap.SOAPBinding.ParameterStyle;
<font color="navy"><b>import</b></font> javax.jws.soap.SOAPBinding.Style;
 
 
<font color="navy"><b>import</b></font> org.jboss.wsf.spi.annotation.WebContext;
 
 
@WebContext(contextRoot=<font color="red">"/TestService"</font>)
@WebService
@SOAPBinding(style= Style.DOCUMENT, parameterStyle = ParameterStyle.WRAPPED)
<font color="navy"><b>public</b></font> <font color="navy"><b>interface</b></font> TestService <font color="navy">{</font>
 
 
          @WebMethod
          <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> sendInfo(TestObject to);
 
<font color="navy">}</font>
 
 
 
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>TestServiceBean</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>import</b></font> javax.ejb.Stateless;
<font color="navy"><b>import</b></font> javax.jws.WebMethod;
<font color="navy"><b>import</b></font> javax.jws.WebService;
<font color="navy"><b>import</b></font> org.jboss.wsf.spi.annotation.WebContext;
 
 
@WebContext(contextRoot=<font color="red">"/Test-Service"</font>)
@WebService(serviceName=<font color="red">"TestService"</font>, endpointInterface=<font color="red">"testing.TestService"</font>)
@Stateless
<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> TestServiceBean <font color="navy"><b>implements</b></font> TestService <font color="navy">{</font>
 
 
          @WebMethod
          <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> sendInfo(TestObject to) <font color="navy">{</font>
               System.out.println(to.get_data());
               System.out.println(to.get_key());
          <font color="navy">}</font>
 
 
<font color="navy">}</font>
 
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>TestObject Class</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>import</b></font> javax.xml.bind.annotation.XmlElement;
 
 
<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> TestObject <font color="navy">{</font>
 
 
          <font color="navy"><b>private</b></font> String _data;
 
          <font color="navy"><b>private</b></font> <font color="navy"><b>int</b></font> _key;
 
          @XmlElement(name = <font color="red">"_data"</font>, required = <font color="navy"><b>true</b></font>)
          <font color="navy"><b>public</b></font> String get_data() <font color="navy">{</font>
               <font color="navy"><b>return</b></font> _data;
          <font color="navy">}</font>
 
 
          <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> set_data(String _data) <font color="navy">{</font>
               this._data = _data;
          <font color="navy">}</font>
 
 
          <font color="navy"><b>public</b></font> <font color="navy"><b>int</b></font> get_key() <font color="navy">{</font>
               <font color="navy"><b>return</b></font> _key;
          <font color="navy">}</font>
 
 
          <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> set_key(<font color="navy"><b>int</b></font> _key) <font color="navy">{</font>
               this._key = _key;
          <font color="navy">}</font>
 
 
 
<font color="navy">}</font>
 
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="margin-bottom: 0.0001pt;"><span style="color: #333333;"><em><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">As you can see by code, analyzing TestObject class, Idecided that the "_data" attribute should be necessarly required</span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;"> and it must be not “nillable”</span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">. Once deployed, the generated WSDL is this one:</span></em></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>TestServiceBean.wsdl</p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag"><span><definitions name="TestService" targetNamespace="</span><a class="jive-link-external-small" href="http://testing/" target="_blank">http://testing/</a><span>" xmlns="</span><a class="jive-link-external-small" href="http://schemas.xmlsoap.org/wsdl/" target="_blank">http://schemas.xmlsoap.org/wsdl/</a><span>" xmlns:soap="</span><a class="jive-link-external-small" href="http://schemas.xmlsoap.org/wsdl/soap/" target="_blank">http://schemas.xmlsoap.org/wsdl/soap/</a><span>" xmlns:tns="</span><a class="jive-link-external-small" href="http://testing/" target="_blank">http://testing/</a><span>" xmlns:xsd="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema" target="_blank">http://www.w3.org/2001/XMLSchema</a><span>"></span></span>
<span class="jive-xml-tag"><types></span>
  <span class="jive-xml-tag"><span><xs:schema targetNamespace="</span><a class="jive-link-external-small" href="http://testing/" target="_blank">http://testing/</a><span>" version="1.0" xmlns:tns="</span><a class="jive-link-external-small" href="http://testing/" target="_blank">http://testing/</a><span>" xmlns:xs="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema" target="_blank">http://www.w3.org/2001/XMLSchema</a><span>"></span></span>
   <span class="jive-xml-tag"><xs:element name="sendInfo" type="tns:sendInfo"/></span>
   <span class="jive-xml-tag"><xs:element name="sendInfoResponse" type="tns:sendInfoResponse"/></span>
   <span class="jive-xml-tag"><xs:complexType name="sendInfo"></span>
    <span class="jive-xml-tag"><xs:sequence></span>
     <span class="jive-xml-tag"><xs:element minOccurs="0" name="arg0" type="tns:testObject"/></span>
    <span class="jive-xml-tag"></xs:sequence></span>
   <span class="jive-xml-tag"></xs:complexType></span>
   <span class="jive-xml-tag"><xs:complexType name="testObject"></span>
    <span class="jive-xml-tag"><xs:sequence></span>
     <span class="jive-xml-tag"><xs:element name="_data" type="xs:string"/></span>
     <span class="jive-xml-tag"><xs:element name="_key" type="xs:int"/></span>
    <span class="jive-xml-tag"></xs:sequence></span>
   <span class="jive-xml-tag"></xs:complexType></span>
   <span class="jive-xml-tag"><xs:complexType name="sendInfoResponse"></span>
    <span class="jive-xml-tag"><xs:sequence/></span>
   <span class="jive-xml-tag"></xs:complexType></span>
  <span class="jive-xml-tag"></xs:schema></span>
<span class="jive-xml-tag"></types></span>
<span class="jive-xml-tag"><message name="TestService_sendInfoResponse"></span>
  <span class="jive-xml-tag"><part element="tns:sendInfoResponse" name="sendInfoResponse"/></span>
<span class="jive-xml-tag"></message></span>
<span class="jive-xml-tag"><message name="TestService_sendInfo"></span>
  <span class="jive-xml-tag"><part element="tns:sendInfo" name="sendInfo"/></span>
<span class="jive-xml-tag"></message></span>
<span class="jive-xml-tag"><portType name="TestService"></span>
  <span class="jive-xml-tag"><operation name="sendInfo" parameterOrder="sendInfo"></span>
   <span class="jive-xml-tag"><input message="tns:TestService_sendInfo"/></span>
   <span class="jive-xml-tag"><output message="tns:TestService_sendInfoResponse"/></span>
  <span class="jive-xml-tag"></operation></span>
<span class="jive-xml-tag"></portType></span>
<span class="jive-xml-tag"><binding name="TestServiceBinding" type="tns:TestService"></span>
  <span class="jive-xml-tag"><span><soap:binding style="document" transport="</span><a class="jive-link-external-small" href="http://schemas.xmlsoap.org/soap/http" target="_blank">http://schemas.xmlsoap.org/soap/http</a><span>"/></span></span>
  <span class="jive-xml-tag"><operation name="sendInfo"></span>
   <span class="jive-xml-tag"><soap:operation soapAction=""/></span>
   <span class="jive-xml-tag"><input></span>
    <span class="jive-xml-tag"><soap:body use="literal"/></span>
   <span class="jive-xml-tag"></input></span>
   <span class="jive-xml-tag"><output></span>
    <span class="jive-xml-tag"><soap:body use="literal"/></span>
   <span class="jive-xml-tag"></output></span>
  <span class="jive-xml-tag"></operation></span>
<span class="jive-xml-tag"></binding></span>
<span class="jive-xml-tag"><service name="TestService"></span>
  <span class="jive-xml-tag"><port binding="tns:TestServiceBinding" name="TestServiceBeanPort"></span>
   <span class="jive-xml-tag"><span><soap:address location="</span><a class="jive-link-external-small" href="http://127.0.0.1:8180/Test-Service/TestServiceBean" target="_blank">http://127.0.0.1:8180/Test-Service/TestServiceBean</a><span>"/></span></span>
  <span class="jive-xml-tag"></port></span>
<span class="jive-xml-tag"></service></span>
<span class="jive-xml-tag"></definitions></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><em>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</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Generated TestObject Stub detail</p><pre class="jive-pre"><code class="jive-code jive-java">@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = <font color="red">"testObject"</font>, propOrder = <font color="navy">{</font>
    <font color="red">"data"</font>,
    <font color="red">"key"</font>
<font color="navy">}</font>)
<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> TestObject <font color="navy">{</font>
 
 
    @XmlElement(name = <font color="red">"_data"</font>, required = <font color="navy"><b>true</b></font>)
    <font color="navy"><b>protected</b></font> String data;
    @XmlElement(name = <font color="red">"_key"</font>)
    <font color="navy"><b>protected</b></font> <font color="navy"><b>int</b></font> key;
.....
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="margin-bottom: 0.0001pt;"><span style="color: #333333;"><em><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">The generated Stub contains the"required" constraint over the "_data" attribute.</span></em></span></p><p style="margin-bottom: 0.0001pt;"><span style="color: #333333;"><em><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;"> </span></em></span></p><p style="margin-bottom: 0.0001pt;"><span style="color: #333333;"><em><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">In order to be consistent, I think that if Itry to use the TestObject omitting the "_data" value, JBossWS </span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">should</span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;"> not allow the service request. This is the client main method using to request the service. </span></em></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Main class</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>public</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>void</b></font> main(String[] args) <font color="navy">{</font>
 
          TestService_Service srv = <font color="navy"><b>new</b></font> TestService_Service();
          TestService test_srv = srv.getTestServiceBeanPort();
 
          TestObject to = <font color="navy"><b>new</b></font> TestObject();
          to.setKey(3);
 
          test_srv.sendInfo(to);
 
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="margin-bottom: 0.0001pt;"><strong style="color: #333333;"><em><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">Running</span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;"> the client, it will perform the request without any Exception </span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">on </span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">its side and </span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">the </span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">"null" value for the "_data"attribute</span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;"> is received by service implementation</span><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">.</span></em></strong></p><p style="margin-bottom: 0.0001pt;"><span style="color: #333333;"><em><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;"> </span></em></span></p><p style="margin-bottom: 0.0001pt;"><span style="color: #333333;"><em><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">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?</span></em></span></p><p style="margin-bottom: 0.0001pt;"><span style="color: #333333;"><em><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;"> </span></em></span></p><p style="margin-bottom: 0.0001pt;"><span style="color: #333333;"><em><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;">Thank you for support again.</span></em></span></p><p style="margin-bottom: 0.0001pt;"><span style="color: #333333;"><em><span lang="EN-US" style="font-family: Arial, sans-serif; font-size: 10pt;"> </span></em></span></p><p style="margin-bottom: 0.0001pt;"><span style="color: #333333;"><em style="font-size: 10pt; font-family: Arial, sans-serif;">Vincenzo </em></span></p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/600002#600002">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Web Services at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2044">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>