Esempio n. 1
0
        public override bool Sent() => base.SentImpl(!Proxy.IsTwoway); // done = true if it's not a two-way proxy

        public override bool Response()
        {
            Debug.Assert(Is != null);
            //
            // NOTE: this method is called from ConnectionI.parseMessage
            // with the connection locked. Therefore, it must not invoke
            // any user callbacks.
            //
            Debug.Assert(Proxy.IsTwoway); // Can only be called for twoways.

            if (ChildObserver != null)
            {
                ChildObserver.Reply(Is.Size - Protocol.headerSize - 4);
                ChildObserver.Detach();
                ChildObserver = null;
            }

            byte replyStatus;

            try
            {
                replyStatus = Is.ReadByte();

                switch (replyStatus)
                {
                case ReplyStatus.replyOK:
                    {
                        break;
                    }

                case ReplyStatus.replyUserException:
                {
                    if (Observer != null)
                    {
                        Observer.UserException();
                    }
                    break;
                }

                case ReplyStatus.replyObjectNotExist:
                case ReplyStatus.replyFacetNotExist:
                case ReplyStatus.replyOperationNotExist:
                {
                    var ident = new Ice.Identity(Is);

                    //
                    // For compatibility with the old FacetPath.
                    //
                    string[] facetPath = Is.ReadStringSeq();
                    string   facet;
                    if (facetPath.Length > 0)
                    {
                        if (facetPath.Length > 1)
                        {
                            throw new Ice.MarshalException();
                        }
                        facet = facetPath[0];
                    }
                    else
                    {
                        facet = "";
                    }

                    string operation = Is.ReadString();

                    Ice.RequestFailedException ex;
                    switch (replyStatus)
                    {
                    case ReplyStatus.replyObjectNotExist:
                    {
                        ex = new Ice.ObjectNotExistException();
                        break;
                    }

                    case ReplyStatus.replyFacetNotExist:
                    {
                        ex = new Ice.FacetNotExistException();
                        break;
                    }

                    case ReplyStatus.replyOperationNotExist:
                    {
                        ex = new Ice.OperationNotExistException();
                        break;
                    }

                    default:
                    {
                        Debug.Assert(false);
                        throw new System.InvalidOperationException();
                    }
                    }

                    ex.Id        = ident;
                    ex.Facet     = facet;
                    ex.Operation = operation;
                    throw ex;
                }

                case ReplyStatus.replyUnknownException:
                case ReplyStatus.replyUnknownLocalException:
                case ReplyStatus.replyUnknownUserException:
                {
                    string unknown = Is.ReadString();

                    Ice.UnknownException ex;
                    switch (replyStatus)
                    {
                    case ReplyStatus.replyUnknownException:
                    {
                        ex = new Ice.UnknownException();
                        break;
                    }

                    case ReplyStatus.replyUnknownLocalException:
                    {
                        ex = new Ice.UnknownLocalException();
                        break;
                    }

                    case ReplyStatus.replyUnknownUserException:
                    {
                        ex = new Ice.UnknownUserException();
                        break;
                    }

                    default:
                    {
                        Debug.Assert(false);
                        throw new System.InvalidOperationException();
                    }
                    }

                    ex.Unknown = unknown;
                    throw ex;
                }

                default:
                {
                    throw new Ice.UnknownReplyStatusException();
                }
                }

                return(ResponseImpl(false, replyStatus == ReplyStatus.replyOK, true));
            }
            catch (Ice.Exception ex)
            {
                return(Exception(ex));
            }
        }
Esempio n. 2
0
 private void exception(Ice.Current current)
 {
     if (current.operation.Equals("ice_ids"))
     {
         throw new Test.TestIntfUserException();
     }
     else if (current.operation.Equals("requestFailedException"))
     {
         throw new Ice.ObjectNotExistException();
     }
     else if (current.operation.Equals("unknownUserException"))
     {
         var ex = new Ice.UnknownUserException();
         ex.unknown = "reason";
         throw ex;
     }
     else if (current.operation.Equals("unknownLocalException"))
     {
         var ex = new Ice.UnknownLocalException();
         ex.unknown = "reason";
         throw ex;
     }
     else if (current.operation.Equals("unknownException"))
     {
         var ex = new Ice.UnknownException();
         ex.unknown = "reason";
         throw ex;
     }
     else if (current.operation.Equals("userException"))
     {
         throw new Test.TestIntfUserException();
     }
     else if (current.operation.Equals("localException"))
     {
         var ex = new Ice.SocketException();
         ex.error = 0;
         throw ex;
     }
     else if (current.operation.Equals("csException"))
     {
         throw new System.Exception("message");
     }
     else if (current.operation.Equals("unknownExceptionWithServantException"))
     {
         throw new Ice.UnknownException("reason");
     }
     else if (current.operation.Equals("impossibleException"))
     {
         throw new Test.TestIntfUserException(); // Yes, it really is meant to be TestIntfException.
     }
     else if (current.operation.Equals("intfUserException"))
     {
         throw new Test.TestImpossibleException(); // Yes, it really is meant to be TestImpossibleException.
     }
     else if (current.operation.Equals("asyncResponse"))
     {
         throw new Test.TestImpossibleException();
     }
     else if (current.operation.Equals("asyncException"))
     {
         throw new Test.TestImpossibleException();
     }
 }
Esempio n. 3
0
        public void finished(BasicStream istr)
        {
            _m.Lock();
            try
            {
                Debug.Assert(_handler.getReference().getMode() == Reference.Mode.ModeTwoway); // Only for twoways.

                Debug.Assert(_state <= StateInProgress);

                if(_remoteObserver != null)
                {
                    _remoteObserver.reply(istr.size() - Protocol.headerSize - 4);
                    _remoteObserver.detach();
                    _remoteObserver = null;
                }

                if(_is == null)
                {
                    _is = new IceInternal.BasicStream(_handler.getReference().getInstance(), 
                                                      Ice.Util.currentProtocolEncoding);
                }
                _is.swap(istr);
                byte replyStatus = _is.readByte();

                switch(replyStatus)
                {
                    case ReplyStatus.replyOK:
                    {
                        _state = StateOK; // The state must be set last, in case there is an exception.
                        break;
                    }

                    case ReplyStatus.replyUserException:
                    {
                        if(_observer != null)
                        {
                            _observer.userException();
                        }
                        _state = StateUserException; // The state must be set last, in case there is an exception.
                        break;
                    }

                    case ReplyStatus.replyObjectNotExist:
                    case ReplyStatus.replyFacetNotExist:
                    case ReplyStatus.replyOperationNotExist:
                    {
                        Ice.RequestFailedException ex = null;
                        switch(replyStatus)
                        {
                            case ReplyStatus.replyObjectNotExist:
                            {
                                ex = new Ice.ObjectNotExistException();
                                break;
                            }

                            case ReplyStatus.replyFacetNotExist:
                            {
                                ex = new Ice.FacetNotExistException();
                                break;
                            }

                            case ReplyStatus.replyOperationNotExist:
                            {
                                ex = new Ice.OperationNotExistException();
                                break;
                            }

                            default:
                            {
                                Debug.Assert(false);
                                break;
                            }
                        }

                        ex.id = new Ice.Identity();
                        ex.id.read__(_is);

                        //
                        // For compatibility with the old FacetPath.
                        //
                        string[] facetPath = _is.readStringSeq();
                        if(facetPath.Length > 0)
                        {
                            if(facetPath.Length > 1)
                            {
                                throw new Ice.MarshalException();
                            }
                            ex.facet = facetPath[0];
                        }
                        else
                        {
                            ex.facet = "";
                        }

                        ex.operation = _is.readString();
                        _exception = ex;

                        _state = StateLocalException; // The state must be set last, in case there is an exception.
                        break;
                    }

                    case ReplyStatus.replyUnknownException:
                    case ReplyStatus.replyUnknownLocalException:
                    case ReplyStatus.replyUnknownUserException:
                    {
                        Ice.UnknownException ex = null;
                        switch(replyStatus)
                        {
                            case ReplyStatus.replyUnknownException:
                            {
                                ex = new Ice.UnknownException();
                                break;
                            }

                            case ReplyStatus.replyUnknownLocalException:
                            {
                                ex = new Ice.UnknownLocalException();
                                break;
                            }

                            case ReplyStatus.replyUnknownUserException:
                            {
                                ex = new Ice.UnknownUserException();
                                break;
                            }

                            default:
                            {
                                Debug.Assert(false);
                                break;
                            }
                        }

                        ex.unknown = _is.readString();
                        _exception = ex;

                        _state = StateLocalException; // The state must be set last, in case there is an exception.
                        break;
                    }

                    default:
                    {
                        _exception = new Ice.UnknownReplyStatusException();
                        _state = StateLocalException;
                        break;
                    }
                }

                _m.Notify();
            }
            finally
            {
                _m.Unlock();
            }
        }
Esempio n. 4
0
        public override bool response()
        {
            //
            // NOTE: this method is called from ConnectionI.parseMessage
            // with the connection locked. Therefore, it must not invoke
            // any user callbacks.
            //
            Debug.Assert(proxy_.IsTwoway); // Can only be called for twoways.

            if (childObserver_ != null)
            {
                childObserver_.reply(is_.size() - Protocol.headerSize - 4);
                childObserver_.detach();
                childObserver_ = null;
            }

            byte replyStatus;

            try
            {
                replyStatus = is_.ReadByte();

                switch (replyStatus)
                {
                case ReplyStatus.replyOK:
                {
                    break;
                }

                case ReplyStatus.replyUserException:
                {
                    if (observer_ != null)
                    {
                        observer_.userException();
                    }
                    break;
                }

                case ReplyStatus.replyObjectNotExist:
                case ReplyStatus.replyFacetNotExist:
                case ReplyStatus.replyOperationNotExist:
                {
                    Ice.Identity ident = new Ice.Identity();
                    ident.ice_readMembers(is_);

                    //
                    // For compatibility with the old FacetPath.
                    //
                    string[] facetPath = is_.ReadStringSeq();
                    ;
                    string facet;
                    if (facetPath.Length > 0)
                    {
                        if (facetPath.Length > 1)
                        {
                            throw new Ice.MarshalException();
                        }
                        facet = facetPath[0];
                    }
                    else
                    {
                        facet = "";
                    }

                    string operation = is_.ReadString();

                    Ice.RequestFailedException ex = null;
                    switch (replyStatus)
                    {
                    case ReplyStatus.replyObjectNotExist:
                    {
                        ex = new Ice.ObjectNotExistException();
                        break;
                    }

                    case ReplyStatus.replyFacetNotExist:
                    {
                        ex = new Ice.FacetNotExistException();
                        break;
                    }

                    case ReplyStatus.replyOperationNotExist:
                    {
                        ex = new Ice.OperationNotExistException();
                        break;
                    }

                    default:
                    {
                        Debug.Assert(false);
                        break;
                    }
                    }

                    ex.id        = ident;
                    ex.facet     = facet;
                    ex.operation = operation;
                    throw ex;
                }

                case ReplyStatus.replyUnknownException:
                case ReplyStatus.replyUnknownLocalException:
                case ReplyStatus.replyUnknownUserException:
                {
                    string unknown = is_.ReadString();

                    Ice.UnknownException ex = null;
                    switch (replyStatus)
                    {
                    case ReplyStatus.replyUnknownException:
                    {
                        ex = new Ice.UnknownException();
                        break;
                    }

                    case ReplyStatus.replyUnknownLocalException:
                    {
                        ex = new Ice.UnknownLocalException();
                        break;
                    }

                    case ReplyStatus.replyUnknownUserException:
                    {
                        ex = new Ice.UnknownUserException();
                        break;
                    }

                    default:
                    {
                        Debug.Assert(false);
                        break;
                    }
                    }

                    ex.unknown = unknown;
                    throw ex;
                }

                default:
                {
                    throw new Ice.UnknownReplyStatusException();
                }
                }

                return(responseImpl(false, replyStatus == ReplyStatus.replyOK, true));
            }
            catch (Ice.Exception ex)
            {
                return(exception(ex));
            }
        }
Esempio n. 5
0
        public void finished(BasicStream istr)
        {
            _m.Lock();
            try
            {
                Debug.Assert(_handler.getReference().getMode() == Reference.Mode.ModeTwoway); // Only for twoways.

                Debug.Assert(_state <= StateInProgress);

                if (_remoteObserver != null)
                {
                    _remoteObserver.reply(istr.size() - Protocol.headerSize - 4);
                    _remoteObserver.detach();
                    _remoteObserver = null;
                }

                if (_is == null)
                {
                    _is = new IceInternal.BasicStream(_handler.getReference().getInstance(),
                                                      Ice.Util.currentProtocolEncoding);
                }
                _is.swap(istr);
                byte replyStatus = _is.readByte();

                switch (replyStatus)
                {
                case ReplyStatus.replyOK:
                {
                    _state = StateOK;     // The state must be set last, in case there is an exception.
                    break;
                }

                case ReplyStatus.replyUserException:
                {
                    if (_observer != null)
                    {
                        _observer.userException();
                    }
                    _state = StateUserException;     // The state must be set last, in case there is an exception.
                    break;
                }

                case ReplyStatus.replyObjectNotExist:
                case ReplyStatus.replyFacetNotExist:
                case ReplyStatus.replyOperationNotExist:
                {
                    Ice.RequestFailedException ex = null;
                    switch (replyStatus)
                    {
                    case ReplyStatus.replyObjectNotExist:
                    {
                        ex = new Ice.ObjectNotExistException();
                        break;
                    }

                    case ReplyStatus.replyFacetNotExist:
                    {
                        ex = new Ice.FacetNotExistException();
                        break;
                    }

                    case ReplyStatus.replyOperationNotExist:
                    {
                        ex = new Ice.OperationNotExistException();
                        break;
                    }

                    default:
                    {
                        Debug.Assert(false);
                        break;
                    }
                    }

                    ex.id = new Ice.Identity();
                    ex.id.read__(_is);

                    //
                    // For compatibility with the old FacetPath.
                    //
                    string[] facetPath = _is.readStringSeq();
                    if (facetPath.Length > 0)
                    {
                        if (facetPath.Length > 1)
                        {
                            throw new Ice.MarshalException();
                        }
                        ex.facet = facetPath[0];
                    }
                    else
                    {
                        ex.facet = "";
                    }

                    ex.operation = _is.readString();
                    _exception   = ex;

                    _state = StateLocalException;     // The state must be set last, in case there is an exception.
                    break;
                }

                case ReplyStatus.replyUnknownException:
                case ReplyStatus.replyUnknownLocalException:
                case ReplyStatus.replyUnknownUserException:
                {
                    Ice.UnknownException ex = null;
                    switch (replyStatus)
                    {
                    case ReplyStatus.replyUnknownException:
                    {
                        ex = new Ice.UnknownException();
                        break;
                    }

                    case ReplyStatus.replyUnknownLocalException:
                    {
                        ex = new Ice.UnknownLocalException();
                        break;
                    }

                    case ReplyStatus.replyUnknownUserException:
                    {
                        ex = new Ice.UnknownUserException();
                        break;
                    }

                    default:
                    {
                        Debug.Assert(false);
                        break;
                    }
                    }

                    ex.unknown = _is.readString();
                    _exception = ex;

                    _state = StateLocalException;     // The state must be set last, in case there is an exception.
                    break;
                }

                default:
                {
                    _exception = new Ice.UnknownReplyStatusException();
                    _state     = StateLocalException;
                    break;
                }
                }

                _m.Notify();
            }
            finally
            {
                _m.Unlock();
            }
        }
Esempio n. 6
0
        override public Ice.AsyncCallback completed()
        {
            Debug.Assert(_is != null); // _is has been initialized prior to this call

            //
            // NOTE: this method is called from ConnectionI.parseMessage
            // with the connection locked. Therefore, it must not invoke
            // any user callbacks.
            //

            Debug.Assert(proxy_.ice_isTwoway()); // Can only be called for twoways.

            if (childObserver_ != null)
            {
                childObserver_.reply(_is.size() - Protocol.headerSize - 4);
                childObserver_.detach();
                childObserver_ = null;
            }

            byte replyStatus;

            try
            {
                replyStatus = _is.readByte();

                switch (replyStatus)
                {
                case ReplyStatus.replyOK:
                {
                    break;
                }

                case ReplyStatus.replyUserException:
                {
                    if (observer_ != null)
                    {
                        observer_.userException();
                    }
                    break;
                }

                case ReplyStatus.replyObjectNotExist:
                case ReplyStatus.replyFacetNotExist:
                case ReplyStatus.replyOperationNotExist:
                {
                    Ice.Identity id = new Ice.Identity();
                    id.read__(_is);

                    //
                    // For compatibility with the old FacetPath.
                    //
                    string[] facetPath = _is.readStringSeq();
                    string   facet;
                    if (facetPath.Length > 0)
                    {
                        if (facetPath.Length > 1)
                        {
                            throw new Ice.MarshalException();
                        }
                        facet = facetPath[0];
                    }
                    else
                    {
                        facet = "";
                    }

                    string operation = _is.readString();

                    Ice.RequestFailedException ex = null;
                    switch (replyStatus)
                    {
                    case ReplyStatus.replyObjectNotExist:
                    {
                        ex = new Ice.ObjectNotExistException();
                        break;
                    }

                    case ReplyStatus.replyFacetNotExist:
                    {
                        ex = new Ice.FacetNotExistException();
                        break;
                    }

                    case ReplyStatus.replyOperationNotExist:
                    {
                        ex = new Ice.OperationNotExistException();
                        break;
                    }

                    default:
                    {
                        Debug.Assert(false);
                        break;
                    }
                    }

                    ex.id        = id;
                    ex.facet     = facet;
                    ex.operation = operation;
                    throw ex;
                }

                case ReplyStatus.replyUnknownException:
                case ReplyStatus.replyUnknownLocalException:
                case ReplyStatus.replyUnknownUserException:
                {
                    string unknown = _is.readString();

                    Ice.UnknownException ex = null;
                    switch (replyStatus)
                    {
                    case ReplyStatus.replyUnknownException:
                    {
                        ex = new Ice.UnknownException();
                        break;
                    }

                    case ReplyStatus.replyUnknownLocalException:
                    {
                        ex = new Ice.UnknownLocalException();
                        break;
                    }

                    case ReplyStatus.replyUnknownUserException:
                    {
                        ex = new Ice.UnknownUserException();
                        break;
                    }

                    default:
                    {
                        Debug.Assert(false);
                        break;
                    }
                    }

                    ex.unknown = unknown;
                    throw ex;
                }

                default:
                {
                    throw new Ice.UnknownReplyStatusException();
                }
                }

                return(finished(replyStatus == ReplyStatus.replyOK));
            }
            catch (Ice.Exception ex)
            {
                return(completed(ex));
            }
        }
Esempio n. 7
0
        // ProtocolReplyToMessage
        //
        // Given a response message stream respStream, and the message that
        // originated to call msg, returns an IMethodReturnMessage describing
        // the return value of the function.
        //
        public static IMethodReturnMessage ProtocolReplyToMessage(Stream respStream,
                                                                  IMessage msg)
        {
            IMethodCallMessage mcall = msg as IMethodCallMessage;

            // set up some stuff that we'll need for parsing
            ParameterInfo[] paramInfos = mcall.MethodBase.GetParameters();
            Type            returnType = ((MethodInfo)mcall.MethodBase).ReturnType;

            // at this point, respStream should be pointing to the first byte after the requestId
            Ice.ProtocolReader pr = new Ice.ProtocolReader(respStream);

            // the first byte here is the MessageReplyType
            byte             b         = pr.ReadByte();
            MessageReplyType replyType = (MessageReplyType)Enum.ToObject(typeof(MessageReplyType), b);

            if (replyType == MessageReplyType.Success)
            {
                // what follows is an encapsulation with return value and out params, if any.
                int encapsBytes = pr.ReadEncapsulationHeader();
                if (encapsBytes == 0)
                {
                    // no reply value(s) follow
                    return(new ReturnMessage(null, null, 0, mcall.LogicalCallContext, mcall));
                }
                else
                {
                    // reply values follow: first the out-values in order of declaration,
                    // then the return value
                    object    returnValue = null;
                    ArrayList outArgs     = new ArrayList();
                    int       readOutArgs = 0;

                    for (int i = 0; i < mcall.ArgCount; i++)
                    {
                        if (paramInfos[i].IsOut)
                        {
                            object o;
                            if (Attribute.GetCustomAttribute(paramInfos[i], typeof(Ice.AsProxy)) != null)
                            {
                                o = pr.ReadObjectProxy(paramInfos[i].ParameterType);
                                outArgs.Add(o);
                            }
                            else if (!IceByValue(paramInfos[i].ParameterType))
                            {
                                // add placeholder for patch later
                                outArgs.Add(null);
                                pr.ReadClassInstanceParameterRef(outArgs, readOutArgs);
                            }
                            else
                            {
                                o = pr.ReadObject(paramInfos[i].ParameterType);
                                outArgs.Add(o);
                            }
                            readOutArgs++;
                        }
                    }

                    if (returnType != null && returnType != typeof(void))
                    {
                        returnValue = pr.ReadObject(returnType);
                    }

                    pr.ReadClassInstancesAndPatch();

                    return(new ReturnMessage(returnValue, outArgs.ToArray(), outArgs.Count, mcall.LogicalCallContext, mcall));
                }
            }
            else
            {
                // message was not a success; we ought to parse the exception. TODO FIXME
                Ice.UnknownException e = new Ice.UnknownException();
                e.unknown = "Message reply type was " + replyType;

                return(new ReturnMessage(e, mcall));
            }
        }
Esempio n. 8
0
    // ProtocolReplyToMessage
    //
    // Given a response message stream respStream, and the message that
    // originated to call msg, returns an IMethodReturnMessage describing
    // the return value of the function.
    //
    public static IMethodReturnMessage ProtocolReplyToMessage (Stream respStream,
                                                               IMessage msg)
    {
      IMethodCallMessage mcall = msg as IMethodCallMessage;

      // set up some stuff that we'll need for parsing
      ParameterInfo[] paramInfos = mcall.MethodBase.GetParameters();
      Type returnType = ((MethodInfo) mcall.MethodBase).ReturnType;

      // at this point, respStream should be pointing to the first byte after the requestId
      Ice.ProtocolReader pr = new Ice.ProtocolReader (respStream);

      // the first byte here is the MessageReplyType
      byte b = pr.ReadByte();
      MessageReplyType replyType = (MessageReplyType) Enum.ToObject (typeof(MessageReplyType), b);

      if (replyType == MessageReplyType.Success) {
        // what follows is an encapsulation with return value and out params, if any.
        int encapsBytes = pr.ReadEncapsulationHeader();
        if (encapsBytes == 0) {
          // no reply value(s) follow
          return new ReturnMessage (null, null, 0, mcall.LogicalCallContext, mcall);
        } else {
          // reply values follow: first the out-values in order of declaration,
          // then the return value
          object returnValue = null;
          ArrayList outArgs = new ArrayList();
          int readOutArgs = 0;

          for (int i = 0; i < mcall.ArgCount; i++) {
            if (paramInfos[i].IsOut) {
              object o;
              if (Attribute.GetCustomAttribute (paramInfos[i], typeof(Ice.AsProxy)) != null) {
                o = pr.ReadObjectProxy (paramInfos[i].ParameterType);
                outArgs.Add (o);
              } else if (!IceByValue (paramInfos[i].ParameterType)) {
                // add placeholder for patch later
                outArgs.Add (null);
                pr.ReadClassInstanceParameterRef (outArgs, readOutArgs);
              } else {
                o = pr.ReadObject (paramInfos[i].ParameterType);
                outArgs.Add (o);
              }
              readOutArgs++;
            }
          }

          if (returnType != null && returnType != typeof(void)) {
            returnValue = pr.ReadObject (returnType);
          }

          pr.ReadClassInstancesAndPatch();

          return new ReturnMessage (returnValue, outArgs.ToArray(), outArgs.Count, mcall.LogicalCallContext, mcall);
        }
      } else {
        // message was not a success; we ought to parse the exception. TODO FIXME
        Ice.UnknownException e = new Ice.UnknownException();
        e.unknown = "Message reply type was " + replyType;

        return new ReturnMessage (e, mcall);
      }
    }