Archive for the ‘Work life’ Category

Building a RESTful webservice client in flash, and fighting all the way.

I’ve recently finished struggling with writing a client for a RESTful webservice in flash, and let me tell you it’s been a long painful process, one which i thought i’d like to share. First a (hopefully not too inaccurate) primer on what REST is all about.

RESTful web services use the full http specification in order to send an recieve data. That is, instead of just using POST and GET like most web applications, they also make use of PUT and DELETE, amongst others. Unlike SOAP webservices in which the body of the http message contains contextual information about a request or response, they use HTTP response codes and headers to convey this information in a much more simple lightweight way. I thoughroughly reccommend RESTful webservices by O’Reilly if you want to learn all about them.

They’re becoming increasingly popular, and so I decided I was going to build one for a current job. After scraping the rust off my php skills I managed to get a fully restful webservice together, and feeling pretty pleased with myself I turned to the easy part. Building a client for said webservice in flash.

Well that turned out not to be the easy part.

Problem 1 – No PUT or DELETE

First up I dicovered that the URLLoader class does not support any http methods other than GET and POST. I suspect that this has something to do with the way flash routes requests through the browser, however REST webbservices can accommodate this limitation (as it’s apparently quite common) by using something called overloaded POST, where the request is always sent as a POST with the real request method embedded as a url variable or in the message header. And here we hit problem two.

Problem 2 – No empty POSTs

When sending a POST request from flash, if there is no body in the request, then it is always sent as a GET. Ouch! Although it is sloppy, I figured I could get around this by putting junk vars in the body to stop this. Now because this webservice is out on the public web, it uses HTTP basic authentication as a security layer. To do this an encoded username/password string is sent in the headers of the request. If the correct key is not sent, the browser issues a 401 Unauthorised http code, to challenge the client and inform it what kind of authentication method is being used. You’ll see this in use when your browser pops up a login dialog for some web pages. Flash 9 and above does not allow some blacklisted headers to be sent to the server. Including, you guessed it…

Problem 3 – No authentication headers allowed

Thats right folks. Flash player 9 does no allow the Authentication:Basic header to be sent. 9.0.115 Allows it but only if the flash cross domain policy file on the server explicitly says so. Even if the swf is on the same server. Now in this case I could modify the cross domain file as it was my own webservice, but what about the thousands of webservices that I don’t control? Anyway I couldnt be sure on which domain the client would sit, so I decided to hack my webservice to look for an alternative custom header if Authentication:Basic wasn’t present. This was a horrible way to work around this, and I had no idea what I would do if I needed to talk to a third party webservice that used basic authentication. The next step was to recieve the response from the server to see if the login was correct, and…..

Problem 4 – No support for http status codes

The http spec defines a whole raft of http status codes for use in communicating the status of a request. 200-ok means success, and i’m sure you’re familiar with 404-not found. The problem is even though the URLLoader class has a status event, with a status code property, it doesnt actually work. First up is the fact that in some browsers all codes other than success are returned to the flash player as a 0, which isn’t actually a status code. Then there’s the fact that if anything other than 200 is recieved, flash fires the status event and stop the data from being recieved. This is even if the status code is not an error, but something such as a 201-created which is a subtype of the 200 success code.

So where next?

Well after banging my head against flashes broken HTTP support, i came across a potential solution in as3httpclientlib. An open source library that uses the AS3 socket classes to emulate the entire http specification. This is an awesome library and an absolute joy to use, in no time I had built my client and all was well with the world. Until I uploaded it.

Problem 5 -Socket policy files

This is a dark realm to be dealing with indeed. The current flash player does not allow socket connections to any server, unless a socket policy file is available, even if the client is in the same domain. Ok I thought i’ll just drop one next to my cross domain file. unfortunately its not that simple. The policy file needs to be served by a socket policy server running on port 843 of the same domain, or via the same socket the request was made to in response to a specific socket call. So basically I was screwed. I didnt have enough access to the server to set this up, and even if I could you need to be a sysadmin wiz to do so. I really dont think Adobe could have made this any more dfficult, and though there are articles on how to do this  on their site, they seem not be written for the people most likely to need them, flash developers. This means that the beautiful as3httpclient is esentially only useful for AIR development.

Picking myself up.

In the midst of all this a freind of mine had suggested just giving up and writing an rpc style proxy on the client side to talk to. I told him I refused to be beaten (though I later was, curse my foolish pride) but this planted the seed for my solution. What i have basically written is an extension to as3httpclientlib, that altough behaves the same from the users view, actually interprets full HTTP requests into text based POST meta data, that is sent to a php proxy file. This proxy then make the real request to the server, encodes the response in a similar meta format, then returns this to the flash player via URLloader behind the scenes. This is then deserialised into what appears to be a seamless as3httpclientlib response, et voila.

This is all in early alpha of course, but it seems to be working for me so far. The beauty of it being that this should enable flash to talk to ANY restful webservice, without all the pain you can see i’ve been through. Please have a play with it and let me know what you think. And so i humbly present to you, the snappily titled as3httpproxyclientlib. Its up on google code, under the same MIT licence as its parent library. It requires you have the parent library in your classpath, but otherwise, short of uploading the proxy file to a server of your choosing, and passing this url to the client instance, should behave in the same way. It does require you have CURLlib installed on your php server, but i believe thats pretty common, and I’m open to people contributing proxies in other languages and for other server configurations. In fact any contributions at all are welcomed as i’m no php developer and it’s probably leaves huge room for improvement.

Let me know how you get on, and don’t let flash get you down.

2 Comments


Certified flash certification certificate

It’s been a while coming but i finally got my certification pack today. I suppose it took a while to get all the certificates reprinted after the Macromedia/Adobe merger. It is very shiny though so i’ll let them off.

certificate

On a related note, one thing i forgot to mention in my previous post on the certification was that during the exam, a lot of questions were about code and techniques that beginners to flash would use. This makes a lot of sense, because as an experienced developer you’re supposed to be able to look at code from anybody and figure out whats going on. Not just completely datatyped, and neatly packaged stuff.

Keep that in mind if your coming up to the exam to not only revise the more advanced areas of the program, but also try to remember the techniques you used when you first started with flash.

No Comments


certifiedFlashDevelopers += me

It hasn’t quite sunk in totally, but this morning I took and passed the certified flash developer exam. It was quite an intense experience, but I came out of it with a spring in my step and a respectable 83%.

This has been a goal of mine for quite a while now, and it feels great to have finally accomplished this. The challenge of the certification has certainly helped me to broaden my flash skills into areas that I wouldn’t normally have dived head first into, and this in turn means I can introduce these new elements to the projects I work on.

I started to see the benefit of this exam, long before I actually took the thing. Anything that forces you to learn more about different areas of your field can only be good for your day to day work, and the sense of satisfaction is the icing on the cake.

Apologies if this is a bit of a gushing blog post, but I’m totally stoked at the moment (all be it a bit frazzled)

Anyway, lets move on to the gory details. The testing centre itself was a bizarre experience, first showing a couple of forms of ID before being led through to a room where I had to divulge myself of all my possessions, including my watch. Then on to the control room full of video monitoring equipment, with a big glass window looking through to the test rooms where I was given a short brief on procedures. Then led into the test room, and installed into my booth. I half expected to be sterilised and de-loused!

I can’t go into details about the exam itself, due to the NDA you have to agree to, but lets just say it’s definitely a tough one, like the official study guide says, “tough but fair”. It really was a collection of questions on nearly every area of flash, so you really need to know your onions to get through it.

A couple of resources to look at if you’re going to take the exam would be, firstly the official study guide. This is a great little book that I would recommend even to people who aren’t going to take the exam. It gives an overview of the whole of flash, and can really help to point out your weak spots, plus where you need to look to improve these areas. Secondly, get to know your Essential ActionScript 2.0 by Colin Mook. Better flashers than myself have pretty much covered everything about how great this book is, so let’s just say I concur. Lastly there’s a great mini preparation guide, and example exam by Tom Kitta, that helped a lot in the later stages of my training.

Next up, I’ll be continuing with my Korean language course, and hopefully learning to scuba dive in the near future. At least until they announce the Flash 8 exam! Ever feel like your head is going to explode? :P

7 Comments


Flash SMS to screen demo

As promised, here’s the demo for the sms to screen application I wrote about previously.

Also the Sydney Morning Herald has a great article on the whole event, with a positive write up about the SMS interactivity.

3 Comments


Four weddings and a flash SMS display

We just finished running the SMS to screen apps for the Sydney Festival, as part of Massmedia’s sponsorship of the event. The job entailed running SMS to screen applications at the Domain open air events, and in the Becks Bar at Hyde Park Barracks. Also at the Domain we were running trivia games played via SMS keywords, with some great prizes.

The whole thing was a big success, we had a great response from the audience of both events, especially at the Becks Bar where the app was running all night, even when the bands were on (which meant we had to be careful about the moderation ;) ) We even had quite a few marriage proposals go through on the big screens at the Domain, and one reply of acceptance, so who says Flash can’t do some good in this world. In fact that should go on my resume. Ho ho

The SMS end of the project was powered by our tool Traction allowing the same number to be used for the sms to screen application, and also the keyword driven trivia games that were being played. All the front end was done with Flash projectors, with video output going through a bewildering array of technology that seems to be the stock in trade of the video guys. The amount of wiring was truly terrifying, and i feared for my life when plugging in our gear!

I’ll try and get an example of the Domain display up here soon, all be it without the SMS capability. If i have some time i’ll put in a widget so you can try out some messages in your browser. We used a bottom of screen ticker for Becks Bar, but really went to town for the Domain, with an old style airport timetable display effect to really draw peoples attention to the messages.

Here’s a few pics from the show (the first pics in my blog too)

DSCF4187.jpg
The Domain site, on a lovely day in sunny Sydney

DSCF4177.jpg
A big screen. Could do with one of these for work.

DSCF4191.jpg
There goes the transition

DSCF4153.jpg
This is where the magic happens folks

Also Sydney photographer Pete Murphy has a cool Quicktime VR shot of the Domain during the jazz night. It really captures the beauty of the place. It’s a great outdoor concert venue, and I recommend that anyone who missed it this year goes to check it out in 07. I fact I recommend going to see as much as possible of the whole festival, as there’s some great acts and exhibitions all over the city. Antony and the Johnsons were spectacular in the State Theatre.

Hopefully we’ll be back again next year, and the lessons learned in the whole experience should serve us well for similar projects. Personally I think it’s great fun to get involved in the process of delivering a project such as this to the end user in a live setting. You get a great sense of achievement, and learn a lot about client interaction that you don’t nessesarily get from the web stats and click through reports that most projects produce. Great stuff!

3 Comments


Massmedia, now hiring.

We’re looking for some more Flash talent here at Massmedia. Here’s the beef.

Flash Developer

  • Industry-leading digital communications company
  • Minimum 3 years professional experience
  • Professional, down-to-earth persona
  • Creative warehouse environment in Surry Hills with pool table and drum-kit
  • Are you an experienced Flash Developer with a drive to create industry-leading solutions?

    Would you relish the opportunity to work with a passionate, innovative team of 30 in a great environment?

    Your Role as a Flash Developer

    Due to expansion, MassMedia Studios is looking for a new Flash Developer. A Flash Developer at MassMedia Studios is responsible for developing content based around the Macromedia Flash development platform for delivery over the internet and on multimedia devices such as CD-ROMs, kiosks and potentially, mobile devices.

    This includes the development of games, user interfaces, banner ads, presentation material, applications, e-learning and computer-based training.
    The Flash Developer must also be capable of integrating dynamic, database-driven content and be experienced at publishing to various applications and systems.

    If that sounds good you can find out more details on Seek, or visit the careers section of the Massmedia site. Email your applications to jobs@massmedia.com.au or apply via the websites application form.

    We’ve got some exiting projects coming up, so it should be a blast.

    Hope to hear from you eager job seekers soon (so i can have a christmas holiday ;) )

    No Comments


    They say your worst client is you.

    I always find it difficult to design for myself, (the continuing lack of a main page for this site is testament to that). And web companies creating their own site are no exception, especially if you have different departments with differing needs as to what information needs to be presented.

    It’s been a long hard road, but Massmedia have finally released out shiny new site. The countless graphic revisions we went through to get it right nearly drove our senior designer Tony Dolan, over the edge into the pit of despair and madness. In the end though all parties are happy with the result.

    We’ve thrown all the crayons in the box at it, it’s got DHTML goin’ on all over the place. Our HTML guys have really shone through. I also got to use the Flash/Javascript integration kit for the first time, it’s linking the homepage banner to the navigation. It may not be pushing it to the limits, but it’s still pretty sweet I think.

    All we need to do now is have a bit of AJAX in there, and a few Flex components, and we’ll have pretty much used everything.

    2 Comments


    Christmas party aftermath

    Ouch! Massmedia had our christmas bash last night. Work today isn’t the most focused i can tell you. Kain has posted some incriminating photos here, and i’m sure you’ll agree we’re not a pretty bunch. I for one am looking forward to home time.

    2 Comments


    Melbourne radio madness.

    Tektime have posted the interview i did on melbourne radio a while ago on their website. You can download it here. I’ts a general chat about flash and the industry.

    Rockin’

    No Comments



  • SetPageWidth