【发布时间】:2020-05-06 13:15:04
【问题描述】:
我到处搜索,但找不到这个问题的答案。
我正在使用 spring-ws 创建一个可以使用 SOAP 消息的 url。我遵循了Producing a SOAP web service spring 教程。
当我向这个对象发送一个值时,所有属性都为空。我想要消息属性的值。我似乎无法弄清楚为什么所有属性都为空。
端点如下所示:
@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>
我从端点获取的控制台日志。
首先,我试图立即记录属性。所有属性均为空。接下来我尝试再次将它们编组为一个字符串,这些属性是可见的并且很好。
接下来我尝试再次解组它们,所有属性再次为空。
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