Cross Domain Json (jsonp) Request

From the ever knowledgeable Wikipedia:

JSONP or “JSON with padding” is a communication technique used in JavaScript. It provides a method to request data from a server in a different domain, something prohibited by typical web browsers because of the same origin policy.

Recently, I had the requirement, whereby I needed to send several calls, via javascript, to a server. The catch was, that I needed the server to return the results of my calls, in the order in which the calls were made. Making the calls synchronous achieved this. Heres how:

(With inspiration from  this AJAX guy)

function getJson(arrayOfIds){

       jsonRequest = createSyncCORSRequest(“get”, host + “/info/get/”+arrayOfIds.join);

     if (jsonRequest) {
          jsonRequest.onloadend = function() {
               if(jsonRequest .status==200){
                    var jsonResponse = $j.parseJSON(jsonRequest.responseText);
                         functionWhichProcessesJsonResponse(jsonResponse );

function createSyncCORSRequest(method, url) {
     var xhr = null;
     if (typeof XDomainRequest != “undefined”) {
          xhr = new XDomainRequest();
, url,false);//false parameter makes it synchronous
          xhr.setRequestHeader(‘accept’, “application/json”);
     } else {
          xhr = new XMLHttpRequest();
, url,false);//false parameter makes it synchronous
          xhr.setRequestHeader(‘accept’, “application/json”);
     return xhr;


Nelson Vivas, impersonating json leaping from one domain to the next.

Java method to return NULL as an empty String.

What if the String you are expecting comes back as null? Would it be the end of the world for you? Not if you have good exception handling. This method is also useful.

It will return an empty String “” of the String is null. If the String is not null, it will return the trimmed version of the Java String.

 private String getNullAsEmptyString(Object o){

        if( o instanceof String){
            if( o == null){
                return “”;
            return  o.toString().trim();

        return null;


Nwankwo Kanu, never known to deal with null Strings.

Setting Java Opts In Apache Tomcat

Setting Java Opts in the bin/catalina.(bat/sh) file can be used by your webserver to find files such as your applications property files.


Below is an example of increasing the memory size to hopefully avoid java out of memory errors. Also below, the location of property files is specified.

For windows the catalina.bat file should have the following line straight after the top comment section
set JAVA_OPTS=%JAVA_OPTS% -Xms512m -Xmx512m -XX:MaxPermSize=256m\workspaces\ws_4\application-one-name\properties\dev\\workspaces\ws_4\application-two-name\properties\dev\
For linux the catalina.bat file should have the following line straight after the top comment section
JAVA_OPTS=”$JAVA_OPTS -Xms512m -Xmx512m\workspaces\ws_4\application-one-name\properties\dev\\workspaces\ws_4\application-two-name\properties\dev\prop.propertiess”

Note the quotes in the linux version as well as the absence of the word set.


Lee Dixon, smug in the knowledge that his applications could find their properties files.