简体   繁体   English

对由Apache CXF创建的Wsdl施加限制

[英]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. 我目前正在从事开发一些Web服务的项目,并且我们选择了Apache CXF作为首选技术。 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. 我们正在使用后契约的方法(我们正在对服务进行编码,并允许CXF为我们生成wsdl。)虽然我们已经能够使用Java-WS批注根据需要设置某些字段,但是我们无法弄清楚如何对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? 有没有办法使用CFX对输入字符串施加20个字符的限制?

This isn't something that JAXB provides. 这不是JAXB提供的。 However, there is a project that has forked the jaxb-ri that adds support for this: 但是,有一个项目已经分叉了jaxb-ri,它为此添加了支持:

https://github.com/whummer/jaxb-facets 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. 如果不需要在WSDL中反映该方面,则可以将验证作为JAXB bean的setter方法的一部分进行。

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. 在解组可验证内容的位置后,JAXB bean还可能响应一些事件。 See the afterUnmarshall descriptions in the javadoc: http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/Unmarshaller.html 请参阅Javadoc中的afterUnmarshall描述: 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. 当您对Web服务进行自下而上的方法时(例如,首先实现,之后才是WSDL),您会受到Web服务引擎对数据类型的限制的束缚。

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). 但是,如果您采用自上而下的方法(首先使用WSDL,之后引入),则可以消除此类问题,但是需要您知道如何开发WSDL和应用构面(限制)。

Fortunately, CXF supports both, and you can give a try to wsdl2java . 幸运的是,CXF支持这两种方式,您可以尝试wsdl2java

Also remember, adding a facet doesn't mean that it will be enforced by the webservice engine. 还要记住,添加构面并不意味着它将由Webservice引擎强制实施。 Most of the engines just ignore it, though I am not sure about CXF. 尽管我不确定CXF,但大多数引擎都忽略了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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