问题描述
我用来创建CXF客户端的WSDL文件具有以下元素定义:
The WSDL file I used to create the CXF client has this element definition:
<xsd:element name="Rate">
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">
<xsd:totalDigits value="18" />
<xsd:fractionDigits value="2" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
但是,当我尝试发送SOAP消息时,小数点后的位数超过了最大值。例如,我得到2.48862,而预期为2.48。为了解决这个问题,我计划实现一个XmlAdapter来编组值,但是我无法将WSDL中的元素映射到客户端,因为XmlAdapter的onyl类作为注释传递给了字段清除。
However when I try to send the SOAP message, number of digits in after decimal point exceeds the maximum value. For example I get 2.48862 while expecting 2.48. In order to solve this I was planning to implement a XmlAdapter to marshall the values, however I cannot map the element in WSDL to the client because onyl class of XmlAdapter is passed to field decleration as annotation.
@XmlJavaTypeAdapter(CustomXmlAdapter.class)
似乎无法通知XmlAdapter字段小数点后必须有2位数字。
There seems to be no way to inform the XmlAdapter that field must have 2 digits after decimal point.
小数位数在元素之间变化。我也无权更改WSDL。
The number of fraction digits changes from element to element. I also don't have the access to change the WSDL.
在观察WSDL中指定的小数点位数的同时,是否可以格式化这些元素?
Is there a way to format these elements while observing the number of decimal points specified in the WSDL?
推荐答案
我可能建议在WSDL引用的模式上使用xQuery。模式的名称和位置是WSDL的一部分,也可以通过XQuery检索。
I might suggest the use of xQuery on the schema referenced by the WSDL. The name and location of the schema are part of the WSDL, and can be retrieved via XQuery also.
模式是格式良好的XML,因此您只需确定正确的XPath选择器以检索所需的值-在这种情况下,最小值将类似于...
Schemas are well-formed XML, so you will just have to determine the correct XPath selector to retrieve the desired value - in this case, that will be at a minimum something like...
//xsd:element[@name == 'Rate']//xsd:fractionDigits/@value
应该产生值2。
请记住,最新的JDK中内置了XPath / XQuery解释器。您只需在其上放置某种前端,我相信它将很好地处理流。
Keep in mind that there is an XPath/XQuery interpretor built into the latest JDKs. You merely have to put some kind of front-end on it, and I believe it will handle streams quite nicely.
执行上述操作可使您动态查询模式,如下所示:您正在处理一个给定的元素,例如,允许您在处理Rate时获得正确的小数位数。
Doing the above will let you query the schema dynamically as you are processing a given element, allowing you, for example, to get the correct number of decimal digits when processing the Rate.
这篇关于CXF客户端SOAP消息格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!