Started working on Web Service Foundation 2.0
I’ve created a 2.0 branch in the polarrose-wsf project where I want to try out some new ideas.
Some things on the list:
- Merge the wsf and wsf-examples into one maven project as modules (already done)
- Merge the projects on Google code
- Add the wsf-client module to the project
- Depend on Spring 2.5 for auto detection of action handlers. Just like Spring 2.5 can do with @Controller annotated Spring MVC controllers.
- Remove as many dependencies as possible (commons-*)
- Remove the need for prototype scope beans by seperating handler and parameters (work in progress)
- Write proper JavaDoc for at least all top-level code
I’ve already made a rough implementation of the seperation of Action and Parameters task. The ActionHandler interface now looks like this:
public interface WebServiceActionHandler<Account extends WebServiceAccount, Parameters>
{
Object execute(WebServiceActionContext<Account> context, Parameters parameters)
throws ActionHandlerException;
}
The Parameters parameter is new. So that means you need to define a bean that contains the fields to which the request parameters are mapped. For example the AddNumbersAction action from the example project now becomes:
public class AddNumbersAction implements WebServiceActionHandler<DummyWebServiceAccount, AddNumbersAction.Parameters>
{
public Object execute(WebServiceActionContext<DummyWebServiceAccount> context, Parameters parameters)
throws ActionHandlerException
{
int total = 0;
for (Integer number : parameters.getNumbers()) {
total += number;
}
return total;
}
public static class Parameters
{
private List<Integer> numbers;
public List<Integer> getNumbers() {
return numbers;
}
@WebServiceParameter
public void setNumbers(List<Integer> numbers) {
this.numbers = numbers;
}
}
}
I like to use inner classes to keep the action and parameters together but if you don’t like that then you can also do this of course:
public static class AddNumbersParameters
{
private List<Integer> numbers;
public List<Integer> getNumbers() {
return numbers;
}
@WebServiceParameter
public void setNumbers(List<Integer> numbers) {
this.numbers = numbers;
}
}
public class AddNumbersAction implements WebServiceActionHandler<DummyWebServiceAccount, AddNumbersParameters>
{
public Object execute(WebServiceActionContext<DummyWebServiceAccount> context, AddNumbersParameters parameters)
throws ActionHandlerException
{
int total = 0;
for (Integer number : parameters.getNumbers()) {
total += number;
}
return total;
}
}
Personally I think this is a little cleaner design than what I did for the 1.x version.
The speed also went up!
- 1.2-SNAPSHOT ~ 1200 requests/second
- 2.0-SNAPSHOT ~ 2100 requests/second
This is because the prototype beans are gone of course; they don’t have to be initialized every time. I can probably get the speed up more by caching some things that are looked up every time with introspection.
Spring 2.5 has a lot of interesting new features. I really hope to make WSF 2.0 much more Spring friendly and make it possible to get a web service up and running with as less code and configuration as possible.
Created
