def on_message(self, message): """ :type message: str or unicode The parameter ``message`` is supposed to be in JSON format: .. code-block:: javascript { ["id": unique_id,] ["service": service_name,] ["data": parameter_object,] "method": method_name } When the service is not specified, the interface will act as a service. """ remote = Remote(**(json.loads(message))) if not remote.service: remote.service = self response = Response(remote.call(), remote.id) self.write_message( json.dumps(ArraySerializer.instance().encode(response)) )
def on_message(self, message): """ :type message: str or unicode The parameter ``message`` is supposed to be in JSON format: .. code-block:: javascript { ["id": unique_id,] ["service": service_name,] ["data": parameter_object,] "method": method_name } When the service is not specified, the interface will act as a service. """ data = json.loads(message) remote = Remote(**data) response = None if remote.service: remote.service = self.component(remote.service) else: remote.service = self try: response = Response(remote.call(), remote.id) except AttributeError as e: response = ErrorResponse('The method does not exist.', str(e), data) simplified_response = ArraySerializer.instance().encode(response) simplified_response.update({ 'service': data['service'], 'method': data['method'] }) self.write_message( json.dumps(simplified_response) )