<?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>Mon, 07 May 2012 18:40:10 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Fun with jsonselect</title><link>http://werxltd.com/wp/2011/11/16/fun-with-jsonselect/</link> <comments>http://werxltd.com/wp/2011/11/16/fun-with-jsonselect/#comments</comments> <pubDate>Wed, 16 Nov 2011 16:39:07 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[javascript]]></category> <category><![CDATA[css]]></category> <category><![CDATA[json]]></category> <category><![CDATA[jsonselect]]></category> <category><![CDATA[noschema]]></category> <category><![CDATA[selector]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=1063</guid> <description><![CDATA[One of the strengths of CSS and jQuery is that it provides a common and powerful mechanism known as a selector language for referencing bits of data, especially data whose structure is not exactly known at runtime which makes such an addressing scheme a perfect fit for the often lumpy world of HTML. Increasingly JSON [...]]]></description> <content:encoded><![CDATA[<p>One of the strengths of CSS and jQuery is that it provides a common and powerful mechanism known as a selector language for referencing bits of data, especially data whose structure is not exactly known at runtime which makes such an addressing scheme a perfect fit for the often lumpy world of HTML.</p><p>Increasingly JSON is being used as a transport medium for data and with the rise of NoSQL solutions, having a selector language for JSON makes a lot of sense when dealing with JSON documents whose structure isn&#8217;t deterministic.</p><p><a
href="http://jsonselect.org/">JSONSelect</a> provides a good implementation of just such a JSON selector language but after working with it on a project I found myself needing to do more than it allowed me to do. Namely, I wanted 1. to be able to perform a selection and receive matching paths instead of the data contained in those paths and I wanted 2. to be able to modify data specified at a path location in-place.</p><pre class="brush:javascript">
jsonselect.match(sel, obj, asPath); // Added the asPath flag to return a path instead of the values
jsonselect.forEach(sel, obj, fun, asPath); // Added the same flag to forEach, I use this to
jsonselect.get(path,obj); // For getting the value using a path
jsonselect.set(path, value, obj); // For setting the value of a path
jsonselect.del(path,root); // For deleting a path
</pre><p><a
href="http://werxltd.com/wp/wp-content/uploads/2011/11/jsonselect.js?9d7bd4">Here is my modified version of jsonselect</a> in case anyone needs help solving the same problems I mentioned above.</p><div
class="betterrelated none"><p>No related content found.</p></div><p><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://werxltd.com/wp/2011/11/16/fun-with-jsonselect/"></a><a
class="a2a_button_twitter_tweet addtoany_special_service" data-count="none" data-url="http://werxltd.com/wp/2011/11/16/fun-with-jsonselect/" data-text="Fun with jsonselect"></a><a
class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://werxltd.com/wp/2011/11/16/fun-with-jsonselect/"></a><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F11%2F16%2Ffun-with-jsonselect%2F&amp;linkname=Fun%20with%20jsonselect" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F11%2F16%2Ffun-with-jsonselect%2F&amp;title=Fun%20with%20jsonselect" id="wpa2a_2">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2011/11/16/fun-with-jsonselect/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Introducing jpoxy, the simple json-rpc implementation for Java</title><link>http://werxltd.com/wp/2011/03/19/introducing-jpoxy-the-simple-json-rpc-implementation-for-java/</link> <comments>http://werxltd.com/wp/2011/03/19/introducing-jpoxy-the-simple-json-rpc-implementation-for-java/#comments</comments> <pubDate>Sat, 19 Mar 2011 17:24:03 +0000</pubDate> <dc:creator>wes</dc:creator> <category><![CDATA[java]]></category> <category><![CDATA[software development]]></category> <category><![CDATA[glue]]></category> <category><![CDATA[jpoxy]]></category> <category><![CDATA[json]]></category> <category><![CDATA[json-rpc]]></category><guid
isPermaLink="false">http://werxltd.com/wp/?p=917</guid> <description><![CDATA[werx-jsonrpc has been renamed to jpoxy (hosted on Google Code). But the project name isn&#8217;t the only thing that&#8217;s changed. Based on some excellent feedback I&#8217;ve made the following changes: The project is now thread-safe. I&#8217;ve removed request and response as global objects and, instead, made sure they get passed along the request chain. This [...]]]></description> <content:encoded><![CDATA[<p>werx-jsonrpc has been renamed to <a
href="http://code.google.com/p/jpoxy/">jpoxy</a> (hosted on Google Code). But the project name isn&#8217;t the only thing that&#8217;s changed. Based on some excellent feedback I&#8217;ve made the following changes:</p><ul><li>The project is now thread-safe. I&#8217;ve removed request and response as global objects and, instead, made sure they get passed along the request chain.</li><li>This means the events for request and response have been taken out (which, I&#8217;ve been informed, I didn&#8217;t make a big enough deal about last time). The only event that you will get now is the init complete event which will provide your application a copy of the servlet configuration.</li><li>You can still access the request object (and, subsequently, the session object) by accepting a single HashMap parameter in your method.</li><li>A new annotation has been added, @Jpoxy(enabled = false), which allows you to tell the framework not to expose a method if it is public. This means you can mark all your internal event listener code so they aren&#8217;t exposed to the public.</li><li>You can now expose methods which accept a complex Java object. This means you can expose a method which accepts, say, a User object and the framework will use <a
href="http://jackson.codehaus.org/">Jackson</a> to marshal the parameters you provide into that object.</li></ul><p>We also now have a <a
href="http://groups.google.com/group/jpoxy">Google group</a>! So if you have any questions or comments we would love to hear from you.</p><div
class="betterrelated none"><p>No related content found.</p></div><p><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://werxltd.com/wp/2011/03/19/introducing-jpoxy-the-simple-json-rpc-implementation-for-java/"></a><a
class="a2a_button_twitter_tweet addtoany_special_service" data-count="none" data-url="http://werxltd.com/wp/2011/03/19/introducing-jpoxy-the-simple-json-rpc-implementation-for-java/" data-text="Introducing jpoxy, the simple json-rpc implementation for Java"></a><a
class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://werxltd.com/wp/2011/03/19/introducing-jpoxy-the-simple-json-rpc-implementation-for-java/"></a><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F03%2F19%2Fintroducing-jpoxy-the-simple-json-rpc-implementation-for-java%2F&amp;linkname=Introducing%20jpoxy%2C%20the%20simple%20json-rpc%20implementation%20for%20Java" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2011%2F03%2F19%2Fintroducing-jpoxy-the-simple-json-rpc-implementation-for-java%2F&amp;title=Introducing%20jpoxy%2C%20the%20simple%20json-rpc%20implementation%20for%20Java" id="wpa2a_4">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2011/03/19/introducing-jpoxy-the-simple-json-rpc-implementation-for-java/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <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"}} No related content [...]]]></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><div
class="betterrelated none"><p>No related content found.</p></div><p><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://werxltd.com/wp/2010/07/27/hbase-json-rpc-bridge-updated-allows-scanning/"></a><a
class="a2a_button_twitter_tweet addtoany_special_service" data-count="none" data-url="http://werxltd.com/wp/2010/07/27/hbase-json-rpc-bridge-updated-allows-scanning/" data-text="HBase JSON-RPC Bridge updated, allows scanning"></a><a
class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://werxltd.com/wp/2010/07/27/hbase-json-rpc-bridge-updated-allows-scanning/"></a><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2010%2F07%2F27%2Fhbase-json-rpc-bridge-updated-allows-scanning%2F&amp;linkname=HBase%20JSON-RPC%20Bridge%20updated%2C%20allows%20scanning" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2010%2F07%2F27%2Fhbase-json-rpc-bridge-updated-allows-scanning%2F&amp;title=HBase%20JSON-RPC%20Bridge%20updated%2C%20allows%20scanning" id="wpa2a_6">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2010/07/27/hbase-json-rpc-bridge-updated-allows-scanning/feed/</wfw:commentRss> <slash:comments>1</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://werxltd.com/wp/wp-content/uploads/2010/01/jsonrpc_example-0.91.zip?9d7bd4">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><div
class="betterrelated none"><p>No related content found.</p></div><p><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://werxltd.com/wp/2010/01/12/simple-json-rpc-updated-to-0-9-5/"></a><a
class="a2a_button_twitter_tweet addtoany_special_service" data-count="none" data-url="http://werxltd.com/wp/2010/01/12/simple-json-rpc-updated-to-0-9-5/" data-text="Simple JSON-RPC updated to 0.9.5"></a><a
class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://werxltd.com/wp/2010/01/12/simple-json-rpc-updated-to-0-9-5/"></a><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2010%2F01%2F12%2Fsimple-json-rpc-updated-to-0-9-5%2F&amp;linkname=Simple%20JSON-RPC%20updated%20to%200.9.5" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2010%2F01%2F12%2Fsimple-json-rpc-updated-to-0-9-5%2F&amp;title=Simple%20JSON-RPC%20updated%20to%200.9.5" id="wpa2a_8">Share/Save</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><a
href="http://werxltd.com/wp/2009/12/29/simple-java-implantation-of-json-rpc/#footnote_0_323" id="identifier_0_323" class="footnote-link footnote-identifier-link" title="Lightweight in both size and resources required to process data encoded in JSON vs. XML.">1</a></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><a
href="http://werxltd.com/wp/2009/12/29/simple-java-implantation-of-json-rpc/#footnote_1_323" id="identifier_1_323" class="footnote-link footnote-identifier-link" title="I did find this project 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 OSI-approved licence. If you are interested in helping me with this project, feel free to let me know!">2</a></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><div
class="betterrelated none"><p>No related content found.</p></div><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><p><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://werxltd.com/wp/2009/12/29/simple-java-implantation-of-json-rpc/"></a><a
class="a2a_button_twitter_tweet addtoany_special_service" data-count="none" data-url="http://werxltd.com/wp/2009/12/29/simple-java-implantation-of-json-rpc/" data-text="Simple Java implementation of JSON-RPC"></a><a
class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://werxltd.com/wp/2009/12/29/simple-java-implantation-of-json-rpc/"></a><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2009%2F12%2F29%2Fsimple-java-implantation-of-json-rpc%2F&amp;linkname=Simple%20Java%20implementation%20of%20JSON-RPC" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2009%2F12%2F29%2Fsimple-java-implantation-of-json-rpc%2F&amp;title=Simple%20Java%20implementation%20of%20JSON-RPC" id="wpa2a_10">Share/Save</a></p>]]></content:encoded> <wfw:commentRss>http://werxltd.com/wp/2009/12/29/simple-java-implantation-of-json-rpc/feed/</wfw:commentRss> <slash:comments>2</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><div
class="betterrelated none"><p>No related content found.</p></div><p><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://werxltd.com/wp/2009/07/29/magical-php-json-object-cleaner/"></a><a
class="a2a_button_twitter_tweet addtoany_special_service" data-count="none" data-url="http://werxltd.com/wp/2009/07/29/magical-php-json-object-cleaner/" data-text="Magical PHP JSON Object Cleaner"></a><a
class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://werxltd.com/wp/2009/07/29/magical-php-json-object-cleaner/"></a><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2009%2F07%2F29%2Fmagical-php-json-object-cleaner%2F&amp;linkname=Magical%20PHP%20JSON%20Object%20Cleaner" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2009%2F07%2F29%2Fmagical-php-json-object-cleaner%2F&amp;title=Magical%20PHP%20JSON%20Object%20Cleaner" id="wpa2a_12">Share/Save</a></p>]]></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><a
href="http://werxltd.com/wp/2009/07/16/soapjr-the-new-soap/#footnote_0_131" id="identifier_0_131" class="footnote-link footnote-identifier-link" title="And I would argue that even there processing time is being misused processing the data.">1</a></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><div
class="betterrelated none"><p>No related content found.</p></div><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><p><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://werxltd.com/wp/2009/07/16/soapjr-the-new-soap/"></a><a
class="a2a_button_twitter_tweet addtoany_special_service" data-count="none" data-url="http://werxltd.com/wp/2009/07/16/soapjr-the-new-soap/" data-text="SOAPjr, the new SOAP?"></a><a
class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://werxltd.com/wp/2009/07/16/soapjr-the-new-soap/"></a><a
class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwerxltd.com%2Fwp%2F2009%2F07%2F16%2Fsoapjr-the-new-soap%2F&amp;linkname=SOAPjr%2C%20the%20new%20SOAP%3F" title="LinkedIn" rel="nofollow" target="_blank"><img
src="http://werxltd.com/wp/wp-content/plugins/add-to-any/icons/linkedin.png?9d7bd4" width="16" height="16" alt="LinkedIn"/></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwerxltd.com%2Fwp%2F2009%2F07%2F16%2Fsoapjr-the-new-soap%2F&amp;title=SOAPjr%2C%20the%20new%20SOAP%3F" id="wpa2a_14">Share/Save</a></p>]]></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>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using apc
Page Caching using apc
Database Caching 1/38 queries in 0.034 seconds using apc
Object Caching 800/906 objects using apc

Served from: werxltd.com @ 2012-05-21 19:16:04 -->
