Beispiel #1
0
        public override object ReadObject(Hessian2Reader reader, ObjectDefinition definition)
        {
            var result = new JavaStackTrace();

            reader.AddRef(result);
            foreach (var key in definition.Fields)
            {
                switch (key)
                {
                case "declaringClass":
                    result.DeclaringClass = reader.ReadString();
                    break;

                case "methodName":
                    result.MethodName = reader.ReadString();
                    break;

                case "fileName":
                    result.FileName = reader.ReadString();
                    break;

                case "lineNumber":
                    result.LineNumber = reader.ReadInt();
                    break;
                }
            }
            return(result);
        }
        public override object ReadMap(Hessian2Reader reader)
        {
            string val = null;

            while (!reader.HasEnd())
            {
                if ("name" == reader.ReadString())
                {
                    val = reader.ReadString();
                }
                else
                {
                    reader.ReadObject();
                }
            }
            reader.ReadToEnd();
            if (string.IsNullOrEmpty(val))
            {
                throw new HessianException($"the value is null or empty where read enum type {Type.FullName}");
            }
            var result = Enum.Parse(Type, val);

            reader.AddRef(result);
            return(result);
        }
Beispiel #3
0
        public override object ReadMap(Hessian2Reader reader)
        {
            var result = new JavaStackTrace();

            reader.AddRef(result);
            while (!reader.HasEnd())
            {
                var key = reader.ReadString();
                switch (key)
                {
                case "declaringClass":
                    result.DeclaringClass = reader.ReadString();
                    break;

                case "methodName":
                    result.MethodName = reader.ReadString();
                    break;

                case "fileName":
                    result.FileName = reader.ReadString();
                    break;

                case "lineNumber":
                    result.LineNumber = reader.ReadInt();
                    break;
                }
            }
            reader.ReadToEnd();
            return(result);
        }
Beispiel #4
0
        public override object ReadMap(Hessian2Reader reader)
        {
            var result = new JavaException();

            reader.AddRef(result);
            string msg = null;

            JavaStackTrace[] traces = null;
            JavaException[]  suppressedExceptions = null;
            JavaException    innerException       = null;

            while (!reader.HasEnd())
            {
                var key = reader.ReadString();
                switch (key)
                {
                case "detailMessage":
                    msg = reader.ReadString();
                    break;

                case "stackTrace":
                    traces = reader.ReadObject <JavaStackTrace[]>();
                    break;

                case "suppressedExceptions":
                    suppressedExceptions = reader.ReadObject <JavaException[]>();
                    break;

                case "cause":
                    innerException = reader.ReadObject <JavaException>();
                    break;

                default:
                    result.Data.Add(key, reader.ReadObject());
                    break;
                }
            }
            reader.ReadToEnd();
            result.ResumeException(string.Empty, msg, traces, suppressedExceptions, innerException);
            return(result);
        }
        public override object ReadMap(Hessian2Reader reader)
        {
            string value = null;

            while (!reader.HasEnd())
            {
                var key = reader.ReadString();
                if (key == "value")
                {
                    value = reader.ReadString();
                }
                else
                {
                    reader.ReadObject();
                }
            }
            reader.ReadToEnd();
            var result = convertFunc(value);

            reader.AddRef(result);
            return(result);
        }
Beispiel #6
0
        public override object ReadObject(Hessian2Reader reader, ObjectDefinition definition)
        {
            var result = new JavaException();

            reader.AddRef(result);
            string msg = null;

            JavaStackTrace[] traces = null;
            JavaException[]  suppressedExceptions = null;
            JavaException    innerException       = null;

            foreach (var key in definition.Fields)
            {
                switch (key)
                {
                case "detailMessage":
                    msg = reader.ReadString();
                    break;

                case "stackTrace":
                    traces = reader.ReadObject <JavaStackTrace[]>();
                    break;

                case "suppressedExceptions":
                    suppressedExceptions = reader.ReadObject <JavaException[]>();
                    break;

                case "cause":
                    innerException = reader.ReadObject <JavaException>();
                    break;

                default:
                    var info = reader.ReadObject();
                    if (info != result)
                    {
                        result.Data.Add(key, reader.ReadObject());
                    }
                    break;
                }
            }

            result.ResumeException(definition.Type, msg, traces, suppressedExceptions, innerException == result ? null : innerException);
            return(result);
        }
        public override object ReadObject(Hessian2Reader reader, ObjectDefinition definition)
        {
            string value = null;

            foreach (var name in definition.Fields)
            {
                if ("value" == (name))
                {
                    value = reader.ReadString();
                }
                else
                {
                    reader.ReadObject();
                }
            }
            var result = convertFunc(value);

            reader.AddRef(result);
            return(result);
        }
        public override object ReadMap(Hessian2Reader reader)
        {
            var result = _creator();

            reader.AddRef(result);
            while (!reader.HasEnd())
            {
                var field = reader.ReadString();
                if (fieldSetters.TryGetValue(field, out var setter))
                {
                    setter.SetValue(result, reader.ReadObject(setter.FieldType));
                }
                else
                {
                    reader.ReadObject();
                }
            }
            reader.ReadToEnd();
            return(result);
        }
        public override object ReadMap(Hessian2Reader reader)
        {
            var result = _creator();

            reader.AddRef(result);

            while (!reader.HasEnd())
            {
                var propertyName = reader.ReadString();
                if (_propertyInfos.TryGetValue(propertyName, out var setter))
                {
                    setter(result, reader);
                }
                else
                {
                    reader.ReadObject();
                }
            }

            reader.ReadToEnd();
            return(result);
        }
        public override object ReadObject(Hessian2Reader reader, ObjectDefinition definition)
        {
            string val = null;

            foreach (var name in definition.Fields)
            {
                if ("name" == name)
                {
                    val = reader.ReadString();
                }
                else
                {
                    reader.ReadObject();
                }
            }
            if (string.IsNullOrEmpty(val))
            {
                throw new HessianException($"the value is null or empty where read enum type {Type.FullName}");
            }
            var result = Enum.Parse(Type, val);

            reader.AddRef(result);
            return(result);
        }
        public override object ReadObject(Hessian2Reader reader)
        {
            switch (_type)
            {
            case BasicType.Null:
                return(reader.ReadObject());

            case BasicType.Bool:
                return(reader.ReadBool());

            case BasicType.Byte:
                return((byte)reader.ReadInt());

            case BasicType.SByte:
                return((sbyte)reader.ReadInt());

            case BasicType.Short:
                return(reader.ReadShort());

            case BasicType.UShort:
                return((ushort)reader.ReadInt());

            case BasicType.Int:
                return(reader.ReadInt());

            case BasicType.UInt:
                return((uint)reader.ReadLong());

            case BasicType.Long:
                return(reader.ReadLong());

            case BasicType.Float:
                return(reader.ReadFloat());

            case BasicType.Double:
                return(reader.ReadDouble());

            case BasicType.Char:
                var str = reader.ReadString();
                return(string.IsNullOrEmpty(str) ? (char)0 : str[0]);

            case BasicType.CharArray:
                var charsString = reader.ReadString();
                return(string.IsNullOrEmpty(charsString) ? new char[0] : charsString.ToCharArray());

            case BasicType.String:
                return(reader.ReadString());

            case BasicType.Date:
                return(reader.ReadDate());

            case BasicType.ByteArray:
                return(reader.ReadBytes());

            case BasicType.Object:
                return(reader.ReadObject());

            case BasicType.BoolArray:
            case BasicType.ShortArray:
            case BasicType.IntArray:
            case BasicType.LongArray:
            case BasicType.FloatArray:
            case BasicType.StringArray:
            case BasicType.DoubleArray:
            case BasicType.SByteArray:
            case BasicType.UShortArray:
            case BasicType.UIntArray:
            case BasicType.DateArray:
            case BasicType.ObjectArray:
                return(reader.ReadObject());

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #12
0
        public static Response DecodeResponse(Stream inputStream)
        {
            var resHeader = new byte[16];

            inputStream.ReadBytes(resHeader);

            if ((resHeader[2] & RequestFlag) != 0)
            {
                throw new ArgumentException("decode response fail. the stream is not response.");
            }

            var response = new Response
            {
                ResponseId = resHeader.ReadLong(4),
                Status     = resHeader[3],
                IsEvent    = (resHeader[2] & EventFlag) != 0,
                IsTwoWay   = (resHeader[2] & TwowayFlag) != 0
            };
            var request    = RequestTasks.GetRequestTask(response.ResponseId);
            var bodyLength = resHeader.ReadInt(12);
            var body       = new byte[bodyLength];

            inputStream.ReadBytes(body);
            var reader = new Hessian2Reader(new MemoryStream(body));

            if (response.IsOk)
            {
                if (response.IsEvent)
                {
                    response.Result = reader.ReadObject();
                }
                else
                {
                    var resultType = request?.Request.ReturnType;
                    var flag       = (byte)reader.ReadInt();
                    switch (flag)
                    {
                    case Response.Null:
                        break;

                    case Response.Value:
                        response.Result = reader.ReadObject(resultType);
                        break;

                    case Response.Exception:
                        response.Error = reader.ReadObject <JavaException>();
                        break;

                    case Response.NullWithAttachment:
                        response.Attachments = reader.ReadObject <Dictionary <string, string> >();
                        break;

                    case Response.ValueWithAttachment:
                        response.Result      = reader.ReadObject(resultType);
                        response.Attachments = reader.ReadObject <Dictionary <string, string> >();
                        break;

                    case Response.ExceptionWithAttachment:
                        response.Error       = reader.ReadObject <JavaException>();
                        response.Attachments = reader.ReadObject <Dictionary <string, string> >();
                        break;

                    default:
                        throw new IOException("Unknown result flag, expect '0' '1' '2', get " + flag);
                    }
                }
            }
            else
            {
                response.ErrorMessage = reader.ReadString();
                response.Error        = new Exception(response.ErrorMessage);
            }

            request?.Task.TrySetResult(response);
            return(response);
        }