Restlet, is one technology that I have been looking into, and following its getting started guide. It seems promising, and once I'm over the learning curve, it might fit.
public static void main(String[] args) throws Exception {
Server mailServer = new Server(Protocol.HTTP, 8111);
mailServer.setNext(new MailServerApplication());
mailServer.start();
}
Then define your routes:
Router router = new Router(getContext());
router.attach(base + "/", RootServerResource.class);
router.attach(base + "/accounts/", AccountsServerResource.class);
router.attach(base + "/accounts/{accountId}", AccountServerResource.class);
return router;
Make interfaces for your resources.
public interface AccountResource {
@Get("txt")
public String represent();
@Put("txt")
public void store(String account);
@Delete
public void remove();
}
Then, your concrete implementation, to actually do stuff:
public class AccountServerResource extends ServerResource implements AccountResource {
private int accountId;
@Override
protected void doInit() {
this.accountId = Integer.parseInt(getAttribute("accountId"));
}
@Override
public String represent() {
return AccountsServerResource.getAccounts().get(this.accountId);
}
@Override
public void store(String account) {
AccountsServerResource.getAccounts().set(this.accountId, account);
}
@Override
public void remove() {
AccountsServerResource.getAccounts().remove(this.accountId);
}