java Apache CXF:SOAP 1.2 消息在发送到仅限 SOAP 1.1 的端点时无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39356351/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:18:30  来源:igfitidea点击:

Apache CXF: A SOAP 1.2 message is not valid when sent to a SOAP 1.1 only endpoint

javaweb-servicessoapcxf

提问by Aurasphere

first of all, I know that there are already some questions on SO about this topic but none of them solved my problem (or I am too stupid to understand them, that's a possibility as well).

首先,我知道关于这个主题已经有一些关于 SO 的问题,但没有一个解决了我的问题(或者我太愚蠢而无法理解它们,这也是一种可能性)。

So, I have a WSDL. From the WSDL I've generated a Java client using Eclipse CXF plugin. Now I'm doing this:

所以,我有一个 WSDL。我使用 Eclipse CXF 插件从 WSDL 生成了一个 Java 客户端。现在我这样做:

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(MyServiceInterface.class);
factory.setAddress("myEndpoint");
List<Interceptor<? extends Message>> interceptors = new ArrayList<Interceptor<? extends Message>>();
interceptors.add(new HeaderOutInterceptor());
factory.setOutInterceptors(interceptors);

MyServiceInterface service = (MyServiceInterface) factory.create();

The interceptor only adds an header to the requests I'm sending through the client:

拦截器只向我通过客户端发送的请求添加一个标头:

message.put(Message.CONTENT_TYPE, "application/soap+xml");

I'm adding this manually since by default the content type is text/xml and I get a 415 error.

我正在手动添加它,因为默认情况下内容类型是 text/xml 并且我收到 415 错误。

The problem is that with this configuration I get this exception:

问题是使用这种配置我得到了这个异常:

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:178)
at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:69)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)

I've tried adding this annotation to the generated client interface:

我尝试将此注释添加到生成的客户端界面:

@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)

But nothing changed. Can anybody help me?

但什么都没有改变。有谁能够帮我?

EDIT

编辑

I've added a cxf.xml file under the classpath. This is the content:

我在类路径下添加了一个 cxf.xml 文件。这是内容:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://cxf.apache.org/bindings/soap 
       http://cxf.apache.org/schemas/configuration/soap.xsd
       http://cxf.apache.org/jaxws 
       http://cxf.apache.org/schemas/jaxws.xsd">

<jaxws:endpoint serviceName="ClabService" endpointName="ClabServicePort">
    <jaxws:binding>
        <soap:soapBinding version="1.2" mtomEnabled="true" />
    </jaxws:binding>
</jaxws:endpoint>

</beans>

However, now I get this exception:

但是,现在我得到了这个例外:

Exception in thread "main" java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.cxf.jaxws.EndpointImpl---51955260': Invocation of init method failed; nested exception is javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: serviceClass must be set to a valid service interface or class

I've tried to add this during the factory configuration:

我尝试在出厂配置期间添加此内容:

factory.setServiceClass(MyServiceInterface_Service.class);

but nothing changed.

但什么都没有改变。

回答by Vijendra Kumar Kulhade

You can use JaxWsClientFactoryBean to create client. It will have option to setBinding to Soap 1.2.

您可以使用 JaxWsClientFactoryBean 创建客户端。它可以选择将绑定设置为 Soap 1.2。

JaxWsClientFactoryBean factory = new JaxWsClientFactoryBean();
factory.setServiceClass(MyServiceInterface.class);
factory.setAddress("myEndpoint");
List<Interceptor<? extends Message>> interceptors = new ArrayList<Interceptor<? extends Message>>();
interceptors.add(new HeaderOutInterceptor());
factory.setOutInterceptors(interceptors);
factory.setBindingId("http://www.w3.org/2003/05/soap/bindings/HTTP/");//soap 1.2
MyServiceInterface service = (MyServiceInterface) factory.create();

回答by aliopi

gegalready said it, I just want to make it more visible:

geg已经说过了,我只是想让它更显眼:

import javax.xml.ws.soap.SOAPBinding;
...
factory.setBindingId(SOAPBinding.SOAP12HTTP_BINDING);