Monthly Archives: February 2009

Review: Spring Recipes

springrecipesThis is a review of the book “Spring Recipes” by Gary Mak

I picked up this book as a supplement to the “Spring in Action” 1st/2nd editions that I have. This book takes the same approach as the O’Reilly Cookbook series and covers Spring 2.5. Basically it is a task/problem oriented book. Each little section addresses a small specific task such as “Unit testing Spring MVC Controllers” or ” Checking Properties with Dependency Checking”. Despite the task oriented recipes approach, the book is still structured in a progressive manner whereby a newcomer to the framework could start reading from the start to the end, learning the basics to the more complex. Each recipe is structured with a “Problem/Solution/How it works” section which presents a consistent approach to all content within the book. The examples are clear and in many places the author provides helpful diagrams to help the reader visualize the relationships involved in a particular problem.

I’ve gone through about 1/2 the book and stopped until I had an actual need for a specific recipe, however I do recommend the book and it is something I have cracked open as I’ve encountered problems.

Recommended: YES
Skills: Java / Beginner’s all the way to Advanced

Tagged , , ,

Book Review: JBoss in Action

This is a review of the the book JBoss in Action by Javid Jamae and Peter Johnson. The last time I looked at JBoss was about 2 years ago when our team was evaluating migrating our in house DAM application to the platform. We looked at JBoss mainly due to its integrated JGroups distributed caching capabilities which was what we wanted to use to enable our app to move horizontally. Anyways, long story short, that team no longer exists and I am working with Flex/AS3 now, so I picked up this book to keep up to speed on the latest going on with JBoss and to get an overview of its features.

This book is excellent. For such a complex application server, the authors do an excellent job of tackling each major JEE container service that JBoss provides, in a clear and concise manner and well explained and with small examples. This book is targeted towards advanced Java developers and even JEE app server admins, however I also feel that an intermediate Java developer could pick up this book and get started with this container just as easily. The book covers all the major JEE container services as well as JBoss Portal, and finally some excellent coverage on moving to production which covers clustering and tuning etc.

Overall I would give this book an A++.

Tagged ,

Easy Multipart file uploads / POSTs using URLStream or AS3HttpClientLib

When working on a cross runtime Zinc/AIR method method of posting files to a remote server, I came across Mike Stead’s URLFileVariable and URLRequestBuilder classes which makes the process of uploading multiple files (or ByteArray’s of data) via an HTTP POST much easier. Click here get his code

The basic concept is this: assuming you have one or more ByteArray’s of file data and the filenames to go with them, you prepare one or more URLFileVariable’s. The URLFIleVariable’s are added to the URLVariables as follows:

// create the standard "URLVariables"
var vars:URLVariables = new URLVariables(); 
// lets set a ByteArray of JPG data with the filename "myFile.jpg" against the POST variable "file1"
vars.file1 = new URLFileVariable(myByteArray, "myFIle.jpg");

Now at this point, as in my case, I am passing these URLVariables to either an AIR implementation of an HTTP client (using URLStream) or a Zinc implementation (using AS3HttpClientLib). This was all described here in another post.

In my AIR implementation of an HTTP client abstraction I use an URLStream and the code that deals with the URLVariables works something like the following.


/* Standard URLStream code that interacts with URLVariables
which contain Mike Stead's URLFIleVariables and uses his URLRequestBuilder */

var stream:URLStream = new URLStream();

// [ REGISTER for your stream listeners here...

/* use Mike Stead's URLRequestBuilder to properly build the 
URLRequest and encode it to contain all the multi-part data and filenames in the "vars" created above */
var req:URLRequest = new URLRequestBuilder(vars).build();

// ensure a POST because URLRequestBuilder only specifies POST if the variables contains files.
req.method = URLRequestMethod.POST; 

// define some URL to post to
req.url = "http://my.something.com.xyz/url_to_post_to.xyz";

// fire off the POST
stream.load(req);

// as the load completes, your event handlers for the stream should take over

Now on the other hand, if you happen to be using AS3HttpClientLib (as described in one of my other posts) you will be coding the equivalent of the URLStream code above, however using AS3HttpClientLib as follows. Here we do not use the URLRequestBuilder but simply manually retrieve the appropriate information from Mike's URLFileVariable instance.

....

// our AS3HttpClientLib HttpClient
var client:HttpClient = new HttpClient();

...
// [Remember to setup your "client" event hooks as described in the AS3HttpClientLib docs here]

// create a new POST request
var postReq:HttpRequest = new Post();

// lets create an Array to hold all the different "parts" of this multipart post
var parts:Array = new Array();

/* lets push the URLFileVariable we created earlier into the parts Array 
according to how AS3HttpClientLib expects it, as a Part object. Here
we are simply creating a new Part and populating it with the data
that we defined up above when we created the URLFileVariable */

parts.push(new Part("file1",vars.file1.data, "application/octet-stream", [{name:"filename",value:vars.file1.name}]));

// create a multipart that points to the "parts" Array
var mp:Multipart = new Multipart(parts);
postReq.setMultipart(mp);
					
// create a URI
var uri:URI = new URI("http://my.something.com.xyz/url_to_post_to.xyz");	

// fire off the request
client.request(uri,postReq);

Thanks again to Mike Stead’s UrlFileVariable and URLRequestBuilder classes for helping me make an generic HTTP multipart post process easier and I hope my post will give those reading some help along the way on implementing their own.

Tagged , , , , ,
Follow

Get every new post delivered to your Inbox.