Hello.
You don't have to write webservice for that. Even a standalone java program fits in to your requirements.
No matter whether the running program is a webservice, servlet, etc; the logic...