在Soap服务的响应中获取空值

我想打电话给肥皂服务。我没有得到任何异常,但响应包含空值。但是服务至少返回错误消息。请找到或指导任何解决方案。

@Component("createCardServiceImpl")

public class CreateCardServiceImpl implements CreateCardService {

private static final ObjectFactory WS_CLIENT_FACTORY = new ObjectFactory();

private WebServiceTemplate webServiceTemplate;

@Autowired

public void YourServiceClient(WebServiceTemplate webServiceTemplate) {

this.webServiceTemplate = webServiceTemplate;

}

@Override

public FVCardUpdateResponse createUpdateCardRequest(FVCardUpdateRequest fvCardUpdateRequest) {

FVCardUpdateResponse fvCardUpdateResponse=new FVCardUpdateResponse();

try{

FVCardUpdateRequest request = WS_CLIENT_FACTORY.createFVCardUpdateRequest();

request=fvCardUpdateRequest;

SoapActionCallback actionCallBack = new SoapActionCallback("https://www.sampleService/Selfservice.asmx") {

public void doWithMessage(WebServiceMessage msg) {

SoapMessage smsg = (SoapMessage)msg;

SoapHeader soapHeader = smsg.getSoapHeader();

try{

StringSource headerSource = new StringSource("<UserCredentials xmlns='http://www.corecard.com/Prepaid'>\n" +

"<userid>"+"srihari"+"</userid>\n" +

"<password>"+"srihari123"+"</password>\n" +

"</UserCredentials>");

Transformer transformer = TransformerFactory.newInstance().newTransformer();

transformer.transform(headerSource, soapHeader.getResult());

smsg.setSoapAction("http://www.sampleservice/CardUpdate");

}catch(Exception e)

{

e.printStackTrace();

}

}

};

fvCardUpdateResponse = (FVCardUpdateResponse) webServiceTemplate.marshalSendAndReceive("https://www.sampleService/Selfservice.asmx", request, actionCallBack);

System.out.println("source "+fvCardUpdateResponse);

}catch (SoapFaultClientException e) {

System.out.println("fault code "+e.getFaultCode());

System.out.println("fault string "+e.getFaultStringOrReason());

System.out.println("stack trace "+e.fillInStackTrace().getLocalizedMessage());

e.printStackTrace();

} catch (WebServiceIOException we) {

System.out.println("In web service IO Exception "+we.getRootCause());

we.printStackTrace();

} catch (Exception e) {

e.printStackTrace();

}

return fvCardUpdateResponse;

}

}

这是我的Objec tFactory类

@XmlRegistry

public class ObjectFactory {

public ObjectFactory() {

}

public FVCardUpdateRequest createFVCardUpdateRequest() {

return new FVCardUpdateRequest();

}

public FVCardUpdateResponse createFVCardUpdateResponse()

{

return new FVCardUpdateResponse();

}

}

这是我的要求课

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "CARDUPDATE",propOrder={"CLIENTID","CARDNUMBER","FIRSTNAME"})

@XmlRootElement(name = "CARDUPDATE")

public class FVCardUpdateRequest {

@XmlElement(name = "CLIENTID")

private String CLIENTID;

@XmlElement(name = "CARDNUMBER")

private String CARDNUMBER;

//Other setters and getters

}

这是我的回应课

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "CardUpdateResponse",propOrder={"CARDUPDATE_RET"})

@XmlRootElement(name = "CardUpdateResponse",namespace="http://www.sampleurl.com/Prepaid")

public class FVCardUpdateResponse {

@XmlElement(name="CARDUPDATE_RET")

private CARDUPDATE_RET CARDUPDATE_RET;

//Setters and getters

}

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "CARDUPDATE_RET", propOrder = {

"ResErrorMsg",

"ResErrorCode",

"ResCode",

"AccountNumber"

})

public class CARDUPDATE_RET {

@XmlElement(name = "AccountNumber")

private String AccountNumber;

@XmlElement(name = "ResCode")

private String ResCode;

@XmlElement(name = "ResErrorCode")

private String ResErrorCode;

@XmlElement(name = "ResErrorMsg")

private String ResErrorMsg;

}

这是我的示例xml响应:

<?xml version="1.0" encoding="UTF-8"?>

<CardUpdateResponse xmlns="http://www.sampleurl.com/Prepaid">

<CARDUPDATE_RET>

<ResErrorMsg>Card Updated Successfully</ResErrorMsg>

<ResErrorCode>Msgcu01</ResErrorCode>

<ResCode>1</ResCode>

<ACCOUNTNUMBER>2000000003918246</ACCOUNTNUMBER>

</CARDUPDATE_RET>

</CardUpdateResponse>

回答:

最后,我在我的应用程序中发现我的错误,即我的请求和响应pojo不正确。

我的回应是这样的

@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

}

}

以上是 在Soap服务的响应中获取空值 的全部内容, 来源链接: utcz.com/qa/417172.html

回到顶部