将轴肥皂Web服务迁移到spring ws-端点方法中RequestPayload对象的值变为null

时间:2019-05-29 12:31:10

标签: soap wsdl soapui axis spring-ws

使用由wsdl file生成的旧AXIS使其与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);

    }

1 个答案:

答案 0 :(得分:0)

axis 1不支持在spring ws or CXF中生成的WSDL。因此,从WSDL生成的Java类将不会包含unmarshellingJAXB发出的spring的请求所需的信息。因此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);