gpt4 book ai didi

GWT:尝试进行 Ajax 调用时在 GWTTestCase 中获取 404

转载 作者:行者123 更新时间:2023-12-04 22:13:21 25 4
gpt4 key购买 nike

我正在使用 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>

这是服务实现接口(interface)的方式......

@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 的正确方法是什么?下面的堆栈跟踪。谢谢,-戴夫

[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>

另见 common pitfalls在本文档中。

关于GWT:尝试进行 Ajax 调用时在 GWTTestCase 中获取 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8158818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com