Thursday, May 26, 2011

Using Groovy Code in SoapUI Requests


SoapUI is simply amazing. It's really a pity that I found out about it so soon. I could have used in so many projects before. Just listing its incredible features is a topic for a new post ...

Anyway, this particular post will deal with one specific feature of SoapUI, namely, the enhancement of the request being sent to the server. I was very fascinated to find out that SoapUI can manage the entire request/response cycle even when it comes to AMF. That was great ... for most cases. There were some exceptional use cases where I could not simply put data as a simple input parameter. One of those cases was when I wanted to use file upload on one of my projects.

The way I had implemented this file upload involved sending a byte array with the file's bitmap data from the client to the server. At the beginning I thought that it was not possible to send anything more complex than strings and numbers through SoapUI. The only other option was to test it through the application itself which involved a lot of complications.

Then, out of a sudden, I found out that arguments sent via a SoapUI request could be augmented, or event completely overriden by using short Groovy scripts directly within the request interface

As you can see it on the shot, it is very easy to jump in, and "hack" the request, before it is sent to the server. You can even log whatever you need at runtime, (please don't try to log the contents of the bytes array, as I did, because you'll be prompted with an immensely huge and difficult to close popup window :)))



The code is not my most beautiful creation, but it works anyway.

No comments: