2012-03-20 41 views
1

我使用注释驱动的Spring WS 2.0.4来创建一个简单的Web服务,但没有找到enpoint映射。没有发现使用注释驱动Spring WS与动态wsdl和JAXB的端点映射

输入和输出是JAXB元素。

web服务与Java 1.7在Tomcat 7上运行,显示在卡特琳娜日志警告:

警告:未找到[SaajSoapMessage {终点映射http://mycompany.com/hr/schemas } HolidayRequest]

代码可供下载here

架构(WEB-INF /小时 - 数据 - 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配置(/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 /主/ COM/myCompany的/小时/服务/ 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> 

下面是一个简单的请求,我使用了S发送给http://localhost:8080/holidayService/holidayService/ oapUI

<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> 

回答

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> 
+0

我将其更改为HolidayRequest,并且它在catalina日志中仍显示相同的警告 – 2012-03-20 11:02:39

+0

您可以显示您发送到Web服务的请求吗? – jddsantaella 2012-03-20 11:11:14

+1

当然,我添加了我要发送到我的问题底部的请求 – 2012-03-20 11:40:59

1

端点不应该被ao​​p增强;否则,springws不能映射肥皂!