Search code examples
google-app-enginegwtrestlet

GWT Restlet Parameters Always Null


I am brand new to both REST and RESTlet- I got everything up and communicating last night but what I found this morning is that everything I pass into the server is always becoming null.

just as a sample app i have the following - a User Objectify entity (id, emailAddress, and version), and a RESTUserProxy object (id, emailAddress) - I wasn't originally sure if i could pass Objectify Entities back and after not being able to see anything switched it to the Proxy object - if i can get it to work this way I will try switching it back

the front end is as follows:

public interface RESTUserResourceProxy extends ClientProxy {

  @Get
  public void find(String emailAddress, Result<RESTUserProxy> callback);

  @Put
  public void persist(RESTUserProxy user, Result<Void> callback);

  @Delete
  public void delete(RESTUserProxy user, Result<Void> callback);
}

the backend code is as follows (this is currently extremely ugly - i got a little frustrated just trying to see something and put in a ton of sysouts)

public class RESTUserServerResource extends ServerResource implements RESTUserResource {

  private final UserDao userDao;

  public RESTUserServerResource() {
    System.out.println("CREATED USER RESOURCE IMPL");
    userDao = new UserDao();
  }

  @Override
  @Get
  public RESTUserProxy find() {
    System.out.println("reference = " + getReference());
    Form queryParams = getReference().getQueryAsForm();
    System.out.println("query params = " + queryParams);
    System.out.println("query = " + getQuery());
    System.out.println("query string = " + getQuery().getQueryString());
    String searchQuery = (String) getRequest().getAttributes().get("searchQuery");
    System.out.println("search query = " + searchQuery) ;
    return null;
//    if (emailAddress == null) {
//      return null;
//    }
//    System.out.println("user resource impl find [" + emailAddress + "]");
//    final User user = userDao.find(emailAddress.getText());
//    if (user != null) {
//      System.out.println("found user ");
//      return new RESTUserProxy(user.getId(), user.getEmailAddress());
//    } else {
//      System.out.println("found absolutely nothing");
//      return null;
//    }
  }

  @Override
  @Put
  public void persist(RESTUserProxy userProxy) {
    System.out.println("user proxy = " + userProxy);
    if (userProxy == null) {
      return;
    }
    final User user = userDao.find(userProxy.getId());
    user.setEmailAddress(userProxy.getEmailAddress());
    user.setId(userProxy.getId());
    userDao.persist(user);
  }

  @Override
  @Delete
  public void delete(RESTUserProxy userProxy) {
    final User user = userDao.find(userProxy.getId());
    userDao.delete(user);
  }
}

what im having problems with is that eerythings coming through as null - a lot of other answers on here said to get the query to get the params - but here the query is null

below is the output of calling find and persist

reference = http://127.0.0.1:8888/users/123
query params = []
query = []
query string = 
search query = null

i'm sure i'm doing something stupid here i just have no idea how to proceed right now. Any help as to what i'm doing wrong would be greatly appreciated.


Solution

  • This is due to GAE not supporting chunked encoding. See workaround here: http://wiki.restlet.org/docs_2.1/13-restlet/21-restlet/318-restlet/303-restlet.html#dsy303-restlet_gwt