Might be a fun idea. There are so many weird gotchas in the Google Apps
Engine/Java system (and the Google Web Toolkit), it might be good to have a
place documenting them and the workarounds...
something I forgot to mention was the site I have where the Jython edition
of the GWT demo app is:
http://primary-test.appspot.com
This is the demo found here:
http://code.google.com/webtoolkit/tutorials/1.6/gettingstarted.html
Followed by the internationalization steps here:
http://code.google.com/webtoolkit/tutorials/1.6/i18n.html
and then the client-server GWT-RPC part here:
http://code.google.com/webtoolkit/tutorials/1.6/RPC.html
and finally the Google Apps Engine part here:
http://code.google.com/webtoolkit/tutorials/1.6/appengine.html
Then a rewrite of the server components into Jython, using what Josh has
written up in the Jython book:
http://jythonpodcast.hostjava.net/jythonbook/chapter18.html#google-app-engine
Just part of me figuring out how to levy using Jython with GWT in the GAE/J
environment. As I said before, my next step is to make something from
scratch, which I'm currently in the middle of.
Something I want to try is to have some Jython functions stored in the
datastore, which then I can dynamically load into the server components and
have them run the functions... which would be something a bit more dynamic
than Java usually is capable of. I'm also looking at using some jython
generators to drive a series of AJAX functions to process and update a UI
element... really try and do some fun things with this all.
On Tue, Aug 11, 2009 at 7:18 AM, Josh Juneau <juneau001@...> wrote:
> Nice work Cliff! This is very interesting stuff...always great to see
> Jython used in different ways.
>
> I wonder if we should start a wiki page dedicated to posting solutions such
> as this? Thoughts?
>
>
> Josh Juneau
> juneau001@...
> http://jj-blogger.blogspot.com
> Twitter ID: javajuneau
>
>
> On Mon, Aug 10, 2009 at 4:52 PM, Cliff Hill <xlorep@...> wrote:
>
>> Ok, so my further experiments in how to make Jython work on GAE/J have led
>> me to attempting the Google Web Toolkit example, and see if I can drive the
>> server code using Jython, and I have success. So, with GWT, I can build a UI
>> in Java (that compiles into JavaScript), and then I can write the
>> server-side components in Jython (thanks to Josh's little Object Factory
>> trick he helped me with earlier), so I can build the server-end with Jython
>> (the only limitation is dealing with the DataStore, using JDO, I still need
>> to build a couple Java classes to handle that gracefully, but even that
>> works like a charm).
>>
>> JDO:
>>
>> - I don't know how to use this directly in Jython, so like I said
>> earlier, I simply make a Java class with the JDO annotations, and use that
>> class in Jython. Not really all that difficult.
>> - There is a gotcha: The PersistenceManagerFactory, when you do the
>> following in Jython:
>>
>> from import javax.jdo import JDOHelper
>>
>> PMF = JDOHelper.getPersistenceManagerFactory("transactions-optional")
>>
>> pm = PMF.getPersistenceManager()
>>
>> try:
>> pm.makePersistent(Stock(user, symbol)) # Any class properly annotated
>> for JDO here
>> finally:
>> pm.close()
>> This *will* fail. The reason is because the getPersistenceManager() method
>> doesn't return a PersistenceManager object, but something else from the
>> DataNucleus system. Building a PMF class (as outlined in the GAE/J example
>> for "guestbook"), and adding a method to return a PersistenceManager object
>> directly in Java like:
>> package com.google.gwt.sample.stockwatcher.server;
>>
>> import javax.jdo.JDOHelper;
>> import javax.jdo.PersistenceManager;
>> import javax.jdo.PersistenceManagerFactory;
>>
>> public final class PMF {
>> private static final PersistenceManagerFactory pmfInstance =
>> JDOHelper.getPersistenceManagerFactory("transactions-optional");
>>
>> private PMF() {}
>>
>> public static PersistenceManager getPM() {
>> return (PersistenceManager) pmfInstance.getPersistenceManager();
>> }
>> }
>> And then loading that into the above Python code changes it to:
>> from import javax.jdo import JDOHelper
>> from com.google.gwt.sample.stockwatcher.server import PMF
>>
>> pm = PMF.getPM()
>>
>> try:
>> pm.makePersistent(Stock(user, symbol)) # Any class properly annotated
>> for JDO here
>> finally:
>> pm.close()
>> This will work correctly then.
>>
>> GWT:
>>
>> - Unfortunately, writing Jython and having it compile into JavaScript
>> for the client side doesn't work. It would be incredible if it did, but
>> that's neither here nor there right now... Where Jython comes in handy is
>> driving the server side of things. GWT makes it incredibly convenient to
>> have AJAX calls be handled directly inside the Jython code, without needing
>> to actually *write* AJAX code. Another nice detail is that GWT conveniently
>> sets up an interface for the servlet to implement... which makes building
>> the Object Factory code that Josh shows in the Jython book able to
>> immediately use the Jython servlet without the need of implementing another
>> interface (simply have it use the one GWT requires)
>> - Here is an example of a servlet changes the stock prices in the
>> StockWatcher example for GWT:
>>
>> from com.google.gwt.user.server.rpc import RemoteServiceServlet
>>
>> from com.google.gwt.sample.stockwatcher.client import StockPrice,
>> StockPriceService, DelistedException
>>
>> import sys
>>
>> sys.path.insert(0, 'WEB-INF/python-lib/Lib.zip')
>>
>> import random
>>
>> MAX_PRICE = 100.0 # $100.00
>> MAX_PRICE_CHANGE = 0.02 # +/- 2%
>>
>> class StockPriceServiceImpl(RemoteServiceServlet, StockPriceService):
>>
>> def getPrices(self, symbols):
>> prices = []
>> for i in range(len(symbols)):
>> if symbols[i] == "ERR":
>> raise DelistedException("ERR")
>>
>> price = random.random() * MAX_PRICE
>> change = price * MAX_PRICE_CHANGE * (random.random() * 2.0 -
>> 1.0)
>>
>> prices.append(StockPrice(symbols[i], price, change))
>>
>> return prices
>>
>> - Oh, and the Object Factory code in Java:
>>
>> package com.google.gwt.sample.stockwatcher.server;
>>
>> import com.google.gwt.user.server.rpc.RemoteServiceServlet;
>>
>> import org.plyjy.factory.JythonObjectFactory;
>>
>> import com.google.gwt.sample.stockwatcher.client.DelistedException;
>> import com.google.gwt.sample.stockwatcher.client.StockPrice;
>> import com.google.gwt.sample.stockwatcher.client.StockPriceService;
>>
>> public class StockPriceServiceFacade extends RemoteServiceServlet
>> implements StockPriceService {
>>
>> private JythonObjectFactory factory = null;
>>
>> String pyServletName = null;
>>
>> @Override
>> public StockPrice[] getPrices(String[] symbols) throws
>> DelistedException {
>> factory = factory.getInstance();
>> pyServletName = getInitParameter("PyServletName");
>> StockPriceService jythonServlet = (StockPriceService)
>> factory.createObject(StockPriceService.class, pyServletName);
>> return jythonServlet.getPrices(symbols);
>> }
>>
>> }
>>
>> So, now that I have done this... my next step is to try and build
>> something from scratch with all of this. I'm really enjoying the ability to
>> use Jython on the Google Apps Engine...
>>
>> --
>> "I'm not responcabel fer my computer's spleling errnors" - Xlorep DarkHelm
>> Website: http://darkhelm.org
>> Sent from Santa Maria, California, United States
>>
>>
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
>> 30-Day
>> trial. Simplify your report design, integration and deployment - and focus
>> on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>> _______________________________________________
>> Jython-users mailing list
>> Jython-users@...
>> https://lists.sourceforge.net/lists/listinfo/jython-users
>>
>>
>
--
"I'm not responcabel fer my computer's spleling errnors" - Xlorep DarkHelm
Website: http://darkhelm.org
|