GWT Guice + RPC服务获得404 Not Found

时间:2013-09-29 05:58:03

标签: java gwt firebug guice rpc

我正在访问我的服务时遇到404 Not not Exception ...我正在向GWT Guice webapp添加一个非常简单的servlet ...我正在使用RPC来实现我的servlet。

**更新(我的更改后仍然遇到同样的问题):我意识到我可能需要在ServletModule类中绑定,所以我添加了这个:

protected void configureServlets() {
    bind(BCDWebImpl.class).in(Singleton.class);
    serve("/a-bcd/abcd/bcdWebUtil").with(BCDWebImpl.class);

我还在我的代码中添加了一个Window.alert(GWT.getModuleBaseURL()),输出:

http://xx.xx.xx.xx:8080/a-bcd/abcd/

这是我从firebug获得的输出:

Request Headersview source
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Authorization   Basic YWxsVXNlcjpwYXNzd29yZA==
Cache-Control   no-cache
Connection  keep-alive
Content-Length  148
Content-Type    text/x-gwt-rpc; charset=utf-8
Cookie  JSESSIONID=97FA0BE47F77E170C18B105C509F980D
Host    xx.xx.xx.xx:8080
Pragma  no-cache
Referer http://xx.xx.xx.xx:8080/a-bcd/
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0
X-GWT-Module-Base   http://xx.xx.xx.xx:8080/a-bcd/abcd/
X-GWT-Permutation   35D972F27B5773A4C5ACAFE8EA5C1F36

这是我的web.xml:

<filter>
    <filter-name>guiceFilter</filter-name>
    <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>guiceFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
    <servlet-name>BCDWebImpl</servlet-name>
    <servlet-class>com.pz.abcd.server.rest.BCDWebImpl</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>BCDWebImpl</servlet-name>
    <url-pattern>/a-bcd/abcd/BCDWeb</url-pattern>
</servlet-mapping>

BCDWeb类:

@RemoteServiceRelativePath("bcdWeb")
public interface BCDWeb extends RemoteService
{
  public String getName ();
}

gwt.xml:

<module rename-to='abcd'>
    <servlet class="com.pz.abcd.server.rest.BCDWebImpl" path="/bcdWeb" />

BCDEntryPoint.java:

public void onModuleLoad() {
    // This is required for Gwt-Platform proxy's generator
    DelayedBindRegistry.bind(ginjector);        

    ginjector.getPlaceManager().revealCurrentPlace();
    setUpEnv();

}

private void setUpEnv(){
    BCDWebAsync web = GWT.create(BCDWeb.class);
    ServiceDefTarget endpoint = (ServiceDefTarget)web;
    endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "bcdWeb");
    web.getName(new AsyncCallback<String>() {

        @Override
        public void onFailure(Throwable caught) {
            GWT.log(caught.getMessage());
        }

        @Override
        public void onSuccess(final String name) {
            // do something here;  
        }
    });
}

同样,这个webapp正在使用guice,但我正在尝试添加一个非常简单的RPC servlet ...任何想法可能是什么问题?

提前致谢。

1 个答案:

答案 0 :(得分:0)

网址格式区分大小写

你在web.xml

中给出了
<url-pattern>/a-bcd/abcd/BCDWeb</url-pattern>
                            ^____
                                 |
 @RemoteServiceRelativePath("bcdWeb");   //and using the path in small letters.

尝试将模式更改为

<url-pattern>/a-bcd/abcd/bcdWeb</url-pattern>