Search code examples
xmlgwtxml-rpcrpc

Cannot make RemoteServiceRelativePath and XML work (GWT)


I think I have a bad configuration of my XML files for my GTW project because when I try to contact the remote service I get this error: "Problem accessing /myresults/compress. Reason: NOT_FOUND". Please find below the important pieces of my code if anyone can help me, I think it is related to RemoteServiceRelativePath and my XML.

UPDATE: When I change in web.xml the content of URL-PATTERN I still get exactly the same message with path /myresults/compress.

CompressionService.java

package myProject.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/* The client side stub for the RPC service. */
@RemoteServiceRelativePath("compress")
public interface CompressionService extends RemoteService {
    String compress(String name) throws IllegalArgumentException;
}

CompressionServiceImpl.java

package myProject.server;
import myProject.client.CompressionService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/* The server side implementation of the RPC service. */
public class CompressionServiceImpl extends RemoteServiceServlet implements
        CompressionService {
    public String compress(String input) throws IllegalArgumentException {
        String output = "aaaa";
        return output;
    }
}

CompressionService.java

package myProject.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
/* The async counterpart of <code>CompressService</code> */
public interface CompressionServiceAsync {
    void compress(String input, AsyncCallback<String> callback)
            throws IllegalArgumentException;
}

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>
  <servlet>
    <servlet-name>compressionService</servlet-name>
    <servlet-class>myProject.server.CompressionServiceImpl</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>compressionService</servlet-name>
    <url-pattern>/myresults/compress</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>MyResults.html</welcome-file>
  </welcome-file-list>
</web-app>

MyResults.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='myresults'>
  <inherits name='com.google.gwt.user.User'/>
  <inherits name='com.google.gwt.user.theme.clean.Clean'/>
  <entry-point class='myProject.client.MyResults'/>
  <source path='client'/>
  <source path='shared'/>
</module>

MyResults.java

private final CompressionServiceAsync compressionService = GWT.create(CompressionService.class);
compressionService.compress(text, new AsyncCallback<String>() {
              public void onFailure(Throwable caught) {
                // Show the RPC error message to the user
                download.setText(caught.getMessage()));             
              }
              public void onSuccess(String result) {
                download.setText(result);
              }
});

Solution

  • I guess you are already thinking on the right lines. The problem seems to be that your @RemoteServiceRelativePath and web.xml url-mapping doesn't agree with each other.

    Probably changing servlet-mapping in web.xml to following will fix your problem:

      <servlet-mapping>
        <servlet-name>compressionService</servlet-name>
        <url-pattern>/compress</url-pattern>
      </servlet-mapping>