<?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>Werx Limited &#187; json</title>
	<atom:link href="http://werxltd.com/wp/tag/json/feed/" rel="self" type="application/rss+xml" />
	<link>http://werxltd.com/wp</link>
	<description>We make IT work.</description>
	<lastBuildDate>Thu, 29 Jul 2010 19:00:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>HBase JSON-RPC Bridge updated, allows scanning</title>
		<link>http://werxltd.com/wp/2010/07/27/hbase-json-rpc-bridge-updated-allows-scanning/</link>
		<comments>http://werxltd.com/wp/2010/07/27/hbase-json-rpc-bridge-updated-allows-scanning/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 18:05:04 +0000</pubDate>
		<dc:creator>wes</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[bigdata]]></category>
		<category><![CDATA[bigtable]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[jsonrpc]]></category>
		<category><![CDATA[mapreduce]]></category>

		<guid isPermaLink="false">http://werxltd.com/wp/?p=632</guid>
		<description><![CDATA[The HBase JSON-RPC bridge has been updated to allow scanning on non-key columns. Now, passing a filter parameter creates a scanner using a RegexStringComparator. Results are returned in 100 block chunks until null is returned, in which case the ResultScanner is closed Here is an example query that is now possible: http://localhost:8080/hbasebridge/rpc?debug=true&#38;data={"method":"lookup","params":{"table":"hbasetable","filter":"searchstring"}}]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://code.google.com/p/hbasebridge/">HBase JSON-RPC bridge</a> has been updated to allow scanning on non-key columns. Now, passing a filter parameter creates a scanner using a <a href="http://hbase.apache.org/docs/r0.20.5/api/org/apache/hadoop/hbase/filter/RegexStringComparator.html">RegexStringComparator</a>. <a href="http://hbase.apache.org/docs/r0.20.5/api/org/apache/hadoop/hbase/client/Result.html">Result</a>s are returned in 100 block chunks until null is returned, in which case the <a href="http://hbase.apache.org/docs/r0.20.4/api/org/apache/hadoop/hbase/client/ResultScanner.html">ResultScanner</a> is closed</p>
<p>Here is an example query that is now possible:</p>
<pre>http://localhost:8080/hbasebridge/rpc?debug=true&amp;data={"method":"lookup","params":{"table":"hbasetable","filter":"searchstring"}}</pre>
]]></content:encoded>
			<wfw:commentRss>http://werxltd.com/wp/2010/07/27/hbase-json-rpc-bridge-updated-allows-scanning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple JSON-RPC updated to 0.9.5</title>
		<link>http://werxltd.com/wp/2010/01/12/simple-json-rpc-updated-to-0-9-5/</link>
		<comments>http://werxltd.com/wp/2010/01/12/simple-json-rpc-updated-to-0-9-5/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 12:00:52 +0000</pubDate>
		<dc:creator>wes</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[json-rpc]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[simple jsonrpc]]></category>

		<guid isPermaLink="false">http://werxltd.com/wp/?p=437</guid>
		<description><![CDATA[The simple JSON-RPC package has been updated to 0.9.5 It has undergone some extensive refactoring and now includes documentation, and an example project. The source to this package is also available here. For more information (and for future updates), visit the new project page here. If you are interested in using, contributing to, or reporting bugs for this [...]]]></description>
			<content:encoded><![CDATA[<p>The simple JSON-RPC package has been updated to 0.9.5 It has undergone some extensive refactoring and now includes <a href="http://werxltd.com/docs/jsonrpc/">documentation</a>, and an <a href="http://werx-jsonrpc.googlecode.com/files/jsonrpc_example-0.9.zip">example project</a>. The source to this package is also <a href="https://code.google.com/p/werx-jsonrpc/">available here</a>.</p>
<p>For more information (and for future updates), visit the <a href="http://werxltd.com/wp/portfolio/json-rpc/simple-java-json-rpc/">new project page here</a>.</p>
<p>If you are interested in using, contributing to, or reporting bugs for this project, <a href="http://werxltd.com/wp/contact-us/">contact us</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://werxltd.com/wp/2010/01/12/simple-json-rpc-updated-to-0-9-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Java implementation of JSON-RPC</title>
		<link>http://werxltd.com/wp/2009/12/29/simple-java-implantation-of-json-rpc/</link>
		<comments>http://werxltd.com/wp/2009/12/29/simple-java-implantation-of-json-rpc/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 12:00:49 +0000</pubDate>
		<dc:creator>wes</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[json-rpc]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[pom]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[war]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://werxltd.com/wp/?p=323</guid>
		<description><![CDATA[Preamble Explanation of standard formats and protocols: JSON (JavaScript Object Notation) is a lightweight1 data-interchange format with language bindings for C, C++, C#, Java, JavaScript, Perl, TCL and many others. JSON-RPC is a simple remote procedure call protocol similar to XML-RPC although it uses the lightweight JSON format instead of XML. What is it? I [...]]]></description>
			<content:encoded><![CDATA[<h2>Preamble</h2>
<p>Explanation of standard formats and protocols:</p>
<ul>
<li><strong><a href="http://www.json.org/">JSON</a></strong> (JavaScript Object Notation) is a lightweight<sup>1</sup> data-interchange format with language bindings for C, C++, C#, Java, JavaScript, Perl, TCL and many others.</li>
<li><strong><a href="http://json-rpc.org/">JSON-RPC</a></strong> is a simple remote procedure call protocol similar to <a href="http://www.xmlrpc.com/">XML-RPC</a> although it uses the lightweight <a href="http://www.json.org/">JSON</a> format instead of <a href="http://en.wikipedia.org/wiki/XML">XML</a>.</li>
</ul>
<h2>What is it?</h2>
<p>I love the simplicity of <a href="http://json-rpc.org/">JSON-RPC</a> when it comes to rapidly devloping cutting-edge web applications.</p>
<p>I recently decided to start writing more server-side code in <a href="http://en.wikipedia.org/wiki/Java_Servlet">Java servlets</a> in order to take advantage of cloud-based infrastructures such as the <a href="http://code.google.com/appengine/">Google App Engine</a>. Until now I have written my web applications using <a href="http://php.net/">PHP</a> as the server-side language. Specifically using frameworks such as <a href="http://www.symfony-project.org/">Symfony</a> or <a href="http://www.kohanaphp.com/">Kohana</a>, which makes writing simple JSON-RPC services relatively trivial.</p>
<p>So I started looking for a simple JSON-RPC system I could use in Java to abstract my business logic classes from the mundane tasks associated with handling web requests. I found several packages which all claimed to implement the JSON-RPC protocol via Java servlets, however they seemed to require far more by way of setup than I wanted and they all seemed to require the developer to write applications to their specific implementation&#8217;s standards.<sup>2</sup></p>
<p>So I decided to write yet another Java implementation of the JSON-RPC specification myself with the following goals in mind:</p>
<ul>
<li>Easy to implement. Setup for this package should be kept at a minimum. This includes both development as well as production setup.</li>
<li>Easy to code in. Application developers using this class should not need to know much about JSON-RPC beyond exposing methods in their code that can be called remotely from other applications via the web.</li>
<li>Non-invasive. Developers using this implementation should be able to reuse <a href="http://en.wikipedia.org/wiki/Plain_Old_Java_Object">plain old Java object</a> (POJO) classes as much as possible, making the transport layer of JSON-RPC as transparent as possible.</li>
</ul>
<p>With these goals in mind I set off to develop the package com.werxltd.jsonrpc to be a simple wrapper designed to be used inside of a <a href="http://mindprod.com/jgloss/warfile.html">standard .war project</a>.</p>
<h2>Setting it up</h2>
<p>You can either <a href="http://maven.werxltd.com/com/werxltd/jsonrpc/0.9/jsonrpc-0.9.jar">download the .jar file here</a> to include in your project manually or (and this is my preferred method) you can import the com.werxltd.jsonrpc package as a dependency in your Maven-managed project by specifying the following in your project&#8217;s <a href="http://maven.apache.org/pom.html">pom.xml</a> configuration file:</p>
<pre class="brush:xml">&lt;repositories&gt;
    &lt;repository&gt;
        &lt;id&gt;werxltd&lt;/id&gt;
        &lt;url&gt;http://maven.werxltd.com &lt;/url&gt;
        &lt;snapshots&gt;
            &lt;enabled&gt;true&lt;/enabled&gt;
        &lt;/snapshots&gt;
        &lt;releases&gt;
           &lt;enabled&gt;true&lt;/enabled&gt;
       &lt;/releases&gt;
    &lt;/repository&gt;
&lt;/repositories&gt;

&lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;com.werxltd&lt;/groupId&gt;
        &lt;artifactId&gt;jsonrpc&lt;/artifactId&gt;
        &lt;version&gt;0.9&lt;/version&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;</pre>
<p>Next, you&#8217;ll need to specify endpoints in your .war file&#8217;s <a href="http://en.wikipedia.org/wiki/WAR_(Sun_file_format)">web.xml</a> configuration file. Here&#8217;s an example:</p>
<pre class="brush:xml">&lt;web-app&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;example&lt;/servlet-name&gt;
        &lt;servlet-class&gt;com.werxltd.jsonrpc.RPC&lt;/servlet-class&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;rpcclasses&lt;/param-name&gt;
            &lt;param-value&gt;YourClass&lt;/param-value&gt;
        &lt;/init-param&gt;
    &lt;/servlet&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;example&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/example&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
&lt;/web-app&gt;</pre>
<p>That&#8217;s it! Now your project is configured to filter all requests sent to /example through the JSON-RPC class which examines the class name you passed in (in this case, YourClass) for public methods it can expose. An instance of your class is created internally if your class is not static and it will remain in memory throughout the life of the servlet. Any exceptions your class generates are gracefully wrapped inside a JSON-RPC error message for proper handling upstream.</p>
<h2>Using it</h2>
<p>While the setup is pretty much straightforward, due to the loose typing found in JavaScript (and, as a result, JSON) there are some caveats in how methods are called. Specifically in how arguments are passed to those methods.</p>
<p>Scanned methods are stored internally with a signature consisting of the method name and how many arguements that method accepts. When a JSON-RPC request is made, the servlet determines how many parameters were included and attempts to match the method requested with a corresponding internal method which has the same number of parameters/arguements.</p>
<p>Because parameters are passed in via the web, only Java primitive data types along with three others, <a href="http://www.json.org/javadoc/org/json/JSONObject.html">JSONObject</a>, <a href="http://www.json.org/javadoc/org/json/JSONArray.html">JSONArray</a> and <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html">java.lang.String</a> are accepted as valid parameter data types.</p>
<p>If a match of method name and number of parameters is found, an attempt is made to parse the passed-in data into the method&#8217;s required type. Any methods which accept as their first parameter a parameter of the JSONObject type, this method automatically takes prescience over all other parameters.</p>
<p>To use the JSON-RPC interface from another application, you must pass a valid JSON-RPC object to your final servlet as a parameter named &#8220;json&#8221; via either GET or POST. Here is an example of the valid JSON-RPC object you need to pass:</p>
<pre class="brush:javascript">{
    "method":"add",
    "params":[1 2 3]
}</pre>
<p>This JSON-RPC implementation accepts either named parameters or positional parameters like the ones shown above. Here is a named parameters example:</p>
<pre class="brush:javascript">{
    "method":"echo",
    "params":{
        "text":"testing"
    }
}</pre>
<h2>The road ahead</h2>
<p>Future development of this class will include more formalized access between the JSON-RPC layer and the underlying classes.</p>
<p>I&#8217;m also planning to post the <a href="http://en.wikipedia.org/wiki/Javadoc">Javadocs</a> and the source to an example project that utilizes the JSON-RPC transport package.</p>
<p>Hope this helps someone else. I&#8217;m looking forward to using this class as a central component in many <a href="http://en.wikipedia.org/wiki/Rich_Internet_application">rich web projects</a> I have planned.</p>
<ol class="footnotes"><li id="footnote_0_323" class="footnote">Lightweight in both size and resources required to process data encoded in JSON vs. XML.</li><li id="footnote_1_323" class="footnote">I did find <a href="http://software.dzhuvinov.com/json-rpc-2.0-base-java-classes.html">this project</a> after finishing the first revision of my class. It looks great and like it would do much of what I wanted, however the code is proprietary. After I finish documenting my classes I plan on releasing them under an <a href="http://www.opensource.org/licenses">OSI-approved licence</a>. If you are interested in helping me with this project, feel free to let me know!</li></ol>]]></content:encoded>
			<wfw:commentRss>http://werxltd.com/wp/2009/12/29/simple-java-implantation-of-json-rpc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magical PHP JSON Object Cleaner</title>
		<link>http://werxltd.com/wp/2009/07/29/magical-php-json-object-cleaner/</link>
		<comments>http://werxltd.com/wp/2009/07/29/magical-php-json-object-cleaner/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 14:27:03 +0000</pubDate>
		<dc:creator>wes</dc:creator>
				<category><![CDATA[software development]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[recursive]]></category>

		<guid isPermaLink="false">http://werxltd.com/wp/?p=159</guid>
		<description><![CDATA[I wrote this method the other day that takes a simple PHP object, inspects it&#8217;s properties and &#8220;prunes&#8221; empty ones. I wrote this method in order to compress JSON objects by removing null properties before sending them down the wire, a big problem when using base objects or models. If you find this useful or [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote this method the other day that takes a simple PHP object, inspects it&#8217;s properties and &#8220;prunes&#8221; empty ones. I wrote this method in order to compress JSON objects by removing null properties before sending them down the wire, a big problem when using base objects or models.</p>
<p>If you find this useful or a have a suggestion, feel free to let me know!</p>
<pre class="brush:php">
private function getStripped($obj) {
		$objVars = get_object_vars($obj);

		if(count($objVars) > 0) {
			foreach($objVars as $propName => $propVal) {
				if(gettype($propVal) == "object") {
					$cObj = $this->getStripped($propVal);
					if($cObj == null) {
						unset($obj->$propName);
					} else {
						$obj->$propName = $cObj;
					}
				} else {
					if(empty($propVal)) {
						unset($obj->$propName);
					}
				}
			}
		} else {
			return null;
		}
		return $obj;
	}</pre>
]]></content:encoded>
			<wfw:commentRss>http://werxltd.com/wp/2009/07/29/magical-php-json-object-cleaner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SOAPjr, the new SOAP?</title>
		<link>http://werxltd.com/wp/2009/07/16/soapjr-the-new-soap/</link>
		<comments>http://werxltd.com/wp/2009/07/16/soapjr-the-new-soap/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 19:59:44 +0000</pubDate>
		<dc:creator>wes</dc:creator>
				<category><![CDATA[software development]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[soapjr]]></category>
		<category><![CDATA[web communication]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://werxltd.com/wp/?p=131</guid>
		<description><![CDATA[XML was the data exchange format that was supposed to be the Holy Grail of information exchange mediums. SOAP was a protocol built around it that was supposed to make web-based communication robust, flexible, and&#8230; slow. While SOAP has been widely adopted and used in web-based applications, and while XML has become the predominant information exchange [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.w3.org/TR/xml/">XML</a> was the data exchange format that was supposed to be the Holy Grail of information exchange mediums. <a href="http://en.wikipedia.org/wiki/SOAP_%28protocol%29#History">SOAP</a> was a protocol built around it that was supposed to make web-based communication robust, flexible, and&#8230;</p>
<p>slow.</p>
<p>While SOAP has been widely adopted and used in web-based applications, and while XML has become the predominant information exchange medium, we&#8217;re finding out that they just aren&#8217;t as efficient as they could be. The main problem stems mostly from bloat inherit in the XML specification. In a nutshell, XML requires a root node and well-formed tags in order to make it &#8220;valid&#8221;. So the way you would send a simple name/value pair in XML would be:</p>
<pre class="brush:xml"><root>
     <name>value</name>
</root></pre>
<p>While this may not be too bad for console-based applications<sup>1</sup> this is extremely inefficient for web-based applications because of it&#8217;s size and the processing that is required to parse or &#8220;walk&#8221; the XML nodes in order to get the data you want.</p>
<p>Because of these (and other) issues, <a href="http://json.org/">JSON</a> was developed as a lightweight, cross-browser, alternative. JSON is essentially shorthand JavaScript Object Notation that allows us to pass name/value pairs in the format</p>
<pre class="brush:javascript">
{
     "name":"value"
}
</pre>
<p>which, as you can see compared to the XML above, saves a considerable amount of space and processing time on the client since JavaScript merely has to <a href="http://www.w3schools.com/jsref/jsref_eval.asp">eval()</a> the JSON string in order to parse it into a usable data object.</p>
<p>The problem we have now is that SOAP is only designed to use XML, not JSON, and the other communication alternatives like <a href="http://json-rpc.org/">JSON-RPC</a> are generally too lightweight and require extra code to handle errors not to mention the non-uniformity of the data that is often returned.</p>
<p>Enter <a href="http://soapjr.org/">SOAPjr</a>, a lightweight alternative to SOAP and JSON-RPC that uses <a href="http://json-schema.org/">JSON schemas</a> for data validation.</p>
<p>While SOAPjr doesn&#8217;t have very many tools and libraries at the moment, it is a very promising answer to the need for a lightweight and yet robust communications protocol. I plan on helping out with the development by helping to create tools in my favorite languages and frameworks like PHP, ExtJS, Java, GXT, Symfony, etc.</p>
<p>If you want to help out, get in touch with the SOAPjr team by emailing them at tools [at] SOAPjr.org.</p>
<ol class="footnotes"><li id="footnote_0_131" class="footnote">And I would argue that even there processing time is being misused processing the data.</li></ol>]]></content:encoded>
			<wfw:commentRss>http://werxltd.com/wp/2009/07/16/soapjr-the-new-soap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
