using @ServiceName and locator

234 views
Skip to first unread message

olive...@gmail.com

unread,
Jan 18, 2011, 1:51:15 PM1/18/11
to google-we...@googlegroups.com
Hello,
There is some I don't understand using ServiceLayer stuff.
My sample :
I have a bean called Application and some already existing various libs to handle this (persist save etc...).
So I have created an interface :
@ProxyFor(Application.class)
public interface ApplicationProxy extends EntityProxy
Then the RequestContext
@ServiceName(value = "bla.bla.ApplicationService", 
    locator = "bla.bla.ApplicationServiceLocator")
interface ApplicationRequest extends RequestContext
InstanceRequest<ApplicationProxy, Void> save();
InstanceRequest<ApplicationProxy, Void> persist();

Note the bla.bla.ApplicationService is the interface to the implementation which handle CRUD and other stuff and has methods :
Application save( Application application )
Application save( Application application )

bla.bla.ApplicationServiceLocator is in charge of returning the implementation (in my case tru Guice).

So here I was thinking everything was correct :-).

But we running (in dev mode), gwt complains with :

[ERROR] 18 janv. 2011 19:46:15 xxxx.webapp.ui.client.request.application.ApplicationRequest com.google.gwt.requestfactory.shared.InstanceRequest persist()
[ERROR] GRAVE: Could not find matching method in xxxx.model.services.application.ApplicationService.
[ERROR] Possible matches:
[ERROR]   xxx.model.Application persist(xxxx.model.Application )
[ERROR]
[ERROR] 18 janv. 2011 19:46:15 xxxx.webapp.ui.client.request.application.ApplicationRequest com.google.gwt.requestfactory.shared.InstanceRequest save()
[ERROR] GRAVE: Could not find matching method in cxxx.model.services.application.ApplicationService.
[ERROR] Possible matches:
[ERROR]   xxxx.model.Application save(xxxx.model.Application )
[ERROR]
[ERROR] 18 janv. 2011 19:46:15 com.google.gwt.requestfactory.server.ServiceLayerDecorator die
[ERROR] GRAVE: The RequestContext type xxxx.webapp.ui.client.request.application.ApplicationRequest did not pass validation
[ERROR] 18 janv. 2011 19:46:15 com.google.gwt.requestfactory.server.RequestFactoryServlet doPost

Thanks in advance,

Thomas Broyer

unread,
Jan 18, 2011, 4:06:58 PM1/18/11
to google-we...@googlegroups.com


On Tuesday, January 18, 2011 7:51:15 PM UTC+1, ol...@apache.org wrote:
Hello,
There is some I don't understand using ServiceLayer stuff.
My sample :
I have a bean called Application and some already existing various libs to handle this (persist save etc...).
So I have created an interface :
@ProxyFor(Application.class)
public interface ApplicationProxy extends EntityProxy
Then the RequestContext
@ServiceName(value = "bla.bla.ApplicationService", 
    locator = "bla.bla.ApplicationServiceLocator")
interface ApplicationRequest extends RequestContext
InstanceRequest<ApplicationProxy, Void> save();
InstanceRequest<ApplicationProxy, Void> persist();

You're saying here that the server-side domain object that ApplicationProxy is a @ProxyFor (i.e. Application) has instance methods save() and persist() that return 'void'.
(in other words, InstanceRequest<P, R> reads: there's an instance method on P that returns R, actually replace P and R with their server-side domain objects)

Note the bla.bla.ApplicationService is the interface to the implementation which handle CRUD and other stuff and has methods :
Application save( Application application )
Application save( Application application )

This is not what you declared in your ApplicationRequest (not that it is an error, a server-side object can have more methods than those that are exposed in the RequestContext, but you didn't declare those methods to be callable from the client-side through RequestFactory).

If you want to expose those methods to the client, you have to use Request (not InstanceRequest):
   Request<ApplicationProxy> save(ApplicationProxy application);
   Request<ApplicationProxy> persist(ApplicationProxy application);

olive...@gmail.com

unread,
Jan 19, 2011, 5:15:54 AM1/19/11
to google-we...@googlegroups.com
Thanks sounds better (thanks for the non RTFM response :-) ).

Now there is something I don't understand in the error I have :

[ERROR] com.google.gwt.requestfactory.server.UnexpectedException: Could not find static method with a single parameter of a key type

Whereas I have the following stuff :
* ApplicationRequest : Request<ApplicationProxy> findApplication( Long id );
* ApplicationService : Application findApplication( Long idApp );

And I thought using ServicesLocator was to prevent using static methods

Thanks in advance for your help,
--
Olivier

Thomas Broyer

unread,
Jan 19, 2011, 11:28:10 AM1/19/11
to google-we...@googlegroups.com
You have to provide a Locator for your ApplicationProxy/Applicatin if you don't want the findApplication static method.

I know you already read it, but:
For entities, RequestFactory will have to load them by their identifier (so it can apply the diffs sent from the client before landing them to the service methods). To do so, it will either ask a Locator (that it will first instantiate, of course) or fallback to using a static method named findXxx (where Xxx is the name of the entity class).

Never forget how RF processes requests: applies operations (and thus needs object instances, through Locators or findXxx static methods), then calls invocations (where ServiceLocators might be used)

olive...@gmail.com

unread,
Jan 19, 2011, 12:29:18 PM1/19/11
to google-we...@googlegroups.com
Perfect !

Note for myself : next time read more documentation :-)
Reply all
Reply to author
Forward
0 new messages