在soap服务的响应中获取null值 [英] Getting null value in the response from a soap service

查看:110
本文介绍了在soap服务的响应中获取null值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to call a soap service. I did't get any exception but response contains null value. But service atleast returns error message. please find or guide any solution.

@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类

This is my Objec tFactory class

@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回复:

This is my exaple xml response:

<?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是不正确的。

我的回复pojo就像这样

Finally i found my mistake in my application that my request and response pojo's are not correct.
My response pojo is like this

@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服务的响应中获取null值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆