I wrote some services (used by an Android app) which takes a request and sends th response in json. Now I have a scenario where I have to consume a third party web service,
Finally I'm able to access Third services.
This is my method to access service
public void createSoapActionCallBack(ValidateCardRequest validateCardRequest) {
//This is used to send header message
SoapActionCallback actionCallBack=new SoapActionCallback(soapAction);
try{
actionCallBack = new SoapActionCallback(ResponseConstants.SOAPACTION_DEFAULT_URL) {
public void doWithMessage(WebServiceMessage msg) {
SoapMessage smsg = (SoapMessage)msg;
SoapHeader soapHeader = smsg.getSoapHeader();
try{
//To send header message
StringSource headerSource = new StringSource("\n" +
""+"ABCD"+" \n" +
""+"ABCD"+" \n" +
" ");
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(headerSource, soapHeader.getResult());
smsg.setSoapAction(soapAction);
}catch(Exception e)
{
e.printStackTrace();
}
}
};
validateCardResponse = (FVValidateCardResponse) webServiceTemplate.marshalSendAndReceive(URL, validateCardRequest, actionCallBack);
} catch (Exception e) {
e.printStackTrace();
}
}
This is my configuration xml file:
com.waleteros.firstviewmodel.FVValidateCardRequest
com.waleteros.firstviewmodel.FVValidateCardResponse
Create pojo's according to your xmls Here is example
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "CardUpdateResponse",namespace="http://www.corecard.com/Prepaid")
public class FVCardUpdateResponse {
@XmlElement(name="CARDUPDATE_RET", namespace="http://www.corecard.com/Prepaid")
private CARDUPDATE_RET response;
//Getters and Setters
public static class CARDUPDATE_RET{
@XmlElement(name = "ACCOUNTNUMBER", namespace="http://www.corecard.com/Prepaid")
private String AccountNumber;
@XmlElement(name = "ResCode", namespace="http://www.corecard.com/Prepaid")
private String ResCode;
@XmlElement(name = "ResErrorCode", namespace="http://www.corecard.com/Prepaid")
private String ResErrorCode;
@XmlElement(name = "ResErrorMsg", namespace="http://www.corecard.com/Prepaid")
private String ResErrorMsg;
//Getters and Setters
}
}