Ejemplo n.º 1
0
    public override void OnMessage(ConnectionManager connMgr, Message message)
    {
        try
        {
            //o Run the message through the GMSEC API-supplied validation
            connMgr.GetSpecification().ValidateMessage(message);

            //o In this example scenario, we are expecting to receive a
            // GMSEC PROD message containing a URI to a location on the disk
            // where a product file has been placed for retrieval.  In this
            // case, we want to validate that the location on the disk is
            // in an area which we would expect (i.e. Something that the
            // team has agreed upon prior to operational deployment).
            //
            // By validating this URI, we ensure that no malicious users
            // have infiltrated the system and somehow modified the messages
            // to cause us to retrieve a file from an unknown location.

            //o Start by checking to ensure that this is a PROD message
            if (IsProdMsg(message))
            {
                GMSEC.API.MIST.MESSAGE.ProductFileMessage prodMessage = new GMSEC.API.MIST.MESSAGE.ProductFileMessage(message.ToXML());

                //o Extract the Product File URI location(s) from the
                // message using a ProductFileIterator
                ProductFileIterator prodIter = prodMessage.GetProductFileIterator();

                while (prodIter.HasNext())
                {
                    ProductFile prodFile = prodIter.Next();

                    //o Check to ensure that the URI contains "//hostname/dir"
                    String prodUri = prodFile.GetURI();
                    if (prodUri.IndexOf("//hostname/dir") == -1)
                    {
                        String errorMsg = "Received an invalid PROD Message (bad URI):\n" + message.ToXML();
                        throw new GMSEC_Exception(StatusClass.MIST_ERROR, StatusCode.MESSAGE_FAILED_VALIDATION, errorMsg);
                    }
                }

                Log.Info("Received a valid message:\n" + message.ToXML());
            }
        }
        catch (Exception e)
        {
            Log.Error(e.ToString());
        }
    }