GWT:当尝试进行Ajax调用时,在GWTTestCase中得到404



我使用的是GWT 2.4。我试图写一个测试用例,我做一个Ajax调用,但我得到一个404。下面是我如何在我的。gwt.xml文件中定义服务…

<module>
  <!-- Inherit our applications main module.                      -->
  <inherits name='com.myco.clearing.product.ProductPlus' />
  <!-- Specify the path to any remote services.                   -->
  <servlet path="/xmlhelperservice" class="com.myco.clearing.product.server.XmlHelperServiceImpl" />
</module>

服务实现的接口是这样的…

@RemoteServiceRelativePath( "xmlhelperservice" )
public interface XmlHelperService extends RemoteService {
    Node getNode(final String fileName) throws IOException;
}

,但在我的测试类(扩展GWTTestCase),我得到一个404时,试图调用服务…

public void testDocument() throws Exception {
    xmlHelperService = GWT.create(XmlHelperService.class);
    xmlHelperService.getNode("doc.xml", new AsyncCallback<Node>() {
        @Override
        public void onSuccess(Node node) {
            ...
        }
        @Override
        public void onFailure(Throwable caught) {
            caught.printStackTrace(System.err);
            fail(caught.getMessage());
        }
    });
}

定义/调用服务以避免404的正确方法是什么?下面的堆栈跟踪。谢谢,- Dave

[WARN] 404 - POST /com.myco.clearing.product.ProductPlusJUnit.JUnit/xmlhelperservice (10.40.70.197) 1450 bytes
com.google.gwt.user.client.rpc.StatusCodeException: 404 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 404 NOT_FOUND</title>
</head>
<body><h2>HTTP ERROR: 404</h2><pre>NOT_FOUND</pre>
<p>RequestURI=/com.myco.clearing.product.ProductPlusJUnit.JUnit/xmlhelperservice</p><p><i><small><a href="http://jetty.mortbay.org/">Powered by Jetty://</a></small></i></p><br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
</body>
</html>
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:209)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:220)
at sun.reflect.GeneratedMethodAccessor26.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:662)

看看您是否在web.xml文件中忽略了这一点。

<servlet>
    <servlet-name>XmlHelperServiceImpl</servlet-name>
    <servlet-class>com.myco.clearing.product.server.XmlHelperServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>XmlHelperServiceImpl</servlet-name>
    <url-pattern>/com.myco.clearing.product.ProductPlus/xmlhelperservice</url-pattern>
</servlet-mapping>

相关内容

  • 没有找到相关文章

最新更新