Refactoring COSM gateway in order to support both WS and HTTP APIs.