Input and output mappings are the way to go, obviously it will work if you put it inside a script task but I don't recommend that way at all. Using java snipets inside an xml file is definitely not a good approach. WorkItems will allows you to hook different implementations for different environments, like for example a MockService for your unit tests and the RealService for your production environments.
Cheers