【问题标题】:migrate axis soap webservice to spring ws - RequestPayload object values coming as null in endpoint method将axis soap webservice迁移到spring ws-端点方法中的RequestPayload对象值为null
【发布时间】:2019-05-29 12:31:10
【问题描述】:

使用由AXIS 生成的旧wsdl file 使其与spring ws 一起使用。在做了一些调整之后,我可以使用旧的 wsdl 生成 java 源代码。

现在我正在尝试从 soap UI 发出请求,但请求值在 endpoint method 中显示为 null。请求正确地传入backend,但不是values

WSDL 文件

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:onl="http://online.mysite.com">
   <soapenv:Header/>
   <soapenv:Body>
      <onl:getSummary soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <in0 xsi:type="onl:SummaryObject">
            <docid xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">doc123</docid>
            <amount xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</amount>
            <duenew xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</duenew>
            <reference xsi:type="xsd:long">?</reference>
            <sortBy xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</sortBy>
            <startDate xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</startDate>
         </in0>
      </onl:getSummary>
   </soapenv:Body>
</soapenv:Envelope>

肥皂请求:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:onl="http://online.mysite.com">
   <soapenv:Header/>
   <soapenv:Body>
      <onl:getSummary soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <in0 xsi:type="onl:SummaryObject">
            <docid xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">doc123</docid>
            <amount xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</amount>
            <duenew xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</duenew>
            <reference xsi:type="xsd:long">121212121</reference>
            <sortBy xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</sortBy>
            <startDate xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</startDate>
            <visibility xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</visibility>
         </in0>
      </onl:getSummary>
   </soapenv:Body>
</soapenv:Envelope>

端点方法:

@PayloadRoot(namespace = NAMESPACE_URI, localPart ="getSummary")
    @ResponsePayload
    public JAXBElement<EObjects> getSummary(@RequestPayload SummaryObject summaryObject) {

            System.out.println("Am done with this"+summaryObject.getDocId());
        ObjectFactory factory = new ObjectFactory();
        EObjects objects = factory.createEObjects();
        QName qname = new QName("http://online.mysite.com", "eobjects");
        return new JAXBElement(qname, EObjects.class, objects);

    }

【问题讨论】:

    标签: soap wsdl soapui axis spring-ws


    【解决方案1】:

    axis 1 中生成的 WSDL 不再受 spring ws or CXF 支持。因此,从 WSDL 生成的 java 类将不会具有spring 中的JAXB 请求的unmarshelling 所需的信息。因此request 对象将作为null 出现。

    我已经完成了一项工作,有两件事要做

    1. 在从 WSDL 生成的请求对象类之上添加 xml 根元素注释。

    @XmlRootElement(name="getSomething",namespace = "http://yoursite.com")

    1. 手动解组请求对象,如下所示:

    代码

    SoapMessage message = (SoapMessage) messageContext.getRequest();
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                message.writeTo(out);
                String strMsg = new String(out.toByteArray());  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                dbf.setNamespaceAware(true);
                DocumentBuilder db = dbf.newDocumentBuilder();
                Document d = db.parse(new InputSource(new StringReader(strMsg)));
     Node getrequestObject = d.getElementsByTagName("yourtag").item(0);
    
    JAXBContext jc = JAXBContext.newInstance(MyRequestObject.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        JAXBElement<SummaryObject> je = unmarshaller.unmarshal(new
    DOMSource(getrequestObject), MyRequestObject.class);
    

    【讨论】:

      猜你喜欢
      • 2019-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-02
      • 1970-01-01
      • 1970-01-01
      • 2020-10-31
      • 2012-11-08
      相关资源
      最近更新 更多