我是Spring的新手,从一开始就开始自学,因为我想开发基于Spring-WS的Web服务。
我在schemas.xsd, spring-ws-servlet.xml
文件夹中创建了web.xml
和WEB-INF
个文件。
还实现了使用@Endpoint
注释的端点。
在我的scehmas.xsd
我有以下元素
<xsd:element name="SimpleRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="reName" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
并在web.xml
中指定spring-ws消息调度程序servlet,如下所示。
<servlet>
<servlet-name>spring-ws</servlet-name>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-ws-servlet.xml</param-value>
</init-param>
<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>
在spring-ws-servlet.xml
中我定义了端点
<context:component-scan base-package="com.test" />
<sws:annotation-driven />
<sws:dynamic-wsdl id="form" portTypeName="GUIForm"
locationUri="/forms/">
<sws:xsd location="/WEB-INF/schemas.xsd" />
</sws:dynamic-wsdl>
<bean id="formsEndpoint" class="com.test.FormsEndpoint" />
<bean
class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
<property name="defaultEndpoint" ref="formsEndpoint" />
</bean>
在我的FormsEndpoint
课程中,我有以下方法,
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "SimpleRequest")
@ResponsePayload
public Element handleFormsRequest(@RequestPayload Element simpleRequest) throws JDOMException, ParserConfigurationException
{
System.out.println("================ Hit on Endpoint ========================");
String formId = formIdExpression.valueOf(simpleRequest);
}
在formIdExpression.valueOf(simpleRequest);
行,它总是抛出
java.lang.ClassCastException: com.sun.xml.internal.messaging.saaj.soap.ver1_1.BodyElement1_1Impl cannot be cast to org.jdom.Element
at org.jaxen.jdom.DocumentNavigator.getDocumentNode(DocumentNavigator.java:396)
at org.jaxen.expr.DefaultAbsoluteLocationPath.evaluate(DefaultAbsoluteLocationPath.java:102)
at org.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:102)
at org.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:674)
at org.jaxen.BaseXPath.selectSingleNodeForContext(BaseXPath.java:698)
at org.jaxen.BaseXPath.stringValueOf(BaseXPath.java:279)
at org.jdom.xpath.JaxenXPath.valueOf(JaxenXPath.java:182)
at com.neurotec.mmafis.FormsEndpoint.handleFormsRequest(FormsEndpoint.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.ws.server.endpoint.MethodEndpoint.invoke(MethodEndpoint.java:134)
at org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter.invokeInternal(DefaultMethodEndpointAdapter.java:240)
at org.springframework.ws.server.endpoint.adapter.AbstractMethodEndpointAdapter.invoke(AbstractMethodEndpointAdapter.java:53)
at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:233)
at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:173)
at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:88)
at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:59)
at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:292)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
我在eclipse中使用soapUI插件测试了一个请求。关于为什么发生这种情况的任何想法都将受到高度赞赏。
答案 0 :(得分:0)
您必须首先生成与“SimpleRequest”对应的类。您可以使用JAXB。
然后,
public Element handleFormsRequest(@RequestPayload Element simpleRequest)
应该是
public Element handleFormsRequest(@RequestPayload **clazz** simpleRequest)
其中clazz是生成的类
答案 1 :(得分:0)
当我开始使用Jdom
而非Jdom2
问题得到解决时,Jdom
出现问题。