我正在使用注释驱动的Spring WS 2.0.4创建一个简单的Web服务,但找不到enpoint映射。
输入和输出是JAXB元素。
Web服务在Tomcat 7上运行Java 1.7,它在catalina日志中显示警告:
警告:找不到[SaajSoapMessage {http://mycompany.com/hr/schemas} HolidayRequest]的端点映射
该代码可供下载here
架构(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>
以下是我使用SoapUI发送给http://localhost:8080/holidayService/holidayService/的示例请求
<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>
答案 0 :(得分:4)
Localpart应为“HolidayRequest”
修改:试试这个:
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest")
public HolidayResponse handleHolidayRequest(HolidayRequest request) {
HolidayResponse response = new HolidayResponse(); // JAXB object
response.setIsApproved(holidaySvc.requestHoliday(request.getEmpId(), request.getDays()));
response.setEmpId(request.getEmpId());
return response;
}
编辑 2(您的基础包应该包含端点类!!):
您的配置应如下所示:
<sws:annotation-driven/>
<context:component-scan base-package="com.mycompany" />
<!-- enable autowire -->
<context:annotation-config />
<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>
答案 1 :(得分:1)
端点不应该由aop增强;否则,springws
无法将肥皂映射到它!