Some Web Service Foundation Improvements
Being in the office (thanks Aldert/Milton) with nothing but a big screen and no crying cat climbing up my legs certainly helps
I just committed a bunch of good improvements to the WSF framework. I ‘generified’ some of the WSF classes and also introduced a WebServiceActionContext.
The WebServiceActionHandler now looks like this:
public interface WebServiceActionHandler<Account extends WebServiceAccount>
{
Object execute(WebServiceActionContext<Account> context) throws ActionHandlerException;
}
Using the Account type parameter you can specify a WebServiceAccount subclass to be used. This is useful if you have a WebServiceAccountManager that returns more info than just the public and secret key. In our case we also need the user’s id for example.
Also remember, the Actions are Spring (prototype) beans so if you need a reference to some application component then simply wire that up in your beans xml or use any of the other Spring mechanisms.
Generics are great
I realize that even more now because of my C++ expeditions.
There is now also a WebServiceActionContext that contains the before-mentioned Account, the HttpServletRequest and the current web service request id. Actions sometimes need to access all of those to execute their logic.
Example:
public class SayHelloAction implements WebServiceActionHandler<DummyWebServiceAccount>
{
private String name;
@WebServiceParameter
public void setName(String name) {
this.name = name;
}
public Object execute(WebServiceActionContext<DummyWebServiceAccount> context) throws ActionHandlerException {
return new String[] {
"Hello, " + name + "!",
"Your user id is " + context.getAccount().getUserId(),
"Your IP is " + context.getHttpServletRequest().getRemoteAddr()
};
}
}
Which returns:
{
'webServiceCallId': '9585ece2-07d4-44bb-a4a8-258eaf9aa6e2',
'response': [
'Hello, Stefan!',
'Your user id is 42',
'Your IP is 0:0:0:0:0:0:0:1%0'
]
}
Pretty nifty! This little framework is getting in shape quickly now. There is still some work to do, including cleaning up some monster 300 line function. When that is done I will declare a v1.0 release.
The project is hosted at Google Code as PolarRose WSF
Created
