Ok it works like a charm with a custom RequestTransport and a custom
header. Thanks for that tip!

But RequestFactory docs should really mention what to add to web.xml
and that you need a json implementation from json.org and a
javax.validation implementation in your server classpath to make
things work with Eclipse + GWT Plugin + Jetty. Otherwise you got some
nice java.lang.NoClassDefFoundError from jetty.



On 6 Nov., 21:35, Thomas Broyer <[email protected]> wrote:
> On 6 nov, 19:26, Jack <[email protected]> wrote:
>
>
>
>
>
> > Hi,
>
> > we would like to integrate GWT 2.1 RequestFactory in our application.
> > Our application's backend uses JPA and has one database per customer.
> > So we have to tell our EntityManagerFactory which database it should
> > use, depending on the customer who did the server request.
> > Currently we havehttp://our-app.com/<unique-customername> as
> > application URL and we send <unique-customername> to our backend on
> > each request. That way we can construct an EntityManagerFactory with a
> > custom properties map which contains a datasource name similar to
> > "appdatasource-<unique-customername>". So every time we got a new
> > customer, we just have to add a new JDBC resource and connection pool
> > which points to the new customers database to our J2EE server.
>
> > So we tried this approach with RequestFactory and defined our service
> > interface like this:
>
> > @Service(Person.class)
> > public interface PersonRequest extends RequestContext {
>
> >   Request<List<PersonProxy>> findAllPersons(String
> > uniqueCustomerName);
>
> >   Request<List<PersonProxy>> findPersonsByAge(int min, int max, String
> > uniqueCustomerName);
>
> >   InstanceRequest<PersonProxy, Void> persist(String
> > uniqueCustomerName);
>
> >   InstanceRequest<PersonProxy, Void> remove(String
> > uniqueCustomerName);
>
> >   Request<PersonProxy> findPerson(Long id);
>
> > }
>
> > So everything is fine except the method "Request<PersonProxy>
> > findPerson(Long id)" which is required by the GWT RequestFactory
> > servlet. So we can't add a second parameter to this method. But this
> > second parameter is required for our dynamic EntityManagerFactory
> > configuration.
>
> > Are there any plans for a GWT 2.1.x release which supports such a
> > scenario?
>
> The changes to expect are listed 
> inhttp://code.google.com/p/google-web-toolkit/wiki/RequestFactory_2_1_1
>
> > It would be nice if the required findEntity method would
> > support additional custom parameters (maybe via Java5 VarArgs) or if
> > there is a way to transport additional information from client to
> > server during a RequestFactory request which can then be accessed
> > during server side method execution.
>
> > Does anybody have an idea for a nasty workaround for that problem that
> > is possible with the current GWT 2.1 implementation?
>
> One that I wouldn't call "nasty":
> 1. extend DefaultRequestTransport to send the uniqueCustomerName (say,
> within an HTTP header)
> 2. initialize() your RequestFactory with an instance of your extended
> RequestTransport
> 3. on the server-side, get the HttpServletRequest using
> RequestFactoryServlet.getThreadLocalRequest(), to extract the
> uniqueCustomerName from it and use it to create the
> EntityManagerFactory.
> That way, you don't have to send the uniqueCustomerName explicitly in
> each and every request, it'll be done automatically and transparently
> by your RequestTransport.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to