<?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; notes</title>
	<atom:link href="http://www.zugiart.com/tag/notes/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>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>Test post via my n900</title>
		<link>http://www.zugiart.com/2010/08/test-post-via-my-n900/</link>
		<comments>http://www.zugiart.com/2010/08/test-post-via-my-n900/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 08:06:53 +0000</pubDate>
		<dc:creator>zen</dc:creator>
				<category><![CDATA[geeky]]></category>
		<category><![CDATA[thoughts]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[notes]]></category>

		<guid isPermaLink="false">http://www.zugiart.com/2010/08/test-post-via-my-n900/</guid>
		<description><![CDATA[This is a test post using my nokia n900, let&#8217;s see how we go :p this is a very good way of capturing notes on the go. This is done through an application called MaStory. Seriously, is there anything this phone can&#8217;t do!? Btw I am gathering notes on n900 configuration. It will be one [...]]]></description>
			<content:encoded><![CDATA[<p>This is a test post using my nokia n900, let&#8217;s see how we go :p</p>
<p>this is a very good way of capturing notes on the go. This is done through an application called MaStory. Seriously, is there anything this phone can&#8217;t do!?</p>
<p>Btw I am gathering notes on n900 configuration. It will be one hell of a guide once it&#8217;s done. <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/2010/08/test-post-via-my-n900/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

