无适配器端点SWS [英] No adapter for endpoint SWS
问题描述
我试图使用这个创建一个简单的Hello World的WebService一>教程。
我在运行Java 1.7.0_04,春季2.1,一切都建成使用Maven和部署的tomcat6。然而,尝试发送SOAP请求(soapUI的)时,服务器返回我
无适配器端点[公共org.jdom.Element中com.mycompany.hr.ws.HolidayEndpoint.handleHolidayRequest(org.jdom.Element中)抛出java.lang.Exception的]:是您的端点标注为@Endpoint呢,还是像实现MessageHandler的或PayloadEndpoint支持的接口?
我觉得这是有注释的问题,但是这是我的文件,怎么是这样的:
的web.xml
<?XML版本=1.0编码=UTF-8&GT?;
< web应用程序的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
版本=2.4> <显示-名称> Khozzy定制的WebService< /显示-名称> <&servlet的GT;
< servlet的名称>春-WS< / servlet的名称>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class> &LT;初始化参数&GT;
&LT;参数-名称&gt;&transformWsdlLocations LT; /参数 - 名称&gt;
&LT;参数值&GT;真&LT; /参数值&GT;
&LT; /初始化参数&GT;
&LT; / servlet的&GT; &LT; Servlet映射&GT;
&LT; servlet的名称&gt;春-WS&LT; / servlet的名称&gt;
&LT; URL模式&GT; / *&LT; / URL模式&GT;
&LT; / Servlet映射&GT;&LT; / web-app的&GT;
弹簧WS-servlet.xml中
&LT;?XML版本=1.0编码=UTF-8&GT?;
&LT;豆的xmlns =http://www.springframework.org/schema/beans
XMLNS:XSI =http://www.w3.org/2001/XMLSchema-instance
的xmlns:上下文=http://www.springframework.org/schema/context
的xmlns:申万=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\"> &LT;背景:组件扫描基包=com.mycompany.hr.ws/&GT;
&LT;背景:组件扫描基包=com.mycompany.hr.service/&GT; &LT; SWS:注解驱动/&GT; &LT; SWS:动态WSDL ID =假期portTypeName =HumanResourcelocationUri =/ holidayService /的targetNamespace =http://mycompany.com/hr/definitions&GT;
&LT;申银万国:XSD位置=/ WEB-INF / hr.xsd/&GT;
&LT; / SWS:动态WSDL&GT;
&LT; /豆&GT;
HolidayEndpoint.java
包com.mycompany.hr.ws;进口com.mycompany.hr.service.HumanResourceService;
进口org.jdom.Document中;
进口org.jdom.Element中;
进口org.jdom.JDOMException;
进口org.jdom.Namespace;
进口org.jdom.xpath.XPath;
进口org.springframework.beans.factory.annotation.Autowired;
进口org.springframework.ws.server.endpoint.annotation.Endpoint;
进口org.springframework.ws.server.endpoint.annotation.PayloadRoot;
进口org.springframework.ws.server.endpoint.annotation.RequestPayload;
进口org.springframework.ws.server.endpoint.annotation.ResponsePayload;进口java.text.SimpleDateFormat的;
进口java.util.Date;@Endpoint
公共类HolidayEndpoint {
私有静态最后弦乐NAMESPACE_URI =http://mycompany.com/hr/schemas;
私人的XPath startDateEx pression;
私人的XPath endDateEx pression;
私人的XPath nameEx pression; 私人HumanResourceService humanResourceService; @Autowired
公共HolidayEndpoint(HumanResourceService humanResourceService)抛出JDOMException {
this.humanResourceService = humanResourceService; 命名空间= Namespace.getNamespace(HR,NAMESPACE_URI); startDateEx pression = XPath.newInstance(// HR:起始日期);
startDateEx pression.addNamespace空间(namespace); endDateEx pression = XPath.newInstance(// HR:结束日期);
endDateEx pression.addNamespace空间(namespace); nameEx pression = XPath.newInstance(CONCAT(//小时:名字,'',//小时:名字));
nameEx pression.addNamespace空间(namespace);
} @PayloadRoot(命名空间= NAMESPACE_URI,的localpart =HolidayRequest)
@ResponsePayload
公共元素handleHolidayRequest(@RequestPayload元holidayRequest)抛出异常{
元素toReturn = NULL; SimpleDateFormat的日期格式=新的SimpleDateFormat(YYYY-MM-DD);
日期的startDate = dateFormat.parse(startDateEx pression.valueOf(holidayRequest));
日期结束日期= dateFormat.parse(endDateEx pression.valueOf(holidayRequest));
字符串名称= nameEx pression.valueOf(holidayRequest); humanResourceService.bookHoliday(的startDate,结束日期,姓名);
返回toReturn;
}
}
hr.xsd
&LT;?XML版本=1.0&GT?;
&LT; XS:架构的xmlns:XS =http://www.w3.org/2001/XMLSchema
的xmlns:HR =http://mycompany.com/hr/schemas
将elementFormDefault =合格
的targetNamespace =http://mycompany.com/hr/schemas&GT; &LT; XS:元素的名称=HolidayRequest&GT;
&LT; XS:复杂类型&GT;
&LT; XS:所有与GT;
&LT; XS:元素的名称=假日TYPE =HR:HolidayType/&GT;
&LT; XS:元素的名称=雇员TYPE =HR:EmployeeType/&GT;
&LT; / XS:所有与GT;
&LT; / XS:复杂类型&GT;
&LT; / XS:组件&gt; &LT; XS:复杂类型名称=HolidayType&GT;
&LT; XS:序列&GT;
&LT; XS:元素的名称=起始日期类型=XS:DATE/&GT;
&LT; XS:元素的名称=结束日期类型=XS:DATE/&GT;
&LT; / XS:序列&GT;
&LT; / XS:复杂类型&GT; &LT; XS:复杂类型名称=EmployeeType&GT;
&LT; XS:序列&GT;
&LT; XS:元素的名称=数字类型=XS:整数/&GT;
&LT; XS:元素的名称=名字类型=XS:字符串/&GT;
&LT; XS:元素的名称=姓氏类型=XS:字符串/&GT;
&LT; / XS:序列&GT;
&LT; / XS:复杂类型&GT;&LT; / XS:架构&GT;
这是工作解决您的问题:
添加此依赖于您的的pom.xml
更改源的进口JDOM来jdom2
这是HolidayEndpoint的更新版本:
包com.mycompany.ws_template.endpoint;进口com.mycompany.ws_template.service.HumanResource;
进口java.text.SimpleDateFormat的;
进口java.util.Date;进口org.jdom2.JDOMException;
进口org.jdom2.Namespace;
进口org.jdom2.Element;
进口org.jdom2.filter.Filters;
进口org.jdom2.xpath.XPathEx pression;
进口org.jdom2.xpath.XPathFactory;进口org.springframework.beans.factory.annotation.Autowired;
进口org.springframework.ws.server.endpoint.annotation.Endpoint;
进口org.springframework.ws.server.endpoint.annotation.PayloadRoot;
进口org.springframework.ws.server.endpoint.annotation.RequestPayload;
@Endpoint
公共类HolidayEndpoint {私有静态最后弦乐NAMESPACE_URI =http://www.mycompany.com/holiday-service/schemas/holiday-request;私人XPathEx pression&LT;组件&gt; startDateEx pression;
私人XPathEx pression&LT;组件&gt; endDateEx pression;
私人XPathEx pression&LT;组件&gt; nameEx pression;
私人XPathEx pression&LT;组件&gt; surnameEx pression;@Autowired私人HumanResource holidayService;公共HolidayEndpoint()抛出JDOMException { 命名空间= Namespace.getNamespace(HR,NAMESPACE_URI); 的XPathFactory XPathFactory是否= XPathFactory.instance();
startDateEx pression = xpathFactory.compile(// HR:起始日期,Filters.element(),NULL,命名空间);
endDateEx pression = xpathFactory.compile(// HR:结束日期,Filters.element(),NULL,命名空间);
nameEx pression = xpathFactory.compile(// HR:EmployeeName,Filters.element(),NULL,命名空间);
surnameEx pression = xpathFactory.compile(// HR:EmployeeSurname,Filters.element(),NULL,命名空间);
}@PayloadRoot(命名空间= NAMESPACE_URI,的localpart =HolidayRequest)
公共无效handleHolidayRequest(@RequestPayload元holidayRequest)抛出异常{ SimpleDateFormat的SDF =新的SimpleDateFormat(YYYY-MM-DD);
日期的startDate = sdf.parse(startDateEx pression.evaluate(holidayRequest)获得(0).getValue());
日期结束日期= sdf.parse(endDateEx pression.evaluate(holidayRequest)获得(0).getValue());
字符串名称= nameEx pression.evaluate(holidayRequest)获得(0).getValue()+ surnameEx pression.evaluate(holidayRequest)获得(0).getValue(); holidayService.bookHoliday(的startDate,结束日期,姓名);
}}
I'm trying to create a simple Hello World WebService using this tutorial.
I'm running Java 1.7.0_04, Spring 2.1, everything is built with Maven and deployed with Tomcat6. However, when trying to send a SOAP request (soapUI), server returns me
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?
I think there is a problem with annotations, however this is how my files look like:
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>
spring-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>
This is the working solution to your problem:
add this dependencies to your pom.xml
Change the imports in your source for jdom to jdom2
And this is the updated version of 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);
}
}
这篇关于无适配器端点SWS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!