func (c *clientCodec) ReadResponseHeader(response *rpc.Response) error { if c.enableOneway { select { case ow := <-c.onewayRequests: response.ServiceMethod = ow.method response.Seq = ow.seq return nil case _ = <-c.twowayRequests: } } name, messageType, seq, err := c.conn.ReadMessageBegin() if err != nil { return err } response.ServiceMethod = name response.Seq = uint64(seq) if messageType == MessageTypeException { exception := &ApplicationException{} if err := DecodeStruct(c.conn, exception); err != nil { return err } response.Error = exception.String() return c.conn.ReadMessageEnd() } return nil }
func (self *RPCServer) Error(s string) error { var r rpc.Response r.ServiceMethod = self.lastServiceMethod r.Seq = self.lastSeq r.Error = s return self.codec.WriteResponse(&r, nil) }
func (self *RPCServer) SendOkay() error { var r rpc.Response r.ServiceMethod = self.lastServiceMethod r.Seq = self.lastSeq r.Error = "" return self.codec.WriteResponse(&r, "OK") }
func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error { // If return err: // - io.EOF will became ErrShutdown or io.ErrUnexpectedEOF // - it will be returned as is for all pending calls // - client will be shutdown // So, return io.EOF as is, return *Error for all other errors. if err := c.dec.Decode(&c.resp); err != nil { if err == io.EOF { return err } return NewError(errInternal.Code, err.Error()) } if c.resp.ID == nil { return c.resp.Error } c.mutex.Lock() r.ServiceMethod = c.pending[*c.resp.ID] delete(c.pending, *c.resp.ID) c.mutex.Unlock() r.Error = "" r.Seq = *c.resp.ID if c.resp.Error != nil { r.Error = c.resp.Error.Error() } return nil }
func (self *RPCServer) Send(obj interface{}) error { var r rpc.Response r.ServiceMethod = self.lastServiceMethod r.Seq = self.lastSeq r.Error = "" return self.codec.WriteResponse(&r, obj) }
func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error { msg := <-c.msgs c.resp.reset() if err := json.Unmarshal(msg.Body, &c.resp); err != nil { return err } seq, err := strconv.ParseUint(msg.CorrelationId, 0, 64) if err != nil { return err } c.Lock() r.Seq = seq r.ServiceMethod = c.pending[seq] delete(c.pending, seq) c.Unlock() r.Error = "" if c.resp.Error != nil || c.resp.Result == nil { x, ok := c.resp.Error.(string) if !ok { return fmt.Errorf("invalid error %v", c.resp.Error) } if x == "" { x = "unspecified error" } r.Error = x } return nil }
func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error { c.resp.reset() if err := c.dec.Decode(&c.resp); err != nil { return err } c.mutex.Lock() r.ServiceMethod = c.pending[c.resp.Id] delete(c.pending, c.resp.Id) c.mutex.Unlock() r.Error = "" r.Seq = c.resp.Id if c.resp.Error != nil { x, ok := c.resp.Error.(string) if !ok { return fmt.Errorf("invalid error %v", c.resp.Error) } if x == "" { x = "unspecified error" } r.Error = x } return nil }
func (c *clientCodec) ReadResponseHeader(rpcres *rpc.Response) error { f, err := read(c.r) if err != nil { return err } res := &Response{} if err := proto.Unmarshal(f, res); err != nil { return err } c.mutex.Lock() p, ok := c.pending[res.GetId()] if !ok { c.mutex.Unlock() return errors.New("invalid sequence number in response") } c.res = res delete(c.pending, res.GetId()) c.mutex.Unlock() rpcres.Seq = p.Seq rpcres.ServiceMethod = p.ServiceMethod rpcres.Error = res.GetError() return nil }
func (c *clientCodec) ReadResponseHeader(r *rpc.Response) (err error) { c.bufs.Reset() // Read message parts, err := c.sock.RecvMultipart(0) if err != nil { return } else if len(parts) != 2 { err = errors.New("Unexpected number of parts to reply: " + fmt.Sprintf("%d", len(parts))) return } // log.Println("Client recieved multipart mesage:", Stringify(parts)) hdr := parts[0] data := parts[1] c.bufs.body.SetBuf(data) h := new(Header) c.bufs.header.SetBuf(hdr) err = c.bufs.header.Unmarshal(h) if err != nil { return } r.Seq = h.GetId() r.ServiceMethod = h.GetServiceMethod() r.Error = h.GetError() // log.Println("Client recieved service response:", r) return nil }
func (c *serverCodec) WriteResponse(response *rpc.Response, thriftStruct interface{}) error { c.mu.Lock() methodName := c.methodName[response.Seq] delete(c.methodName, response.Seq) c.mu.Unlock() response.ServiceMethod = methodName mtype := byte(MessageTypeReply) if response.Error != "" { mtype = MessageTypeException etype := int32(ExceptionInternalError) if strings.HasPrefix(response.Error, "rpc: can't find") { etype = ExceptionUnknownMethod } thriftStruct = &ApplicationException{response.Error, etype} } if err := c.protocol.WriteMessageBegin(c.transport, response.ServiceMethod, mtype, int32(response.Seq)); err != nil { return err } if err := EncodeStruct(c.transport, c.protocol, thriftStruct); err != nil { return err } if err := c.protocol.WriteMessageEnd(c.transport); err != nil { return err } if flusher, ok := c.transport.(Flusher); ok { return flusher.Flush() } return nil }
func writeResponse(c *serverCodec) error { head := rpc.Response{} head.ServiceMethod = "TestFunc" head.Seq = 2 head.Error = "call failed" body := testpb.Result{} body.Title = proto.String("www.zhihu.com") return c.WriteResponse(&head, &body) }
func (mux *multiplexCodec) ReadResponseHeader(res *rpc.Response) error { select { case err := <-mux.errorChan: return err case msg := <-mux.responseChan: res.ServiceMethod = responseMethod res.Seq = *msg.Sequence } return nil }
func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error { if err := c.readResponseHeader(&c.respHeader); err != nil { return err } r.Seq = c.respHeader.Id r.ServiceMethod = c.respHeader.GetMethod() r.Error = c.respHeader.Error return nil }
func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error { var rsp protorpcpb.Response if err := readFrame(c.rwc, &rsp); err != nil { return err } r.ServiceMethod = rsp.GetMethod() r.Seq = rsp.GetSeq() r.Error = rsp.GetErr() return nil }
func (c *codec) ReadResponseHeader(r *rpc.Response) error { c.header = internal.Header{} // reset if err := c.decode(&c.header); err != nil { return err } r.ServiceMethod = c.header.Method r.Seq = c.header.SeqID r.Error = c.header.Error return nil }
// ReadResponseHeader receives and decodes a net/rpc response header r. func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error { var err error var hdr ProtoRPCResponseHeader if err = c.m.ReadMessage(&hdr); err != nil { return util.Logged(err) } r.Seq = *hdr.Seq r.ServiceMethod = *hdr.Op if hdr.Error != nil { r.Error = *hdr.Error } return nil }
func (s *ServerImpl) sendResponse(sending *sync.Mutex, req *rpc.Request, resp *rpc.Response, reply interface{}, codec rpc.ServerCodec, errmsg string) { resp.ServiceMethod = req.ServiceMethod if errmsg != "" { resp.Error = errmsg reply = invalidRequest } resp.Seq = req.Seq sending.Lock() defer sending.Unlock() err := codec.WriteResponse(resp, reply) if err != nil { log.Println("rpc: writing response:", err) } }
func (c *clientCodec) ReadResponseHeader(response *rpc.Response) error { name, messageType, seq, err := c.protocol.ReadMessageBegin(c.transport) if err != nil { return err } response.ServiceMethod = name response.Seq = uint64(seq) if messageType == messageTypeException { exception := &ApplicationException{} if err := DecodeStruct(c.transport, c.protocol, exception); err != nil { return err } response.Error = exception.String() return c.protocol.ReadMessageEnd(c.transport) } return nil }
// ReadResponseHeader reads the header protobuf (which is prefixed by a uvarint // indicating its size) from the connection, decodes it, and stores the fields // in the given request. func (c *ClientCodec) ReadResponseHeader(resp *rpc.Response) error { var header wire.Header if err := ReadProto(c.r, &header); err != nil { return err } if header.Method == nil { return fmt.Errorf("header missing method: %s", header) } if header.Seq == nil { return fmt.Errorf("header missing seq: %s", header) } resp.ServiceMethod = *header.Method resp.Seq = *header.Seq if header.Error != nil { resp.Error = *header.Error } return nil }
func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error { var header wire.Header if err := readProto(c.r, &header); err != nil { return err } c.mutex.Lock() r.ServiceMethod = c.pending[header.GetId()] delete(c.pending, header.GetId()) c.mutex.Unlock() r.Error = "" r.Seq = header.GetId() if header.Error != nil { r.Error = header.GetError() } return nil }
func (s *codec) ReadResponseHeader(resp *rpc.Response) error { if s.Shutdown { return rpc.ErrShutdown } var header rpc4.Header if err := readProto(s.r, &header); err != nil { return err } if header.GetMethod() == "" { return fmt.Errorf("header missing method: %s", header) } resp.ServiceMethod = header.GetMethod() resp.Seq = header.GetSequence() s.responsePayload = header.GetPayloadPresent() return nil }
func (c *clientHttpCodec) ReadResponseHeader(r *rpc.Response) error { c.resp.reset() //read http header tp := textproto.NewReader(c.r) line, err := tp.ReadLine() if err != nil { if err == io.EOF { err = io.ErrUnexpectedEOF } return err } f := strings.SplitN(line, " ", 3) if len(f) < 2 { return errors.New("malformed HTTP response") } _, err = tp.ReadMIMEHeader() if err != nil { if err == io.EOF { err = io.ErrUnexpectedEOF } return err } _, err = readPack(c.r, &c.resp) if err != nil { return err } c.mutex.Lock() Id := (uint64)(c.resp.Id) r.ServiceMethod = c.pending[Id] delete(c.pending, Id) c.mutex.Unlock() r.Error = "" r.Seq = Id if c.resp.Error != "" || c.resp.Result == nil { fmt.Errorf("invalid error %v", c.resp.Error) r.Error = c.resp.Error } return nil }
func (cdc *HrpcClientCodec) ReadResponseHeader(resp *rpc.Response) error { hdr := common.HrpcResponseHeader{} err := binary.Read(cdc.rwc, binary.LittleEndian, &hdr) if err != nil { return errors.New(fmt.Sprintf("Error reading response header "+ "bytes: %s", err.Error())) } resp.ServiceMethod = common.HrpcMethodIdToMethodName(hdr.MethodId) if resp.ServiceMethod == "" { return errors.New(fmt.Sprintf("Error reading response header: "+ "invalid method ID %d.", hdr.MethodId)) } resp.Seq = hdr.Seq if hdr.ErrLength > 0 { if hdr.ErrLength > common.MAX_HRPC_ERROR_LENGTH { return errors.New(fmt.Sprintf("Error reading response header: "+ "error message was %d bytes long, but "+ "MAX_HRPC_ERROR_LENGTH is %d.", hdr.ErrLength, common.MAX_HRPC_ERROR_LENGTH)) } buf := make([]byte, hdr.ErrLength) var nread int nread, err = cdc.rwc.Read(buf) if uint32(nread) != hdr.ErrLength { return errors.New(fmt.Sprintf("Error reading response header: "+ "failed to read %d bytes of error message.", nread)) } if err != nil { return errors.New(fmt.Sprintf("Error reading response header: "+ "failed to read %d bytes of error message: %s", nread, err.Error())) } resp.Error = string(buf) } else { resp.Error = "" } cdc.length = hdr.Length return nil }
func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error { c.resp.reset() _, err := readPack(c.r, &c.resp) if err != nil { return err } c.mutex.Lock() Id := (uint64)(c.resp.Id) r.ServiceMethod = c.pending[Id] delete(c.pending, Id) c.mutex.Unlock() r.Error = "" r.Seq = Id if c.resp.Error != "" || c.resp.Result == nil { fmt.Errorf("invalid error %v", c.resp.Error) r.Error = c.resp.Error } return nil }
func (client *clientCodec) ReadResponseHeader(r *rpc.Response) error { client.curDelivery = <-client.message var err error if err = client.curDelivery.Headers.Validate(); err != nil { return errors.New("error while reading body: " + err.Error()) } if err, ok := client.curDelivery.Headers["error"]; ok { errStr, ok := err.(string) if !ok { return errors.New("error header not a string") } r.Error = errStr } r.ServiceMethod = client.curDelivery.ReplyTo r.Seq, err = strconv.ParseUint(client.curDelivery.MessageId, 10, 64) if err != nil { return err } return nil }