问题
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