Tutorial :How can I add WSDL restrictions programmatically?



Question:

Where I work, we have a policy in place that states we should try to build web services "bottom-up" (code-first).

When doing this, how can I add restrictions within my XSD <types> WSDL element? For example, in the following:

import javax.jws.WebService;  import javax.xml.ws.BindingType;    @WebService  @BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)  public class ProofOfConcept {        public String sayHello(String guest){          return "Hello "+guest;      }  }  

The output in my WSDL is as such:

...  <xs:complexType name="sayHello">      <xs:sequence>          <xs:element minOccurs="0" name="arg0" type="xs:string" />      </xs:sequence>  </xs:complexType>  ...  

I would like to add both minLength and maxLength restrictions to the "guest" String. Is this possible to do through code as opposed to editing the WSDL directly?

I'm aware that I can use a custom class and annotate my fields with @XmlElement or @XmlAttribute to get a few customizations (name, required etc.), but nothing specific for something like a String (length etc.); is it possible to modify / extend those annotations to add support for something like length or pattern?

Thanks.


Solution:1

I find it interesting that your policy is to try to build Web services bottom-up as I recommend building Web services top-down in order to cleanly define the contract. At any rate...

I'm not aware of a specific solution using annotations and I see that you haven't found one in your search either. If you want to automate the process so as to avoid overwriting your changes to the schema every time you regenerate the WSDL you can add an XSL transform to the resulting WSDL to add these attributes. While not an ideal solution it should allow you to set the attributes and continue working.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »