Friday, August 1st, 2008

Another Jaxer 1.0 Release Candidate with new APIs

Category: Aptana

>Greg Murray has blogged about a new release candidate for Aptana Jaxer that contains a lot of new features.

Kevin Hakman told us about the release:

We’ve had server-side JS database APIs all along, but now handing result sets is even easier. There’s also now full fine grain control and access to the entire communication cycle with APIs for message headers, redirects, content and types. Speaking of types… for the first time with Jaxer, you can return content types other than HTML including JSON, XML, GIF, etc… Yes, even GIFs. Jaxer has a fresh new Image API that among other things can convert Canvas to static images and serve them up. Like, Greg, I too really like the idea of using Jaxer for easily creating JSON data services which is a rapidly growing trend as developers discover the powerful capabilities of JSON more and more. In Jaxer, it’s very cool since it’s all native JavaScript on the client, on the wire, and on the server. There’s even enhanced JSON serialization to make it even easier than before on both client and server. JSON services also open Jaxer to be useful in combination with rich internet clients other than Ajax UIs such as Flash, Flex or even Silverlight since all those support JavaScript on the client and can consume JSON data. For Ajax and RIA developers this is a boon since you can now write your client-side and server-side code in the same language. And if you prefer XML data services Jaxer’s native E4X (ECMAScript for XML) support means you can handle XML docs natively in JS on Jaxer as well.

This release also includes a totally new concept: a secure sandbox which as Greg explains, “lets you load, on the server, pages from other domains and allow their JavaScript to execute without giving them access to the Jaxer API or your own server-side code, but still gives your code access to their window objects and anything inside them”. For anyone who has ever done screenscaping for mashups or other applications, this really helps a lot since Ajax pages have historically thwarted scraping operations. With this feature in Jaxer you can securely get a remote page, execute its functions, and scrape the resulting DOM nodes (yes, you need not do tedious manipulations with strings) and voila!

Here are the features:

  • Application context settings that allowing for easier app configuration, app properties, database settings, etc…
  • Database API enhancements with richer APIs for working with result sets.
  • Server-side image manipulation including server-side canvas support and ability to convert to other image types.
  • Native command execution API so that you can run system commands and handle the output from those.
  • Asynchronous server-side JavaScript processing lets you implement callbacks in your server-side code too.
  • Ability to return custom content types (e.g. json, xml, gif, html, etc…)
  • Full control of the request/response lifecycle including setting redirects, headers, content, etc…
  • Secure sandbox supporting cross domain calls, sandboxed JavaScript execution, META refreshes, …
  • Serialization support for JavaScript objects to and from XML, E4X and JSON.

Uri Sarid has a great post that shows how you can do DOM Scraping with Jaxer, and updates it for this latest release:

There’s a lot of other new goodness in Jaxer 1.0, as well as the official released version of the Mozilla engine found in Firefox 3. So for example getElementsByClassName is natively implemented (see John Resig’s speed comparison), in addition to the other Mozilla features such as built-in XPath functionality and a very robust DOM feature set — just what you need for some serious ‘screen scraping’, mashups, and content repurposing.

Let’s see it in action!

It includes code that shows the Sandbox in action, as well as the DOM work:

javascript
< view plain text >
  1. // Gets a fragment of the remote page's HTML, after some cleanup  
  2. function getFragment(title, url, isClassName, identifier, classesToRemove)  
  3. {  
  4.     var sandbox = new Jaxer.Sandbox(url);  
  5.     var contents = sandbox.document[isClassName ? 'getElementsByClassName' : 'getElementById'](identifier);  
  6.     var container = addToPage(title, contents);  
  7.     if (classesToRemove)  
  8.     {  
  9.         if (typeof classesToRemove == "string") classesToRemove = [classesToRemove];  
  10.         classesToRemove.forEach(function(className)  
  11.         {  
  12.             removeNodeList(container.getElementsByClassName(className));  
  13.         });  
  14.     }  
  15.     return container.innerHTML;  
  16. }  
  17. getFragment.proxy = true;

Related Content:

Posted by Dion Almaer at 1:51 pm
7 Comments

++++-
4.2 rating from 32 votes

7 Comments »

Comments feed TrackBack URI

I won’t use until there are BENCHMARKS!! The possiblity to use it with nginx would be great too…

Comment by thatvetguy — August 1, 2008

I’m personally really excited about Jaxer, and am going to try my damnedest to get to use it for my next major app.

Comment by eyelidlessness — August 1, 2008

On the last Jaxer post I commented on my initial impressions of Aptana Studio (which comes with a Jaxer interal server). Since then with help from Aptana I believe I have been able to resolve my performance issues related to crashing and sluggishness.
.
It required a fresh install, changing some memory settings in an ini file, turning off some features I don’t use, and not installing a particular SVN plugin that I think may have been causing some of my PermGen issues, but now it seems to be purring along just fine. I used it for work all day today without any crashes or noticeable sluggishness. Hopefully I am just a random case that has this much trouble getting it running smoothly.
.
In any case, I have found the Aptana team to be rather responsive and friendly, and that impressed me enough to go ahead and purchase a Pro license.
.
Having had another 3 days to fiddle with it, I can say that for a new user you may need to have a bit of patience with it. Hopefully you don’t have all the performance problems to work through that I did, but then there are a few things that don’t seem immediately intuitive for a new user such as setting up FTP for a project, previewing a project, and finding and setting the preferences for particular things. Fortunately for the first two there are screencasts and plenty of documentation.
.
In my last IDE I didn’t really have to change many preferences to get it where I liked. Aptana seems to be a lot more complicated, with a lot more features, and so getting it just right seems to be a lot more work. There are several times more preferences in Studio than my previous IDE and yet I’m still finding there aren’t preferences for some of things I want to turn off or change the default behavior of. I’m just writing tickets for them as I go along.
.
And then as I partially mentioned in my last post there are features that seem strangely missing such as word wrap in the editors and consoles, and find and replace for entire folders where the results display the matched text in each document. The latter is rather handy so you don’t have to open an entire tree of search results one file at a time to see if it is the right one. I should mention however that Aptana currently is working on the word wrap for the editors. I don’t know about the consoles so I created a ticket for it.
.
Having said all that, things are looking a lot more promising than a few days ago. We’ll see how it goes. Cheers.

Comment by GregHouston — August 1, 2008

Interesting on the performance. On a fresh install, where I didn’t install anything special (except for Adobe AIR support), I have periods of 30-45 seconds where the editor is frozen and the hard drive is being hit mercilessly. Seems like they should put some time into figuring this out, as I do not have the same problem with either Komodo or NetBeans.

Comment by Nosredna — August 2, 2008

@Nosredna: I imagine you may very well be having memory problems as well. Here are some suggestions:
.
Go to Window>Preferences>General and select “Show Heap Status”. This will add a little progress bar at the bottom right of your UI so that you can troubleshoot memory issues.
.
Go to Help>Aptana Troubleshooting>View Aptana Studio Log File and see if you aren’t getting either of the two following errors:
.
java.lang.OutOfMemoryError: Java heap space
.
java.lang.OutOfMemoryError: PermGen space
.
If so, go to C:\Program Files\Aptana\Aptana Studio or wherever you have installed it, and open AptanaStudio.ini. Replace everything with the following. Hopefully the blog doesn’t mess this up:

-name
Aptana
Studio
-vmargs
-Xmx512M
-Xms256M
-XX:MaxPermSize=256m
-Djava.awt.headless=true

.
I also turned off Folding and Validation for most of the individual editors in Window>Preferences>Aptana>Editors
.
It’s also probably a good idea to check how much memory you have to spare in your OS’s version of the Window’s Task Manager. Aptana Studio uses 4 times as much memory as my last IDE. With 2GB of RAM on my computer, once I get all the applications open that I normally do while working there is very little available RAM left, a lot of which is due to the VMware XP install that I run solely for the purpose of viewing sites with IE6. In any case I ordered a couple more Gigs of RAM to give me some more breathing room.

Comment by GregHouston — August 2, 2008

Thanks Greg

Comment by Nosredna — August 3, 2008

Back to Jaxer… ;-)

…we are working on at least getting some simple benchmarks online ASAP. The JavaScript part of the benchmarks is already clear: it performs as fast as JavaScript in Firefox 3, which is pretty fast. But we also want to show the performance of DB and file access and of DOM processing, and wrap it up into real-world scenarios showing how fast pages and apps perform.

Comment by Uri — August 4, 2008

Leave a comment

You must be logged in to post a comment.