0
votes

I am building an application which uses, GWT (2.4), App Engine (1.5.4), and Objectify (3.0). As my application is evolving, I am adding more domain classes and this is forcing me to write more services, which more or less look like same. for example they all should have code for CRUD operations. So I tried to create Generic services which look like

//Client side
@RemoteServiceRelativePath("Generic")
public interface GenericService<T extends BaseDomain> extends RemoteService {
....
}

public interface GenericServiceAsync<T extends BaseDomain> {
...
}

//ServerSide

@SuppressWarnings("serial")
public class GenericServiceImpl<T extends BaseDomain>  extends
RemoteServiceServlet implements GenericService<T> {

//implementation

}

When I am trying to create instance of it on client side using

//Domain extends BaseDomain

public static final GenericServiceAsync<Domain> domainService =   
 GWT.create(GenericService.class);

I am getting the following exception

java.lang.RuntimeException: Deferred binding failed for 'com.planner.client.GenericService' (did you forget to inherit a required module?)

I am not sure what I a doing wrong, Would appreciate any pointers, and/or alternative approaches.

1
It is most probably not an issue with generic - can you check if it works without generics. The likely case is that the GenericService interface is not in a package managed by GWT (if you are using the standard layout it is in the server package - not in the client/shared package) - gkamal

1 Answers

1
votes

I don't think your issue comes from using generics in your Server side Service implementations, but from missconfiguring those services. Check the following:

  • that you have the proper GenericServiceAsync interface created for GenericService

  • you have the proper server side implementation of GenericService that implements that interface and extends GWT's RemoteServiceServlet class

  • that in your web.xml file you have properly configure your service as a servlet expecially the servlet-mapping tag which should have a value of :

    <servlet-mapping>
    <servlet-name>genericServiceServlet</servlet-name>
    <url-pattern>/[GWT-module-name]/Generic</url-pattern>
    

where [GWT-module-name] is the name you've given to your GWT project in the GWT descriptor file (the one called xxx.gwt.xml, where if your module tag has a rename-to attribute, than the value of that attribute is yoru GWT-module-name) and "Generic" is the value used in @RemoteServiceRelativePath("Generic")

Also, as a side note, if you want to make a generic service that treats all your domain objects as BaseDomain types you should just have methods that take as arguments that type, no need to use generics to say that it's a sub-type as well, polymorphism takes care of that .