CXF wsdl2java 导致 BINDING_MISSING_TYPE

发布于 2024-11-17 13:16:41 字数 4269 浏览 1 评论 0 原文

使用 java 6、CXF 2.3.1 和 Maven 2。

通过 Maven 插件运行 CXF wsdl2java 工具时,我遇到了 以下问题:

wsdl2java -d C:\devel\adpoint_callback\target\ generated-sources\cxf -impl -validate -verbose 文件:/C:/devel/adpoint_callback/src/main/resources/wsdl/foobar.wsdl wsdl2java - Apache CXF 2.3.1

WSIBP 验证器发现<绑定>不是 SOAP 绑定 [DEBUG]

org.apache.cxf.tools.common.ToolException: org.apache.cxf.wsdl11.WSDLRuntimeException: BINDING_MISSING_TYPE 在 org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:279)

...~20 行

由以下原因引起:org.apache.cxf.wsdl11.WSDLRuntimeException:BINDING_MISSING_TYPE 在 org.apache.cxf.wsdl11.WSDLServiceBuilder.buildServices(WSDLServiceBuilder.java:306) 在 org.apache.cxf.wsdl11.WSDLServiceBuilder.buildServices(WSDLServiceBuilder.java:181)

使用以下改编自 http://www.w3schools.com/WSDL/wsdl_binding.asp

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="notification"   
    targetNamespace="http://example.com/mynamespace" 
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:xsd="http://example.com/mynamespace/xsd" >

    <wsdl:types>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
            xmlns:xsd="http://example.com/mynamespace/xsd" 
            targetNamespace="http://example.com/mynamespace/xsd" >
            <xs:element name="RequestType" type="xsd:content"/>
            <xs:element name="ResponseType" type="xsd:content"/>

            <xs:complexType name="content">
                    <xs:sequence>
                        <xs:element name="text" type="xs:string"/>
                    </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </wsdl:types>

    <wsdl:message name="getTermRequest">
        <wsdl:part name="body" element="xsd:RequestType"/>
    </wsdl:message>

    <wsdl:message name="getTermResponse">
        <wsdl:part name="body" element="xsd:ResponseType"/>
    </wsdl:message>

    <wsdl:portType name="glossaryTerms">
        <wsdl:operation name="getTerm">
            <wsdl:input message="getTermRequest"/>
            <wsdl:output message="getTermResponse"/>
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding name="binding" type="glossaryTerms">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="getTerm">
            <soap:operation soapAction="http://example.com/getTerm" />
            <wsdl:input><soap:body use="literal"/></wsdl:input>
            <wsdl:output><soap:body use="literal"/></wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="testService" >
        <wsdl:port name="testPort" binding="binding">
            <soap:address location="http://example.com/mynamespace"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

服务/绑定用法完全相同WSDL 1.1 规范文档中的示例中使用 http://www.w3.org/TR/wsdl

如果没有 -validate 标志,代码生成也将无法工作 - 验证警告不会显示。

当然,问题是为什么元素不被接受为绑定元素的绑定类型。


[ 编辑:修复]

如果我将默认命名空间设置为与 targetNamespace 相同的值,错误就会消失。 不知何故,CXF 能够处理这样一个事实:我直到它应该处理绑定时才设置默认命名空间。此时,它会抛出有关缺少绑定类型的误导性异常。

因此,修复此问题就像更改 wsdl:definition 标记的属性一样简单 定义默认命名空间:

<wsdl:definitions name="notification"   
    targetNamespace="http://example.com/mynamespace" 
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:xsd="http://example.com/mynamespace/xsd"
        xmlns="http://example.com/mynamespace" >

Using java 6, CXF 2.3.1 and Maven 2.

When running CXF wsdl2java tool via the Maven plugin, I am encountering
the following issue:

wsdl2java -d
C:\devel\adpoint_callback\target\generated-sources\cxf -impl -validate -verbose file:/C:/devel/adpoint_callback/src/main/resources/wsdl/foobar.wsdl
wsdl2java - Apache CXF 2.3.1

WSIBP Validator found <binding> is NOT
a SOAP binding [DEBUG]

org.apache.cxf.tools.common.ToolException:
org.apache.cxf.wsdl11.WSDLRuntimeException:
BINDING_MISSING_TYPE
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:279)

... ~20 rows

Caused by: org.apache.cxf.wsdl11.WSDLRuntimeException: BINDING_MISSING_TYPE
at org.apache.cxf.wsdl11.WSDLServiceBuilder.buildServices(WSDLServiceBuilder.java:306)
at org.apache.cxf.wsdl11.WSDLServiceBuilder.buildServices(WSDLServiceBuilder.java:181)

Using the following minimal WSDL file adapted from http://www.w3schools.com/WSDL/wsdl_binding.asp :

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="notification"   
    targetNamespace="http://example.com/mynamespace" 
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:xsd="http://example.com/mynamespace/xsd" >

    <wsdl:types>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
            xmlns:xsd="http://example.com/mynamespace/xsd" 
            targetNamespace="http://example.com/mynamespace/xsd" >
            <xs:element name="RequestType" type="xsd:content"/>
            <xs:element name="ResponseType" type="xsd:content"/>

            <xs:complexType name="content">
                    <xs:sequence>
                        <xs:element name="text" type="xs:string"/>
                    </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </wsdl:types>

    <wsdl:message name="getTermRequest">
        <wsdl:part name="body" element="xsd:RequestType"/>
    </wsdl:message>

    <wsdl:message name="getTermResponse">
        <wsdl:part name="body" element="xsd:ResponseType"/>
    </wsdl:message>

    <wsdl:portType name="glossaryTerms">
        <wsdl:operation name="getTerm">
            <wsdl:input message="getTermRequest"/>
            <wsdl:output message="getTermResponse"/>
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding name="binding" type="glossaryTerms">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="getTerm">
            <soap:operation soapAction="http://example.com/getTerm" />
            <wsdl:input><soap:body use="literal"/></wsdl:input>
            <wsdl:output><soap:body use="literal"/></wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="testService" >
        <wsdl:port name="testPort" binding="binding">
            <soap:address location="http://example.com/mynamespace"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

The service/binding usage is exactly as used in the example within the WSDL 1.1 specification document http://www.w3.org/TR/wsdl

The code generation will not work without the -validate flag either - The validation warnings just do not show up.

Question is - of course - why the <soap:binding> element is not accepted as a binding type for the binding element as it should.


[ EDIT : Fix ]

If I set the default namespace to the same value as my targetNamespace, the error disappears.
Somehow the CXF is able to handle the fact that I do not set the default namespace up until the moment it was supposed to handle the binding. At that point it throws out a misleading exception about missing binding type.

Therefore, fixing this is as easy as changing the attributes of the wsdl:definition tag
to define the default namespace:

<wsdl:definitions name="notification"   
    targetNamespace="http://example.com/mynamespace" 
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:xsd="http://example.com/mynamespace/xsd"
        xmlns="http://example.com/mynamespace" >

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-11-24 13:16:41

当您使用 targetNamespace="http://example.com/mynamespace" 并像这样定义您的绑定时:

<wsdl:binding name="binding" type="glossaryTerms">
    ...
</wsdl:binding>    

那么您必须在 wsdl:service 中引用该绑定> 具有相应命名空间的部分。具体来说,它应该是:binding=":"。这意味着您必须定义与 targetNamespace 相同的命名空间。例如,命名空间 tns

<wsdl:definitions name="notification"   
    targetNamespace="http://example.com/mynamespace" 
    ...
    xmlns:tns="http://example.com/mynamespace">

然后,在 wsdl:service 部分引用它时:

<wsdl:service name="testService">
    <wsdl:port name="testPort" binding="tns:binding">
        <soap:address location="http://example.com/mynamespace"/>
    </wsdl:port>
</wsdl:service>

When you use the targetNamespace="http://example.com/mynamespace" and define your binding like that:

<wsdl:binding name="binding" type="glossaryTerms">
    ...
</wsdl:binding>    

Then you have to refer to that binding in the wsdl:service section with the corresponding namespace. Specifically, it should be: binding="<namespace>:<binding_name>". It means that you have to define the namespace identical to the targetNamespace. For example, the namespace tns:

<wsdl:definitions name="notification"   
    targetNamespace="http://example.com/mynamespace" 
    ...
    xmlns:tns="http://example.com/mynamespace">

And then, when referring to it in the wsdl:service section:

<wsdl:service name="testService">
    <wsdl:port name="testPort" binding="tns:binding">
        <soap:address location="http://example.com/mynamespace"/>
    </wsdl:port>
</wsdl:service>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文