在soap服务的响应中获取null值

时间:2014-11-24 08:13:46

标签: web-services spring-mvc soap jaxb

我正在尝试拨打肥皂服务。我没有得到任何异常,但响应包含空值。但服务atleast返回错误消息。请找到或指导任何解决方案。

@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;
    }

这是我的exaple 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>

1 个答案:

答案 0 :(得分:2)

最后,我在申请中发现我的错误,即我的请求和回复pojo不正确 我的回答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
    }
}