CXF code first webservice is creating wsdl with xs:element form=“unqualified” not picking up namespace

安稳与你 提交于 2020-01-14 04:06:12

问题


I'm creating webservices with CXF using the code first approach. I want to use namespaces, and therefore elementFormDefault is set to true. The WSDL is fine, except for the elements embedded in the complextypes, i get following xs:element having a form="unqualified" tag. But I want to get rid of the form=unqualified tag

<xs:element form="unqualified" name="LikeSearch" type="xs:boolean"/>

My package-info.java looks like this:

@javax.xml.bind.annotation.XmlSchema(namespace="http://registry.erpel.at",
   attributeFormDefault=javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
   elementFormDefault=javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
   package at.erpel.registry.services.webservice;

The Java endpoint looks like this:

@WebService(targetNamespace = "http://registry.erpel.at", name="CompanyEndpoint")
public interface CompanyEndpoint {
    List<Company> findCompanies(
        @WebParam(name = "FindCompaniesRequest") @XmlElement(required=true) FindCompaniesRequest findCompaniesRequest)
        throws ServiceFault ;

This is the FindCompaniesRequest:

@XmlRootElement(name = "FindCompaniesRequest")
public class FindCompaniesRequest extends AbstractRequestType implements Serializable
{
   @XmlElement(name = "LikeSearch", required = true)
   protected boolean likeSearch;
   ...
}

And finally the WSDL:

<xs:complexType name="FindCompaniesRequest">
   <xs:complexContent>
      <xs:extension base="tns:AbstractRequestType">
        <xs:sequence>
            <xs:element form="unqualified" name="LikeSearch" type="xs:boolean"/>

What I want, is to get rid of the form="unqualified" tag

The only solution I have found so far is adding the namespace attribute to every single XMLElement:

 @XmlElement(name = "LikeSearch", required = true, namespace="http://registry.erpel.at")
 protected boolean likeSearch;

But I want the child elements just to pick up the namespace from the parent elements. I have tried adding the namespace attribute to the @XMLRootElement annotation, to the @WebParam annotation, and to the @XmlElement annotation in the method description, but without any success.

Anyone knows how to get this working?


回答1:


The package-info.java file can only declare JAXB defaults for the classes in the same package; you've got to put one in each package that gets tooled into doing class generation (or define a whole lot more attributes of your annotations, which isn't much fun).

Fortunately, this is pretty much cut-n-paste coding. Just copy a single package info file around and tweak it if you want the namespace to change.



来源:https://stackoverflow.com/questions/6777136/cxf-code-first-webservice-is-creating-wsdl-with-xselement-form-unqualified-no

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