Server Push In Java with Atmosphere

After socket.io and node.js – I wanted to check if there is something that can be useful for enterprise java webapps that are typically deployed into Tomcat.

I had read about Jetty Supporting Server push and tomcat 7 having something similar.

Wanted something that will have server and client side pieces – very similar to socket.io on node.

Stumbled upon Atmosphere – https://github.com/Atmosphere/atmosphere

The only Portable WebSocket/Comet Framework supporting Scala, Groovy and Java — Read more

http://jfarcand.wordpress.com

Will start my exploration on that

Node.js Error: listen EACCES

I was really looking forward to get started with Node.js. Wrote a very small program called eg1.js

<code>

console.log(“Hello node”);
var http = require(‘http’);
var url = require(‘url’);
http.createServer(function (req, res) {
console.log(“Request: ” + req.method + ” to ” + req.url);
res.writeHead(200, “OK”);
res.write(“<h1>Hello</h1>Node.js is working”);
res.end();
}).listen(81); // LOOK AT THIS
console.log(“Ready on port 8081”);

</code>

When I ran it

sai@sai-home:~/nodes$ node

Hello node
Ready on port 8081

events.js:68
throw arguments[1]; // Unhandled ‘error’ event
^
Error: listen EACCES
at errnoException (net.js:769:11)
at Server._listen2 (net.js:892:19)
at listen (net.js:936:10)
at Server.listen (net.js:985:5)
at Object.<anonymous> (/home/sai/nodes/example1.js:9:4)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)

As we could the console.log are print – so I was thinking about the other anonymous calls – eaily understood that it was the listen call that failing.

But I was confused as 81 was a free port (confirmed thro netstat as well).

Thanks to stackoveflow

http://stackoverflow.com/questions/12127293/writing-a-node-application-and-encountering-an-error-when-running-node-server-j

I needed to change the port to something > 1024 or use sudo while running the program

Debugging Dojo Part1 : djConfig.debugAtAllCosts

More often than not, we use the dojo.require(“dependant modules”) to load various dependent modules into our pages. But when we set a debug break point in firebug & step into, we see the following code – almost a deadend since dojo uses evals for loading the modules

Dojo dead end - not able to see the code of internally loaded modules

Other alternative is to use the djconfig.debugAtAllCosts by making the following change.

Enabling debugAtAllCosts

Thus we could use this flag to make sure dojo uses dynamically inserted script tags to load the various modules.

With any facility, comes its own caveats to be beware of – debugAtAllCosts is no exception.

Kindly refer to the How DebugAtAllCosts Works for a detailed explanation on reasons related due to debugAtAllCosts can fail.

More into this my next post

“Object doesn’t support this action” error in IE7/IE8

Yet another IE woe – if you want your code to work on IE – be forewarned that harmless looking like the one below would break with “Object doesn’t support this action” error.

items=[];//define a array
length=items.length;//throws error since the term length is treated special in IE
for(item in items){
//again the term item is treated in a special way in IE – would throw the same error.
}

Either make sure these are local variables by prefixing them with var.

items=[];//define a array
var length=items.length;//throws error since the term length is treated special in IE
for(var item in items){
//again the term item is treated in a special – would throw the same error.
}
otherwise rename the variables
items=[];//define a array
mylength=items.length;//throws error since the term length is treated special in IE
for(myitem in items){
//again the term item is treated in a special – would throw the same error.
}

After a lot of digging, I found that any variable declared without the var keyword is considered to global in Javascript. Specifically in IE – They get attached to a global collection called document.all.

So helper methods associated with document.all such as

  1. item
  2. namedItem
  3. tags
  4. urns

and the property “length” are all considered reserved with respect to global variables in IE.

Also refrain from using these words as IDs for any HTML element.

JQuery Select Button

To get the current value is very simple using val().

JavaScript: $(‘#selectList’).val();

But sometimes you may need to get the selected option’s text. This is not as straight forward. First, we get the selected option with :selected selector. Then once we have the option, we can get the text with the function, text().

JavaScript: $(‘#selectList :selected’).text();

All credits to :http://marcgrabanski.com/article/jquery-select-list-values