Example #1
0
 /// <summary>
 /// Initializes a new instance of the ResponseBody class.
 /// </summary>
 /// <param name="requestBody"></param>
 /// <param name="content"></param>
 public ResponseBody(AMFBody	requestBody, object content)
 {
     _requestBody = requestBody;
     Target = requestBody.Response + OnResult;
     Content = content;
     Response = "null";
 }
Example #2
0
		/// <summary>
		/// Initializes a new instance of the ResponseBody class.
		/// </summary>
		/// <param name="requestBody"></param>
		/// <param name="content"></param>
		public ResponseBody(AMFBody	requestBody, object content)
		{
			_requestBody = requestBody;
			_target = requestBody.Response + AMFBody.OnResult;
			_content = content;
			_response = "null";
		}
Example #3
0
	    /// <summary>
		/// Initializes a new instance of the ErrorResponseBody class.
		/// </summary>
		/// <param name="requestBody"></param>
		/// <param name="error"></param>
		public ErrorResponseBody(AMFBody requestBody, string error):base(requestBody)
		{
			IgnoreResults = requestBody.IgnoreResults;
			Target = requestBody.Response + AMFBody.OnStatus;
			Response = null;
			Content = new ExceptionASO(error);
		}
Example #4
0
 public ResponseBody(AMFBody requestBody, object content)
 {
     this._requestBody = requestBody;
     base._target      = requestBody.Response + "/onResult";
     base._content     = content;
     base._response    = "null";
 }
Example #5
0
		/// <summary>
		/// Initializes a new instance of the ErrorResponseBody class.
		/// </summary>
		/// <param name="requestBody"></param>
		/// <param name="message"></param>
		/// <param name="exception"></param>
		public ErrorResponseBody(AMFBody requestBody, IMessage message, Exception exception):base(requestBody)
		{
			ErrorMessage errorMessage = ErrorMessage.GetErrorMessage(message, exception);
			Content = errorMessage;
            Target = requestBody.Response + AMFBody.OnStatus;
			IgnoreResults = requestBody.IgnoreResults;
			Response = "";
		}
Example #6
0
        /// <summary>
        /// Initializes a new instance of the ErrorResponseBody class.
        /// </summary>
        /// <param name="requestBody"></param>
        /// <param name="message"></param>
        /// <param name="exception"></param>
        public ErrorResponseBody(AMFBody requestBody, IMessage message, Exception exception) : base(requestBody)
        {
            ErrorMessage errorMessage = ErrorMessage.GetErrorMessage(message, exception);

            Content       = errorMessage;
            Target        = requestBody.Response + AMFBody.OnStatus;
            IgnoreResults = requestBody.IgnoreResults;
            Response      = "";
        }
Example #7
0
        public ResponseBody GetResponse(AMFBody requestBody)
		{
			for(int i = 0; i < _bodies.Count; i++)
			{
				ResponseBody responseBody = _bodies[i] as ResponseBody;
				if( responseBody.RequestBody == requestBody )
					return responseBody;
			}
			return null;
		}
		public CachedBody(AMFBody requestBody, IMessage message, object content):base(requestBody, content)
		{
			//Fix content of body for flex messages
			AcknowledgeMessage responseMessage = new AcknowledgeMessage();
			responseMessage.body = content;
			responseMessage.correlationId = message.messageId;
			responseMessage.destination = message.destination;
			responseMessage.clientId = message.clientId;

			this.Content = responseMessage;
		}
Example #9
0
        public CachedBody(AMFBody requestBody, IMessage message, object content) : base(requestBody, content)
        {
            AcknowledgeMessage message2 = new AcknowledgeMessage {
                body          = content,
                correlationId = message.messageId,
                destination   = message.destination,
                clientId      = message.clientId
            };

            base.Content = message2;
        }
Example #10
0
 public ResponseBody GetResponse(AMFBody requestBody)
 {
     for (int i = 0; i < base._bodies.Count; i++)
     {
         ResponseBody body = base._bodies[i] as ResponseBody;
         if (body.RequestBody == requestBody)
         {
             return(body);
         }
     }
     return(null);
 }
Example #11
0
        public CachedBody(AMFBody requestBody, IMessage message, object content) : base(requestBody, content)
        {
            //Fix content of body for flex messages
            AcknowledgeMessage responseMessage = new AcknowledgeMessage();

            responseMessage.body          = content;
            responseMessage.correlationId = message.messageId;
            responseMessage.destination   = message.destination;
            responseMessage.clientId      = message.clientId;

            this.Content = responseMessage;
        }
Example #12
0
        private AMFBody ReadBody(JsonReader reader, Type objectType, object existingValue,
            JsonSerializer serializer)
        {
            if (reader.TokenType != JsonToken.StartObject)
                throw new JsonReaderException("AMFBody must be a JSON Object");

            AMFBody body = new AMFBody();

            for (reader.Read(); reader.TokenType != JsonToken.EndObject; reader.Read())
            {
                if (reader.TokenType != JsonToken.PropertyName)
                    throw new JsonReaderException("JSON format error, JSON Object must have property");

                string propertyName = (string)reader.Value;
                switch (propertyName)
                {
                    case "Target":
                        reader.Read();
                        if (reader.TokenType != JsonToken.String)
                            throw new JsonReaderException("AMFBody 'Target' must be JSON String");
                        body.Target = (string) reader.Value;
                        break;
                    case "Response":
                        reader.Read();
                        if (reader.TokenType != JsonToken.String)
                            throw new JsonReaderException("AMFBody 'Response' must be JSON String");
                        body.Response = (string)reader.Value;
                        break;
                    case "Content":
                        reader.Read();
                        if (reader.TokenType != JsonToken.StartArray)
                            throw new JsonReaderException("AMFBody 'Response' must be JSON String");

                        List<MessageBase> list = new List<MessageBase>();
                        for (reader.Read(); reader.TokenType != JsonToken.EndArray; reader.Read())
                        {
                            MessageBase ds = serializer.Deserialize<MessageBase>(reader);
                            list.Add(ds);
                        }
                        body.Content = list;
                        break;
                    default:
                        throw new NotSupportedException("AMFBody dont support property " + propertyName + ", please report this");
                        break;
                }
            }
            return body;
        }
Example #13
0
        private AMFBody ReadBody()
        {
            this.Reset();
            string target = base.ReadString();

            // Response that the client understands.
            string response = base.ReadString();
            int    length   = base.ReadInt32();

            try
            {
                object    content   = base.ReadData();
                AMFBody   amfBody   = new AMFBody(target, response, content);
                Exception exception = this.LastError;
                if (exception != null)
                {
                    ErrorResponseBody errorResponseBody = GetErrorBody(amfBody, exception);
                    _failedAMFBodies.Add(errorResponseBody);
#if !SILVERLIGHT
                    if (log.IsFatalEnabled)
                    {
                        log.Fatal(__Res.GetString(__Res.Amf_ReadBodyFail), exception);
                    }
#endif
                    return(null);
                }
                return(amfBody);
            }
            catch (Exception exception)
            {
                //Try to build a valid response from partialy deserialized amf body
                AMFBody           amfBody           = new AMFBody(target, response, null);
                ErrorResponseBody errorResponseBody = GetErrorBody(amfBody, exception);
                _failedAMFBodies.Add(errorResponseBody);
#if !SILVERLIGHT
                if (log.IsFatalEnabled)
                {
                    log.Fatal(__Res.GetString(__Res.Amf_ReadBodyFail), exception);
                }
#endif
                throw;
            }
        }
Example #14
0
 private ErrorResponseBody GetErrorBody(AMFBody amfBody, Exception exception)
 {
     try
     {
         object content = amfBody.Content;
         if (content is IList)
         {
             content = (content as IList)[0];
         }
         if (content is IMessage)
         {
             return(new ErrorResponseBody(amfBody, content as IMessage, exception));
         }
         return(new ErrorResponseBody(amfBody, exception));
     }
     catch
     {
         return(new ErrorResponseBody(amfBody, exception));
     }
 }
Example #15
0
		/// <summary>
		/// Initializes a new instance of the ErrorResponseBody class.
		/// </summary>
		/// <param name="requestBody"></param>
		/// <param name="exception"></param>
		public ErrorResponseBody(AMFBody requestBody, Exception exception):base(requestBody)
		{
			if( requestBody.IsEmptyTarget )
			{
				object content = requestBody.Content;
				if( content is IList )
					content = (content as IList)[0];
				IMessage message = content as IMessage;
				//Check for Flex2 messages and handle
				if( message != null )
				{
					ErrorMessage errorMessage = ErrorMessage.GetErrorMessage(message, exception);
					Content = errorMessage;
				}
			}
            if( Content == null )
                Content = new ExceptionASO(exception);
			IgnoreResults = requestBody.IgnoreResults;
            Target = requestBody.Response + AMFBody.OnStatus;
			Response = null;
		}
Example #16
0
 public ErrorResponseBody(AMFBody requestBody, Exception exception) : base(requestBody)
 {
     base.Content = exception;
     if (requestBody.IsEmptyTarget)
     {
         object content = requestBody.Content;
         if (content is IList)
         {
             content = (content as IList)[0];
         }
         IMessage message = content as IMessage;
         if (message != null)
         {
             ErrorMessage errorMessage = ErrorMessage.GetErrorMessage(message, exception);
             base.Content = errorMessage;
         }
     }
     base.IgnoreResults = requestBody.IgnoreResults;
     base.Target        = requestBody.Response + "/onStatus";
     base.Response      = null;
 }
Example #17
0
        public AMFMessage ReadAMFMessage()
        {
            int        num3;
            AMFMessage message = new AMFMessage(base.ReadUInt16());
            int        num2    = base.ReadUInt16();

            for (num3 = 0; num3 < num2; num3++)
            {
                message.AddHeader(this.ReadHeader());
            }
            int num4 = base.ReadUInt16();

            for (num3 = 0; num3 < num4; num3++)
            {
                AMFBody body = this.ReadBody();
                if (body != null)
                {
                    message.AddBody(body);
                }
            }
            return(message);
        }
Example #18
0
		public DescribeService(AMFBody amfBody)
		{
			_amfBody = amfBody;
		}
Example #19
0
        public void WriteMessage(AMFMessage amfMessage)
        {
            try
            {
                base.WriteShort(amfMessage.Version);
                int headerCount = amfMessage.HeaderCount;
                base.WriteShort(headerCount);
                for (int i = 0; i < headerCount; i++)
                {
                    this.WriteHeader(amfMessage.GetHeaderAt(i), ObjectEncoding.AMF0);
                }
                int bodyCount = amfMessage.BodyCount;
                base.WriteShort(bodyCount);
                for (int i = 0; i < bodyCount; i++)
                {
                    ResponseBody responseBody = amfMessage.GetBodyAt(i) as ResponseBody;
                    if (responseBody != null && !responseBody.IgnoreResults)
                    {
                        //Try to catch serialization errors
                        if (this.BaseStream.CanSeek)
                        {
                            long position = this.BaseStream.Position;

                            try
                            {
                                responseBody.WriteBody(amfMessage.ObjectEncoding, this);
                            }
                            catch (Exception exception)
                            {
                                this.BaseStream.Seek(position, SeekOrigin.Begin);
                                //this.BaseStream.Position = position;

#if !SILVERLIGHT
                                if (log.IsFatalEnabled)
                                {
                                    log.Fatal(__Res.GetString(__Res.Amf_SerializationFail), exception);
                                }
#endif

                                ErrorResponseBody errorResponseBody;
                                if (responseBody.RequestBody.IsEmptyTarget)
                                {
                                    object content = responseBody.RequestBody.Content;
                                    if (content is IList)
                                    {
                                        content = (content as IList)[0];
                                    }
                                    IMessage         message          = content as IMessage;
                                    MessageException messageException = new MessageException(exception);
                                    messageException.FaultCode = __Res.GetString(__Res.Amf_SerializationFail);
                                    errorResponseBody          = new ErrorResponseBody(responseBody.RequestBody, message, messageException);
                                }
                                else
                                {
                                    errorResponseBody = new ErrorResponseBody(responseBody.RequestBody, exception);
                                }

                                try
                                {
                                    errorResponseBody.WriteBody(amfMessage.ObjectEncoding, this);
                                }
#if !SILVERLIGHT
                                catch (Exception exception2)
                                {
                                    if (log.IsFatalEnabled)
                                    {
                                        log.Fatal(__Res.GetString(__Res.Amf_ResponseFail), exception2);
                                    }
                                    throw;
                                }
#else
                                catch (Exception)
                                {
                                    throw;
                                }
#endif
                            }
                        }
                        else
                        {
                            responseBody.WriteBody(amfMessage.ObjectEncoding, this);
                        }
                    }
                    else
                    {
                        AMFBody amfBody = amfMessage.GetBodyAt(i);
                        FluorineFx.Util.ValidationUtils.ObjectNotNull(amfBody, "amfBody");
                        amfBody.WriteBody(amfMessage.ObjectEncoding, this);
                    }
                }
            }
#if !SILVERLIGHT
            catch (Exception exception)
            {
                if (log.IsFatalEnabled)
                {
                    log.Fatal(__Res.GetString(__Res.Amf_SerializationFail), exception);
                }
                throw;
            }
#else
            catch (Exception)
            {
                throw;
            }
#endif
        }
Example #20
0
 /// <summary>
 /// Adds a body to the AMF packet.
 /// </summary>
 /// <param name="body">The body object to add.</param>
 public void AddBody(AMFBody body)
 {
     this._bodies.Add(body);
 }
Example #21
0
        public bool ContainsResponse(AMFBody requestBody)
		{
			return GetResponse(requestBody) != null;
		}
Example #22
0
 public CachedBody(AMFBody requestBody, object content) : base(requestBody, content)
 {
 }
Example #23
0
		/// <summary>
		/// Initializes a new instance of the CachedBody class.
		/// </summary>
		/// <param name="requestBody"></param>
		/// <param name="content"></param>
		public CachedBody(AMFBody requestBody, object content):base(requestBody, content)
		{
		}
Example #24
0
		/// <summary>
		/// Initializes a new instance of the ResponseBody class.
		/// </summary>
		/// <param name="requestBody"></param>
		public ResponseBody(AMFBody	requestBody)
		{
			_requestBody = requestBody;
		}
Example #25
0
        public void WriteMessage(AMFMessage amfMessage)
        {
            Exception exception;

            try
            {
                int num2;
                base.WriteShort(amfMessage.Version);
                int headerCount = amfMessage.HeaderCount;
                base.WriteShort(headerCount);
                for (num2 = 0; num2 < headerCount; num2++)
                {
                    this.WriteHeader(amfMessage.GetHeaderAt(num2), ObjectEncoding.AMF0);
                }
                int bodyCount = amfMessage.BodyCount;
                base.WriteShort(bodyCount);
                for (num2 = 0; num2 < bodyCount; num2++)
                {
                    ResponseBody bodyAt = amfMessage.GetBodyAt(num2) as ResponseBody;
                    if ((bodyAt != null) && !bodyAt.IgnoreResults)
                    {
                        if (this.BaseStream.CanSeek)
                        {
                            long position = this.BaseStream.Position;
                            try
                            {
                                bodyAt.WriteBody(amfMessage.ObjectEncoding, this);
                            }
                            catch (Exception exception1)
                            {
                                ErrorResponseBody body2;
                                exception = exception1;
                                this.BaseStream.Seek(position, SeekOrigin.Begin);
                                if (log.get_IsFatalEnabled())
                                {
                                    log.Fatal(__Res.GetString("Amf_SerializationFail"), exception);
                                }
                                if (bodyAt.RequestBody.IsEmptyTarget)
                                {
                                    object content = bodyAt.RequestBody.Content;
                                    if (content is IList)
                                    {
                                        content = (content as IList)[0];
                                    }
                                    IMessage         message    = content as IMessage;
                                    MessageException exception2 = new MessageException(exception)
                                    {
                                        FaultCode = __Res.GetString("Amf_SerializationFail")
                                    };
                                    body2 = new ErrorResponseBody(bodyAt.RequestBody, message, exception2);
                                }
                                else
                                {
                                    body2 = new ErrorResponseBody(bodyAt.RequestBody, exception);
                                }
                                try
                                {
                                    body2.WriteBody(amfMessage.ObjectEncoding, this);
                                }
                                catch (Exception exception3)
                                {
                                    if (log.get_IsFatalEnabled())
                                    {
                                        log.Fatal(__Res.GetString("Amf_ResponseFail"), exception3);
                                    }
                                    throw;
                                }
                            }
                        }
                        else
                        {
                            bodyAt.WriteBody(amfMessage.ObjectEncoding, this);
                        }
                    }
                    else
                    {
                        AMFBody body3 = amfMessage.GetBodyAt(num2);
                        ValidationUtils.ObjectNotNull(body3, "amfBody");
                        body3.WriteBody(amfMessage.ObjectEncoding, this);
                    }
                }
            }
            catch (Exception exception5)
            {
                exception = exception5;
                if (log.get_IsFatalEnabled())
                {
                    log.Fatal(__Res.GetString("Amf_SerializationFail"), exception);
                }
                throw;
            }
        }
Example #26
0
 public bool ContainsResponse(AMFBody requestBody)
 {
     return(this.GetResponse(requestBody) != null);
 }
Example #27
0
 /// <summary>
 /// Initializes a new instance of the ResponseBody class.
 /// </summary>
 /// <param name="requestBody"></param>
 public ResponseBody(AMFBody requestBody)
 {
     _requestBody = requestBody;
 }
Example #28
0
		/// <summary>
		/// Initializes a new instance of the ErrorResponseBody class.
		/// </summary>
		/// <param name="requestBody"></param>
		/// <param name="message"></param>
		/// <param name="errorMessage"></param>
		public ErrorResponseBody(AMFBody requestBody, IMessage message, ErrorMessage errorMessage):base(requestBody)
		{
			Content = errorMessage;
            Target = requestBody.Response + AMFBody.OnStatus;
			IgnoreResults = requestBody.IgnoreResults;
			Response = "";
		}
Example #29
0
        private AMFBody ReadBody()
        {
            object            obj2;
            AMFBody           body;
            Exception         lastError;
            ErrorResponseBody errorBody;
            AMFBody           body3;

            base.Reset();
            string target   = base.ReadString();
            string response = base.ReadString();
            int    num      = base.ReadInt32();

            if (base.BaseStream.CanSeek)
            {
                long position = base.BaseStream.Position;
                try
                {
                    obj2      = base.ReadData();
                    body      = new AMFBody(target, response, obj2);
                    lastError = base.LastError;
                    if (lastError != null)
                    {
                        errorBody = this.GetErrorBody(body, lastError);
                        this._failedAMFBodies.Add(errorBody);
                        if (log.get_IsFatalEnabled())
                        {
                            log.Fatal(__Res.GetString("Amf_ReadBodyFail"), lastError);
                        }
                        return(null);
                    }
                    return(body);
                }
                catch (Exception exception1)
                {
                    lastError = exception1;
                    base.BaseStream.Position = position + num;
                    body      = new AMFBody(target, response, null);
                    errorBody = this.GetErrorBody(body, lastError);
                    this._failedAMFBodies.Add(errorBody);
                    if (log.get_IsFatalEnabled())
                    {
                        log.Fatal(__Res.GetString("Amf_ReadBodyFail"), lastError);
                    }
                    return(null);
                }
            }
            try
            {
                obj2      = base.ReadData();
                body      = new AMFBody(target, response, obj2);
                lastError = base.LastError;
                if (lastError != null)
                {
                    errorBody = this.GetErrorBody(body, lastError);
                    this._failedAMFBodies.Add(errorBody);
                    if (log.get_IsFatalEnabled())
                    {
                        log.Fatal(__Res.GetString("Amf_ReadBodyFail"), lastError);
                    }
                    return(null);
                }
                body3 = body;
            }
            catch (Exception exception2)
            {
                lastError = exception2;
                body      = new AMFBody(target, response, null);
                errorBody = this.GetErrorBody(body, lastError);
                this._failedAMFBodies.Add(errorBody);
                if (log.get_IsFatalEnabled())
                {
                    log.Fatal(__Res.GetString("Amf_ReadBodyFail"), lastError);
                }
                throw;
            }
            return(body3);
        }