Tuesday, 12 January 2010

Webscripts need refreshing!

Gotcha #1 for today is that when working with webscripts. They need refreshed . For those used to working in php and seeing results immediately, it's a bit of a trial having to remember. However it will save you a lot of pain and woe if you get into your head that after every change to your webscript, refresh it before debugging any further.You can do this either by restarting the server, or going to

http://localhost:8080//console and refreshing from there.

NOTE: If working on Alfresco webscripts within the alfresco system, it should be

http://localhost:8080/alfresco/service/

And refresh from there.

Monday, 11 January 2010

Error in the Chapter 2 Tutorial

I suppose it serves me right for following the tutorial so blindly and assuming that all the code was correct. My first attempt at doing a webscript (as per tutorial) nearly came to an abrupt end.

In the tutorial when it's talking about setting up the newsfeed script, there are some errors in the javascript and also in the freemarker template.

For newsfeed.get.js, the code should read...

//Define the remove service url                       
var newsServiceUrl = "http://www.renewableenergyworld.com/rss/renews.rss";
//Create an instance of remote connector. We will use http type.
var connector = remote.connect("http");
var re = /^http:\/\//;
if (!re.test(newsServiceUrl))
{
   newsServiceUrl = "http://" + newsServiceUrl;
}
//Make the HTTP connection.
var result = connector.call(newsServiceUrl);

if (result !== null)
{
    //Conver the result into String.

    var rssXml = new String(result);   
    var re = /<[r|R][s|S]{2}/; // Is this really an RSS document?
    //Make sure it is a RSS XML document.
    if (re.test(rssXml))
    {
        model.message = "We got into the processing bit";
        // Strip out any preceding xml processing instructions or E4X will choke
        var idx = rssXml.search(re);
        rssXml = rssXml.substring(idx);
       
        // It looks we need to get rid of the trailing junk as well.
        if ( rssXml.indexOf('') != -1 ) {       
            rssXml = rssXml.substring(0,rssXml.indexOf('')+6);
        }
       
        // Parse the xml document using E4X APIs.
        var rss = new XML(rssXml);
        model.title = rss.channel.title.toString();
        model.items = [];
   
        var item, obj;
        //Loop over all feed items.
        for each (item in rss.channel.item)
        {
           //Retrieve field valuse and populate the JSON object that later will be
           //passed on the the view template.
           obj = {
              "title": item.title.toString(),
              "description": item.description.toString(),
              "link": item.link.toString()
           };
          
           model.items.push(obj);
        }       
       
    }    else {
       
        model.message = "Doesn't work!";
       
    }
}
Notice the "<" arrow in the "re" variable for testing whether its an RSS feed or not. It's was round the wrong way.

Secondly, in the freemaker template, it should be...


  
${title}

  
${message}

  

    <#if items?exists && (items?size > 0)>
        <#list items as item>
            

            
${item.description}

       
   
   
<#-- end of body -->
<#-- end of dashlet -->
 For some reason the "items?size > 0" does not equate to a true/false expression. It needs to be enclosed in ( ) for it to work.

SpringSource Tool Suite

Getting a bit tired of the whole command line thing. Makes it slightly easier, but still a bit hard to follow in places.

Time to move on to the SpringSource Tool Suite and see how the roo/surf plugins/addons in relation to making things easier.

The first, almost immediate difference I notice is that deploying (and more importantly REdeploying) out to the tomcat server is done with a minimum of hassle. Made a quick change to the footer, redeployed, and Bob's your Auntie May, it worked. No errors generated, no confusing messages, it just worked!

The next stage is to see how much more quickly I can go through the tutorials for Chapter 2 before I come across some other problems.

Problems with deployment

Well it would seem that although the initial deployment takes place without any problems, deploying any changes is not as straight forward. Here's what I'm encountering...
  1. Changes made to some of the webscripts. Nothing exiting at the moment, just changing the footer text of the basic template.
  2. Trying to do mvn tomcat:deploy results in a build error saying that it "Cannot invoke Tomcat manager: FAIL - Application already exists at path /community.
  3. Ok, perhaps that's a valid message I said to myself. Standard logic might suggest that it cant deploy something that's already there. So, after a bit of poking around I try mvn tomcat:redeploy
  4. Uh oh, although I now get a build successful message, when trying to view the site I get a 404 message.
  5. Not only that, when I go back in to view the file on which I did the original edit, it has reverted back to its pre-edit state.
Bit stumped at the moment, the investigation continues.

Sunday, 10 January 2010

Installing

Well, it wasn't really as smooth as I had thought. I'm not sure how much of it was me "thinking" I was reading the instructions correctly, and how much of it was little bugs here and there.

In saying that, the docs at http://www.springsurf.org/sites/1.0.0.M2/spring-surf-devtools/spring-surf-roo-addon/reference/html/intro.html are really good and a credit to the developers that a framework that is still in its infancy is coming with such detailed docs. Some points to note are:

  1. The main problem I had was in the deployment to the tomcat server. When typing in mvn tomcat:deploy it produced a whole load of what I thought were errors and attempts to download various pieces of software from repos located around the net. The main issue was with me not having setting up the tomcat config as per the docs. I didn't realise that maven was using that user to deploy the application (although...thinking about it...it does make sense!)
  2. I had some other issues when it came to deployment and maven trying to reference the old roo plugin and not the updated one. Uninstalling the plugin from the roo console using:

    addon uninstall *surf*.zip

    and then reinstalling the plugin with

    addon install --url file:/path/to/file

    Also helpful to do a clean using

    mvn clean

  3. When trying to access the extra surf commands, it's important to realise that you wont actually be able to do this until the application has successfully deployed. Once that has happened it should come up fine.
  4. Other problems encountered were simply me not reading the docs closely enough. Serves me right for trying to do this at a weekend.

Starting Out

When it was announced that Alfresco were collaborating with Spring on a new framework to make building Surf applications a lot easier, I was thrilled to say the least. My first tentative steps into building applications with Surf had not gone very well. Although the potential of the Surf platform was evident, it was very clunky, involved lots and lots of XML configuration files, and trying to get your head around how everything fitted together made the whole product seem impenetrable.

So, here goes with Roo. Hopefully a quick an easy command line tool (or eclipse add in) that will make the whole process a lot less painful. I'll try and document my successes and pitfalls along the way for my own, as well as anyone elses future benefit!