Middleware implemention in Java