I am trying to call a soap webservice using spring integration's MarshallingWebServiceOutboundGateway. The following is my flow which is quite simple:
@Bean
public IntegrationFlow asghar() throws Exception {
Map<String, Object> action = new HashMap<>();
action.put("ws_soapAction", "getCardTypes");
return IntegrationFlows.from("inputChannel")
.enrichHeaders(action)
.handle(asgharWebserviceGateway()).get();
}
The object in the message payload that comes through "inputChannel" is of the Type CardGroup. Then I create the gateway as follows:
@Bean
public MarshallingWebServiceOutboundGateway asgharWebserviceGateway() throws Exception {
SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory(
MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL));
messageFactory.afterPropertiesSet();
WebServiceTemplate webServiceTemplate = new WebServiceTemplate(messageFactory);
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("my.package.to.webservice.entities");
marshaller.setCheckForXmlRootElement(false);
marshaller.afterPropertiesSet();
webServiceTemplate.setMarshaller(marshaller);
webServiceTemplate.afterPropertiesSet();
MarshallingWebServiceOutboundGateway asghar = new MarshallingWebServiceOutboundGateway("http://uri.to.webservice/MobileService", webServiceTemplate);
asghar.setReplyChannel(replyChannel());
return asghar;
}
this is a part of the service interface generated by cxf from wsdl
@WebMethod
@WebResult(name = "return", targetNamespace = "http://ws.gateway.manager.br.com/", partName = "return")
public CardTypesResponse getCardTypes(
@WebParam(partName = "cardGroup", name = "cardGroup")
CardGroup cardGroup
);
and this is the wsdl for the same part:
<wsdl:message name="getCardTypes">
<wsdl:part name="cardGroup" type="tns:cardGroup">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getCardTypesResponse">
<wsdl:part name="return" type="tns:cardTypesResponse">
</wsdl:part>
</wsdl:message>
<wsdl:operation name="getCardTypes">
<wsdl:input message="tns:getCardTypes" name="getCardTypes">
</wsdl:input>
<wsdl:output message="tns:getCardTypesResponse" name="getCardTypesResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getCardTypes">
<soap:operation soapAction="" style="rpc"/>
<wsdl:input name="getCardTypes">
<soap:body namespace="http://ws.gateway.manager.br.com/" use="literal"/>
</wsdl:input>
<wsdl:output name="getCardTypesResponse">
<soap:body namespace="http://ws.gateway.manager.br.com/" use="literal"/>
</wsdl:output>
</wsdl:operation>
As you can see there is no soapAction in wsdl and the above-mentioned code produces this soap message:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<tns:cardGroup xmlns:tns="http://ws.gateway.manager.br.com/">
<code>9865421</code>
<title>654965587</title>
</tns:cardGroup>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Now I want to know how I can use the operation name (getCardTypes) and where should I set it so that the soap message is created correctly which must be this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<tns:getCardTypes xmlns:tns="http://ws.gateway.manager.br.com/">
<tns:cardGroup xmlns:tns="http://ws.gateway.manager.br.com/">
<code>9865421</code>
<title>654965587</title>
</tns:cardGroup>
</tns:getCardTypes>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<wsdl:message name="getCardTypes">
<wsdl:part name="cardGroup" type="tns:cardGroup">
</wsdl:part>
</wsdl:message>
So, your CardGroup
object must be wrapped into a GetCardTypes
object. Spring WS is not a CXF, so you need to get used to its Contract First approach.