Web Services - Amazon Style
It’s been quiet here but that doesn’t mean I’ve been sitting still. I’ve been quite busy actually.
Currently I’m working on a simple framework that needs to become Polar Rose’s standard way to do (public) web services. It is modelled after Amazon’s Query-style web services that they use for things like SQS and EC2 where the invokation is basically a simple GET with traditional CGI encoded parameters. Except that I don’t return responses in XML but in JSON, which I find much more easy to deal with from the client side.
Here is a simple example. This is the source code for a simple SayHello action:
public class SayHelloAction implements WebServiceActionHandler
{
private String name;
@WebServiceParameter
public void setName(String name) {
this.name = name;
}
public Object execute() throws ActionHandlerException {
return "Hello, " + name + "!";
}
}
This translates to a call like this:
http://localhost:8080/api ?Action=SayHello &Name=Stefan &Timestamp=2007-11-07T10%3A07%3A33%2B00%3A00 &AccessKey=TestAccount &Version=2007-10-10 &SignatureVersion=1 &Signature=V9G6XhL%2BW6vQDNIcs9O%2F%2FEufSzQ%3D
And returns a response that looks like this:
{
"response": "Hello, Stefan!",
"webServiceCallId":"?5EE80743-6B11-434B-93C8-193AF5EF2F78"
}
I’m now finishing the work to support more complex types beyond String and fixing some validation issues. I’ll post a more complex example when that is done.
If you are interested in following this code then check it out at Google Code. It’s a little rough at the moment but I will guarantee that this will shine when we take it into production here.
Created
