<!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;">&#160;</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;">&#160;</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&rsquo;s parameters. In particular I&rsquo;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;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>This is the service code:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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;
&#160;
&#160;
<font color="navy"><b>import</b></font> org.jboss.wsf.spi.annotation.WebContext;
&#160;
&#160;
@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>
&#160;
&#160;
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;@WebMethod
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> sendInfo(TestObject to);
&#160;
<font color="navy">}</font>
&#160;
&#160;
&#160;
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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;
&#160;
&#160;
@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>
&#160;
&#160;
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;@WebMethod
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> sendInfo(TestObject to) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;System.out.println(to.get_data());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;System.out.println(to.get_key());
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<font color="navy">}</font>
&#160;
&#160;
<font color="navy">}</font>
&#160;
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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;
&#160;
&#160;
<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> TestObject <font color="navy">{</font>
&#160;
&#160;
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<font color="navy"><b>private</b></font> String _data;
&#160;
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<font color="navy"><b>private</b></font> <font color="navy"><b>int</b></font> _key;
&#160;
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;@XmlElement(name = <font color="red">"_data"</font>, required = <font color="navy"><b>true</b></font>)
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<font color="navy"><b>public</b></font> String get_data() <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<font color="navy"><b>return</b></font> _data;
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<font color="navy">}</font>
&#160;
&#160;
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> set_data(String _data) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;this._data = _data;
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<font color="navy">}</font>
&#160;
&#160;
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<font color="navy"><b>public</b></font> <font color="navy"><b>int</b></font> get_key() <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<font color="navy"><b>return</b></font> _key;
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<font color="navy">}</font>
&#160;
&#160;
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<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>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;this._key = _key;
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;<font color="navy">}</font>
&#160;
&#160;
&#160;
<font color="navy">}</font>
&#160;
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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 &ldquo;nillable&#8221;</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;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>TestServiceBean.wsdl</p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag"><span>&lt;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>"&gt;</span></span>
 <span class="jive-xml-tag">&lt;types&gt;</span>
&#160; <span class="jive-xml-tag"><span>&lt;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>"&gt;</span></span>
&#160;&#160; <span class="jive-xml-tag">&lt;xs:element name="sendInfo" type="tns:sendInfo"/&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;xs:element name="sendInfoResponse" type="tns:sendInfoResponse"/&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;xs:complexType name="sendInfo"&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;xs:sequence&gt;</span>
&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;xs:element minOccurs="0" name="arg0" type="tns:testObject"/&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/xs:sequence&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;/xs:complexType&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;xs:complexType name="testObject"&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;xs:sequence&gt;</span>
&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;xs:element name="_data" type="xs:string"/&gt;</span>
&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;xs:element name="_key" type="xs:int"/&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/xs:sequence&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;/xs:complexType&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;xs:complexType name="sendInfoResponse"&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;xs:sequence/&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;/xs:complexType&gt;</span>
&#160; <span class="jive-xml-tag">&lt;/xs:schema&gt;</span>
 <span class="jive-xml-tag">&lt;/types&gt;</span>
 <span class="jive-xml-tag">&lt;message name="TestService_sendInfoResponse"&gt;</span>
&#160; <span class="jive-xml-tag">&lt;part element="tns:sendInfoResponse" name="sendInfoResponse"/&gt;</span>
 <span class="jive-xml-tag">&lt;/message&gt;</span>
 <span class="jive-xml-tag">&lt;message name="TestService_sendInfo"&gt;</span>
&#160; <span class="jive-xml-tag">&lt;part element="tns:sendInfo" name="sendInfo"/&gt;</span>
 <span class="jive-xml-tag">&lt;/message&gt;</span>
 <span class="jive-xml-tag">&lt;portType name="TestService"&gt;</span>
&#160; <span class="jive-xml-tag">&lt;operation name="sendInfo" parameterOrder="sendInfo"&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;input message="tns:TestService_sendInfo"/&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;output message="tns:TestService_sendInfoResponse"/&gt;</span>
&#160; <span class="jive-xml-tag">&lt;/operation&gt;</span>
 <span class="jive-xml-tag">&lt;/portType&gt;</span>
 <span class="jive-xml-tag">&lt;binding name="TestServiceBinding" type="tns:TestService"&gt;</span>
&#160; <span class="jive-xml-tag"><span>&lt;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>"/&gt;</span></span>
&#160; <span class="jive-xml-tag">&lt;operation name="sendInfo"&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;soap:operation soapAction=""/&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;input&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;soap:body use="literal"/&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;/input&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;output&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;soap:body use="literal"/&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;/output&gt;</span>
&#160; <span class="jive-xml-tag">&lt;/operation&gt;</span>
 <span class="jive-xml-tag">&lt;/binding&gt;</span>
 <span class="jive-xml-tag">&lt;service name="TestService"&gt;</span>
&#160; <span class="jive-xml-tag">&lt;port binding="tns:TestServiceBinding" name="TestServiceBeanPort"&gt;</span>
&#160;&#160; <span class="jive-xml-tag"><span>&lt;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>"/&gt;</span></span>
&#160; <span class="jive-xml-tag">&lt;/port&gt;</span>
 <span class="jive-xml-tag">&lt;/service&gt;</span>
<span class="jive-xml-tag">&lt;/definitions&gt;</span>

</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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;">&#160;</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>
&#160;&#160;&#160; <font color="red">"data"</font>,
&#160;&#160;&#160; <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>
&#160;
&#160;
&#160;&#160;&#160; @XmlElement(name = <font color="red">"_data"</font>, required = <font color="navy"><b>true</b></font>)
&#160;&#160;&#160; <font color="navy"><b>protected</b></font> String data;
&#160;&#160;&#160; @XmlElement(name = <font color="red">"_key"</font>)
&#160;&#160;&#160; <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;">&#160;</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;">&#160;</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>
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TestService_Service srv = <font color="navy"><b>new</b></font> TestService_Service();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TestService test_srv = srv.getTestServiceBeanPort();
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TestObject to = <font color="navy"><b>new</b></font> TestObject();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; to.setKey(3);
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; test_srv.sendInfo(to);
&#160;
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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>