I have a source web service which has an operation which does not take any body as a request. This is the request it expects:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body/>
</soap:Envelope>
I have a consumer service that calls this operation using camel-cxf:cxfEndpoint. The endpoint is configured to have the dataFormat as "Payload". Something like this:
<camel-cxf:cxfEndpoint
address="SOURCE_ENDPOINT"
id="abcEndpoint" serviceClass="PATH_TO_GENERATED_SERVICE_CLASS">
<camel-cxf:properties>
<entry key="dataFormat" value="PAYLOAD"/>
</camel-cxf:properties>
<camel-cxf:outInterceptors>
<ref component-id="wss4jOutInterceptor"/>
</camel-cxf:outInterceptors>
</camel-cxf:cxfEndpoint>
I am setting the body as null while calling this operation, expecting the CXFInterceptor to wrap the body with the SOAPEnvelope. However, when i am calling the service, I get :
java.lang.IllegalArgumentException: The PayLoad elements cannot fit with the message parts of the BindingOperation. Please check the BindingOperation and PayLoadMessage
I checked the generated ServiceClass from the source wsdl to check if the operation expects any body. Here is the method it expects:
@WebMethod(operationName = "SomeOperation", action = "SomeOperation")
@WebResult(name = "Result", targetNamespace = "namespace_for_the_service", partName = "data")
public Result someOperation();
I also tried using an XSLT to transform into an XML which does not add any elements but that does not solve anything. Am I missing something? Is it because of the dataFormat which is Payload ?
I was able to solve this issue by creating an empty CxfPayload:
List<Source> elements = new ArrayList<Source>();
CxfPayload<SoapHeader> cxfPayload = new CxfPayload<SoapHeader>(null, elements, null);
exchange.getIn().setBody(cxfPayload);
This worked for me!!!!