简体   繁体   中英

Imposing limits on Wsdl created by Apache CXF

I'm currently working on a project to develop some web services, and we've chosen Apache CXF as the technology of choice. We're working with a contract-last methodology (We're coding our service and allowing CXF to generate the wsdl for us.) While we have been able to use Java-WS annotations to set certain fields as required, we have been unable to figure out how to impose character limits on strings elements in the wsdl. While it isn't a huge deal (we're fairly close with the vendor we're working with, so a casual agreement to not let the requests coming to us exceed said length is enough for now), we are curious is there is a way to do this.

Is there a way to with CFX to impose something like a 20 character limit on an input string?

This isn't something that JAXB provides. However, there is a project that has forked the jaxb-ri that adds support for this:

https://github.com/whummer/jaxb-facets

If you don't need to have the facet reflected in the WSDL, you could just do the validation as part of the setter method of the JAXB beans.

setName(String s) {
   if (s.length() > 20) thrown new Exception(....);
   name = s;
}

There are also some events that the JAXB bean could respond to after unmarshalling where you could validate things. See the afterUnmarshall descriptions in the javadoc: http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/Unmarshaller.html

When you do a bottom up approach to webservice(ie impl first, WSDL later), you are at the webservice engine's mercy wrt to thew restrictions on the datatypes.

But if you go thru the top-down approach(WSDL first, impl later), you can eliminate those kind of problems, but would require you to know how to develop WSDLs and apply facets (restrictions).

Fortunately, CXF supports both, and you can give a try to wsdl2java .

Also remember, adding a facet doesn't mean that it will be enforced by the webservice engine. Most of the engines just ignore it, though I am not sure about CXF.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM