Search code examples
eclipsegwtubuntu-12.04gwt-rpc

Google Sample for GWT RPC Returns HTTP Error 405 in Eclipse


I have been working through the GWT tutorials on Google's developer site, and have gotten to the section on GWT RPC here. The gist of the problem is that I've followed the instructions on the tutorial carefully, and have encountered a problem when I run the code in development mode on Eclipse Juno. The error is: "Error 405 HTTP method GET is not supported by this URL".

The environment I'm in is:

  • Eclipse Juno 4.2
  • Ubuntu 12.04 LTS (No significant updates recently.)
  • Using default GWT SDK (GWT - 2.4.0).
  • Using default GAE SDK (App Engine - 1.7.2).
  • Chrome Version 21.0.1180.89

Referencing the code in the sample, I've started focusing on the web.xml file and the servlet-mappings in there as a part of the problem. What I have in web.xml code is the following:

   <?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>stockPriceServiceImpl</servlet-name>
        <servlet-class>com.google.gwt.sample.stockwatcher.server.StockPriceServiceImpl</servlet-class>
      </servlet>

      <servlet-mapping>
        <servlet-name>stockPriceServiceImpl</servlet-name>
        <url-pattern>/stockwatcher/stockPrices</url-pattern>
      </servlet-mapping>

  </web-app>

The good thing is that the server is finding the code, but somewhere between finding the code and rendering it, it fails.

I've researched this problem pretty thoroughly, and I have not found anything that seems to point to the cause of the problem. What I do know is the following:

  1. A better understanding of the HttpServlet class is required.
  2. GWT should be taking care of the doPost, and doGet implementations.

If anyone has any suggestions as to what the problem may be, I'm all ears. Or another interpretation of what the error means would be helpful to me and to anyone else having this problem.

EDIT:

I was able to resolve my problem, in part, thanks to Colin Alworth. The problem was how I was thinking about accessing the servlets. Going through the HTML page was indeed the correct way to access the application, and because I was not calling the method that initiates the AsyncCallback method (somehow I missed that), it appeared that the HTML page and the servlet were disconnected.


Solution

  • The StockPriceServlet should be extending RemoteServiceServlet, which is just for RPC calls, and thus does not support GET. Don't direct your browser to that url, instead use the html files that are provided in the app. The actual url should be shown on the Dev Mode console. On the https://developers.google.com/web-toolkit/doc/latest/tutorial/gettingstarted tutorial, this is described in step 2 on https://developers.google.com/web-toolkit/doc/latest/tutorial/create - the url will be http://localhost:8888/StockWatcher.html or, more likely if using dev mode, http://localhost:8888/StockWatcher.html?gwt.codesvr=localhost:9997. From the web.xml, you don't even need to list the html file itself:

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

    http://localhost:8888/?gwt.codesvr=localhost:9997 should suffice.

    Servlets aren't always intended to serve up html, and this is one of those cases - the express purpose of this type of servlet is to be a way for the GWT client to interact with Java methods on the server, by passing objects back and forth. Check out https://developers.google.com/web-toolkit/doc/latest/tutorial/RPC for more details on how this servlet is intended to be used - only from within client code.