代码之家  ›  专栏  ›  技术社区  ›  Dherik Pascal Sancho

没有标签上的NS2:无法读取SOAP信息。为什么?

  •  0
  • Dherik Pascal Sancho  · 技术社区  · 5 年前

    我正试图从一个SOAP呼叫中接收一些信息。成功调用了我的端点,但类中的信息是 null . 只有当我更改 <XYZFullDesc / <order_no> <ns2:XYZFullDesc / <ns2:order_no> ,但我需要接收XML 没有任何变化 .

    我的SOAP服务需要接收的整个XML:

    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
       <S:Header/>
       <S:Body>
          <ns2:publishXYZFullModifyUsingXYZFullDesc xmlns:ns2="http://www.oracle.com/retail/igsla/integration/services/XYZFullPublishingService/v1">
             <XYZFullDesc xmlns="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <order_no>2445460</order_no>
             </XYZFullDesc>
           </ns2:publishXYZFullModifyUsingXYZFullDesc>
       </S:Body>
    </S:Envelope>
    

    我目前的XSD是:

    <s:schema xmlns:s="http://www.w3.org/2001/XMLSchema"
               xmlns:tns="http://www.oracle.com/retail/igsla/integration/services/XYZFullPublishingService/v1"
               targetNamespace="http://www.oracle.com/retail/igsla/integration/services/XYZFullPublishingService/v1"
              elementFormDefault="qualified">
    
        <s:element name="publishXYZFullModifyUsingXYZFullDesc">
            <s:complexType>
                <s:sequence>
                    <s:element name="XYZFullDesc" type="tns:XYZFullDesc"/>
                </s:sequence>
            </s:complexType>
        </s:element>
    
        <s:complexType name="XYZFullDesc">
            <s:sequence>
                <s:element minOccurs="0" maxOccurs="1" name="order_no" type="s:string"/>
            </s:sequence>
        </s:complexType>
    
    </s:schema>
    

    我的弹簧终点:

    private static final String NAMESPACE_URI = "http://www.oracle.com/retail/igsla/integration/services/XYZFullPublishingService/v1";
    
    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "publishXYZFullModifyUsingXYZFullDesc")
    @ResponsePayload
    public void receberPedidoRequest(@RequestPayload PublishXYZFullModifyUsingXYZFullDesc request) {
        // code...
    }
    

    那么,是什么解释这种行为的存在/不存在 ns2 ?如何在不做任何更改的情况下读取上面的XML?

    1 回复  |  直到 5 年前
        1
  •  0
  •   Dherik Pascal Sancho    5 年前

    最后我得到了下面的解决方案。

    因为我希望在同一个模式上有两个名称空间,以便理解对主题的读取,所以 import 在我的XSD上是必要的。我最初的想法是设置不同的命名空间,但我只能为 PublishXYZFullModifyUsingXYZFullDesc 并将命名空间设置为 XYZFullDesc 忽略(不为空,视为无效),使用 ref .

    主要的XSD:

    <s:schema xmlns:s="http://www.w3.org/2001/XMLSchema"
               xmlns:po="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1"
               targetNamespace="http://www.oracle.com/retail/abcd/integration/services/XYZFullPublishingService/v1"
              elementFormDefault="qualified">
    
        <s:import schemaLocation="po.xsd"
                   namespace="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1" />
    
        <s:element name="publishXYZFullModifyUsingXYZFullDesc">
            <s:complexType>
                <s:sequence>
                    <s:element ref="po:XYZFullDesc"/>
                </s:sequence>
            </s:complexType>
        </s:element>
    
    </s:schema>
    

    导入的po.xsd:

    <?xml version="1.0" encoding="utf-16" ?>
    <s:schema targetNamespace="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1"
               xmlns:s="http://www.w3.org/2001/XMLSchema"
               xmlns="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1"
               elementFormDefault="qualified">
    
        <s:element name="XYZFullDesc" type="XYZFullDesc"/>
    
        <s:complexType name="XYZFullDesc">
            <s:sequence>
                <s:element minOccurs="0" maxOccurs="1" name="order_no" type="s:string"/>
            </s:sequence>
        </s:complexType>
    
    </s:schema>
    

    生成的Java存根:

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "xyzFullDesc"
    })
    @XmlRootElement(name = "publishXYZFullModifyUsingXYZFullDesc", namespace = "http://www.oracle.com/retail/abcd/integration/services/XYZFullPublishingService/v1")
    public class PublishXYZFullModifyUsingXYZFullDesc {
    
        @XmlElement(name = "XYZFullDesc", required = true) // no namespace, but works for me
        protected XYZFullDesc xyzFullDesc;
    
    }