Я создаю веб-сервис SOAP с помощью Spring Boot. Файл .wsdl предоставлен третьей стороной, и я создаю классы Java с помощью wsdl2java.
При тестировании с SoapUI я могу нажать на свою EndPoint. Однако запрос всегда пуст, если я не изменю XML-запрос вручную в SoapUI.
Вот wsdl
<definitions name="Employee"
targetNamespace="http://example.com/Employee.wsdl"
xmlns:tns="http://example.com/Employee.wsdl"
xmlns:tns0="http://example.com/Employee.wsdl/types/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<types>
<schema targetNamespace="http://example.com/Employee.wsdl/types/"
xmlns:tns="http://example.com/Employee.wsdl/types/"
elementFormDefault="qualified"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:soap11-enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<complexType name="EmployeeIdRecUserArray">
<sequence>
<element name="EmployeeIdRecUser" type="tns:EmployeeIdRecUser" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
<complexType name="EmployeeIdRecUser">
<complexContent>
<extension base="tns:EmplyeeIdParRecBase">
<sequence>
<element name="employeeId" type="string" nillable="true"/>
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="EmplyeeIdParRecBase">
<sequence/>
</complexType>
<complexType name="EmployeeDetailRecUserArray">
<sequence>
<element name="EmployeeFinDetailRecUser" type="tns:EmployeeFinDetailRecUser" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
<complexType name="EmployeeFinDetailRecUser">
<complexContent>
<extension base="tns:EmployeeDetailRecBase">
<sequence>
<element name="employeeId" type="string" nillable="true"/>
<element name="firstName" type="string" nillable="true"/>
<element name="lastName" type="string" nillable="true"/>
<element name="mailingAddress" type="string" nillable="true"/>
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="EmployeeDetailRecBase">
<sequence/>
</complexType>
</schema>
</types>
<message name="getEmployeeDetails">
<wsdl:part name="employeeIdTab" type="tns0:EmployeeIdRecUserArray"/>
</message>
<message name="getEmployeeDetailsResponse">
<wsdl:part name="result" type="tns0:EmployeeDetailRecUserArray"/>
</message>
<portType name="Employee">
<wsdl:operation name="getEmployeeDetails" parameterOrder="employeeIdTab">
<wsdl:input message="tns:getEmployeeDetails"/>
<wsdl:output message="tns:getEmployeeDetailsResponse"/>
</wsdl:operation>
</portType>
<binding name="EmployeeSoapHttp" type="tns:Employee">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getEmployeeDetails">
<soap:operation soapAction="http://example.com/Employee.wsdl/getEmployeeDetails"/>
<wsdl:input>
<soap:body use="literal" namespace="http://example.com/Employee.wsdl" parts="employeeIdTab"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal" namespace="http://example.com/Employee.wsdl" parts="result"/>
</wsdl:output>
</wsdl:operation>
</binding>
<service name="Employee">
<wsdl:port name="EmployeeSoapHttpPort" binding="tns:EmployeeSoapHttp">
<soap:address location="http://localhost:8087/ws/example/EmployeeSoapHttpPort"/>
</wsdl:port>
</service>
</definitions>
У меня есть простая EndPoint для тестирования:
@Endpoint
public class EmployeeEndpoint {
private static final Logger LOGGER = LoggerFactory.getLogger(EmployeeEndpoint.class);
@PayloadRoot(namespace = "http://example.com/Employee.wsdl", localPart = "getEmployeeDetails")
@ResponsePayload
public JAXBElement<EmployeeDetailRecUserArray> getEmployeeDetails(@RequestPayload JAXBElement<EmployeeIdRecUserArray> request) {
if (request.getValue().getEmployeeIdRecUser().isEmpty())
LOGGER.info("Request is empty.");
else
LOGGER.info("Request is not empty");
return null;
}
}
При загрузке этого wsdl в SoapUI он генерирует такой запрос:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:emp="http://example.com/Employee.wsdl" xmlns:typ="http://example.com/Employee.wsdl/types/">
<soapenv:Header/>
<soapenv:Body>
<emp:getEmployeeDetails>
<employeeIdTab>
<!--Zero or more repetitions:-->
<typ:EmployeeIdRecUser>
<typ:employeeId>123</typ:employeeId>
</typ:EmployeeIdRecUser>
</employeeIdTab>
</emp:getEmployeeDetails>
</soapenv:Body>
</soapenv:Envelope>
Это дает мне пустой запрос в моей конечной точке.
Если я отправлю этот запрос вместо этого, все будет работать нормально.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:emp="http://example.com/Employee.wsdl" xmlns:typ="http://example.com/Employee.wsdl/types/">
<soapenv:Header/>
<soapenv:Body>
<emp:getEmployeeDetails>
<!--Zero or more repetitions:-->
<typ:EmployeeIdRecUser>
<typ:employeeId>123</typ:employeeId>
</typ:EmployeeIdRecUser>
</emp:getEmployeeDetails>
</soapenv:Body>
</soapenv:Envelope>
Как я могу исправить эту проблему, изменив мой код, но без изменения исходного wsdl или XML-запроса?