CXF/JAXB Code-first service: modify XMLSchemaType of inputs

纵然是瞬间 提交于 2020-01-04 07:52:07

问题


I am working on a CXF/JAXB code-first web service. I would like to be able to modify the WSDL definitions of some of the inputs.

For example, given the following interface snippet:

@WebMethod
public void Something(@WebParam(name="date") Date date);

The WSDL will generate the XMLSchema for the input "date" to be a "datetime" xml element. I would like it to be simply a "date" element instead.

It would also be nice to be able to specify the some of the other input attributes, such as minOccurs, etc.

For a custom object, the sub-elements can define all of these things through annotations such as XmlElement and XmlSchemaType. However, these annotations are not legal on an input parameter.

I know earlier versions of CXF did not handle this, but I'm not sure about the later versions. I'm currently running CXF 2.3.5.


回答1:


Here is the answer I got from the cxf-users list:

1) Endorse the JAXB 2.2 API jar via one of the JDK endorsement mechanisms. Then the XmlElement and XmlSchemaType annotations can be used on the parameter.

(This is not quite correct--the 2.2 jaxb that I endorsed did allow the @XmlElement annotation on a parameter, but it did not allow the @XmlSchemaType annotation)

2) Create the wrapper type beans (you can use java2ws -warpperBeans as a starting point) and add the @RequestWrapper/@ResponseWrapper annotations to the method to point at them. You can finely control the appearance of the wrapper schema via annotations in the beans.

3) You CAN configure extra subclasses of AbstractServiceConfiguration into the factories where you override some of the methods to set various minOccurs/maxOccurs/etc.. type things. VERY fine level of control, but very complex to do.



来源:https://stackoverflow.com/questions/8057203/cxf-jaxb-code-first-service-modify-xmlschematype-of-inputs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!