Wednesday, March 19, 2008

django+jython+jetty

UPDATE: since this is now 2 years old, and one of my key links is broken i've written a quick update here: http://tristanking.blogspot.com/2010/01/re-jettydjangojython.html

Yep, you read that right. Django, running ontop of jython, running inside jetty.

Why? The idea just popped into my head while in a meeting discussing our project's deployment strategy. I thought "hey, we already have a tomcat server running for other people's projects, I wonder if i can get django+jython running inside a servlet container". Seeing that jython already came with a PyServlet class, i figured the base work was already there and decided to give it a go.

So I started off looking at the PyServlet class that ships with Jython. PyServlet allows you to write servlets from python code, implementing the standard doPost, doPost, etc functions, from which you access by going to a URL which matches the path name of you .py file. This doesn't match the REST method django uses, so the PyServlet needed some work. It turned out to almost be an entire rewrite, the only things remaining from PyServlet being the PySystemState initialisation.

As well as the DjangoServlet, a django handler module had to be created to bridge the gap between the java servlet request and response objects and the django python request and response objects. The already existing modpython handler provided a great guideline to make this, and it turned out to be a breeze.

Currently, I build the DjangoServlet on it's own using maven and install it into my local maven repo (for people who have not used maven before, this involves a single command line call). The servlet handler module is put straight into django in the same location as the other handlers (django.core.handlers.servlet). I then have another maven project with a dependency on the DjangoServlet project, and a web.xml. The web.xml requires a few init-params: one for the jython home, one for the django handler class and one for the django app location.

With everything set up, using the maven jetty plugins, i fire jetty up, which loads the DjangoServlet and BAM! django running in a servlet container.

So far I've not noticed any difference in performance, but one nice 'feature' is being able to use maven's dependency management to set up the classpath with the jars required to run your app (it definitely beats having the edit the $CLASSPATH before starting jython and my settings.LIB_DIRECTORY method).

A few things still need to be done to make this really easy to setup and use, It may be best to try move the handler module out of the core django code, so that once jython is up to the task of running django without any modifications it is possible to deploy this on a pure django+jython install. I also need to write scripts to build the pom.xml and web.xml files.

If you want to have a look at this, or deploy it yourself, you can grab the projects from github. Here for the DjangoServlet project, servlet.py for the django handler module and hydrant is my django app which has example pom.xml and web.xmls for you to use as a reference for your own (until i have proper scripts/docs to build them).

20 comments:

H Eriksson said...

Really cool stuff. Good job. I had plans on doing something similar a while back when I was playing around with CherryPy + Jetty + Jython. In that work I used modjy. Have you thought about using modjy and the django WSGI handler? I have no idea if it would work...

Ken Garland said...

what a hassle, just to integrate with customer's java environments. but hey, well done. ;)

uiyui said...

I would gold für wow cultivate courage.buy wow gold “Nothing is so mild wow gold cheap and gentle as courage, nothing so cruel and pitiless as cowardice,” syas a wise author. We too often borrow trouble, and anticipate that may never appear.”wow gold kaufen The fear of ill exceeds the ill we fear.” Dangers will arise in any career, but presence of mind will often conquer the worst of them. Be prepared for any fate, and there is no harm to be freared. If I were a boy again, I would look on the cheerful side. life is very much like a mirror:sell wow gold if you smile upon it,maple mesos I smiles back upon you; but if you frown and look doubtful on it,cheap maplestory mesos you will get a similar look in return. Inner sunshine warms not only the heart of the owner,world of warcraft power leveling but of all that come in contact with it. “ who shuts love out ,in turn shall be shut out from love.” If I were a boy again, I would school myself to say no more often.billig wow gold I might cheap mesos write pages maple meso on the importance of learning very early in life to gain that point where a young boy can stand erect, and decline doing an unworthy act because it is unworthy.wow powerleveling If I were a boy again, I would demand of myself more courtesy towards my companions and friends,wow leveling and indeed towards strangers as well.Maple Story Account The smallest courtesies along the rough roads of life are wow powerleveln like the little birds that sing to us all winter long, and make that season of ice and snow more endurable. Finally,maple story powerleveling instead of trying hard to be happy,archlord online gold as if that were the sole purpose of life, I would , if I were a boy again, I would still try harder to make others happy.

mei said...

You smart and buy Sword of the New World Vis, you play the game is right, Sword of the New World Gold. you have a wonderful time, buy vis, I have it cheap snw vis, I buy Sword of the New World money.

I find job Tales Of Pirates gold, this is a nice work and Tales Of Pirates money . I do not want to rely on my parents cheap Tales Of Pirates gold, They look after me so long time, they pay me too much and very tired buy Tales Of Pirates Gold.

game gold said...

At one time or another, I do not have the rf gold ; at the first time, I am not willing to buy rf cp . But I do not wonder I buy the rf online gold , my friend thinks that I am ill. But when I have it, it carries the magic from such a group, such a link in the world, rf money , it is the key bring you to this world. But buy cheap rf gold is the best desire that I make.

Without thinking I buy some runescape gold . I use some buy runescape and want to find a good group. We often buy rs gold together on Monday. As if it is a rule. I think it is the real friendship. runescape money is already become the essential thing in my life. So I will introduce my friends have the cheap rs gold , we can be consist of a group, it must be very interesting.

陈凯燕 said...

Do you know Asda Story gold? I like it.
My brother often go to the internet bar to buy Asda Story money and play it.
After school, He likes playing games using these buy Asda Story Gold with his friend.
I do not like to play it. Because I think that it not only costs much money but also spend much time. One day, he give me manycheap Asda Story gold and play the game with me.

Do you know Archlord gold? I like it.
My brother often go to the internet bar to buy Archlord money and play it.
After school, He likes playing games using these archlord online Gold with his friend.
I do not like to play it. Because I think that it not only costs much money but also spend much time. One day, he give me many cheap Archlord gold and play the game with me.
I came to the bar following him and found buy Archlord gold was so cheap. After that, I also go to play game with him.

cheng said...

Do you want to know the magic of online games, and here you can get more angels gold. Do you want to have a try? Come on and angels online gold can make you happy. You can change a lot buy angels gold for play games. And you can use the cheap angels online gold do what you want to do in the online game.
Do you want to know the magic of online games, and here you can get more Rose zuly. Do you want to have a try? Come on and rose zulie can make you happy. You can change a lot rose online zuly for play games. Playing online games can make much rose online zulie. And you can Arua ROSE zuly do what you want to do in the online game.

筱娅 said...

Have you heared about a game which you need use priston tale Gold to play, and you can also borrow priston tale Money from other players? But you can buy priston tale Gold, or you will lose the choice if you do not have cheap priston tale Gold. If you get it, you can continue this game.
Have you heared about 9Dragons which you need use 9Dragons gold to play, and you can also borrow 9 Dragons gold from other players? But you can buy 9 Dragons gold, or you will lose the choice if you do not have cheap 9Dragons gold. If you get 9Dragons money, you can continue this game.

feilin said...

I like holic gold very much. Since I entered into this game, I learnt skills to earn holic money. Thanks to holic online gold let me know a lot of friends. It is my habit to buy holic online money, and I get some cheap holic gold from my friends and Internet.
I like to play last chaos, because I like its name, also I like last chaos gold. My friend told me that she would buy lastchaos gold for me, and I was so happy. I do not like to go shopping, because it always spends a lot of money, but I never hesitate to buy last chaos gold. You can buy cheap lastchaos gold; it is so easy and convenient. I believe the future of lastchaos money is bright.

milf said...

dessicant air dryerpediatric asthmaasthma specialistasthma children specialistcarpet cleaning dallas txcarpet cleaners dallascarpet cleaning dallas

vero beach vacationvero beach vacationsbeach vacation homes veroms beach vacationsms beach vacationms beach condosmaui beach vacationmaui beach vacationsmaui beach clubbeach vacationsyour beach vacationscheap beach vacations

bob hairstylebob haircutsbob layeredpob hairstylebobbedclassic bobCare for Curly HairTips for Curly Haircurly hair12r 22.5 best pricetires truck bustires 12r 22.5

washington new housenew house houstonnew house san antonionew house ventura

milf said...

new houston house houston house txstains removal dyestains removal clothesstains removalteeth whiteningteeth whiteningbright teeth

jennifer grey nosejennifer nose jobscalebrities nose jobsWomen with Big NosesWomen hairstylesBig Nose Women, hairstyles

milf said...

black mold exposureblack mold symptoms of exposurewrought iron garden gatesiron garden gates find them herefine thin hair hairstylessearch hair styles for fine thin hairnight vision binocularsbuy night vision binocularslipitor reactionslipitor allergic reactionsluxury beach resort in the philippines

afordable beach resorts in the philippineshomeopathy for eczema.baby eczema.save big with great mineral makeup bargainsmineral makeup wholesalersprodam iphone Apple prodam iphone prahacect iphone manualmanual for P 168 iphonefero 52 binocularsnight vision Fero 52 binocularsThe best night vision binoculars here

night vision binoculars bargainsfree photo albums computer programsfree software to make photo albumsfree tax formsprintable tax forms for free craftmatic air bedcraftmatic air bed adjustable info hereboyd air bedboyd night air bed lowest price

milf said...

find air beds in wisconsinbest air beds in wisconsincloud air beds

best cloud inflatable air bedssealy air beds portableportables air bedsrv luggage racksaluminum made rv luggage racksair bed raisedbest form raised air bedsbed air informercialsbest informercials bed airmattress sized air beds

bestair bed mattress antique doorknobsantique doorknob identification tipsdvd player troubleshootingtroubleshooting with the dvd playerflat panel television lcd vs plasmaflat panel lcd television versus plasma pic the bestadjustable bed air foam The best bed air foam

hoof prints antique equestrian printsantique hoof prints equestrian printsBuy air bedadjustablebuy the best adjustable air bedsair beds canadian storesCanadian stores for air beds

migraine causemigraine treatments floridaflorida headache clinicdrying dessicantair drying dessicant

gfh said...

we offer wow power leveling and wow gold wow gold

Emblem Parade said...

Hey, the servlet.py doesn't seem to exist anymore. Any chance you can get it back online or email it to me? I'm doing some cool experiments with Django/Jython!

jimmychooshoes said...

mcqueen shoes
alexander mcqueen heels
Alexander McQueen Store
Jimmy Choo sale
Replica jimmy choo shoes
manolo blahnik online store
manolo shoes
manolo blahnik sale
replica christian louboutin shoes
discount christian louboutin shoes
alexander mcqueen shoes
jimmy choo outlet
jimmy choos
jimmy shoes
Manolo Blahnik Shoes
christian shoes
Christian Louboutin Alta Perla Strass 100 sandals
Christian Louboutin - Declic leather pumps
Manolo Blahnik Something Blue Satin Pump
Manolo Blahnik Satin Jeweled d'Orsay Pump

Vinny said...

Excellent task ! Your internet page has supplied me much of the tips I desired .
Naperville locksmiths
Locksmith MARGATE FL
Berkeley locksmith
Locksmith Mountain View CA
Locksmith Mountain View
Mountain View locksmith
Locksmith Mountain View CA
Locksmith Mountain View CA
Elgin Locksmith
Locksmith Elgin IL
Locksmith Elgin
Elgin Locksmith
Locksmith Elgin
Locksmith Elgin
Elgin Locksmith
Locksmith Elgin
Elgin Locksmith
Locksmith Elgin IL
Locksmith Elgin IL
Locksmith Elgin
Locksmith Elgin IL
Elgin Locksmith
irvine locksmith
irvine locksmith
pembroke pines locksmith
Aventura FL locksmith
locksmith hialeah
locksmith hialeah
irvine locksmith
locksmith hialeah
pembroke pines locksmith

luck said...

Importantly make sure the Nike Air Max are very good vibrates resistancewe.Nike Air Max 91 with Nike shoe sole for traction technology and physical mobility Nike Free technology.TheNike Air Max Shoes is a beautiful ship and very flawless.The shoes Nike Air Max Boots hovercraft significantly in the heel which is visible side of the base on most models.the design using cotton lining inspired Leahter feet. There are more and more popular, the success is to make materials and design feature styles. Nike Shoes Us is worth buying, rushed to use the time for direct purchase, brings great joy to you.Christian Louboutin Outlet

abercrombiefitch said...

Thank you for your article to share with us, our online store Nike Outlets, have a good product Nike Air Max shoes, interested welcome to come in and see 2011 Cheap Nike Air Max Online Store, Hot products: Mens Nike Air Presto 2009 Gray Red Training Shoes. Best Nike Shoes Where can you buy UGG Outlet Store?.

dolinna said...

This is the good news.The information you provide is very useful for me.Thank you for sharing it.I will come to see if you have new post every day.I am a china tour lover,You can learn more: China vacation packages | China Travel Agency | Tibet Tours