[jboss-user] [JBoss Web Services] - @XMLElement(required = true) Validation

Vincenzo Esposito do-not-reply at jboss.com
Thu Apr 14 06:48:07 EDT 2011

Vincenzo Esposito [http://community.jboss.org/people/vesposito] created the discussion

"@XMLElement(required = true) Validation"

To view the discussion, visit: http://community.jboss.org/message/600002#600002

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.+

Reply to this message by going to Community

Start a new discussion in JBoss Web Services at Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110414/f66a3472/attachment-0001.html 

More information about the jboss-user mailing list