Ejemplo n.º 1
0
 def call(self, method, *args, **kwargs):
     provider = self.registry.get_random_provider(self.interface, version=self.version, group=self.group)
     client = HttpClient(url="http://{0}{1}".format(provider.location, provider.path))
     try:
         return client.call(method, *args, **kwargs)
     except HTTPError, e:
         raise ConnectionFail(None, e.filename)
Ejemplo n.º 2
0
 def call(self, method, *args, **kwargs):
     provides = self.registry.get_provides(self.interface,
                                           version=self.version,
                                           group=self.group)
     if len(provides) == 0:
         raise NoProvider('can not find provide', self.interface)
     ip_port, service_url = random.choice(provides.items())
     # print service_url.location
     client = HttpClient(
         url="http://{0}{1}".format(ip_port, service_url.path))
     try:
         return client.call(method, *args, **kwargs)
     except HTTPError, e:
         raise ConnectionFail(None, e.filename)
Ejemplo n.º 3
0
 def call(self, method, *args, **kwargs):
     provider = self.registry.get_random_provider(self.interface, version=self.version, group=self.group)
     # print service_url.location
     url = "http://{0}{1}".format(provider.location, provider.path)
     # print(url)
     client = HTTPClient(url)
     try:
         response = client.request(method, *args, **kwargs)
         if response.data.ok:
             return response.data.result
         else:
             raise DubboClientError(message=response.text, data=response.data)
     except HTTPError as e:
         raise ConnectionFail(None, e.filename)
     except ReceivedNon2xxResponseError as error:
         if error.code in dubbo_client_errors:
             message = str(error)
             raise dubbo_client_errors[error.code](message=message, data=error.args, code=error.code)
         else:
             message = str(error)
             raise DubboClientError(message=message, data=error.args, code=error.code)
     except ReceivedErrorResponseError as error:
         if error.response.code in dubbo_client_errors:
             message = str(error.response.message)
             raise dubbo_client_errors[error.response.code](message=message, data=error.response.data,
                                                            code=error.response.code)
         else:
             message = str(error.response.message)
             raise DubboClientError(message=message, data=error.args, code=error.code)
     except JsonRpcClientError as error:
         raise DubboClientError(message=str(error), data=error.args)
     except Exception as ue:
         if hasattr(ue, 'message'):
             if hasattr(ue, 'reason'):
                 raise InternalError(ue.message, ue.reason)
             else:
                 raise InternalError(ue.message, None)
         else:
             raise InternalError(str(ue), None)