Apache CXF:SOAP 1.2 消息在发送到仅 SOAP 1.1 端点时无效
Apache CXF: A SOAP 1.2 message is not valid when sent to a SOAP 1.1 only endpoint
首先,我知道关于这个主题已经有一些关于 SO 的问题,但是其中 none 解决了我的问题(或者我太笨而无法理解它们,这也是一种可能性)。
所以,我有一个 WSDL。从 WSDL,我使用 Eclipse CXF 插件生成了一个 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();
拦截器仅向我通过客户端发送的请求添加 header:
message.put(Message.CONTENT_TYPE, "application/soap+xml");
我是手动添加的,因为默认情况下内容类型是 text/xml,我收到 415 错误。
问题是使用这个配置我得到这个异常:
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)
我已尝试将此注释添加到生成的客户端界面:
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
但没有任何改变。有人可以帮助我吗?
编辑
我在类路径下添加了一个 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>
但是,现在我得到这个异常:
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
我尝试在出厂配置中添加:
factory.setServiceClass(MyServiceInterface_Service.class);
但没有任何改变。
您可以使用 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();
geg已经说了,我只是想让它更显眼:
import javax.xml.ws.soap.SOAPBinding;
...
factory.setBindingId(SOAPBinding.SOAP12HTTP_BINDING);
首先,我知道关于这个主题已经有一些关于 SO 的问题,但是其中 none 解决了我的问题(或者我太笨而无法理解它们,这也是一种可能性)。
所以,我有一个 WSDL。从 WSDL,我使用 Eclipse CXF 插件生成了一个 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();
拦截器仅向我通过客户端发送的请求添加 header:
message.put(Message.CONTENT_TYPE, "application/soap+xml");
我是手动添加的,因为默认情况下内容类型是 text/xml,我收到 415 错误。
问题是使用这个配置我得到这个异常:
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)
我已尝试将此注释添加到生成的客户端界面:
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
但没有任何改变。有人可以帮助我吗?
编辑
我在类路径下添加了一个 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>
但是,现在我得到这个异常:
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
我尝试在出厂配置中添加:
factory.setServiceClass(MyServiceInterface_Service.class);
但没有任何改变。
您可以使用 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();
geg已经说了,我只是想让它更显眼:
import javax.xml.ws.soap.SOAPBinding;
...
factory.setBindingId(SOAPBinding.SOAP12HTTP_BINDING);