<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jython Journeys &#187; java</title>
	<atom:link href="http://jython.xhaus.com/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://jython.xhaus.com</link>
	<description>Notes about my work with jython and python</description>
	<lastBuildDate>Tue, 01 Dec 2009 19:37:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Transforming with XSLT on Google AppEngine and jython.</title>
		<link>http://jython.xhaus.com/transforming-with-xslt-on-google-appengine-and-jython/</link>
		<comments>http://jython.xhaus.com/transforming-with-xslt-on-google-appengine-and-jython/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 18:42:26 +0000</pubDate>
		<dc:creator>alan.kennedy</dc:creator>
				<category><![CDATA[google appengine]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jython]]></category>
		<category><![CDATA[cloud computing]]></category>
		<category><![CDATA[java scripting]]></category>
		<category><![CDATA[web technology]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://jython.xhaus.com/?p=171</guid>
		<description><![CDATA[I&#8217;m writing this post in response to a challenge. I wrote a post entitled Jython on Google AppEngine: Why bother?, which was a reply to a statement made by a Google engineer about not seeing the point of running jython on AppEngine. And a similar statement was repeated in a comment on that blog post [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m writing this post in response to a challenge. I wrote a post entitled <a href="http://jython.xhaus.com/jython-on-google-appengine-why-bother/">Jython on Google AppEngine: Why bother?</a>, which was a reply to a statement made by a Google engineer about not seeing the point of running jython on AppEngine. And a similar statement was repeated in a <a href="http://jython.xhaus.com/jython-on-google-appengine-why-bother/#comments">comment on that blog post</a> (i.e. &#8220;<i>the gist of what I intended to say was that while it was possible to run Jython on App Engine, I couldn’t think why you’d want to</i>.&#8221;)</p>
<p>So rather than get into a back-and-forth of yes-it-is-no-it-isnt-yes-it-is, I thought I&#8217;d reply with some simple code that demonstrates <b>something that cannot (currently) be done in cpython on AppEngine</b>, but is <b>easy with jython on AppEngine</b>: XSLT transforms. </p>
<p><span id="more-171"></span></p>
<p>So, without further ado, here is the jython source code for running an XSLT transform on Google AppEngine. It is implemented as a jython WSGI application, using xhaus.com&#8217;s <a href="http://modjy.xhaus.com">modjy WSGI gateway for java servlets</a> that was <a href="http://jython.xhaus.com/modjy-now-fully-integrated-into-jython/">contributed to the jython project a few months back</a>.</p>
<p>In order to get this code running, I suggest you download the <a href="http://downloads.xhaus.com/modjy_webapp_google_appengine/">modjy on google appengine demo</a> from our <a href="http://downloads.xhaus.com">downloads site</a>. In that download, there is a jython file called &#8220;demo_app.py&#8221;. Simply replace the entire contents of that file with the code below, and you&#8217;re good to go. If you need help with getting the modjy demo application working on Google AppEngine, see the documentation on the modjy wiki: <a href="http://opensource.xhaus.com/projects/modjy/wiki/ModjyGoogleAppEngine">Running jython WSGI applications on Google AppEngine, with modjy</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">__doc__ = <span style="color: #483d8b;">&quot;&quot;&quot;
A demonstration of how to run XSLT transforms on Google AppEngine with jython (not cpython).
Please feel free to use this code in whatever way you wish.
&quot;&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">from</span> java.<span style="color: black;">io</span> <span style="color: #ff7700;font-weight:bold;">import</span> StringReader, StringWriter
<span style="color: #ff7700;font-weight:bold;">from</span> javax.<span style="color: #dc143c;">xml</span>.<span style="color: black;">transform</span> <span style="color: #ff7700;font-weight:bold;">import</span> Transformer, TransformerFactory
<span style="color: #ff7700;font-weight:bold;">from</span> javax.<span style="color: #dc143c;">xml</span>.<span style="color: black;">transform</span>.<span style="color: black;">stream</span> <span style="color: #ff7700;font-weight:bold;">import</span> StreamResult, StreamSource
&nbsp;
xml_data = <span style="color: #483d8b;">&quot;&quot;&quot;
&lt;books&gt;
  &lt;book&gt;
    &lt;title&gt;2001 - A Space Odyssey&lt;/title&gt;
    &lt;author&gt;Arthur C Clarke&lt;/author&gt;
  &lt;/book&gt;
  &lt;book&gt;
    &lt;title&gt;I, Robot&lt;/title&gt;
    &lt;author&gt;Isaac Asimov&lt;/author&gt;
  &lt;/book&gt;
  &lt;book&gt;
    &lt;title&gt;Kil'n people&lt;/title&gt;
    &lt;author&gt;David Brin&lt;/author&gt;
  &lt;/book&gt;
&lt;/books&gt;
&quot;&quot;&quot;</span>
&nbsp;
xslt_source = <span style="color: #483d8b;">&quot;&quot;&quot;
&lt;xsl:stylesheet
  xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;
&gt;
&nbsp;
&lt;xsl:template match=&quot;books&quot;&gt;
&lt;html&gt;
  &lt;head&gt;&lt;title&gt;A list of books, transformed into html from xml using xslt and jython.&lt;/title&gt;&lt;/head&gt;
  &lt;body&gt;
    &lt;table border=&quot;1&quot; width=&quot;50%&quot; align=&quot;center&quot;&gt;
      &lt;caption&gt;A list of books, transformed into html from xml using xslt and jython.&lt;/caption&gt;
      &lt;tr&gt;&lt;th&gt;Title&lt;/th&gt;&lt;th&gt;Author&lt;/th&gt;&lt;/tr&gt;
    &lt;xsl:for-each select=&quot;book&quot;&gt;
      &lt;tr&gt;&lt;td&gt;&lt;xsl:value-of select=&quot;title/text()&quot;/&gt;&lt;/td&gt;&lt;td&gt;&lt;xsl:value-of select=&quot;author/text()&quot;/&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;/xsl:for-each&gt;
    &lt;/table&gt;
  &lt;/body&gt;
&lt;/html&gt;
&lt;/xsl:template&gt;
&nbsp;
&lt;/xsl:stylesheet&gt;
&quot;&quot;&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> generate_html<span style="color: black;">&#40;</span>xml_data, xslt_source<span style="color: black;">&#41;</span>:
  transformer = TransformerFactory.<span style="color: black;">newInstance</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">newTransformer</span><span style="color: black;">&#40;</span>StreamSource<span style="color: black;">&#40;</span>StringReader<span style="color: black;">&#40;</span>xslt_source<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
  output_buffer = StringWriter<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  transformer.<span style="color: black;">transform</span><span style="color: black;">&#40;</span>StreamSource<span style="color: black;">&#40;</span>StringReader<span style="color: black;">&#40;</span>xml_data<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>, StreamResult<span style="color: black;">&#40;</span>output_buffer<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> output_buffer.<span style="color: black;">buffer</span>.<span style="color: black;">toString</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> handler<span style="color: black;">&#40;</span>environ, start_response<span style="color: black;">&#41;</span>:
  result = generate_html<span style="color: black;">&#40;</span>xml_data, xslt_source<span style="color: black;">&#41;</span>
  start_response<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;200 Hoopy&quot;</span>, <span style="color: black;">&#91;</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">'content-type'</span>, <span style="color: #483d8b;">'text/html'</span><span style="color: black;">&#41;</span> <span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span>result<span style="color: black;">&#93;</span></pre></div></div>

<p>Happy Transforming!</p>
]]></content:encoded>
			<wfw:commentRss>http://jython.xhaus.com/transforming-with-xslt-on-google-appengine-and-jython/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Jython on Google AppEngine: Why bother?</title>
		<link>http://jython.xhaus.com/jython-on-google-appengine-why-bother/</link>
		<comments>http://jython.xhaus.com/jython-on-google-appengine-why-bother/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 14:40:09 +0000</pubDate>
		<dc:creator>alan.kennedy</dc:creator>
				<category><![CDATA[google appengine]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jython]]></category>
		<category><![CDATA[cloud computing]]></category>
		<category><![CDATA[java scripting]]></category>
		<category><![CDATA[web technology]]></category>

		<guid isPermaLink="false">http://jython.xhaus.com/?p=160</guid>
		<description><![CDATA[Why on earth would you want to run jython applications on Google Appengine?

First off, I must apologise for the flippant nature of the attention grabbing title. I&#8217;m a jython committer, and a jython user, so I believe that there are very good reasons for running jython on Google AppEngine. (You can read how to do [...]]]></description>
			<content:encoded><![CDATA[<p>Why on earth would you want to run <a href="http://www.jython.org">jython</a> applications on <a href="http://appengine.google.com">Google Appengine</a>?</p>
<p><span id="more-160"></span></p>
<p>First off, I must apologise for the flippant nature of the attention grabbing title. I&#8217;m a jython committer, and a jython user, so I believe that there are very good reasons for running jython on Google AppEngine. (You can read how to do so on the modjy wiki: <a href="http://opensource.xhaus.com/projects/modjy/wiki/ModjyGoogleAppEngine">how to run jython applications on Google AppEngine</a>).</p>
<p>The title is essentially a paraphrase of a statement made by a Google AppEngine Evangelist, at a talk about AppEngine that I attended here in Dublin. The speaker was of the opinion that there was no valid reason for running jython on AppEngine, a statement which I couldn&#8217;t let pass.</p>
<p>I think that the core of his reasoning for making that statement was a simple misunderstanding, but a misunderstanding that is common among users who are familiar with python, or users of cpython, but who are not familiar with jython&#8217;s use as a <a href="http://www.javaworld.com/javaworld/jw-11-2007/jw-11-jsr223.html">JVM scripting language</a>. The misunderstanding is that the only reason for running jython is so that one can run python applications on the JVM, using python&#8217;s wealth of &quot;batteries included&quot; APIs. If that is the case, then why bother running jython, when one can simply use the <a href="http://code.google.com/appengine/docs/python/gettingstarted/">cpython support on AppEngine</a> directly?</p>
<p>To explain, when writing a cpython application that processes email, for example, one can make use of the python&#8217;s <a href="http://docs.python.org/library/email.html">email module</a>, which provides a wealth of features for dealing with the many complexities of parsing, processing and generating email messages, MIME, etc. Users of jython can also use the python email modules, since those modules are written in pure python. But since jython runs on the Java Virtual Machine(JVM) and permits seamless integration of java and python code, jython users writing email processing also have the option of using the excellent <a href="http://java.sun.com/products/javamail/">JavaMail APIs</a>, which are just as robust as the pure python modules, and arguably more efficient. So jython users have the best of both worlds: they can use either python APIs or java APIs, with equal ease.</p>
<p>Processing email is perhaps too straightforward an example, in that both python and java have excellent email processing support. But due to the more widespread use of java in the development community in general, java generally has far more support for any given technology need, since there are often multiple options available. A good example of this is cryptography: there is a wealth of <a href="http://www.homeport.org/~adam/crypto/">java cryptography libraries</a> available, including the excellent <a href="bouncycastle.org">Bouncy Castle</a>, <a href="http://www.cryptix.org/">Cryptix</a>, <a href="http://www.flexiprovider.de/">Flexiprovider</a>, etc. The choice of crypto libraries in python is generally narrower, supports less functionality, and is sometimes abandon-ware.</p>
<p>So if one&#8217;s understanding of jython is simply that it is a way to run pure python modules on the JVM, then the above mentioned mis-understanding is forgivable. But it is simply not the case that the primary usage of jython is to run pure python modules: Jython excels as a dynamic/scripting language for the JVM, and permits the use of java APIs, without having to write java code.</p>
<p>In discussion with the Google engineer after the talk, he conceded that there was one possible use case for running jython on AppEngine, namely that of prototyping java applications. In this scenario, applications would</p>
<ol>
<li>Be developed in jython, taking advantage of the enormous productivity increases gained by developing in python</li>
<li>Be translated to java once the functionality of the application is complete</li>
</ol>
<p>My reply to this is: <b>&#8220;Why bother with step 2&#8243;</b>?</p>
<p>If you&#8217;ve got a running application that is fully functional and written in jython, then you don&#8217;t need to translate it to java. You should only consider translating it, or parts of it, into java <b>if you really have to</b>. For example, after profiling your jython application, you may find one or two core pieces that are performance bottlenecks: these are prime candidates for translation to java, to improve performance. But there&#8217;s no reason to translate the rest of the application: maintainability and productivity is best served by simply leaving the jython code exactly as is.</p>
<p>I suppose a part of the reason why this mis-perception of jython has come about is because python is such an excellent language that it is in the unique position of having two completely independent implementations of the language that run on Google AppEngine. But just because both cpython and jython run on AppEngine doesn&#8217;t mean that their usages should be identical. Jython&#8217;s place in the AppEngine ecosystem is primarily as a JVM dynamic language.</p>
<p>So, in summary, jython is more than just a mechanism for running pure python code on the JVM: it is an excellent JVM development platform in it&#8217;s own right.</p>
<p>I hope I&#8217;ve given you some good reasons to consider developing your next Google AppEngine project on jython.</p>
]]></content:encoded>
			<wfw:commentRss>http://jython.xhaus.com/jython-on-google-appengine-why-bother/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>A list of open source HTTP proxies written in Java.</title>
		<link>http://jython.xhaus.com/a-list-of-open-source-http-proxies-written-in-java/</link>
		<comments>http://jython.xhaus.com/a-list-of-open-source-http-proxies-written-in-java/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 15:48:51 +0000</pubDate>
		<dc:creator>alan.kennedy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[web technology]]></category>

		<guid isPermaLink="false">http://jython.xhaus.com/?p=153</guid>
		<description><![CDATA[A few years ago, as an aide to python web programers, I compiled a database of open source HTTP proxies written in python, which became surprisingly popular.
So I&#8217;ve decided to expand the database to encompass the other language that I regularly use, java, and publish a database of open source HTTP proxies written in java.

While [...]]]></description>
			<content:encoded><![CDATA[<p>A few years ago, as an aide to python web programers, I compiled a <a href="http://proxies.xhaus.com/python/">database of open source HTTP proxies written in python</a>, which became surprisingly popular.</p>
<p>So I&#8217;ve decided to expand the database to encompass the other language that I regularly use, java, and publish a <a href="http://proxies.xhaus.com/java/">database of open source HTTP proxies written in java</a>.</p>
<p><span id="more-153"></span></p>
<p>While carrying out a web development project a few years ago, I needed a HTTP proxy to help with development and debugging. Rather than write my own, I decided to research what open source options were already available.</p>
<p>However, Python is such an easy language to write web servers and proxies in that a lot people had written and puiblished HTTP proxies, so making the decision wasn&#8217;t easy. It required a lot of research, which basically meant a code and architectural review of all of the open source python proxies available.</p>
<p>Since most web programmers use a HTTP proxy at some stage, I thought it would be a useful exercise to compile a complete list of the available options, with a comparison table to enable a feature by feature comparison.</p>
<p>The result of that was this <a href="http://proxies.xhaus.com/python/">comparison table of open source HTTP proxies written in python</a>, which became quite popular, because it saved python programmers going through the same complex comparison and review process I had undertaken.</p>
<p>Since I&#8217;m currently working on another proxy-related project, I needed to review available open source HTTP proxies written in java. And I thought I&#8217;d save someone some research time by publishing a similar <a href="http://proxies.xhaus.com/java/">comparison table of open source HTTP proxies in java</a>.</p>
<p>I hope you find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://jython.xhaus.com/a-list-of-open-source-http-proxies-written-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
