9

我简述:

如何让 wsdl2java 生成 SOAP 1.2 绑定?

详细说明:

我使用工具(apache cxf 3.0.2)为wsdl生成了 java 服务类:wsdl2java

MBA-Anton:bin asmirnov$ ./wsdl2java -server -catalog /tmp/wsdl/catalog  -d /tmp/onvif/server http://www.onvif.org/onvif/ver10/network/wsdl/remotediscovery.wsdl

然后我创建了服务代码并运行它,它正在运行:

public static void main(String args[]) throws InterruptedException {
        System.out.println("Starting Server");
        Endpoint.publish("udp://239.255.255.250:3702", new DiscoveryService());

        System.out.println("Server ready...");

        Thread.sleep(10 * 60 * 1000); // 10 min
        System.out.println("Server exiting");
        System.exit(0);
    }

启动日志:

Starting Server
28.11.2014 19:51:59 org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://www.onvif.org/ver10/network/wsdl}DiscoveryService from class org.onvif.ver10.network.wsdl.DiscoveryLookupPort
28.11.2014 19:52:00 org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be udp://239.255.255.250:3702
28.11.2014 19:52:00 org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
INFO: Creating Service {http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01}Discovery from WSDL: classpath:/org/apache/cxf/ws/discovery/wsdl/wsdd-discovery-1.1-wsdl-os.wsdl
28.11.2014 19:52:00 org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be soap.udp://239.255.255.250:3702
28.11.2014 19:52:00 org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01}DiscoveryProxy from class org.apache.cxf.jaxws.support.DummyImpl
Server ready...

开始后我立即进入日志:

28.11.2014 19:52:01 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
WARNING: Interceptor for {http://www.onvif.org/ver10/network/wsdl}DiscoveryService has thrown exception, unwinding now
org.apache.cxf.binding.soap.SoapFault: A SOAP 1.2 message is not valid when sent to a SOAP 1.1 only endpoint.
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:168)
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:65)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at org.apache.cxf.transport.udp.UDPDestination$MCastListener$2.run(UDPDestination.java:106)
    at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl.java:428)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(AutomaticWorkQueueImpl.java:353)
    at java.lang.Thread.run(Thread.java:695)

然后我尝试使用 ONVIF 客户端(使用 WS-Discovery 查找设备)发现服务,并且在日志中遇到相同的错误。这让我觉得 wsdl2java 生成了 SOAP 1.1 绑定,而我的 web 服务无法解析 SOAP 1.2 客户端消息。

如何让 wsdl2java 生成 SOAP 1.2 绑定?

PS。春天是可行的:

<soap:soapBinding mtomEnabled="true" version="1.2"/>
4

0 回答 0