CXF 代码第一个 web 服务正在使用 xs:element form="unqualified" 创建 wsdl没有选择命名空间 [英] CXF code first webservice is creating wsdl with xs:element form="unqualified" not picking up namespace

查看:23
本文介绍了CXF 代码第一个 web 服务正在使用 xs:element form="unqualified" 创建 wsdl没有选择命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用代码优先的方法使用 CXF 创建网络服务.我想使用命名空间,因此 elementFormDefault 设置为 true.WSDL 很好,除了复杂类型中嵌入的元素,我得到以下 xs:element 具有 form="unqualified" 标记.但我想去掉 form=unqualified 标签

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"/>

我的 package-info.java 看起来像这样:

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;

Java 端点如下所示:

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 ;

这是 FindCompaniesRequest:

This is the FindCompaniesRequest:

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

最后是 WSDL:

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

我想要的是去掉form="unqualified"标签

到目前为止,我找到的唯一解决方案是为每个 XMLElement 添加命名空间属性:

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;

但我希望子元素只是从父元素中获取命名空间.我曾尝试将命名空间属性添加到@XMLRootElement 注释、@WebParam 注释和方法描述中的 @XmlElement 注释,但没有任何成功.

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?

推荐答案

package-info.java 文件只能为同一个包中的类声明 JAXB 默认值;您必须在 每个 包中放入一个用于生成类的工具(或者定义更多的注释属性,这没什么意思).

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.

这篇关于CXF 代码第一个 web 服务正在使用 xs:element form="unqualified" 创建 wsdl没有选择命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆