Re: GWT 2.1.1 RequestFactory Persist method

202 views
Skip to first unread message

giannisdag

unread,
Dec 27, 2010, 6:19:37 PM12/27/10
to Google Web Toolkit
Hi I am trying to use the service layer of GWT 2.1.1. I have created
the infrastracture meaning:
1. An entity proxy, entity and entity locator
2. A request, a service and a service locator
I am using an interface which I annotate as service, and which I
implement. Everything works ok, except that of the persist and
probably remove methods. The problem is that, I cannot have access to
the object that is going to be saved, because I need to have access to
the instance that will be saved. When I tried to, I am getting the
following error:
ERROR] Could not invoke method persist
java.lang.IllegalArgumentException: object is not an instance of
declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:
100)
at
com.google.gwt.requestfactory.server.ReflectiveServiceLayer.invoke(ReflectiveServiceLayer.java:
164)
at
com.google.gwt.requestfactory.server.ServiceLayerDecorator.invoke(ServiceLayerDecorator.java:
89)
at
com.google.gwt.requestfactory.server.ServiceLayerDecorator.invoke(ServiceLayerDecorator.java:
89)
at
com.google.gwt.requestfactory.server.SimpleRequestProcessor.processInvocationMessages(SimpleRequestProcessor.java:
440)
at
com.google.gwt.requestfactory.server.SimpleRequestProcessor.process(SimpleRequestProcessor.java:
218)
at
com.google.gwt.requestfactory.server.SimpleRequestProcessor.process(SimpleRequestProcessor.java:
125)
at
com.google.gwt.requestfactory.server.RequestFactoryServlet.doPost(RequestFactoryServlet.java:
118)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
511)

When I am debugging, I can see that the problem is that in the
ServiceLayerDecorator.invoke(Method domainMethod, Object... args) it
gets the domain method right, it is the persist method of the service
interface, but in the arguments it refers to the entity DAO. So what
to do? I should extend the ServiceLayerDecorator, trying to make the
invoke method to get the right parameters, or I should try some other
solution. Can someone help please?

Thomas Broyer

unread,
Dec 27, 2010, 6:37:15 PM12/27/10
to google-we...@googlegroups.com


On Tuesday, December 28, 2010 12:19:37 AM UTC+1, giannisdag wrote:
Hi I am trying to use the service layer of GWT 2.1.1. I have created
the infrastracture meaning:
1. An entity proxy, entity and entity locator
2. A request, a service and a service locator
I am using an interface which I annotate as service, and which I
implement.

Er, you mean that you have "similar" methods on your service stub (interface) and service implementation (referenced by the @Service annotation), right?

When I am debugging, I can see that the problem is that in the
ServiceLayerDecorator.invoke(Method domainMethod, Object... args) it
gets the domain method right, it is the persist method of the service
interface, but in the arguments it refers to the entity DAO. So what
to do?

Hard to tell without seeing your code (at lease how you declared the method in both the service stub and implementation, and how you implemented your ServiceLocator)
 
I should extend the ServiceLayerDecorator, trying to make the
invoke method to get the right parameters, or I should try some other
solution.

Definitely try another solution!
 
Can someone help please?

If you used RF without the locators, then it really is similar:
 - service methods had to be static on the service implementation class, now they can be instance method, with the ServiceLocator providing the instance
 - instance methods (those returning InstanceRequest) had a "resolution" bug: they were looked up on the service class rather than the domain object.
 - domain objects had to have a no-arg constructor, findXxx static method, and getId and getVersion instance methods, now you can use a Locator to fulfill those requirements (instantiation, finder, and id and version provider) by other means.

It must be a mis-declaration of your service method (stub and/or implementation) or a mis-implementation of your ServiceLocator.

giannisdag

unread,
Dec 28, 2010, 3:37:04 AM12/28/10
to Google Web Toolkit
thank you Thomas. Before trying the new service layer, I have looked
this thread, http://groups.google.com/group/google-web-toolkit/browse_thread/thread/846564e9fc303be0,
to understand how it works. I have pasted my code here.
http://paste.pocoo.org/show/310712/.
It must be a mis-declaration of your service method (stub and/or
implementation) or a mis-implementation of your ServiceLocator.
Probably is a mis-implementation of my ServiceLocator, but I am not
sure.
As far as I can see, the problem with the persist method is this:
When the new request for persist is created as following example,
Request<Void> createReq = request.persist().using(EntityObject);
it gets as parameter the EntityObject. Then request factory, tries to
persist the object, but when it invokes the persist method, it assumes
that the object which owns the method is the entity object, as it used
to, before the use of the service layer. But now it is different,
because the object that owns the method is the service object. I have
somehow inform the ServiceLayerDecorator about this change. Maybe I
could do that through servicelocator, but I haven' t understand fully
how the request factory manages to "RequestFactory sends diffs on the
wire (client-to-server)" as you have said before, in the thread that
you mention.

Thomas Broyer

unread,
Dec 28, 2010, 7:20:16 AM12/28/10
to google-we...@googlegroups.com
You declared your method as InstanceRequest<UserProxy, Void>, i.e. "this is an instance method of UserProxy, that returns void". If your method is in your service, then it has to be a Request<Void> and takes the UserProxy/UserDAO as argument.

giannisdag

unread,
Dec 29, 2010, 11:07:42 AM12/29/10
to Google Web Toolkit
Thank you Thomas, that was all, you are very helpful.
Reply all
Reply to author
Forward
0 new messages