<?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>.zugiart &#187; geeky</title>
	<atom:link href="http://www.zugiart.com/category/geeky/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zugiart.com</link>
	<description>Software Engineering, buddhism, and everything else in between.</description>
	<lastBuildDate>Mon, 09 Jan 2012 05:50:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>mount.cifs Centos5 and Windows Server 2003</title>
		<link>http://www.zugiart.com/2012/01/mount-cifs-centos5-and-windows-server-2003/</link>
		<comments>http://www.zugiart.com/2012/01/mount-cifs-centos5-and-windows-server-2003/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 05:06:53 +0000</pubDate>
		<dc:creator>zen</dc:creator>
				<category><![CDATA[geeky]]></category>
		<category><![CDATA[cifs]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mount]]></category>
		<category><![CDATA[server2003]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.zugiart.com/?p=1805</guid>
		<description><![CDATA[We were trying to mount a remote directory shared by Windows Server 2003 SP2 machine using CIFS, or Common internet filesystem,&#160;from a Linux CentOS5 machine and we couldn&#8217;t get it going. So then I went on and scoured info from the net, until finally I stumbled upon all this info.&#160;In many post/pages on the net, [...]]]></description>
			<content:encoded><![CDATA[<p>We were trying to mount a remote directory shared by Windows Server 2003 SP2 machine using CIFS, or Common internet filesystem,&nbsp;from a Linux CentOS5 machine and we couldn&#8217;t get it going. So then I went on and scoured info from the net, until finally I stumbled upon all this info.&nbsp;In many post/pages on the net, people usually only tell you either information on Windows side, or information on Linux side, I&#8217;ll try to post both of my finding.&nbsp;</p>
<p><span style="font-size: large;">Windows Server authentication configuration</span></p>
<p style="padding-left: 30px;">It is important to know what specific protocol is being used to authenticate the client that tries to access the shared folder (e.g. NTLM or NTLMv2 ?). Especially in a corporate setting, the authentication setting is quite key and is strongly enforced. I figure out the settings when I stumble upon the guide to <a href="http://www.imss.caltech.edu/node/395">Enable NTLMv2 on Windows Server 2003</a>&nbsp;(from which I link the image below without prior consent <img src='http://www.zugiart.com/main/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</p>
<p style="padding-left: 30px;">To do this, you go to Start &gt; Program Files &gt; Administration Tools &gt; Local Security Policy</p>
<p style="padding-left: 30px;"><img src="http://www-test.imss.caltech.edu/sites/default/files/legacy/ntlmv2-w2k3sp1-02.jpg" alt="Enabling NTLMv2 On Windows Server 2003" width="600" height="304" /></p>
<p style="padding-left: 30px;">The guide shows how to set Windows Server 2003 to use NTLMv2, but in knowing this, you will know what the configuration is on the server that you are trying to access/mount into the linux box. If you are the sysadmin of the windows server, then all is well. But otherwise, you know how and what to ask from the sysadmin.&nbsp;</p>
<p><span style="font-size: large;">Using mount.cifs in /etc/fstab</span></p>
<p style="padding-left: 30px;">As we know, <a href="http://en.wikipedia.org/wiki/Fstab">/etc/fstab</a>&nbsp;is used to specify the filesystem mounting. Mount directive specified here will be executed during system startup, so whatever you put in here will persist across reboots. The command <strong>mount -a</strong>&nbsp;forces Linux to reload the config.</p>
<p style="padding-left: 30px;">Information about CIFS mount can be found in the man page. The command <a href="http://linux.die.net/man/8/mount.cifs">man mount.cifs</a>&nbsp;reveals all that you need to know about CIFS mount in Linux.</p>
<p style="padding-left: 30px;">The below is extracted from Wikipedia, which actually provides the working configuration that got our problem solved:</p>
<pre class="de1" style="font-family: monospace, Courier !important; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; background-color: #f9f9f9; font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-bottom: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: top; font-size: 13px; text-align: left; border-image: initial; padding-left: 30px; border: 0px none white;"><span class="co0" style="color: #666666; font-style: italic;"># mounting cifs</span>
<span class="sy0" style="font-weight: bold;">//</span>pingu<span class="sy0" style="font-weight: bold;">/</span>ashare  <span class="sy0" style="font-weight: bold;">/</span>store<span class="sy0" style="font-weight: bold;">/</span>pingu cifs <span class="re2" style="color: #007800;">credentials</span>=<span class="sy0" style="font-weight: bold;">/</span>root<span class="sy0" style="font-weight: bold;">/</span>smbpass.txt,<span style="color: #007800;">sec</span>=ntlmv2 <span class="nu0">0</span> <span class="nu0">0</span></pre>
<p style="padding-left: 30px;">&nbsp;</p>
<p style="padding-left: 30px;"><strong><span style="font-size: medium;">credentials=/path/to/file</span></strong></p>
<p style="padding-left: 30px;">The option can be used to specify the file that contains the credential information. In this case, the file may look like this:</p>
<pre class="de1" style="font-family: monospace, Courier !important; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; background-color: #f9f9f9; font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-bottom: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: top; font-size: 13px; text-align: left; border-image: initial; padding-left: 30px; border: 0px none white;"><span class="re2" style="color: #007800;">username</span>=&lt;username&gt;
</pre>
<pre class="de1" style="font-family: monospace, Courier !important; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; background-color: #f9f9f9; font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-bottom: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: top; font-size: 13px; text-align: left; border-image: initial; padding-left: 30px; border: 0px none white;">
<pre class="de1" style="font-family: monospace, Courier !important; border-image: initial; font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-bottom: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: top; padding: 0px; border: 0px none white;"><span class="re2" style="color: #007800;">password</span>=&lt;password&gt;</pre>
</pre>
<p style="padding-left: 30px;">The nice thing with this approach is, as the creds are stored in the file, even though it is in clear text, you can protect it as usual with the good ol&#8217; filesystem security. You may put it in /root, or in any other directory and set the appropriate permission. On top of <strong>username</strong>&nbsp;and <strong>password</strong>, you can also specify <strong>domain</strong>&nbsp;in the credential file. However, Windows server usually assumes a default domain (as the server should be registerer against a domain controller). So usually, the domain part is not needed.</p>
<p style="padding-left: 30px;"><span style="font-size: medium;"><strong>sec=ntlmv2</strong></span></p>
<p style="padding-left: 30px;">Credentials&nbsp;are not the only option you can use. If you try the above and fail, know that CIFS support different authentication protocol. So check the server side config, choose the right auth type try it on in <strong>/etc/fstab</strong>, do <strong>mount -a</strong> and see what happens.&nbsp;</p>
<p><span style="font-size: large;">Debugging</span></p>
<p style="padding-left: 30px;">To see what the OS is doing you can try <strong>dmesg | less</strong></p>
<p style="padding-left: 30px;">To see the CIFS mount status, you can try <strong>cat /proc/fs/cifs/DebugData</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zugiart.com/2012/01/mount-cifs-centos5-and-windows-server-2003/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generic Python XML-RPC CLI Client (With apache extension support)</title>
		<link>http://www.zugiart.com/2011/10/generic-python-xml-rpc-cli-client-with-apache-extension-support/</link>
		<comments>http://www.zugiart.com/2011/10/generic-python-xml-rpc-cli-client-with-apache-extension-support/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 05:10:16 +0000</pubDate>
		<dc:creator>zen</dc:creator>
				<category><![CDATA[geeky]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[xml-rpc]]></category>

		<guid isPermaLink="false">http://www.zugiart.com/?p=1757</guid>
		<description><![CDATA[This code snippet is a generic python xml-rpc client that supports custom extensions. This is tested with pytnon 2.6 &#8211; usage is as follow: Interactive mode # run the client like so: python client.py --url=http://serverUrl:port/path/to/serverPoint &#160; # in interactive mode, you see the CLI interface like so: &#91;timestamp&#93; http://serverUrl:port/path/to/serverPoint xmlrpc &#62;&#62; helloWorld&#40;&#34;hello zen&#34;&#41; hello zen [...]]]></description>
			<content:encoded><![CDATA[<p>This code snippet is a generic python xml-rpc client that supports custom extensions. This is tested with pytnon 2.6 &#8211; usage is as follow: </p>
<h3>Interactive mode</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># run the client like so:</span>
python client.py <span style="color: #660033;">--url</span>=http:<span style="color: #000000; font-weight: bold;">//</span>serverUrl:port<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>serverPoint
&nbsp;
<span style="color: #666666; font-style: italic;"># in interactive mode, you see the CLI interface like so: </span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>timestamp<span style="color: #7a0874; font-weight: bold;">&#93;</span> http:<span style="color: #000000; font-weight: bold;">//</span>serverUrl:port<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>serverPoint
xmlrpc <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> helloWorld<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;hello zen&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
hello zen <span style="color: #666666; font-style: italic;">#&lt;- this is the response from the server</span></pre></div></div>

<h3>Oneliner mode</h3>
<p>You can invoke the client as a one-liner, by passing the xmlrpc function to be called using the &#8211;cmd option. Like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">python client.py <span style="color: #660033;">--url</span>=http:<span style="color: #000000; font-weight: bold;">//</span>serverUrl:port<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>serverPoint <span style="color: #660033;">--cmd</span>=<span style="color: #ff0000;">'helloWorld(&quot;hello zen&quot;)'</span></pre></div></div>

<p>Which is quite powerful, because now we can include this as part of shell scripts that can invoke/leverage existing xml-rpc service. </p>
<h2>client.py script</h2>
<p>The <b>CustomXmlRpcExtensionTransport</b> is what allows xml-rpc extensions to be parsed properly via the client. Here, (limited) support for <a href="http://ws.apache.org/xmlrpc/types.html">Apache xml-rpc extension data types</a> is added. Specifically &#8211; ex:nil as None; ex:i2, ex:i4, ex:i8 as numbers/int. This approach does not override original xmlrpclib implementation, but rather extends it.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">xmlrpclib</span> <span style="color: #ff7700;font-weight:bold;">import</span> Transport, ServerProxy
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">readline</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">cmd</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">traceback</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">pprint</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">optparse</span> <span style="color: #ff7700;font-weight:bold;">import</span> OptionParser
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> CustomXmlRpcExtensionTransport<span style="color: black;">&#40;</span>Transport<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    This Transport allows for the parser's dispatch object to be modified to cater for additional 
    extension tags. In case the client need to be extend to interoperate with other provider, 
    such as apache xml-rpc service points. 
    see also http://bugs.python.org/issue8792
    &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> getparser<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #dc143c;">parser</span>, unmarshaller = Transport.<span style="color: black;">getparser</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
        dispatch = unmarshaller.<span style="color: black;">dispatch</span>.<span style="color: #dc143c;">copy</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        unmarshaller.<span style="color: black;">dispatch</span> = dispatch
        <span style="color: #808080; font-style: italic;"># Now we can add custom types</span>
        dispatch<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;ex:nil&quot;</span><span style="color: black;">&#93;</span> = dispatch<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;nil&quot;</span><span style="color: black;">&#93;</span>
        dispatch<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;ex:i2&quot;</span><span style="color: black;">&#93;</span>  = dispatch<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;int&quot;</span><span style="color: black;">&#93;</span>
        dispatch<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;ex:i4&quot;</span><span style="color: black;">&#93;</span>  = dispatch<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;int&quot;</span><span style="color: black;">&#93;</span>
        dispatch<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;ex:i8&quot;</span><span style="color: black;">&#93;</span>  = dispatch<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;int&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">parser</span>, unmarshaller                                                                                                                                                                                                                                                                                                                              
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> XmlRpcClientConsole<span style="color: black;">&#40;</span><span style="color: #dc143c;">cmd</span>.<span style="color: black;">Cmd</span><span style="color: black;">&#41;</span>: 
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Generic xml rpc client console. Allows for seamlessly working with compatible xml-rpc server.
    &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, url<span style="color: black;">&#41;</span>:
        <span style="color: #dc143c;">cmd</span>.<span style="color: black;">Cmd</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">url</span> = url<span style="color: #66cc66;">;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">server</span> = ServerProxy<span style="color: black;">&#40;</span>url, transport=CustomXmlRpcExtensionTransport<span style="color: black;">&#40;</span>use_datetime=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#verbose=True,)</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">pp</span> = <span style="color: #dc143c;">pprint</span>.<span style="color: black;">PrettyPrinter</span><span style="color: black;">&#40;</span>indent=<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">updatePrompt</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> updatePrompt<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">prompt</span> = <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>[%s] %s<span style="color: #000099; font-weight: bold;">\n</span>xmlrpc &gt;&gt; &quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span><span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%Y.%m.%d %H:%M:%S&quot;</span><span style="color: black;">&#41;</span>,<span style="color: #008000;">self</span>.<span style="color: black;">url</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> default<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, line<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            result=<span style="color: #008000;">None</span>
            <span style="color: #ff7700;font-weight:bold;">exec</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;result=self.server.%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">pp</span>.<span style="color: #dc143c;">pprint</span><span style="color: black;">&#40;</span>result<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># default formatter: pretty print the resultant data</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">Exception</span>, ex:
            <span style="color: #dc143c;">traceback</span>.<span style="color: black;">print_exc</span><span style="color: black;">&#40;</span>ex<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: #66cc66;">;</span> <span style="color: #008000;">self</span>.<span style="color: black;">updatePrompt</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> do_help<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,line<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;-------------------------------------&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;GENERIC XML RPC CLIENT CONSOLE - HELP&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;-------------------------------------&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Simply type in the function name on the xml-rpc service end, like you would&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;on any good ol' python program. For example, if the other side has a method&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;called helloWorld(strparam), you can invoke it like so:&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;... xmlrpc &gt;&gt; helloWorld('hello zen')&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;the client is therefore completely transparent and exposes the full capabilities&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;of the server end. have fun.&quot;</span> <span style="color: #808080; font-style: italic;"># -zen</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> 
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #dc143c;">parser</span> = OptionParser<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&quot;&quot;Generic XML RPC Client console&quot;&quot;&quot;</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">parser</span>.<span style="color: black;">add_option</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;--url&quot;</span>, dest=<span style="color: #483d8b;">&quot;url&quot;</span>, <span style="color: #008000;">help</span>=<span style="color: #483d8b;">&quot;The XML RPC service URL to connect&quot;</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">parser</span>.<span style="color: black;">add_option</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;--cmd&quot;</span>, dest=<span style="color: #483d8b;">&quot;cmd&quot;</span>, <span style="color: #008000;">help</span>=<span style="color: #483d8b;">&quot;A one-off command to execute&quot;</span><span style="color: black;">&#41;</span>
    <span style="color: black;">&#40;</span>options, args<span style="color: black;">&#41;</span> = <span style="color: #dc143c;">parser</span>.<span style="color: black;">parse_args</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> options.<span style="color: black;">url</span> == <span style="color: #008000;">None</span> :
        <span style="color: #dc143c;">parser</span>.<span style="color: black;">print_help</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
    console = XmlRpcClientConsole<span style="color: black;">&#40;</span>options.<span style="color: black;">url</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> options.<span style="color: #dc143c;">cmd</span> <span style="color: #66cc66;">!</span>= <span style="color: #008000;">None</span> :
        <span style="color: #808080; font-style: italic;"># run the cmd and bomb out</span>
        console.<span style="color: black;">default</span><span style="color: black;">&#40;</span>options.<span style="color: #dc143c;">cmd</span><span style="color: black;">&#41;</span>
        <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;for help using the console, type 'help'&quot;</span>
        <span style="color: #808080; font-style: italic;"># enter into cmd loop for interactive session</span>
        console.<span style="color: black;">cmdloop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zugiart.com/2011/10/generic-python-xml-rpc-cli-client-with-apache-extension-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>apache xml-rpc handling null/nil</title>
		<link>http://www.zugiart.com/2011/07/apache-xml-rpc-handle-null-nil/</link>
		<comments>http://www.zugiart.com/2011/07/apache-xml-rpc-handle-null-nil/#comments</comments>
		<pubDate>Sun, 17 Jul 2011 15:37:30 +0000</pubDate>
		<dc:creator>zen</dc:creator>
				<category><![CDATA[geeky]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[xml-rpc]]></category>

		<guid isPermaLink="false">http://www.zugiart.com/?p=1685</guid>
		<description><![CDATA[If you have used xml-rpc extensively, you will know that one of the most annoying aspect of XML-RPC is the fact that NULL values are not supported as part of the core spec. This is an issue, because NULL is such a key concept in the mainstream languages such as Python, Java and .NET &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>If you have used xml-rpc extensively, you will know that one of the most annoying aspect of XML-RPC is the fact that NULL values are not supported as part of the core spec. This is an issue, because NULL is such a key concept in the mainstream languages such as Python, Java and .NET &#8211; not to mention that NULL is also a supported data type in mainstream relational DB such as MySQL and Postgres. This means that if you write an xml-rpc service that publishes a data service on top of a database, your code have to handle what to do with NULL values that are stored in the db.</p>
<p>For this, we rely on the vendor extension. Now, Python&#8217;s extension uses &lt;nil /&gt;. Jayrock&#8217;s .NET xml rpc extension for null is also &lt;nil /&gt;. However for Apache&#8217;s xml-rpc implementation, the null extension is expressed as &lt;ex:nil /&gt;. If you have stumbled across this, fear not. You CAN tell apache xml-rpc to use both &lt;nil /&gt; and &lt;ex:nil /&gt; for Null:</p>
<h3>XmlRpcTypeNil : The  implementation</h3>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.ws.commons.util.NamespaceContextImpl</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.xmlrpc.common.TypeFactoryImpl</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.xmlrpc.common.XmlRpcController</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.xmlrpc.common.XmlRpcStreamConfig</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.xmlrpc.parser.NullParser</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.xmlrpc.parser.TypeParser</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.xmlrpc.serializer.NullSerializer</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.xmlrpc.serializer.TypeSerializer</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.xml.sax.SAXException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * This class extends Type Factory Impl to provide concrete type factory for handling
 * Null values. In this case the tag comparison uses NullSerializer.NIL_TAG as opposed
 * to EX_NIL_TAG
 *
 * @author zsugiart
 *
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> XmlRpcTypeNil <span style="color: #000000; font-weight: bold;">extends</span> TypeFactoryImpl <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> XmlRpcTypeNil<span style="color: #009900;">&#40;</span>XmlRpcController pController<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>pController<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> TypeParser getParser<span style="color: #009900;">&#40;</span>XmlRpcStreamConfig pConfig, NamespaceContextImpl pContext, <span style="color: #003399;">String</span> pURI, <span style="color: #003399;">String</span> pLocalName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>NullSerializer.<span style="color: #006633;">NIL_TAG</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>pLocalName<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> NullSerializer.<span style="color: #006633;">EX_NIL_TAG</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>pLocalName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> NullParser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">getParser</span><span style="color: #009900;">&#40;</span>pConfig, pContext, pURI, pLocalName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> TypeSerializer getSerializer<span style="color: #009900;">&#40;</span>XmlRpcStreamConfig pConfig, <span style="color: #003399;">Object</span> pObject<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> SAXException <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>pObject <span style="color: #000000; font-weight: bold;">instanceof</span> XmlRpcTypeNil<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> NullSerializer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">getSerializer</span><span style="color: #009900;">&#40;</span>pConfig, pObject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Client &amp; Server configuration</h3>
<p>The most important thing here is the <a href="http://people.apache.org/~jochen/xmlrpc/apidocs/org/apache/xmlrpc/common/XmlRpcController.html">XmlRpcController&#8217;s setTypeFactory method</a>. Also remember that both XmlRpcClient and XmlRpcServer extends from XmlRpcController. Which means:</p>
<p>On the client end..</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">XmlRpcClientConfigImpl config <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlRpcClientConfigImpl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
config.<span style="color: #006633;">setServerURL</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://xmlrpc.url&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
XmlRpcClient client <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlRpcClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
client.<span style="color: #006633;">setTypeFactory</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> XmlRpcTypeNil<span style="color: #009900;">&#40;</span>client<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// yes it's this easy!</span>
client.<span style="color: #006633;">setConfig</span><span style="color: #009900;">&#40;</span>config<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// client.execute(...)</span></pre></div></div>

<p>And on the server end&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">XmlRpcServer xmlRpcServer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">webServer</span>.<span style="color: #006633;">getXmlRpcServer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// or however it is setup</span>
xmlRpcServer.<span style="color: #006633;">setTypeFactory</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> XmlRpcTypeNil<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">xmlRpcServer</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Conclusion</h3>
<p>This is such a simple trick, but it took me a while to work out how to work the apache xml-rpc API to make it do this. The benefit is also quite significant, with this implementation alone, we now can enable NULL data to be transported transparently between xml-rpc services implemented in Python, Java, .NET and other implementation that supports &lt;nil /&gt; for Null.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zugiart.com/2011/07/apache-xml-rpc-handle-null-nil/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Classic ASP: cross domain json-rpc proxy controller</title>
		<link>http://www.zugiart.com/2011/07/classic-asp-cross-domain-json-rpc-proxy-controller/</link>
		<comments>http://www.zugiart.com/2011/07/classic-asp-cross-domain-json-rpc-proxy-controller/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 01:26:37 +0000</pubDate>
		<dc:creator>zen</dc:creator>
				<category><![CDATA[geeky]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[json-rpc]]></category>
		<category><![CDATA[notes]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[rpc]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://www.zugiart.com/?p=1676</guid>
		<description><![CDATA[A controller written in classic ASP / VBScript to proxy json-rpc request to a remote service point.]]></description>
			<content:encoded><![CDATA[<p>Through some sheer bad luck, I am now working on restructuring a system written in classic ASP. There&#8217;s a json-rpc service point on a separate domain that the app could consume, and I wanted it to consume it rather than reinventing the functionality again on the system. As much as I hate VBscript, ASP and IIS, I went googling and figure out a way forward.</p>
<p>Basically, it&#8217;s difficult to integrate JSON-RPC into a classic ASP system. However, it is very easy to integrate it into jQuery. Problem is, the service existed on an external domain, so what I needed is a proxy asp controller that will forward json-rpc request &amp; response back and forth between the local client and the external json-rpc point.</p>
<p><a href="http://www.zugiart.com/main/wp-content/uploads/2011/07/proxy-json-rpc.png"><img class="aligncenter size-full wp-image-1678" title="proxy-json-rpc" src="http://www.zugiart.com/main/wp-content/uploads/2011/07/proxy-json-rpc.png" alt="" width="605" height="143" /></a></p>
<p>One word of warning though: I haven&#8217;t tested this code extensively so use it at your own risk. &#8211; anyway here&#8217;s the controller script:</p>

<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span><span style="color: #006600; font-weight: bold;">@</span> LANGUAGE<span style="color: #006600; font-weight: bold;">=</span>VBScript <span style="color: #000000; font-weight: bold;">%&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;%</span>
<span style="color: #008000;">'# ==========================================================================================================</span>
<span style="color: #008000;">'#</span>
<span style="color: #008000;">'# JSON-RPC Proxy ASP [classic asp]</span>
<span style="color: #008000;">'#</span>
<span style="color: #008000;">'# This asp page/component will forward the json-rpc request to an existing json-rpc service </span>
<span style="color: #008000;">'# and transparently forward the result back to the caller via the HTTP response. </span>
<span style="color: #008000;">'# </span>
<span style="color: #008000;">'# @author Zen Sugiarto</span>
<span style="color: #008000;">'# ==========================================================================================================</span>
&nbsp;
<span style="color: #008000;">'# configuration</span>
<span style="color: #008000;">'# -------------</span>
&nbsp;
<span style="color: #008000;">'# This URl points to the json-rpc service point. </span>
<span style="color: #008000;">'# if your system uses a different configuration mechanism, please adjust it accordingly</span>
<span style="color: #008000;">'#</span>
<span style="color: #990099; font-weight: bold;">Dim</span> servicePointUrl
servicePointUrl <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;http://url-to-json-rpc/point&quot;</span>
&nbsp;
<span style="color: #008000;">'# main body of execution</span>
<span style="color: #008000;">'# ----------------------</span>
&nbsp;
<span style="color: #008000;">'# this function allows for msg to be logged into a log file so we can trace / analyze the traffic.</span>
<span style="color: #0000ff; font-weight: bold;">Sub</span> logInfo <span style="color: #006600; font-weight:bold;">&#40;</span>message<span style="color: #006600; font-weight:bold;">&#41;</span>
	logFile <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #990099; font-weight: bold;">Server</span>.<span style="color: #330066;">MapPath</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;event.log&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span>
    <span style="color: #990099; font-weight: bold;">Const</span> ForWriting   <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #800000;">2</span>
    <span style="color: #990099; font-weight: bold;">Const</span> ForAppending <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #800000;">8</span>
    <span style="color: #990099; font-weight: bold;">Set</span> fs <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #330066;">CreateObject</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;Scripting.FileSystemObject&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span>
    <span style="color: #990099; font-weight: bold;">If</span> fs.<span style="color: #330066;">FileExists</span><span style="color: #006600; font-weight:bold;">&#40;</span>logFile<span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #990099; font-weight: bold;">Then</span>
        <span style="color: #990099; font-weight: bold;">Set</span> logFile <span style="color: #006600; font-weight: bold;">=</span> fs.<span style="color: #330066;">OpenTextFile</span><span style="color: #006600; font-weight:bold;">&#40;</span>logFile, ForAppending<span style="color: #006600; font-weight:bold;">&#41;</span>
    <span style="color: #990099; font-weight: bold;">Else</span>
        <span style="color: #990099; font-weight: bold;">Set</span> logFile <span style="color: #006600; font-weight: bold;">=</span> fs.<span style="color: #9900cc;">CreateTextFile</span><span style="color: #006600; font-weight:bold;">&#40;</span>logFile, <span style="color: #0000ff; font-weight: bold;">True</span><span style="color: #006600; font-weight:bold;">&#41;</span>
    <span style="color: #990099; font-weight: bold;">End</span> <span style="color: #990099; font-weight: bold;">If</span>    
    logFile.<span style="color: #9900cc;">WriteLine</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #330066;">Now</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> vbTab <span style="color: #006600; font-weight: bold;">&amp;</span> message<span style="color: #006600; font-weight:bold;">&#41;</span>
    logFile.<span style="color: #330066;">Close</span>
    <span style="color: #990099; font-weight: bold;">Set</span> logFile <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">nothing</span>
    <span style="color: #990099; font-weight: bold;">Set</span> fs <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">nothing</span>
<span style="color: #990099; font-weight: bold;">End</span> <span style="color: #0000ff; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #008000;">' we read all of the POST data, json-rpc supports get, but this component only does POST for now.</span>
<span style="color: #008000;">' the safe array read from .BinaryRead is then converted into string, which is then sent into the </span>
<span style="color: #008000;">' forwarding HTTP request object to the bus.</span>
<span style="color: #990099; font-weight: bold;">dim</span> safeArray, <span style="color: #330066;">totalBytes</span>
<span style="color: #330066;">totalBytes</span><span style="color: #006600; font-weight: bold;">=</span><span style="color: #990099; font-weight: bold;">Request</span>.<span style="color: #330066;">TotalBytes</span>
safeArray<span style="color: #006600; font-weight: bold;">=</span><span style="color: #990099; font-weight: bold;">Request</span>.<span style="color: #330066;">BinaryRead</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #330066;">totalBytes</span><span style="color: #006600; font-weight:bold;">&#41;</span>
jsonBody <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;&quot;</span>
<span style="color: #990099; font-weight: bold;">For</span> n <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #800000;">1</span> <span style="color: #990099; font-weight: bold;">To</span> LenB<span style="color: #006600; font-weight:bold;">&#40;</span>safeArray<span style="color: #006600; font-weight:bold;">&#41;</span>
  jsonBody <span style="color: #006600; font-weight: bold;">=</span> jsonBody <span style="color: #006600; font-weight: bold;">&amp;</span> Chr<span style="color: #006600; font-weight:bold;">&#40;</span>AscB<span style="color: #006600; font-weight:bold;">&#40;</span>MidB<span style="color: #006600; font-weight:bold;">&#40;</span>safeArray,n,<span style="color: #800000;">1</span><span style="color: #006600; font-weight:bold;">&#41;</span><span style="color: #006600; font-weight:bold;">&#41;</span><span style="color: #006600; font-weight:bold;">&#41;</span>
<span style="color: #990099; font-weight: bold;">Next</span>
&nbsp;
<span style="color: #008000;">' create the HTTP request object to be forwarded into the service bus, </span>
<span style="color: #008000;">' inject the json body in.</span>
<span style="color: #990099; font-weight: bold;">Dim</span> httpreq
<span style="color: #990099; font-weight: bold;">Set</span> httpreq <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #990099; font-weight: bold;">Server</span>.<span style="color: #330066;">CreateObject</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;MSXML2.XMLHTTP&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span>
httpreq.<span style="color: #330066;">open</span> <span style="color: #cc0000;">&quot;POST&quot;</span>,servicePointUrl, <span style="color: #0000ff; font-weight: bold;">False</span>
httpreq.<span style="color: #9900cc;">setRequestHeader</span> <span style="color: #cc0000;">&quot;Content-Type&quot;</span>,<span style="color: #cc0000;">&quot;application/json-rpc&quot;</span>
<span style="color: #008000;">'httpreq.setRequestHeader &quot;Cookie&quot;,Request.Cookies</span>
&nbsp;
<span style="color: #008000;">' Send out the request</span>
<span style="color: #990099; font-weight: bold;">On</span> <span style="color: #990099; font-weight: bold;">Error</span> <span style="color: #990099; font-weight: bold;">Resume</span> <span style="color: #990099; font-weight: bold;">Next</span>
httpreq.<span style="color: #330066;">send</span> jsonBody
logInfo<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;REQUEST={ queryString=&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #990099; font-weight: bold;">Request</span>.<span style="color: #330066;">QueryString</span> <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;, cookies=&quot;</span><span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #990099; font-weight: bold;">Request</span>.<span style="color: #330066;">Cookies</span> <span style="color: #006600; font-weight: bold;">&amp;</span><span style="color: #cc0000;">&quot;, totalBytes=&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #990099; font-weight: bold;">Request</span>.<span style="color: #330066;">TotalBytes</span> <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;, jsonBody=&quot;</span><span style="color: #006600; font-weight: bold;">&amp;</span>jsonBody<span style="color: #006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color: #008000;">' TODO: implement error handling</span>
&nbsp;
<span style="color: #008000;">' get response text, set mime type to application/json-rpc and write the bus response to the response stream</span>
<span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">ContentType</span><span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;application/json-rpc&quot;</span>
<span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">Write</span><span style="color: #006600; font-weight:bold;">&#40;</span>httpreq.<span style="color: #9900cc;">responseText</span><span style="color: #006600; font-weight:bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>

<p>And now I can skip the whole shitty ASP architecture altogether and just go straight to web2.0 style programming. The controller will also log and output the request into a file called event.log. I haven&#8217;t finished writing a proper log rotator and whatnot with it. Just comment out the logInfo part if you&#8217;re not using it. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.zugiart.com/2011/07/classic-asp-cross-domain-json-rpc-proxy-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install/backsync between source and installation directory</title>
		<link>http://www.zugiart.com/2011/05/install-backsync-from-source-an-installation-directory/</link>
		<comments>http://www.zugiart.com/2011/05/install-backsync-from-source-an-installation-directory/#comments</comments>
		<pubDate>Wed, 18 May 2011 05:49:55 +0000</pubDate>
		<dc:creator>zen</dc:creator>
				<category><![CDATA[geeky]]></category>
		<category><![CDATA[notes]]></category>

		<guid isPermaLink="false">http://www.zugiart.com/?p=1660</guid>
		<description><![CDATA[Have this script in my collection since few years back, I thought I should share it. #@ #@ ======================================================================================= #@ SYNCINSTALL.SH #@ Zen Sugiarto 25-03-2009 #@ ======================================================================================= #@ This is a simple script to assist in syncing SOURCE DIR TARGET INSTALL DIR: #@ #@ SYNC PUSH - pushes source file INTO installation dir #@ SYNC [...]]]></description>
			<content:encoded><![CDATA[<p>Have this script in my collection since few years back, I thought I should share it.</p>
<pre lang="bash" class='code'>
#@
#@ =======================================================================================
#@ SYNCINSTALL.SH
#@ Zen Sugiarto 25-03-2009
#@ =======================================================================================
#@ This is a simple script to assist in syncing SOURCE DIR <-> TARGET INSTALL DIR:
#@
#@ SYNC PUSH - pushes source file INTO installation dir
#@ SYNC PULL - pulls update from target installation dir back INTO the source dir.
#@

# override specific logging logic here
function log()
{
	echo "[`date +'%Y%m%d %H:%M:%S'`] $1"
}

#@
#@ cmd: push
#@ this is used to install files from the source directory to the installation dir
#@ assuming that both of them would have the same structure. New files will be added,
#@ and backup automatically done on the files in the installation dir.
#@ push preserves permission of the target file.
function cmd_push() #$1=srcDir #$2=installDir
{
	_srcDir=$1
	_installDir=$2
	log "installing from:$_srcDir -> to:$_installDir"
	if [ ! -d $_srcDir ]; then log "$_srcDir does not exist! "; return 1; fi
	if [ ! -d $_installDir ]; then log "$_installDir does not exist!"; return 1; fi
	rsync -avz --backup --suffix=.backup --exclude=".svn" --perms "$_srcDir/" "$_installDir"
}

#@
#@ cmd: pull
#@ when syncing back, a different logic applies. This is used mostly in cases
#@ where hot changes to a file is done on the installation directory and it needs
#@ to be synced back to the working directory. In this case, we only want to sync
#@ files IF it existed on the source directory.
#@ push preserves permission of the source files
function cmd_pull() #$1=srcDir #$2=installDir
{
	_srcDir=$1
	_installDir=$2
	log "backsync to:$_srcDir <- from:$_installDir"
	if [ ! -d $_srcDir ]; then log "$_srcDir does not exist! "; return 1; fi
	if [ ! -d $_installDir ]; then log "$_installDir does not exist!"; return 1; fi
	if [ -e .hitlist.txt ]; then rm .hitlist.txt; fi

	pushd "$_srcDir" &#038;> /dev/null
	for f in $(find . | grep -v .svn ); do
		fname="${f:0}";
		# construct hitlist based on files in src dir
		if [ -e "$fname" ] &#038;&#038; [ ! -d "$fname" ]; then echo "$fname" >> .hitlist.txt; fi
	done
	rsync -avz --update --files-from=$PWD/.hitlist.txt --perms $_installDir .
	rm .hitlist.txt
	popd &#038;> /dev/null
}

#@
#@ cmd: usage
#@ print short msg on how to use the script
function cmd_usage()
{
	echo " "
	echo "[USAGE]"
	echo "    $0 <cmd>
<params...>"
	echo
	echo "[EXAMPLE]"
	echo "    $0 push /path/to/srcDir /path/to/installDir"
	echo
	echo "[COMMANDS]"
	cat $0 | grep "function cmd_" | grep -v "grep" | cut -d'_' -f2
	echo
}

#@
#@ cmd: help
#@ print help messages
function cmd_help()
{
	cat $0 | grep "#@" | grep -v "cat \$0 \| grep #@" | cut -d'@' -f2-100
}

# ======================================================================================= // MAIN BLOCK

if [ "$1" == "" ]; then echo "not enough arguments"; cmd_usage; exit 1; fi
cmd_$1 $2 $3 $4
if [ $? == 127 ]; then
	echo "no such command: $1";
	cmd_usage
fi
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.zugiart.com/2011/05/install-backsync-from-source-an-installation-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>N900 in Japan via bmobile. At last.</title>
		<link>http://www.zugiart.com/2011/05/n900-in-japan-via-bmobile/</link>
		<comments>http://www.zugiart.com/2011/05/n900-in-japan-via-bmobile/#comments</comments>
		<pubDate>Thu, 12 May 2011 15:16:13 +0000</pubDate>
		<dc:creator>zen</dc:creator>
				<category><![CDATA[geeky]]></category>
		<category><![CDATA[thoughts]]></category>
		<category><![CDATA[bmobile]]></category>
		<category><![CDATA[japan]]></category>
		<category><![CDATA[n900]]></category>

		<guid isPermaLink="false">http://www.zugiart.com/2011/05/n900-in-japan-via-bmobile-hello-japan/</guid>
		<description><![CDATA[This is posted from my n900 via bmobile / docomo FOMA network. Yes, this is the very same n900 that I bought in Australia. No softbank bullshit. Deal &#38; pricing data-only: no sms or phone calls. which sucks. but at least i can do skype IM, browse facebook, upload photo to facebook, sync my calendar [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.zugiart.com/main/wp-content/uploads/2011/05/20110512_003.jpg" alt="" /></p>
<p>This is posted from my n900 via bmobile / docomo FOMA network. Yes, this is the very same n900 that I bought in Australia. No softbank bullshit. <img src='http://www.zugiart.com/main/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Deal &amp; pricing</h3>
<ul>
<li><strong>data-only</strong>:<span style="font-weight: normal;"> no sms or phone calls. which sucks. but at least i can do skype IM, browse facebook, upload photo to facebook, sync my calendar and so on. It&#8217;s not bad in that regard. The speed is capped at 300kbps up&amp;down and you can&#8217;t do streaming. This mans </span>you can&#8217;t do skype call<span style="font-weight: normal;"> either.<br />
</span><br />
<span style="font-weight: normal;"> </span></li>
<li><strong>pricing</strong>: <span style="font-weight: normal;"><a href="http://www.bmobile.ne.jp/sim/charge_plan.html">http://www.bmobile.ne.jp/sim/charge_plan.html </a><a href="http://www.bmobile.ne.jp/sim/charge_plan.html"></a>
<p></span></li>
<li><strong>purchase</strong><span style="font-weight: normal;">: </span><span style="font-weight: normal;">Note that for the 1 month prepaid SIM, you need to order online from <a href="http://www.bmobile.ne.jp/sim/note.html" target="_blank">here</a>. The 6-monthly ones, you can get from BIC CAMERA (see below)
<p></span></li>
<li><strong>continuation</strong>: <span style="font-weight: normal;">I don&#8217;t really know how to &#8216;extend&#8217; it, I would imagine since this is a </span>data only<span style="font-weight: normal;"> sim, just buying another one won&#8217;t be a biggie.</span></li>
</ul>
<h3>How to get the 6-month B-Mobile SIM from BIC CAMERA</h3>
<p>Bic Camera is a mega electronic store &#8211; their sign looked like <a href="http://bit.ly/jkTpQM" target="_blank">this</a>, they are easy to find.</p>
<p>Just rock in there and say you want B-mobile Sim card. They don&#8217;t ask for any gaijin card or anything like that.</p>
<p>You can ask <strong>&#8220;BI-MOBAIRU SIIMU CAADO ARUKA ?&#8221; &#8211; </strong>Or if you want to be less adventurous, simply go to <a href="http://www.bmobile.ne.jp/sim_t/index.html">this page </a>and print it out, then bring it to the shop.</p>
<p>They will give you this booklet, with a bunch of information in japanese and within it is a card (within the card is the SIM card). Take the card out, turn it around, behind you should see 2 set of number. The first one is the number to call, the 2nd one, is your number.</p>
<p>Call the first number, choose <strong>english</strong>, follow the prompt, and <strong>activate</strong> the SIM card. You&#8217;ll need the 2nd number, which is your mobile number to activate it. Activation takes about 10-15 minute.</p>
<p>Then, pop in your SIM card into the trusty n900.</p>
<h3>&#8220;SIM Card Registration Failed&#8221;</h3>
<p>Unfortunately it won&#8217;t work just yet. But fear not &#8211; if you see this msg,  open the XTerminal, elevate to root (sudo gainroot) and then type in the following cmd (credit to <a href="http://twitter.com/#!/tesuri">@tesuri</a> for figuring this out ):</p>
<blockquote><p>dbus-send –system –type=method_call –print-reply –dest=com.nokia.phone.net “/com/nokia/csd/gprs” org.freedesktop.DBus.Properties.Set string:com.nokia.csd.GPRS string:AttachMode variant:string:WhenAvaiable</p></blockquote>
<h3>Then, let&#8217;s set the APN</h3>
<p>For quick reference, here it is. But check with the latest one here in case it changes: <a href="http://www.bmobile.ne.jp/sim/setting.html">http://www.bmobile.ne.jp/sim/setting.html</a></p>
<blockquote><p>APN: dm.jplat.net<br />
Username: bmobile@u300<br />
Password: bmobile</p></blockquote>
<h3>Done!</h3>
<p>Once done, reboot the phone. And you should be in <img src='http://www.zugiart.com/main/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Good luck and have fun.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 947px; width: 1px; height: 1px; overflow: hidden;">
<p><span style="border-collapse: separate; color: #000000; font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;"><span style="color: #666666; font-family: 'Hiragino Kaku Gothic Pro', HiraKakuPro-W3, Verdana, Futura, Arial, メイリオ, 'ＭＳ Ｐゴシック', Osaka, sans-serif; font-size: 16px; line-height: 25px; text-align: left;"> </span></span></p>
<table class="table_device" style="border-collapse: collapse; width: 900px;">
<tbody>
<tr>
<td style="vertical-align: top; font-size: 12px; padding: 5px; margin: 0px; border: 1px solid #dddddd;"><span style="background-color: transparent; font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;"><span style="font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;">APN:</span></span></td>
<td style="vertical-align: top; font-size: 12px; padding: 5px; margin: 0px; border: 1px solid #dddddd;"><span style="background-color: transparent; font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;"><span style="font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;">dm.jplat.net</span></span><br />
<span style="background-color: transparent; font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;"><span style="font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;">(Diemu. Jepierueti. Enuiti)</span></span></td>
</tr>
<tr>
<td style="vertical-align: top; font-size: 12px; padding: 5px; margin: 0px; border: 1px solid #dddddd;"><span style="background-color: transparent; font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;"><span style="background-color: transparent; font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;">Username:</span></span></td>
<td style="vertical-align: top; font-size: 12px; padding: 5px; margin: 0px; border: 1px solid #dddddd;"><span style="background-color: transparent; font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;"><span style="font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;">bmobile @ u300</span></span><br />
<span style="background-color: transparent; font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;"><span style="background-color: transparent; font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;">(Biemuobiaierui @ Yusanzerozero)</span></span></td>
</tr>
<tr>
<td style="vertical-align: top; font-size: 12px; padding: 5px; margin: 0px; border: 1px solid #dddddd;"><span style="background-color: transparent; font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;"><span style="background-color: transparent; font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;">Password:</span></span></td>
<td style="vertical-align: top; font-size: 12px; padding: 5px; margin: 0px; border: 1px solid #dddddd;"><span style="background-color: transparent; font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;"><span style="background-color: transparent; font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;">bmobile</span></span><br />
<span style="background-color: transparent; font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;"><span style="background-color: transparent; font-size: 12px; outline-width: 0px; vertical-align: baseline; display: inline; padding: 0px; margin: 0px;">(Biemuobiaierui)</span></span></td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.zugiart.com/2011/05/n900-in-japan-via-bmobile/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>HTTP redirect and Cookies</title>
		<link>http://www.zugiart.com/2011/04/http-redirect-and-cookies/</link>
		<comments>http://www.zugiart.com/2011/04/http-redirect-and-cookies/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 22:39:21 +0000</pubDate>
		<dc:creator>zen</dc:creator>
				<category><![CDATA[geeky]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://www.zugiart.com/?p=1601</guid>
		<description><![CDATA[Did you know that if a web server sends a HTTP 302 (redirect) response, with a set-cookie, the browser won&#8217;t take the cookie unless the cookie&#8217;s path is set to &#8220;/&#8221; ? This is how it can be set in Java (servlet): Cookie cookie = new Cookie("cookie_name","cookie_value"); cookie.setMaxAge(30000); // expiry cookie.setSecure(true); cokie.setPath("/"); // this is [...]]]></description>
			<content:encoded><![CDATA[<p>Did you know that if a web server sends a HTTP 302 (redirect) response, with a set-cookie, the browser won&#8217;t take the cookie unless the cookie&#8217;s path is set to &#8220;/&#8221; ?</p>
<p>This is how it can be set in Java (servlet):</p>
<pre class='code' lang='java'>
Cookie cookie = new Cookie("cookie_name","cookie_value");
cookie.setMaxAge(30000); // expiry
cookie.setSecure(true);
cokie.setPath("/"); // this is the magic
response.addCookie(cookie);
response.sendRedirect("http://hostname/nextUrl");
</pre>
<p>I thought cookies are simple but in truth they are not. You never know what you will learn until you actually try to do it in anger. So there <img src='http://www.zugiart.com/main/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.zugiart.com/2011/04/http-redirect-and-cookies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple GNU command line parser in Java via Apache commons CLI</title>
		<link>http://www.zugiart.com/2010/11/simple-gnu-apache-commons-cli-java/</link>
		<comments>http://www.zugiart.com/2010/11/simple-gnu-apache-commons-cli-java/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 13:13:57 +0000</pubDate>
		<dc:creator>zen</dc:creator>
				<category><![CDATA[geeky]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[commons]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.zugiart.com/2010/11/simple-gnu-apache-commons-cli-java/</guid>
		<description><![CDATA[I like Apache Commons CLI and I really like the GNU style command line argument / option parsing. The one thing with the commons CLI is that it covers a lot of use cases, but I find it a bit cumbersome to set up again and again for some of my CLI programs, so I [...]]]></description>
			<content:encoded><![CDATA[<p>I like Apache Commons CLI and I really like the GNU style command line argument / option parsing. The one thing with the commons CLI is that it covers a lot of use cases, but I find it a bit cumbersome to set up again and again for some of my CLI programs, so I decided to write a simple wrapper that will help me do 80% of the job in very short amount of time.</p>
<p>Of course, like any wrappers that specialize on a given use case, you lose the flexibility, but in return you gain the convenience. This tradeoff works for me almost all of the time, I hope it does for you too.</p>
<h2>Setup</h2>
<p>Of course, you need the usual apache CLI .jars.</p>
<h2>Example usage</h2>
<p>Now don&#8217;t laugh, it&#8217;s really simple to use:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// initiates the command line using args</span>
<span style="color: #666666; font-style: italic;">// as specified in... void main(string[] args){...</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// --port=&amp;lt;portNum&amp;gt;, hasArgs, mandatory</span>
<span style="color: #666666; font-style: italic;">// --serviceName=&amp;lt;name&amp;gt;, hasArgs, mandatory</span>
<span style="color: #666666; font-style: italic;">// --optional (no args), optional</span>
&nbsp;
SimpleGNUCommandLine cli <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleGNUCommandLine<span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
cli.<span style="color: #006633;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;port&quot;</span>, <span style="color: #0000ff;">&quot;xml-rpc port&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
cli.<span style="color: #006633;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;serviceName&quot;</span>, <span style="color: #0000ff;">&quot;xml-rpc service point name&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
cli.<span style="color: #006633;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;optional&quot;</span>, <span style="color: #0000ff;">&quot;xml-rpc service point name&quot;</span>, <span style="color: #000066; font-weight: bold;">false</span>, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// as you can guess, signature for addOption is: </span>
<span style="color: #666666; font-style: italic;">// .addOption('name','description',hasArgs, isMandatory);</span>
&nbsp;
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>cli.<span style="color: #006633;">getInteger</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;port&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>cli.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;serviceName&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> cli.<span style="color: #006633;">hasOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;optional&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;--optional is provided&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>SimpleGNUCommandLine class</h2>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">zsugiart.util</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.StringTokenizer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.cli.CommandLine</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.cli.CommandLineParser</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.cli.GnuParser</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.cli.HelpFormatter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.cli.MissingOptionException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.cli.OptionBuilder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.cli.Options</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * This simple utility provides a very simple wrapper class to help use the
 * apache commons CLI. The SimpleGNUCommandLine provides the command line
 * parser-wrapper for GNU-style options. It provides basic parsing ability
 * with built in support for printing help into system.out.
 * See example usage in main method
 *
 * @author zsugiart
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleGNUCommandLine
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">/* attribute */</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> Options options <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Options<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> cmdlineArgs<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> CommandLine cmdLine<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> isParsed<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* init &amp;amp; destroy */</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// constructor</span>
	<span style="color: #000000; font-weight: bold;">public</span> SimpleGNUCommandLine<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> cmdLineArgs<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cmdlineArgs</span><span style="color: #339933;">=</span>cmdLineArgs<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;help&quot;</span>, <span style="color: #0000ff;">&quot;when specified, will override and print this help message&quot;</span>, <span style="color: #000066; font-weight: bold;">false</span>, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* option services */</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Adds an option into the command line parser
	 * @param optionName - the option name
	 * @param description - option descriptiuon
	 * @param hasValue - if set to true, --option=value, otherwise, --option is a boolean
	 * @param isMandatory - if set to true, the option must be provided.
	 */</span>
	@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;static-access&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addOption<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> optionName, <span style="color: #003399;">String</span> description, <span style="color: #000066; font-weight: bold;">boolean</span> hasValue, <span style="color: #000066; font-weight: bold;">boolean</span> isMandatory <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		OptionBuilder opt <span style="color: #339933;">=</span> OptionBuilder.<span style="color: #006633;">withLongOpt</span><span style="color: #009900;">&#40;</span>optionName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		opt <span style="color: #339933;">=</span> opt.<span style="color: #006633;">withDescription</span><span style="color: #009900;">&#40;</span>description<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> hasValue <span style="color: #009900;">&#41;</span> opt <span style="color: #339933;">=</span> opt.<span style="color: #006633;">hasArg</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> isMandatory <span style="color: #009900;">&#41;</span> opt <span style="color: #339933;">=</span> opt.<span style="color: #006633;">isRequired</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		options.<span style="color: #006633;">addOption</span><span style="color: #009900;">&#40;</span>opt.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// this method is implicitly called by accessor methods</span>
	<span style="color: #666666; font-style: italic;">// and will only be called on first instance.</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> parse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>
		CommandLineParser parser <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GnuParser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cmdLine</span> <span style="color: #339933;">=</span> parser.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">options</span>, <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cmdlineArgs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>MissingOptionException moe<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>printUsage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">isParsed</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cmdLine</span>.<span style="color: #006633;">hasOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;help&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> printUsage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* accessors &amp;amp; utilities */</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> printUsage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		HelpFormatter formatter <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HelpFormatter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		formatter.<span style="color: #006633;">printHelp</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;available options as follow:&quot;</span>, options <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getString<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> optionname<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">isParsed</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cmdLine</span>.<span style="color: #006633;">getOptionValue</span><span style="color: #009900;">&#40;</span>optionname<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Integer</span> getInteger<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> optionname<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>optionname<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Double</span> getDouble<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> optionname<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #003399;">Double</span>.<span style="color: #006633;">parseDouble</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>optionname<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>String<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> getList<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> optionname, <span style="color: #003399;">String</span> delimiter<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>
		List<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>String<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> arrayList <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>String<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">StringTokenizer</span> tkn <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringTokenizer</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>optionname<span style="color: #009900;">&#41;</span>,delimiter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>tkn.<span style="color: #006633;">hasMoreTokens</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> arrayList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>tkn.<span style="color: #006633;">nextToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> arrayList<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> hasOption<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> optionName<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">isParsed</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cmdLine</span>.<span style="color: #006633;">hasOption</span><span style="color: #009900;">&#40;</span>optionName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Example, to run this class, must
	 * @param args
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>
		SimpleGNUCommandLine cli <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleGNUCommandLine<span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		cli.<span style="color: #006633;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;port&quot;</span>, <span style="color: #0000ff;">&quot;xml-rpc port&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		cli.<span style="color: #006633;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;serviceName&quot;</span>, <span style="color: #0000ff;">&quot;xml-rpc service point name&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		cli.<span style="color: #006633;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;optional&quot;</span>, <span style="color: #0000ff;">&quot;xml-rpc service point name&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span>, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>cli.<span style="color: #006633;">getInteger</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;port&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>cli.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;serviceName&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> cli.<span style="color: #006633;">hasOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;optional&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;--optional is provided&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zugiart.com/2010/11/simple-gnu-apache-commons-cli-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>installing n900 enhanced kernel with conflict</title>
		<link>http://www.zugiart.com/2010/11/installing-n900-enhanced-kernel-with-conflict/</link>
		<comments>http://www.zugiart.com/2010/11/installing-n900-enhanced-kernel-with-conflict/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 06:12:09 +0000</pubDate>
		<dc:creator>zen</dc:creator>
				<category><![CDATA[geeky]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[n900]]></category>

		<guid isPermaLink="false">http://www.zugiart.com/2010/11/installing-n900-enhanced-kernel-with-conflict/</guid>
		<description><![CDATA[Tried to install enhanced kernal 2.6.28.10 on my n900 running PR1.3 firmware and got a message: &#8216;conflict with kernel-maemo&#8217; Did a bit of googling and finally found these commands from: http://wiki.maemo.org/Kernel_Power basically, install manually via apt-get like so: sudo gainroot apt-get install -y kernel-power-flasher apt-get remove kernel-flasher-maemo apt-get install --reinstall -y kernel-power kernel-power-flasher And don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Tried to install enhanced kernal 2.6.28.10 on my n900 running PR1.3 firmware and got a message: &#8216;conflict with kernel-maemo&#8217;</p>
<p>Did a bit of googling and finally found these commands from: <a href="http://wiki.maemo.org/Kernel_Power">http://wiki.maemo.org/Kernel_Power</a></p>
<p>basically, install manually via apt-get like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gainroot
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-y</span> kernel-power-flasher
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> remove kernel-flasher-maemo
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">--reinstall</span> <span style="color: #660033;">-y</span> kernel-power kernel-power-flasher</pre></div></div>

<p>And don&#8217;t forget to take backup prior to doing any of this funky business!</p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" alt="" src="http://img.zemanta.com/pixy.gif?x-id=8bda8627-cb34-8663-be25-0582d84a1c73" /></div>
]]></content:encoded>
			<wfw:commentRss>http://www.zugiart.com/2010/11/installing-n900-enhanced-kernel-with-conflict/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stateful &amp; standalone apache XML-RPC server</title>
		<link>http://www.zugiart.com/2010/09/java-apache-simple-xmlrpc-server/</link>
		<comments>http://www.zugiart.com/2010/09/java-apache-simple-xmlrpc-server/#comments</comments>
		<pubDate>Wed, 15 Sep 2010 07:10:22 +0000</pubDate>
		<dc:creator>zen</dc:creator>
				<category><![CDATA[geeky]]></category>
		<category><![CDATA[java xmlrpc]]></category>

		<guid isPermaLink="false">http://www.zugiart.com/?p=1393</guid>
		<description><![CDATA[Introduction Apache WS-XMLRPC is arguably one of the most popular Java xml-rpc library around. However having tasted the lightness of python I&#8217;m really missing the quick and easy SimpleXmlRpcServer. So here is a simple class that&#8217;ll do the job. Download WS-XMLRPC In case you haven&#8217;t got it already, here&#8217;s a link to the ws-xmlrpc download [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p><a href="http://ws.apache.org">Apache WS-XMLRPC</a> is arguably one of the most popular Java xml-rpc library around. However having tasted the lightness of python I&#8217;m really missing the quick and easy <a href="http://docs.python.org/library/simplexmlrpcserver.html">SimpleXmlRpcServer</a>. So here is a simple class that&#8217;ll do the job.</p>
<h3>Download WS-XMLRPC</h3>
<p>In case you haven&#8217;t got it already, here&#8217;s a link to the <a href="http://www.apache.org/dyn/closer.cgi/ws/xmlrpc/">ws-xmlrpc download page</a>.</p>
<h3>Java Simple Xml Rpc Server</h3>
<p>The purpose of this class is to allow Java programmers to very quickly craft a standalone, simple xml rpc server using the apache xml-rpc library. No servlet or container required.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.xmlrpc.server.PropertyHandlerMapping</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.xmlrpc.server.XmlRpcServer</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.xmlrpc.server.XmlRpcServerConfigImpl</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.xmlrpc.webserver.WebServer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * A simple implementation of XML-RPC server for apache ws-xmlrpc
 * Version 1.2 - support single instance handler object, but not yet multi-threaded
 * Zen Sugiarto
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleXmlRpcServer
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">/* ======================================== runtime attr ========================================== */</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> port<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> WebServer webServer <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> PropertyHandlerMapping phm <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> SimpleXmlRpcRequestHandlerFactory handler <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> XmlRpcServer xmlRpcServer <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* ======================================== init/destroy ========================================== */</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Creates an instance of xml rpc server, using :handler as the class that
	 * will handle all request. Note that a new instance of :handler will be
	 * created at every xml-rpc request.
	 *
	 * @param name
	 * @param port
	 * @param handler
	 * @throws Exception
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> SimpleXmlRpcServer<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> port<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">port</span> <span style="color: #339933;">=</span> port<span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// bind</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">webServer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WebServer<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">port</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">xmlRpcServer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">webServer</span>.<span style="color: #006633;">getXmlRpcServer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">handler</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXmlRpcRequestHandlerFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">phm</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PropertyHandlerMapping<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">phm</span>.<span style="color: #006633;">setRequestProcessorFactoryFactory</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">handler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* ======================================== services ========================================== */</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Adds a handler instance (which CAN be stateful) for each request. Note that
	 * every public method in this object will be callable via xml-rpc client
	 *
	 * @param name - handler name
	 * @param requestHandler - handler obj instance
	 * @throws Exception
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addHandler<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name, <span style="color: #003399;">Object</span> requestHandler<span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">handler</span>.<span style="color: #006633;">setHandler</span><span style="color: #009900;">&#40;</span>name, requestHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">phm</span>.<span style="color: #006633;">addHandler</span><span style="color: #009900;">&#40;</span>name, requestHandler.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Start the xml-rpc server forever. In the rare case of fatal exception, the
	 * web server will be restarted automagically. This is a blocking call (not
	 * thread-based).
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> serve_forever<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// init</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">xmlRpcServer</span>.<span style="color: #006633;">setHandlerMapping</span><span style="color: #009900;">&#40;</span>phm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		XmlRpcServerConfigImpl serverConfig <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>XmlRpcServerConfigImpl<span style="color: #009900;">&#41;</span> xmlRpcServer.<span style="color: #006633;">getConfig</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		serverConfig.<span style="color: #006633;">setEnabledForExtensions</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">webServer</span>.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* ====================================== getter/setter ======================================== */</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getPort<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> port<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setPort<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> port<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">port</span> <span style="color: #339933;">=</span> port<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> WebServer getWebServer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> webServer<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setWebServer<span style="color: #009900;">&#40;</span>WebServer webServer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">webServer</span> <span style="color: #339933;">=</span> webServer<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> PropertyHandlerMapping getPhm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> phm<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setPhm<span style="color: #009900;">&#40;</span>PropertyHandlerMapping phm<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">phm</span> <span style="color: #339933;">=</span> phm<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> SimpleXmlRpcRequestHandlerFactory getHandler<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> handler<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setHandler<span style="color: #009900;">&#40;</span>SimpleXmlRpcRequestHandlerFactory handler<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">handler</span> <span style="color: #339933;">=</span> handler<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> XmlRpcServer getXmlRpcServer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> xmlRpcServer<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setXmlRpcServer<span style="color: #009900;">&#40;</span>XmlRpcServer xmlRpcServer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">xmlRpcServer</span> <span style="color: #339933;">=</span> xmlRpcServer<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This RequestHandlerFactory class provides an instance-based handler that allows the XML-RPC handler to be stateful.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Simple XMLRPC request handler factory - this little magic class allows
 * for a request INSTANCE to be set as the handler for the xml rpc server
 * Ideally, a client shouldn't even NEED to know what this is doing.
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleXmlRpcRequestHandlerFactory
<span style="color: #000000; font-weight: bold;">implements</span> RequestProcessorFactoryFactory,RequestProcessorFactory
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Map</span> handlerMap <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">HashMap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setHandler<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name, <span style="color: #003399;">Object</span> handler<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">handlerMap</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>name, handler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> getHandler<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">handlerMap</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> RequestProcessorFactory getRequestProcessorFactory<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> arg0<span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">throws</span> XmlRpcException <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> getRequestProcessor<span style="color: #009900;">&#40;</span>XmlRpcRequest request<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> XmlRpcException
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> handlerName <span style="color: #339933;">=</span> request.<span style="color: #006633;">getMethodName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,request.<span style="color: #006633;">getMethodName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">lastIndexOf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>handlerMap.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span>handlerName<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> XmlRpcException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Unknown handler: &quot;</span><span style="color: #339933;">+</span>handlerName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> handlerMap.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>handlerName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Example xml-rpc server:</h3>
<p>The tricks above makes the XML-RPC server code much simpler, and with the above code the class CAN be stateful. However, do remember that:</p>
<ul>
<li>This has not yet been tested under multi-threaded environment.</li>
<li>If you want to go hardcore, you&#8217;ll still need a web container.</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleXMLRpcTest
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> hello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;hello world&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>
		SimpleXmlRpcServer server <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXmlRpcServer<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">7777</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		server.<span style="color: #006633;">addHandler</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;zen&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> SimpleXMLRpcTest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		server.<span style="color: #006633;">serve_forever</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Client example ( in python ):</h3>
<p>To test this, we use a 4 line python script to test it:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">xmlrpclib</span>
proxy = <span style="color: #dc143c;">xmlrpclib</span>.<span style="color: black;">ServerProxy</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;http://localhost:8000&quot;</span><span style="color: black;">&#41;</span>
response = proxy.<span style="color: black;">zen</span>.<span style="color: black;">hello</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> response</pre></div></div>

<p>And I got:</p>
<pre>hello world</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.zugiart.com/2010/09/java-apache-simple-xmlrpc-server/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

