javagoogle-app-enginerestresty-gwt

RestyGWT content argument must be a class


I'm trying to have a server-client communication by using restygwt. Therefore I'm having an service interface (client) and a controller (server).

@Path("/user")
public interface UserAdminRestService extends RestService {
    @GET
    @Path("/users")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public void getUsers(MethodCallback<List<GWTUser>> methodCallback);

@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public void getUser(Integer id, MethodCallback<GWTUser> callback);
 }

@Controller
@RequestMapping(value ="/user")
public class AdminSpringController {

    @RequestMapping(value = "/users", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public @ResponseBody List<GWTUser> getUsers() {
        ...
    }

@RequestMapping( value = "/{id}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public @ResponseBody GWTUser getUser(@PathVariable Integer id) throws NotFoundException { ...
    }

}

To get the specific data I make a MethodCall:

Defaults.setServiceRoot(GWT.getHostPageBaseURL());
UserAdminRestService userService = GWT.create(UserAdminRestService.class);
((RestServiceProxy)userService).setResource(new Resource("/user"));


userServiceClient.getUsers(new MethodCallback<List<GWTUser>>() {

    @Override
    public void onFailure(Method method, Throwable exception) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSuccess(Method method, List<GWTUser> response) {
        view.setUserList(response);

    }

});

But when I try to build my application I'm getting the error message:

[INFO] Compiling module my.app.web
[INFO]    Computing all possible rebind results for 'my.app.client.UserAdminRestService'
[INFO]       Rebinding my.app.client.UserAdminRestService
[INFO]          Invoking generator org.fusesource.restygwt.rebind.RestServiceGenerator
[INFO]             Generating: my.app.client.UserAdminRestService_Generated_RestServiceProxy_
[INFO]                [ERROR] Content argument must be a class.
[INFO]    [ERROR] Errors in 'my/app/admin/client/activity/UserListActivity.java'
[INFO]       [ERROR] Line 69: Failed to resolve 'my.app.client.UserAdminRestService' via deferred binding
[INFO]    [WARN] For the following type(s), generated source was never committed (did you forget to call commit()?)
[INFO]       [WARN] my.app.client.UserAdminRestService_Generated_RestServiceProxy_

LINE 69: is UserAdminRestService userService = GWT.create(UserAdminRestService.class);

I have no clue what I'm doing wrong. thanks for any ideas or help :)

EDIT:

GWTUser

public class GWTUser {

/**
 * Certain user entity id. Only for representation, can not be
 * persisted into the database.
 */
private int id;

/**
 * Certain user id.
 */
private String userId;

/**
 * user password.
 */
private String password;

/**
 * Represents a certain status if user is enabled.
 */
private boolean enabled = true;

/**
 * Represents a certain status if user is locked.
 */
private boolean locked = false;

/**
 * user e-mail.
 */
private String email;

/**
 * full user name.
 */
private String name;

/**
 * the version of the real user entity. Only for representation, can not be
 * persisted into the database.
 */
private int version;

// Getter and Setter

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public int getVersion() {
    return version;
}

public void setVersion(int version) {
    this.version = version;
}

public String getUserId() {
    return userId;
}

public void setUserId(String userId) {
    this.userId = userId;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public boolean isEnabled() {
    return enabled;
}

public void setEnabled(boolean enabled) {
    this.enabled = enabled;
}

public boolean isLocked() {
    return locked;
}

public void setLocked(boolean locked) {
    this.locked = locked;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((userId == null) ? 0 : userId.hashCode());
    return result;
}

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    GWTUser other = (GWTUser) obj;
    if (userId == null) {
        if (other.userId != null)
            return false;
    } else if (!userId.equals(other.userId))
        return false;
    return true;
}

@Override
public String toString() {
    StringBuilder builder = new StringBuilder();
    builder.append("User [userId=");
    builder.append(userId);
    builder.append(", name=");
    builder.append(name);
    builder.append(", email=");
    builder.append(email);
    builder.append(", password=");
    builder.append(password != null ? "****" : "<not set>");
    builder.append(", enabled=");
    builder.append(enabled);
    builder.append(", locked=");
    builder.append(locked);
    builder.append("]");
    return builder.toString();
}

}

EDIT:

gwt.gwt.xml file containing all the gwt code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module SYSTEM "gwt-module.dtd">
<module>

    <!-- Inherit the core Web Toolkit stuff. -->
    <inherits name='com.google.gwt.user.User' />
    <inherits name='com.google.gwt.activity.Activity'/>
    <inherits name='com.google.gwt.place.Place' />
    <inherits name='org.fusesource.restygwt.RestyGWT' />

    <!-- Use ClientFactoryImpl by default -->
    <replace-with class="my.app.client.factory.ClientFactoryImpl">
    <when-type-is class="my.app.client.factory.ClientFactory"/>
    </replace-with>

    <!--Specify the app entry point class. -->
    <entry-point class='my.app.client.AdminEntryPoint'/>    

    <source path='rest'/>
    <source path='client'/>
    <source path='consts'/> 
</module>

and the web.gwt.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module SYSTEM "gwt-module.dtd">
<module rename-to="web">

    <!-- Inherit the core Web Toolkit stuff. -->
    <inherits name='com.google.gwt.user.User' />
    <inherits name='org.fusesource.restygwt.RestyGWT' />

    <inherits name='my.app.gwt' /> 

</module>

I thinks because of two modules there is a problem because both the Interface UserAdminRestService and the GWTUser are still the same.


Solution

  • The Problem was not the GWTUser, it was the Payload, meaning:

    when I tried to getUsers(MethodCallback callback) it worked fine but with getUser(int id, MethodCallback callback) i printed an error because int is not a class. Therefore I changed int to Integer and it's working fine.