Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 580
Aurasphere Avatar asked Sep 06 '16 19:09

Aurasphere


2 Answers

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();
like image 179
Vijendra Kumar Kulhade Avatar answered Oct 17 '22 10:10

Vijendra Kumar Kulhade


geg already said it, I just want to make it more visible:

import javax.xml.ws.soap.SOAPBinding;
...
factory.setBindingId(SOAPBinding.SOAP12HTTP_BINDING);
like image 34
aliopi Avatar answered Oct 17 '22 10:10

aliopi