Esempio n. 1
0
        protected virtual Command ReadConnected(StompFrame frame)
        {
            this.remoteWireFormatInfo = new WireFormatInfo();

            if (frame.HasProperty("version"))
            {
                remoteWireFormatInfo.Version = Single.Parse(
                    frame.RemoveProperty("version"), CultureInfo.InvariantCulture);

                if (remoteWireFormatInfo.Version > 1.0f)
                {
                    this.encodeHeaders = true;
                }

                if (frame.HasProperty("session"))
                {
                    remoteWireFormatInfo.Session = frame.RemoveProperty("session");
                }

                if (frame.HasProperty("heart-beat"))
                {
                    string[] hearBeats = frame.RemoveProperty("heart-beat").Split(",".ToCharArray());
                    if (hearBeats.Length != 2)
                    {
                        throw new IOException("Malformed heartbeat property in Connected Frame.");
                    }

                    remoteWireFormatInfo.WriteCheckInterval = Int32.Parse(hearBeats[0].Trim());
                    remoteWireFormatInfo.ReadCheckInterval  = Int32.Parse(hearBeats[1].Trim());
                }
            }
            else
            {
                remoteWireFormatInfo.ReadCheckInterval  = 0;
                remoteWireFormatInfo.WriteCheckInterval = 0;
                remoteWireFormatInfo.Version            = 1.0f;
            }

            if (this.connectedResponseId != -1)
            {
                Response answer = new Response();
                answer.CorrelationId = this.connectedResponseId;
                SendCommand(answer);
                this.connectedResponseId = -1;
            }
            else
            {
                throw new IOException("Received Connected Frame without a set Response Id for it.");
            }

            return(remoteWireFormatInfo);
        }
Esempio n. 2
0
        protected virtual Command ReadConnected(StompFrame frame)
        {
            string responseId = frame.RemoveProperty("response-id");

            this.remoteWireFormatInfo = new WireFormatInfo();

            if (frame.HasProperty("version"))
            {
                remoteWireFormatInfo.Version = Single.Parse(frame.RemoveProperty("version"));

                if (frame.HasProperty("session"))
                {
                    remoteWireFormatInfo.Session = frame.RemoveProperty("session");
                }

                if (frame.HasProperty("heart-beat"))
                {
                    string[] hearBeats = frame.RemoveProperty("heart-beat").Split(",".ToCharArray());
                    if (hearBeats.Length != 2)
                    {
                        throw new IOException("Malformed heartbeat property in Connected Frame.");
                    }

                    remoteWireFormatInfo.WriteCheckInterval = Int32.Parse(hearBeats[0].Trim());
                    remoteWireFormatInfo.ReadCheckInterval  = Int32.Parse(hearBeats[1].Trim());
                }
            }
            else
            {
                remoteWireFormatInfo.ReadCheckInterval  = 0;
                remoteWireFormatInfo.WriteCheckInterval = 0;
                remoteWireFormatInfo.Version            = 1.0f;
            }

            if (responseId != null)
            {
                Response answer = new Response();
                answer.CorrelationId = Int32.Parse(responseId);
                SendCommand(answer);
            }

            return(remoteWireFormatInfo);
        }
Esempio n. 3
0
        protected virtual Command ReadMessage(StompFrame frame)
        {
            Message message        = null;
            string  transformation = frame.RemoveProperty("transformation");

            if (frame.HasProperty("content-length"))
            {
                message         = new BytesMessage();
                message.Content = frame.Content;
            }
            else if (transformation == "jms-map-xml")
            {
                message = new MapMessage(this.mapMarshaler.Unmarshal(frame.Content) as PrimitiveMap);
            }
            else
            {
                message = new TextMessage(encoder.GetString(frame.Content, 0, frame.Content.Length));
            }

            // Remove any receipt header we might have attached if the outbound command was
            // sent with response required set to true
            frame.RemoveProperty("receipt");

            message.Type             = frame.RemoveProperty("type");
            message.Destination      = StompHelper.ToDestination(frame.RemoveProperty("destination"));
            message.ReplyTo          = StompHelper.ToDestination(frame.RemoveProperty("reply-to"));
            message.TargetConsumerId = StompHelper.ToConsumerId(frame.RemoveProperty("subscription"));
            message.CorrelationId    = frame.RemoveProperty("correlation-id");

            Tracer.Debug("RECV - Inbound MessageId = " + frame.GetProperty("message-id"));

            message.MessageId  = StompHelper.ToMessageId(frame.RemoveProperty("message-id"));
            message.Persistent = StompHelper.ToBool(frame.RemoveProperty("persistent"), false);

            // If it came from NMS.Stomp we added this header to ensure its reported on the
            // receiver side.
            if (frame.HasProperty("NMSXDeliveryMode"))
            {
                message.Persistent = StompHelper.ToBool(frame.RemoveProperty("NMSXDeliveryMode"), false);
            }

            if (frame.HasProperty("priority"))
            {
                message.Priority = Byte.Parse(frame.RemoveProperty("priority"));
            }

            if (frame.HasProperty("timestamp"))
            {
                message.Timestamp = Int64.Parse(frame.RemoveProperty("timestamp"));
            }

            if (frame.HasProperty("expires"))
            {
                message.Expiration = Int64.Parse(frame.RemoveProperty("expires"));
            }

            if (frame.RemoveProperty("redelivered") != null)
            {
                // We aren't told how many times that the message was redelivered so if it
                // is tagged as redelivered we always set the counter to one.
                message.RedeliveryCounter = 1;
            }

            // now lets add the generic headers
            foreach (string key in frame.Properties.Keys)
            {
                Object value = frame.Properties[key];
                if (value != null)
                {
                    // lets coerce some standard header extensions
                    if (key == "JMSXGroupSeq" || key == "NMSXGroupSeq")
                    {
                        value = Int32.Parse(value.ToString());
                        message.Properties["NMSXGroupSeq"] = value;
                        continue;
                    }
                    else if (key == "JMSXGroupID" || key == "NMSXGroupID")
                    {
                        message.Properties["NMSXGroupID"] = value;
                        continue;
                    }
                }
                message.Properties[key] = value;
            }

            MessageDispatch dispatch = new MessageDispatch();

            dispatch.Message           = message;
            dispatch.ConsumerId        = message.TargetConsumerId;
            dispatch.Destination       = message.Destination;
            dispatch.RedeliveryCounter = message.RedeliveryCounter;

            return(dispatch);
        }
Esempio n. 4
0
        protected virtual Object CreateCommand(StompFrame frame)
        {
            string command = frame.Command;

            if (command == "RECEIPT" || command == "CONNECTED")
            {
                string text = frame.RemoveProperty("receipt-id");
                if (text != null)
                {
                    Response answer = new Response();
                    if (text.StartsWith("ignore:"))
                    {
                        text = text.Substring("ignore:".Length);
                    }

                    Tracer.Debug("StompWireFormat - Received RESPONSE command: CorrelationId = " + text);

                    answer.CorrelationId = Int32.Parse(text);
                    return(answer);
                }
                else if (command == "CONNECTED")
                {
                    text = frame.RemoveProperty("response-id");

                    Tracer.Debug("StompWireFormat - Received CONNECTED command: ResponseId = " + text);

                    if (text != null)
                    {
                        Response answer = new Response();
                        answer.CorrelationId = Int32.Parse(text);
                        return(answer);
                    }
                }
            }
            else if (command == "ERROR")
            {
                string text = frame.RemoveProperty("receipt-id");

                if (text != null && text.StartsWith("ignore:"))
                {
                    Tracer.Debug("StompWireFormat - Received ERROR Response command: correlationId = " + text);
                    Response answer = new Response();
                    answer.CorrelationId = Int32.Parse(text.Substring("ignore:".Length));
                    return(answer);
                }
                else
                {
                    ExceptionResponse answer = new ExceptionResponse();
                    if (text != null)
                    {
                        answer.CorrelationId = Int32.Parse(text);
                    }

                    BrokerError error = new BrokerError();
                    error.Message    = frame.RemoveProperty("message");
                    answer.Exception = error;
                    Tracer.Debug("StompWireFormat - Received ERROR command: " + error.Message);
                    return(answer);
                }
            }
            else if (command == "MESSAGE")
            {
                Tracer.Debug("StompWireFormat - Received MESSAGE command");
                return(ReadMessage(frame));
            }

            Tracer.Error("Unknown command: " + frame.Command + " headers: " + frame.Properties);

            return(null);
        }
Esempio n. 5
0
        protected virtual Object CreateCommand(StompFrame frame)
        {
            string command = frame.Command;

            if (Tracer.IsDebugEnabled)
            {
                Tracer.Debug("StompWireFormat - Received " + frame.ToString());
            }

            if (command == "RECEIPT")
            {
                string text = frame.RemoveProperty("receipt-id");
                if (text != null)
                {
                    Response answer = new Response();
                    if (text.StartsWith("ignore:"))
                    {
                        text = text.Substring("ignore:".Length);
                    }

                    answer.CorrelationId = Int32.Parse(text);
                    return(answer);
                }
            }
            else if (command == "CONNECTED")
            {
                return(ReadConnected(frame));
            }
            else if (command == "ERROR")
            {
                string text = frame.RemoveProperty("receipt-id");

                if (text != null && text.StartsWith("ignore:"))
                {
                    Response answer = new Response();
                    answer.CorrelationId = Int32.Parse(text.Substring("ignore:".Length));
                    return(answer);
                }
                else
                {
                    ExceptionResponse answer = new ExceptionResponse();
                    if (text != null)
                    {
                        answer.CorrelationId = Int32.Parse(text);
                    }

                    BrokerError error = new BrokerError();
                    error.Message    = frame.RemoveProperty("message");
                    answer.Exception = error;
                    return(answer);
                }
            }
            else if (command == "KEEPALIVE")
            {
                return(new KeepAliveInfo());
            }
            else if (command == "MESSAGE")
            {
                return(ReadMessage(frame));
            }

            Tracer.Error("Unknown command: " + frame.Command + " headers: " + frame.Properties);

            return(null);
        }