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, I have a WSDL. From the WSDL I've generated a Java client using Eclipse CXF plugin. Now I'm doing this:
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.
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:
<?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.
You can use JaxWsClientFactoryBean to create client. It will have option to setBinding to 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 already said it, I just want to make it more visible:
import javax.xml.ws.soap.SOAPBinding;
...
factory.setBindingId(SOAPBinding.SOAP12HTTP_BINDING);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With