2012-07-27 20 views
6

Estoy intentando crear un servicio web Hello World simple usando el tutorial this.No hay adaptador para el punto final SWS

Estoy ejecutando Java 1.7.0_04, Spring 2.1, todo se compila con Maven y se implementa con Tomcat6. Sin embargo, al intentar enviar una solicitud SOAP (soapUI), servidor me vuelve

No adapter for endpoint [public org.jdom.Element com.mycompany.hr.ws.HolidayEndpoint.handleHolidayRequest(org.jdom.Element) throws java.lang.Exception]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint? 

Creo que hay un problema con anotaciones, sin embargo, esta es la forma en mis archivos se parecen:

Web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" 
     version="2.4"> 

    <display-name>Khozzy custom WebService</display-name> 

    <servlet> 
     <servlet-name>spring-ws</servlet-name> 
     <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class> 

     <init-param> 
      <param-name>transformWsdlLocations</param-name> 
      <param-value>true</param-value> 
     </init-param> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>spring-ws</servlet-name> 
     <url-pattern>/*</url-pattern> 
    </servlet-mapping> 

</web-app> 

resorte-ws-servlet.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:sws="http://www.springframework.org/schema/web-services" 
     xsi:schemaLocation=" http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
          http://www.springframework.org/schema/web-services 
          http://www.springframework.org/schema/web-services/web-services-2.0.xsd 
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <context:component-scan base-package="com.mycompany.hr.ws" /> 
    <context:component-scan base-package="com.mycompany.hr.service" /> 

    <sws:annotation-driven /> 

    <sws:dynamic-wsdl id="holiday" portTypeName="HumanResource" locationUri="/holidayService/" targetNamespace="http://mycompany.com/hr/definitions"> 
     <sws:xsd location="/WEB-INF/hr.xsd"/> 
    </sws:dynamic-wsdl> 
</beans> 

HolidayEndpoint.java

package com.mycompany.hr.ws; 

import com.mycompany.hr.service.HumanResourceService; 
import org.jdom.Document; 
import org.jdom.Element; 
import org.jdom.JDOMException; 
import org.jdom.Namespace; 
import org.jdom.xpath.XPath; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.ws.server.endpoint.annotation.Endpoint; 
import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 
import org.springframework.ws.server.endpoint.annotation.RequestPayload; 
import org.springframework.ws.server.endpoint.annotation.ResponsePayload; 

import java.text.SimpleDateFormat; 
import java.util.Date; 

@Endpoint 
public class HolidayEndpoint { 
    private static final String NAMESPACE_URI = "http://mycompany.com/hr/schemas"; 
    private XPath startDateExpression; 
    private XPath endDateExpression; 
    private XPath nameExpression; 

    private HumanResourceService humanResourceService; 

    @Autowired 
    public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException { 
     this.humanResourceService = humanResourceService; 

     Namespace namespace = Namespace.getNamespace("hr",NAMESPACE_URI); 

     startDateExpression = XPath.newInstance("//hr:StartDate"); 
     startDateExpression.addNamespace(namespace); 

     endDateExpression = XPath.newInstance("//hr:EndDate"); 
     endDateExpression.addNamespace(namespace); 

     nameExpression = XPath.newInstance("concat(//hr:FirstName, ' ',//hr:LastName)"); 
     nameExpression.addNamespace(namespace); 
    } 

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest") 
    @ResponsePayload 
    public Element handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception { 
     Element toReturn = null; 

     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
     Date startDate = dateFormat.parse(startDateExpression.valueOf(holidayRequest)); 
     Date endDate = dateFormat.parse(endDateExpression.valueOf(holidayRequest)); 
     String name = nameExpression.valueOf(holidayRequest); 

     humanResourceService.bookHoliday(startDate,endDate,name); 
     return toReturn; 
    } 
} 

hr.xsd

<?xml version="1.0"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      xmlns:hr="http://mycompany.com/hr/schemas" 
      elementFormDefault="qualified" 
      targetNamespace="http://mycompany.com/hr/schemas"> 

    <xs:element name="HolidayRequest"> 
     <xs:complexType> 
      <xs:all> 
       <xs:element name="Holiday" type="hr:HolidayType"/> 
       <xs:element name="Employee" type="hr:EmployeeType"/> 
      </xs:all> 
     </xs:complexType> 
    </xs:element> 

    <xs:complexType name="HolidayType"> 
     <xs:sequence> 
      <xs:element name="StartDate" type="xs:date"/> 
      <xs:element name="EndDate" type="xs:date"/> 
     </xs:sequence> 
    </xs:complexType> 

    <xs:complexType name="EmployeeType"> 
     <xs:sequence> 
      <xs:element name="Number" type="xs:integer"/> 
      <xs:element name="FirstName" type="xs:string"/> 
      <xs:element name="LastName" type="xs:string"/> 
     </xs:sequence> 
    </xs:complexType> 

</xs:schema> 
+0

¿Se puede permitir a un nivel de registro inferior y ver si hay algo más se está imprimiendo en los registros: 'log4j.logger.org.springframework.ws.server.MessageTracing = TRACE' –

+1

Creo que el problema se encuentra aquí https://jira.springsource.org/browse/SWS-782?page=com .atlassian.jira.plugin.system.issuetabpanels: changehistory-tabpanel Hay un error en el mapeo de puntos finales para elementos JDOM – Khozzy

+0

Oh, está bien, sí, suena como eso. –

Respuesta

3

Esta es la solución de trabajo a su problema:

anadir este dependencias a su pom.xml

enter image description here

Cambiar las importaciones en su mejor fuente de jdom a jdom2

Y esta es la versión actualizada de HolidayEndpoint:

package com.mycompany.ws_template.endpoint; 

import com.mycompany.ws_template.service.HumanResource; 
import java.text.SimpleDateFormat; 
import java.util.Date; 

import org.jdom2.JDOMException; 
import org.jdom2.Namespace; 
import org.jdom2.Element; 
import org.jdom2.filter.Filters; 
import org.jdom2.xpath.XPathExpression; 
import org.jdom2.xpath.XPathFactory; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.ws.server.endpoint.annotation.Endpoint; 
import org.springframework.ws.server.endpoint.annotation.PayloadRoot; 
import org.springframework.ws.server.endpoint.annotation.RequestPayload; 


@Endpoint 
public class HolidayEndpoint { 

private static final String NAMESPACE_URI = "http://www.mycompany.com/holiday-service/schemas/holiday-request"; 

private XPathExpression<Element> startDateExpression; 
private XPathExpression<Element> endDateExpression; 
private XPathExpression<Element> nameExpression; 
private XPathExpression<Element> surnameExpression; 

@Autowired private HumanResource holidayService; 

public HolidayEndpoint() throws JDOMException { 

    Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI); 

    XPathFactory xpathFactory = XPathFactory.instance(); 
    startDateExpression = xpathFactory.compile("//hr:StartDate", Filters.element(), null, namespace); 
    endDateExpression = xpathFactory.compile("//hr:EndDate", Filters.element(), null, namespace); 
    nameExpression = xpathFactory.compile("//hr:EmployeeName", Filters.element(), null, namespace); 
    surnameExpression = xpathFactory.compile("//hr:EmployeeSurname", Filters.element(), null, namespace); 
} 

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest") 
public void handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception { 

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
    Date startDate = sdf.parse(startDateExpression.evaluate(holidayRequest).get(0).getValue()); 
    Date endDate = sdf.parse(endDateExpression.evaluate(holidayRequest).get(0).getValue()); 
    String name = nameExpression.evaluate(holidayRequest).get(0).getValue() + surnameExpression.evaluate(holidayRequest).get(0).getValue(); 

    holidayService.bookHoliday(startDate, endDate, name); 
} 

} 
Cuestiones relacionadas