Я использую Spring WS 2.0.4 на основе аннотаций для создания простого Web-сервиса, но отображение enpoint не найдено.
Вход и выход - это элементы JAXB.
Веб-сервисработает с Java 1.7 на Tomcat 7, который отображает предупреждение в журнале каталины:
ПРЕДУПРЕЖДЕНИЕ: не найдено сопоставление конечной точки для [SaajSoapMessage {http://mycompany.com/hr/schemas}HolidayRequest]
Код доступен для загрузки здесь
Схема (WEB-INF / hr-data-contract.xsd):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://mycompany.com/hr/schemas"
xmlns:hr="http://mycompany.com/hr/schemas"
elementFormDefault="qualified">
<xs:element name="HolidayRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="empId" type="xs:integer" />
<xs:element name="days" type="xs:integer" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="HolidayResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="empId" type="xs:integer" />
<xs:element name="isApproved" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Spring config (/ WEB-INF / spring-ws-servlet.xml)
<sws:annotation-driven/>
<context:component-scan base-package="com.mycompany.hr.model" />
<sws:dynamic-wsdl
id="holiday"
portTypeName="HumanResource"
locationUri="/holidayService/"
targetNamespace="http://mycompany.com/hr/definitions">
<sws:xsd location="/WEB-INF/hr-data-contract.xsd" />
</sws:dynamic-wsdl>
Конечная точка (src / main / com / mycompany / hr / service / HolidayEndpoint.java)
@Endpoint
public class HolidayEndpoint {
private static final String NAMESPACE_URI = "http://mycompany.com/hr/schemas";
private HolidayService holidaySvc;
@Autowired
public HolidayEndpoint(HolidayService holidaySvc) {
this.holidaySvc = holidaySvc;
}
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest")
@ResponsePayload
public JAXBElement<HolidayResponse> handleHolidayRequest(@RequestPayload HolidayRequest request) {
HolidayResponse response = new HolidayResponse();
response.setIsApproved(holidaySvc.requestHoliday(request.getEmpId(), request.getDays()));
response.setEmpId(request.getEmpId());
return new JAXBElement<HolidayResponse>(
new QName(
NAMESPACE_URI,
"HolidayResponse"),
HolidayResponse.class,
response);
}
}
И это автоматически сгенерированный WSDL:
<wsdl:definitions targetNamespace="http://mycompany.com/hr/definitions" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="http://mycompany.com/hr/schemas" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://mycompany.com/hr/definitions">
<wsdl:types>
<xs:schema elementFormDefault="qualified" targetNamespace="http://mycompany.com/hr/schemas" xmlns:hr="http://mycompany.com/hr/schemas" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="HolidayRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="empId" type="xs:integer"/>
<xs:element name="days" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="HolidayResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="empId" type="xs:integer"/>
<xs:element name="isApproved" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="HolidayResponse">
<wsdl:part element="sch:HolidayResponse" name="HolidayResponse"/>
</wsdl:message>
<wsdl:message name="HolidayRequest">
<wsdl:part element="sch:HolidayRequest" name="HolidayRequest"/>
</wsdl:message>
<wsdl:portType name="HumanResource">
<wsdl:operation name="Holiday">
<wsdl:input message="tns:HolidayRequest" name="HolidayRequest"/>
<wsdl:output message="tns:HolidayResponse" name="HolidayResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HumanResourceSoap11" type="tns:HumanResource">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Holiday">
<soap:operation soapAction=""/>
<wsdl:input name="HolidayRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="HolidayResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HumanResourceService">
<wsdl:port binding="tns:HumanResourceSoap11" name="HumanResourceSoap11">
<soap:address location="http://localhost:8080/holidayService/holidayService/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Вот пример запроса, который я отправляю на http://localhost:8080/holidayService/holidayService/, используя SoapUI
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://mycompany.com/hr/schemas">
<soapenv:Header/>
<soapenv:Body>
<sch:HolidayRequest>
<sch:empId>1</sch:empId>
<sch:days>3</sch:days>
</sch:HolidayRequest>
</soapenv:Body>
</soapenv:Envelope>