未找到GWT RPC服务 [英] GWT RPC Service not found

查看:125
本文介绍了未找到GWT RPC服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎花了几个小时在网上搜索,但我没有找到答案。
问题是我想测试gwt RPC。
因此,我使用Eclipse插件生成了一个GWT远程服务。
但每次我得到以下失败:[WARN]找不到:/ kuss_projekt / SpeicherService的文件



我尝试了很多,但是我没有knwo是什么问题。
那就是我的代码:

  web.xml:
< web-app>

< servlet>
< servlet-name> SpeicherService< / servlet-name>
< servlet-class> de.fhdo.kuss.server.SpeicherServiceImpl< / servlet-class>
< / servlet>

< servlet-mapping>
< servlet-name> SpeicherService< / servlet-name>
< url-pattern> / kuss_projekt / SpeicherService< / url-pattern>
< / servlet-mapping>

<! - 要投放的默认页面 - >
< welcome-file-list>
< welcome-file> Kuss_Projekt.html< / welcome-file>
< / welcome-file-list>


< / web-app>

-

  Speicherservice:
@RemoteServiceRelativePath(SpeicherService)
public interface SpeicherService extends RemoteService {

String getName(String name);


public static class Util {
private static SpeicherServiceAsync instance;
public static SpeicherServiceAsync getInstance(){
if(instance == null){
instance = GWT.create(SpeicherService.class);
}
返回实例;



-

  SpeicherServiceAsync:
public interface SpeicherServiceAsync {
$ b $ void getName(String name,AsyncCallback< String> callback);

$ b

-

  SpeicherServiceImpl 
public class SpeicherServiceImpl extends RemoteServiceServlet implements SpeicherService {
$ b $ @Override
public String getName(String name){
return(Server meldet sich+ name);


$ / code $ / pre


$ b

  Test():
public void test(){
AsyncCallback< String> callback = new AsyncCallback< String>(){

@Override
public void onFailure(Throwable caught){
// TODO自动生成的方法存根
}

@Override
public void onSuccess(String result){
Window.alert(result);
}
};

SpeicherService.Util.getInstance()。getName(test,callback);


解决方案

 < servlet-mapping>来自servlet映射的c $ c> / kuss_projekt  
< servlet-name> SpeicherService< / servlet-name>
< url-pattern> / SpeicherService< / url-pattern>
< / servlet-mapping>

GWT客户端期望服务在通过 @ RemoteServiceRelativePath 。当您在浏览器中运行时,路径将相对于您的模块基址进行解析。正如您所给出的那样:

  @RemoteServiceRelativePath(SpeicherService)

客户端将请求连接到URL

  GWT.getModuleBaseURL()+SpeicherService

如果您的servlet未映射到此URL,将失败。尝试在控制台上打印 GWT.getModuleBaseURL()+SpeicherService以查看测试用例中的基本URL。一旦你有这个,打开浏览器并转到该网址。如果响应表示Get方法不受支持,则所有内容都正确映射。另一方面,如果你得到一个 404 ,你必须修正你的servlet映射


I have searched the Web almost for hours, but I didn't find an answer. The Problem is that i want to the test the gwt RPC. So I generate with the Eclipse Plugin a GWT remote Service. But everytime I get the following Failure: "[WARN] No file found for: /kuss_projekt/SpeicherService"

I have tryed a lot, but I dont knwo what is the Problem. Thats my Code:

web.xml:
<web-app>

<servlet>
    <servlet-name>SpeicherService</servlet-name>
    <servlet-class>de.fhdo.kuss.server.SpeicherServiceImpl</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>SpeicherService</servlet-name>
    <url-pattern>/kuss_projekt/SpeicherService</url-pattern>
</servlet-mapping>

<!-- Default page to serve -->
<welcome-file-list>
    <welcome-file>Kuss_Projekt.html</welcome-file>
</welcome-file-list>


</web-app>

-

Speicherservice:
@RemoteServiceRelativePath("SpeicherService")
public interface SpeicherService extends RemoteService {

String getName(String name);


public static class Util {
    private static SpeicherServiceAsync instance;
    public static SpeicherServiceAsync getInstance(){
        if (instance == null) {
            instance = GWT.create(SpeicherService.class);
        }
        return instance;
    }
}
}

-

SpeicherServiceAsync:
public interface SpeicherServiceAsync {

void getName(String name, AsyncCallback<String> callback);

}

-

SpeicherServiceImpl
public class SpeicherServiceImpl extends RemoteServiceServlet implements SpeicherService {

@Override
public String getName(String name) {
    return("Server meldet sich " + name);
}
}

-

Test():
    public void test() {
    AsyncCallback<String> callback = new AsyncCallback<String>() {

        @Override
        public void onFailure(Throwable caught) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onSuccess(String result) {
            Window.alert(result);
        }
    };

    SpeicherService.Util.getInstance().getName("test",callback);
}

解决方案

Have you tried removing /kuss_projekt from servlet mapping to make it:

<servlet-mapping>
    <servlet-name>SpeicherService</servlet-name>
    <url-pattern>/SpeicherService</url-pattern>
</servlet-mapping>

GWT client is expecting the service to be available at the URL defined via @RemoteServiceRelativePath. When you are running in browser, the path is resolved relative to your module base url. As you have given:

@RemoteServiceRelativePath("SpeicherService")

the client will make request to the URL made by concatenating

GWT.getModuleBaseURL() + "SpeicherService"

If your servlet is not mapped at this url, the request will fail. Try printing GWT.getModuleBaseURL()+ "SpeicherService" on console to see what is the base url in your test case. Once you have got this, open the browser and go to that url. If the response says something like "Get method is not supported" everything is mapped correctly. On the other hand if you get a 404 you got to fix your servlet mapping

这篇关于未找到GWT RPC服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆