我正在尝试使用GWT进行RPC测试。我正在使用提到的here的默认StockWatcher项目,我下载了该项目,将其导入,一切正常。
然后,我在StockWatcher项目中运行junitcreator:
/Users/stephen/Work/gwt/gwt-mac-1.6.4/junitCreator -junit /Users/stephen/Applications/eclipse/plugins/org.junit_3.8.2.v20080602-1318/junit.jar -module stockwatcher -eclipse StockWatcher com.google.gwt.sample.stockwatcher.StockWatcherTest
这将在适当的测试目录中创建StockWatcherTest.java,并为我提供了一些托管模式和Web模式启动文件。
然后,我还将junit.jar添加到该项目的类路径中。
然后,我修改StockWatcherTest.java以测试我是否能够向服务器发出异步请求。一切看起来都很好,但是当我尝试在托管模式下运行StockWatcherTest.java时,出现以下错误:
在端口0 HTTP上启动HTTP
在端口49569上侦听
开发外壳servlet收到了
请求模块中的“问候”
'com.google.gwt.sample.stockwatcher.StockWatcher.JUnit.gwt.xml'
[WARN]找不到资源:打招呼;
(如果文件从
公用路径或标签
模块中配置错误
com.google.gwt.sample.stockwatcher.StockWatcher.JUnit.gwt.xml
?)
com.google.gwt.user.client.rpc.StatusCodeException:
找不到资源“问候”
模块的公共路径
'com.google.gwt.sample.stockwatcher.StockWatcher.JUnit'
这是我的StockWatcherTest.java类
package com.google.gwt.sample.stockwatcher.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* GWT JUnit tests must extend GWTTestCase.
*/
public class StockWatcherTest extends GWTTestCase {
/**
* Must refer to a valid module that sources this class.
*/
public String getModuleName() {
return "com.google.gwt.sample.stockwatcher.StockWatcher";
}
/**
* Add as many tests as you like.
*/
public void testSimple() {
GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
greetingService.greetServer("Bob",
new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
// Show the RPC error message to the user
System.out.println(caught);
fail("big time failure");
finishTest();
}
public void onSuccess(String result) {
System.out.println("success, biatch");
assertTrue(true);
}
});
delayTestFinish(1000);
}
}
这是com / google / gwt / sample / stockwatcher / StockWatcher.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.6.2//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.6.2/distro-source/core/src/gwt-module.dtd">
<module rename-to='stockwatcher'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.standard.Standard'/>
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<entry-point class='com.google.gwt.sample.stockwatcher.client.StockWatcher'/>
</module>
这是我产生的战争中的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>StockWatcher.html</welcome-file>
</welcome-file-list>
<!-- Servlets -->
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>com.google.gwt.sample.stockwatcher.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/stockwatcher/greet</url-pattern>
</servlet-mapping>
</web-app>
那我在做什么错?任何帮助表示赞赏。谢谢。
最佳答案
1-您需要添加“ finishTest();”在“ onSuccess”方法的末尾。
2,然后解决您遇到的问题:在StockWatcher.gwt.xml中添加servlet问候的路径。
Servlet路径='/ greet'class ='com.google.gwt.sample.stockwatcher.server.GreetingServiceImpl'/