Eway Payment Gateway:使用Java在循环付款中使用SOAP服务添加标题

时间:2014-06-20 05:43:55

标签: java soap runtime-error payment-gateway recurring-billing

我正在尝试使用eway支付网关。在这我使用定期付款。为了重复,他们提供WSDL文件,通过使用Maven Generator,我从WSDL文件创建java类。当我试图调用服务时,它会生成错误,因为服务需要SOAP头中的身份验证信息。从这个Link我找到了使用Jaxb Object在SOAP请求中添加头的解决方案。之后,当我调用SOAP服务时,它会产生不同的错误,这让我很困惑。以下是处理eway定期服务的代码: 1. SOAP Handler

public class EwaySOAPHandler implements SOAPHandler<SOAPMessageContext>{
private JAXBElement<EWAYHeader> jaxbElement = null;

public EwaySOAPHandler(JAXBElement<EWAYHeader> jaxbElement) {
    this.jaxbElement = jaxbElement;
}

public boolean handleMessage(SOAPMessageContext context) {
    Boolean outBoundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    try{
        if(outBoundProperty != null && outBoundProperty.booleanValue()){
            Marshaller marshaller = JAXBContext.newInstance(EWAYHeader.class).createMarshaller();
            SOAPHeader header = context.getMessage().getSOAPPart().getEnvelope().addHeader();
            marshaller.marshal(jaxbElement, header);
        }
        return false;
    }catch(Exception ex){
        System.out.println("Problem In Handel Message");
        ex.printStackTrace();
    }
    return true;
}

public boolean handleFault(SOAPMessageContext context) {
    throw new UnsupportedOperationException("Not Supported Yet");
}

public void close(MessageContext context) {

}

public Set<QName> getHeaders() {
    return new TreeSet<QName>();
}
}

2。 SOAP客户端

public class SOAPClient {
@Test
public void test() {
    ManageRebill manageRebill = new ManageRebill();
    ManageRebillSoap manageRebillSoap = manageRebill.getManageRebillSoap();
    Binding binding = ((BindingProvider) manageRebillSoap).getBinding();
    List<Handler> handlersList = new ArrayList<Handler>();

    EWAYHeader header = new EWAYHeader();
    header.setEWAYCustomerID("87654321");
    header.setPassword("test");
    header.setUsername("test@eway.com.au");

    ObjectFactory factory = new ObjectFactory();
    JAXBElement<EWAYHeader> jaxbElement = factory.createEWAYHeader(header);
    EwaySOAPHandler ewaySOAPHandler = new EwaySOAPHandler(jaxbElement);

    handlersList.add(ewaySOAPHandler);
    binding.setHandlerChain(handlersList);

    manageRebillSoap.createRebillCustomer("Mr", "Pritpal", "Singh",
            "Mohali", "CHD", "Punjab", "netsol", "1610032", "india",
            "abc@abc.com", "123456789", "123456789", "987654321", "Ref123",
            "JavaEE Developer", "comments", "http://google.com");
}}

当我尝试运行SOAPClient测试用例时会生成以下错误: com.sun.xml.internal.ws.streaming.XMLStreamReaderException: unexpected XML tag. expected: {http://www.eway.com.au/gateway/rebill/manageRebill}CreateRebillCustomerResponse but found: {http://www.eway.com.au/gateway/rebill/manageRebill}CreateRebillCustomer。 根据此错误,作为响应,他们需要CreateRebillCustomerResponse但返回CreateRebillCustomer个对象。问题是,我如何更改对象以及这些对象的定义位置?

0 个答案:

没有答案