How to use the dapr.proto.common_v1.InvokeResponse function in dapr

To help you get started, we’ve selected a few dapr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dapr / python-sdk / tests / clients / fake_dapr_server.py View on Github external
headers = headers + (('h' + k, v), )
            trailers = trailers + (('t' + k, v), )

        resp = GrpcAny()
        content_type = ''

        if request.message.method == 'bytes':
            resp.value = request.message.data.value
            content_type = request.message.content_type
        else:
            resp = request.message.data

        context.send_initial_metadata(headers)
        context.set_trailing_metadata(trailers)

        return common_v1.InvokeResponse(data=resp, content_type=content_type)
github dapr / python-sdk / examples / invoke-custom-data / invoke-receiver.py View on Github external
def OnInvoke(self, request, context):
        data=None
        content_type=""
        if request.method == 'my_method':
            custom_response = response_messages.CustomResponse(isSuccess=True, code=200, message="Hello World - Success!")
            data = Any()
            data.Pack(custom_response)
        else:
            data = Any(value='METHOD_NOT_SUPPORTED'.encode('utf-8'))
            content_type="text/plain"

        print(data, flush=True)
        print(content_type, flush=True)
        return common_v1.InvokeResponse(data=data, content_type=content_type)
github dapr / python-sdk / examples / invoke-simple / invoke-receiver.py View on Github external
def OnInvoke(self, request, context):
        data=None
        content_type=""
        if request.method == 'my-method':
            data = Any(value='INVOKE_RECEIVED'.encode('utf-8'))
            content_type = "text/plain; charset=UTF-8"
        else:
            data = Any(value='unsupported methods'.encode('utf-8'))
            content_type = "text/plain; charset=UTF-8"

        # Return response to caller
        return common_v1.InvokeResponse(data=data, content_type=content_type)
github dapr / python-sdk / ext / dapr-ext-grpc / dapr / ext / grpc / _servicier.py View on Github external
if isinstance(resp, (bytes, str)):
            resp_data.set_data(resp)
            resp_data.content_type = DEFAULT_JSON_CONTENT_TYPE
        elif isinstance(resp, GrpcMessage):
            resp_data.set_data(resp)
        elif isinstance(resp, InvokeServiceResponse):
            resp_data = resp
        else:
            context.set_code(grpc.StatusCode.OUT_OF_RANGE)
            context.set_details(f'{type(resp)} is the invalid return type.')
            raise NotImplementedError(f'{request.method} method not implemented!')

        if len(resp_data.get_headers()) > 0:
            context.send_initial_metadata(resp_data.get_headers())

        return common_v1.InvokeResponse(
            data=resp_data.proto, content_type=resp_data.content_type)
github dapr / python-sdk / ext / dapr-ext-grpc / dapr / ext / grpc / _servicier.py View on Github external
def OnInvoke(
            self,
            request: common_v1.InvokeRequest,
            context: grpc.ServicerContext) -> common_v1.InvokeResponse:
        """Invokes service method with InvokeRequest."""
        if request.method not in self._invoke_method_map:
            context.set_code(grpc.StatusCode.UNIMPLEMENTED)
            raise NotImplementedError(f'{request.method} method not implemented!')

        req = InvokeServiceRequest(request.data, request.content_type)
        req.metadata = context.invocation_metadata()
        resp = self._invoke_method_map[request.method](req)

        if not resp:
            return common_v1.InvokeResponse()

        resp_data = InvokeServiceResponse()
        if isinstance(resp, (bytes, str)):
            resp_data.set_data(resp)
            resp_data.content_type = DEFAULT_JSON_CONTENT_TYPE
        elif isinstance(resp, GrpcMessage):
            resp_data.set_data(resp)
        elif isinstance(resp, InvokeServiceResponse):
            resp_data = resp
        else:
            context.set_code(grpc.StatusCode.OUT_OF_RANGE)
            context.set_details(f'{type(resp)} is the invalid return type.')
            raise NotImplementedError(f'{request.method} method not implemented!')

        if len(resp_data.get_headers()) > 0:
            context.send_initial_metadata(resp_data.get_headers())