Spring ws-Every属性返回null



我到处找了,但找不到这个问题的答案
我正在使用spring-ws创建一个可以使用SOAP消息的url。我学习了"生产SOAP web服务"春季教程

向该对象发送值时,所有属性都为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>

有人能帮我吗?这对我来说真的很奇怪。

目前,我们以一种非常肮脏的方式解决了这个问题。我们首先将消息转换为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));

最新更新