Spring ws-每个属性返回null

问题描述 投票:0回答:1

我到处搜索过,但找不到该问题的答案。我正在使用spring-ws创建可以使用SOAP消息的URL。我遵循了Producing a SOAP web service春季教程。当我向该对象发送值时,所有属性均为null。我想要message属性的值。我似乎无法弄清楚为什么所有属性都为null。端点看起来像这样:

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "UICMessage")
@ResponsePayload
public void getMessage(@RequestPayload JAXBElement<UICMessage> request) {
    System.out.println(request.getValue());

    JAXBContext jaxbContext;
    try {
        jaxbContext = JAXBContext.newInstance(UICMessage.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        jaxbMarshaller.setProperty("com.sun.xml.bind.characterEscapeHandler", (CharacterEscapeHandler) (ch, start, length, isAttVal, out) -> out.write(ch, start, length));
        StringWriter sw = new StringWriter();
        jaxbMarshaller.marshal(request, sw);
        String xmlString = sw.toString();

        System.out.println(xmlString);

        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        UICMessage uicMessage = (UICMessage) unmarshaller.unmarshal(new StringSource(xmlString));            

        System.out.println(uicMessage.getMessage());
    } catch (JAXBException e) {
        e.printStackTrace();
    }
}

我正在POST请求中向/ ws / ci上的端点发送的SOAP消息

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:head="http://uic.cc.org/UICMessage/Header" xmlns:uic="http://uic.cc.org/UICMessage">    
   <soapenv:Header>    
      <head:signed>false</head:signed>   
      <head:encrypted>false</head:encrypted>    
      <head:compressed>false</head:compressed>    
      <head:messageIdentifier>xxx</head:messageIdentifier>    
   </soapenv:Header>    
   <soapenv:Body>    
      <uic:UICMessage>      
         <message>    
             <TrainCompositionMessage xmlns="http://taf-jsg.info/schemes" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">XMLVALUE</TrainCompositionMessage>    
          </message>   
          <senderAlias>USER</senderAlias>  
      </uic:UICMessage>    
   </soapenv:Body>    
</soapenv:Envelope>

我从端点获取的控制台日志。首先,我尝试立即记录属性。所有属性均为空。接下来,我尝试再次将它们编组为字符串,这些属性是可见的。接下来,我尝试再次解组它们,所有属性再次为null。

UICMessage{message=[message: null], signature=null, senderAlias=[senderAlias: null], encoding=null}

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:UICMessage xmlns:ns2="http://uic.cc.org/UICMessage">
    <message xmlns:head="http://uic.cc.org/UICMessage/Header" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:uic="http://uic.cc.org/UICMessage">
        <TrainCompositionMessage xmlns="http://taf-jsg.info/schemes" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">XMLVALUE</TrainCompositionMessage>    
    </message>
    <senderAlias xmlns:head="http://uic.cc.org/UICMessage/Header" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:uic="http://uic.cc.org/UICMessage">USER</senderAlias>
</ns2:UICMessage>

[message: null]

我正在使用的wsdl看起来像这样:

<wsdl:definitions xmlns:ns1="http://uic.cc.org/UICMessage/Header" xmlns:ns2="http://schemas.xmlsoap.org/soap/http"
                  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://uic.cc.org/UICMessage"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  name="LIReceiveMessageService" targetNamespace="http://uic.cc.org/UICMessage">
    <wsdl:documentation>
        This WSDL describes the communication protocol for sending TAF/TAP -TSI messages with standard xml Header node
        according TAF/TAP TSI Common Schema to partner using the Common Interface (CI).For more detailed Information
        please refer to the specification document
    </wsdl:documentation>
    <wsdl:types>
        <xs:schema xmlns:tns="http://uic.cc.org/UICMessage" xmlns:xs="http://www.w3.org/2001/XMLSchema"
                   elementFormDefault="unqualified" targetNamespace="http://uic.cc.org/UICMessage" version="1.0">
            <xs:element name="UICMessage" type="tns:UICMessage"/>
            <xs:element name="UICMessageResponse" type="tns:UICMessageResponse"/>
            <xs:complexType name="UICMessage">
                <xs:sequence>
                    <xs:element minOccurs="0" name="message" type="xs:anyType"/>
                    <xs:element minOccurs="0" name="signature" type="xs:anyType"/>
                    <xs:element minOccurs="0" name="senderAlias" type="xs:anyType"/>
                    <xs:element minOccurs="0" name="encoding" type="xs:anyType"/>
                </xs:sequence>
            </xs:complexType>
            <xs:complexType name="UICMessageResponse">
                <xs:sequence>
                    <xs:element minOccurs="0" name="return" type="xs:anyType"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
        <xsd:schema xmlns="http://uic.cc.org/UICMessage/Header" xmlns:tns="http://uic.cc.org/UICMessage"
                    xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified"
                    elementFormDefault="unqualified" targetNamespace="http://uic.cc.org/UICMessage/Header">
            <xsd:element name="messageIdentifier" nillable="true" type="xsd:string"/>
            <xsd:element name="messageLiHost" nillable="true" type="xsd:string"/>
            <xsd:element name="compressed" nillable="true" type="xsd:boolean"/>
            <xsd:element name="encrypted" nillable="true" type="xsd:boolean"/>
            <xsd:element name="signed" nillable="true" type="xsd:boolean"/>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="UICMessage">
        <wsdl:part element="tns:UICMessage" name="parameters"></wsdl:part>
        <wsdl:part element="ns1:messageIdentifier" name="messageIdentifier"></wsdl:part>
        <wsdl:part element="ns1:messageLiHost" name="messageLiHost"></wsdl:part>
        <wsdl:part element="ns1:compressed" name="compressed"></wsdl:part>
        <wsdl:part element="ns1:encrypted" name="encrypted"></wsdl:part>
        <wsdl:part element="ns1:signed" name="signed"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="UICMessageResponse">
        <wsdl:part element="tns:UICMessageResponse" name="parameters"></wsdl:part>
    </wsdl:message>
    <wsdl:portType name="UICReceiveMessage">
        <wsdl:operation name="UICMessage">
            <wsdl:documentation>
                This operation is used to send the message to the Remote CI.
            </wsdl:documentation>
            <wsdl:input message="tns:UICMessage" name="UICMessage"></wsdl:input>
            <wsdl:output message="tns:UICMessageResponse" name="UICMessageResponse"></wsdl:output>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="LIReceiveMessageServiceSoapBinding" type="tns:UICReceiveMessage">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="UICMessage">
            <soap:operation soapAction="" style="document"/>
            <wsdl:input name="UICMessage">
                <soap:header message="tns:UICMessage" part="messageIdentifier" use="literal"></soap:header>
                <soap:header message="tns:UICMessage" part="messageLiHost" use="literal"></soap:header>
                <soap:header message="tns:UICMessage" part="compressed" use="literal"></soap:header>
                <soap:header message="tns:UICMessage" part="encrypted" use="literal"></soap:header>
                <soap:header message="tns:UICMessage" part="signed" use="literal"></soap:header>
                <soap:body parts="parameters" use="literal"/>
            </wsdl:input>
            <wsdl:output name="UICMessageResponse">
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="LIReceiveMessageService">
        <wsdl:port binding="tns:LIReceiveMessageServiceSoapBinding" name="UICReceiveMessagePort">
            <soap:address
                    location="http://EXTERNALLOCATION"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

有人可以帮我吗?对我来说真的很奇怪。

java spring spring-boot soap spring-ws
1个回答
0
投票

目前,我们以一种非常肮脏的方式解决了这个问题。我们首先将消息转换为XML,然后使用子字符串获得正确的部分。接下来,我们将需要的部分转换回jaxb对象。如果有人知道这样做的干净方法,请告诉我。

jaxbContext = JAXBContext.newInstance(UICMessage.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.setProperty("com.sun.xml.bind.characterEscapeHandler", (CharacterEscapeHandler) (ch, start, length, isAttVal, out) -> out.write(ch, start, length));
StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(request, sw);
String xmlString = sw.toString();
String hackedString = xmlString.substring(xmlString.indexOf("<TrainCompositionMessage"), xmlString.indexOf("</message"));
jaxbContext = JAXBContext.newInstance(TrainCompositionMessage.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
TrainCompositionMessage errorMessage = (TrainCompositionMessage) unmarshaller.unmarshal(new StringSource(hackedString));
© www.soinside.com 2019 - 2024. All rights reserved.