コード例 #1
0
        public void init()
        {
            EMSSSLFileStoreInfo storeInfo = new EMSSSLFileStoreInfo();

            if (ssl_trace)
            {
                EMSSSL.SetClientTracer(new System.IO.StreamWriter(System.Console.OpenStandardOutput()));
            }

            if (ssl_target_hostname != null)
            {
                EMSSSL.SetTargetHostName(ssl_target_hostname);
            }

            if (ssl_custom)
            {
                HostVerifier v = new HostVerifier();
                EMSSSL.SetHostNameVerifier(new EMSSSLHostNameVerifier(v.verifyHost));
            }

            if (ssl_trusted != null)
            {
                for (int i = 0; i < ssl_trusted.Count; i++)
                {
                    String certfile = (String)ssl_trusted[i];
                    storeInfo.SetSSLTrustedCertificate(certfile);
                }
            }

            if (ssl_identity != null)
            {
                storeInfo.SetSSLClientIdentity(ssl_identity);
                storeInfo.SetSSLPassword(ssl_password.ToCharArray());
            }

            EMSSSL.SetCertificateStoreType(EMSSSLStoreType.EMSSSL_STORE_TYPE_FILE, storeInfo);
        }
コード例 #2
0
                static void SetEnvironment()
                {

                    //    Configuration SSL = (Configuration)System.Configuration.ConfigurationManager.GetSection("SSL");
                    string password = System.Configuration.ConfigurationManager.ConnectionStrings["password"].ConnectionString;
                    string Username = System.Configuration.ConfigurationManager.ConnectionStrings["username"].ConnectionString;
                    string JNDIContextURL = System.Configuration.ConfigurationManager.ConnectionStrings["JNDIContextURL"].ConnectionString;
                    string Security_Protocol = System.Configuration.ConfigurationManager.ConnectionStrings["Security_Protocol"].ConnectionString;
                    Hashtable Environment = new Hashtable();
                    Environment.Add(LookupContext.SECURITY_PRINCIPAL, Username);
                    Environment.Add(LookupContext.SECURITY_CREDENTIALS, password);
                    //    Environment.Add(LookupContext.PROVIDER_URL, JNDIContextURL);
                     try
                    {
                      
                    switch (Security_Protocol )
                    { 
                        case "ssl" :
                    /*SSL Connection creation  start  */
                     EMSSSLFileStoreInfo storeInfo = new EMSSSLFileStoreInfo();
                        string TargetHostName = System.Configuration.ConfigurationManager.ConnectionStrings["TargetHostName"].ConnectionString;

                        //  EMSSSL.SetTargetHostName(TargetHostName);
                        
                        string JNDIContextSSLURL = System.Configuration.ConfigurationManager.ConnectionStrings["JNDIContextSSLURL"].ConnectionString;
                        /*string EMSServercertiFicate = System.Configuration.ConfigurationManager.ConnectionStrings["EMSServercertiFicate"].ConnectionString;
                        string CA_Certificate = System.Configuration.ConfigurationManager.ConnectionStrings["CA-CertiFicate"].ConnectionString;*/
                        string ssl_trace = System.Configuration.ConfigurationManager.ConnectionStrings["ssl_trace"].ConnectionString;
                        string CertStore = System.Configuration.ConfigurationManager.ConnectionStrings["CertStore"].ConnectionString;



                        /* Standard practice is to specifiy the folder of certs to be individually imported in the TrustStore. Seen it in BW to 
                         * work better. Also supports incremental testing  by placing one cert at a time.The root cert should be in Windows Central store. 
                         * Preferably  left to support people to import the same Or  use EMSSSL class...
                         */
                        foreach (string filename in System.IO.Directory.GetFiles(CertStore))
                        {

                            try
                            {
                                storeInfo.SetSSLTrustedCertificate(new System.Security.Cryptography.X509Certificates.X509Certificate(filename));
                            }

                            catch (Exception E)
                            {
                                Console.WriteLine("\nNot imported into the TrustStore : " + filename);
                                /*replce this writeln  with Debug/Error logging using E object*/
                                ;

                            }

                        }



                        /*storeInfo.SetSSLTrustedCertificate(new System.Security.Cryptography.X509Certificates.X509Certificate(EMSServercertiFicate));


                        Console.WriteLine("\n\n TargetHostName=" + TargetHostName + "\n CA_Certificate=" + CA_Certificate + "\n EMSServercertiFicate=" + EMSServercertiFicate + "\n\n");
                            */

                        Environment.Add(LookupContext.PROVIDER_URL, JNDIContextSSLURL);
                        Environment.Add(LookupContext.SSL_TRACE, ssl_trace);
                        Environment.Add(LookupContext.SSL_STORE_TYPE, EMSSSLStoreType.EMSSSL_STORE_TYPE_FILE);
                        Environment.Add(LookupContext.SECURITY_PROTOCOL, "ssl");
                        Environment.Add(LookupContext.SSL_HOST_NAME_VERIFIER, new EMSSSLHostNameVerifier(new Messaging.EMS.CommonUtils().verifyHost));
                        Environment.Add(LookupContext.SSL_TARGET_HOST_NAME, TargetHostName);
                        Environment.Add(LookupContext.SSL_STORE_INFO, storeInfo);
                        
                        break ;
                        case "tcp":
                        Environment.Add(LookupContext.PROVIDER_URL, JNDIContextURL);
                            break;
                    }

                    LC = new LookupContext(Environment);
                    
                     }
                    catch (Exception E)
                    { throw E; }
                }
コード例 #3
0
    public csLookupSSL(String[] args)
    {
        parseArgs(args);
        if (providerUrl == null)
        {
            providerUrl = defaultProviderURL;
        }

        // Print parameters
        Console.WriteLine("\n------------------------------------------------------------------------");
        Console.WriteLine("csLookupSSL SAMPLE");
        Console.WriteLine("------------------------------------------------------------------------");
        Console.WriteLine("Server....................... " + providerUrl);
        Console.WriteLine("------------------------------------------------------------------------\n");

        try
        {
            Hashtable env = new Hashtable();

            env.Add(LookupContext.PROVIDER_URL, providerUrl);
            if (userName != null)
            {
                env.Add(LookupContext.SECURITY_PRINCIPAL, userName);
                if (password != null)
                {
                    env.Add(LookupContext.SECURITY_CREDENTIALS, password);
                }
            }

            // Creating the SSL related file store info object.
            EMSSSLFileStoreInfo info = new EMSSSLFileStoreInfo();
            if (ssl_identity != null)
            {
                info.SetSSLClientIdentity(ssl_identity);
            }

            if (ssl_password != null)
            {
                string _sslpassword = ssl_password;
                info.SetSSLPassword(_sslpassword.ToCharArray());
            }

            if (ssl_target_hostname == null)
            {
                Console.WriteLine("ssl_target_hostname is required parameter");
                usage();
            }

            // Setting up the SSL properties for the lookup context.
            env.Add(LookupContext.SSL_STORE_INFO, info);
            env.Add(LookupContext.SSL_STORE_TYPE, EMSSSLStoreType.EMSSSL_STORE_TYPE_FILE);
            env.Add(LookupContext.SECURITY_PROTOCOL, "ssl");
            env.Add(LookupContext.SSL_TARGET_HOST_NAME, ssl_target_hostname);

            LookupContext lcxt = new LookupContext(env);

            // Lookup connection factory which must exist in the factories config file.

            ConnectionFactory factory    = null;
            ConnectionFactory sslFactory = null;

            try
            {
                factory = (ConnectionFactory)lcxt.Lookup("ConnectionFactory");
                Console.WriteLine("OK - successfully did lookup ConnectionFactory");

                // Lookup SSL connection factory which must exist in the
                // factories config file.
                sslFactory = (ConnectionFactory)lcxt.Lookup("SSLConnectionFactory");
                Console.WriteLine("OK - successfully did lookup SSLConnectionFactory");

                // Setting additional parameters for this SSL factory.
                sslFactory.SetTargetHostName(ssl_target_hostname);

                // Also, if users want to set any other SSL parameters,
                // i.e EMSSSLFileStoreInfo parameters, they can call GetCertificateStore
                // on the connection factory object.
                EMSSSLFileStoreInfo fileStoreInfo = (EMSSSLFileStoreInfo)sslFactory.GetCertificateStore();
                fileStoreInfo.SetSSLClientIdentity(ssl_identity);
                string _sslpassword = ssl_password;
                fileStoreInfo.SetSSLPassword(_sslpassword.ToCharArray());
            }
            catch (EMSException e)
            {
                Console.Error.WriteLine("**EMSException occurred while doing a lookup");
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine(e.StackTrace);
                Environment.Exit(0); // Can't lookup anything anyway
            }

            // Let's create a connection to the server and a session to verify
            // that the server is running.
            Connection sslConnection = null;
            Session    sslSession    = null;

            try
            {
                sslConnection = sslFactory.CreateConnection(userName, password);
                sslSession    = sslConnection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);
                sslConnection.Close();
            }
            catch (EMSException e)
            {
                Console.Error.WriteLine("**EMSException occurred while creating SSL connection");
                Console.Error.WriteLine("  Most likely the server is not running, the exception trace follows:");
                Console.Error.WriteLine(e.StackTrace);
                Environment.Exit(0); // Can't lookup anything anyway
            }

            // Let's create a connection to the server and a session to verify
            // that the server is running so we can continue with our lookup operations.
            Connection connection = null;
            Session    session    = null;

            try
            {
                connection = factory.CreateConnection(userName, password);
                session    = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);
            }
            catch (EMSException e)
            {
                Console.Error.WriteLine("**EMSException occurred while creating connection");
                Console.Error.WriteLine("  Most likely the server is not running, the exception trace follows:");
                Console.Error.WriteLine(e.StackTrace);
                Environment.Exit(0); // Can't lookup anything anyway
            }

            // Lookup topic 'topic.sample' which must exist in the topics
            // configuration file; if not successfull then most likely such
            // topic does not exist in the config file.
            Topic sampleTopic = null;
            try
            {
                sampleTopic = (Topic)lcxt.Lookup("topic.sample");
                Console.WriteLine("OK - successfully did lookup topic 'topic.sample'");
            }
            catch (NamingException ne)
            {
                Console.Error.WriteLine(ne.StackTrace);
                Console.Error.WriteLine("**NamingException occurred while lookup the topic topic.sample");
                Console.Error.WriteLine("  Most likely such topic does not exist in your configuration.");
                Console.Error.WriteLine("  Exception message follows:");
                Console.Error.WriteLine(ne.Message);
                Environment.Exit(0);
            }

            // Lookup queue 'queue.sample' which must exist in the queues
            // configuration file; if not successfull then it does not exist.
            TIBCO.EMS.Queue sampleQueue = null;
            try
            {
                sampleQueue = (TIBCO.EMS.Queue)lcxt.Lookup("queue.sample");
                Console.WriteLine("OK - successfully did lookup queue 'queue.sample'");
            }
            catch (NamingException ne)
            {
                Console.Error.WriteLine("**NamingException occurred while lookup the queue queue.sample");
                Console.Error.WriteLine("  Most likely such topic does not exist in your configuration.");
                Console.Error.WriteLine("  Exception message follows:");
                Console.Error.WriteLine(ne.Message);
                Environment.Exit(0);
            }

            // Try to lookup a topic when a topic *and* a queue with the
            // same name exist in the configuration. The sample configuration
            // has both topic and queue with the name 'sample' used here. If
            // everything is OK, we will get an exception, then try to lookup
            // those objects using fully-qualified names.
            try
            {
                Object object_Renamed = lcxt.Lookup("sample");

                // If the sample config was not altered, we should not get to this
                // line because lookup() should throw an exception.
                Console.WriteLine("Object named 'sample' has been looked up as: " + object_Renamed);
            }
            catch (NamingException ne)
            {
                Console.Error.WriteLine("OK - NamingException occurred while lookup the object named 'sample'");
                Console.Error.WriteLine("     This is the CORRECT BEHAVIOUR if the exception message below");
                Console.Error.WriteLine("     specifies name conflict situation. Exception message follows:");
                Console.Error.WriteLine("     " + ne.Message);

                // Let's look them up using name qualifiers.
                try
                {
                    Topic t = (Topic)lcxt.Lookup("$topics.sample");
                    Console.WriteLine("OK - successfully did lookup topic '$topics.sample'");
                    TIBCO.EMS.Queue q = (TIBCO.EMS.Queue)lcxt.Lookup("$queues.sample");
                    Console.WriteLine("OK - successfully did lookup queue '$queues.sample'");
                }
                catch (NamingException nex)
                {
                    // These may not be configured: Print a warning and continue.
                    Console.Error.WriteLine("**NamingException occurred while lookup the topic or queue 'sample'");
                    Console.Error.WriteLine("  Exception message follows:");
                    Console.Error.WriteLine("  " + nex.Message);
                }
            }

            // Now let's try to lookup a topic which definitely does not
            // exist. A lookup() operation will throw an exception and then we
            // will try to create such a topic explicitly with the createTopic()
            // method.
            String dynamicName  = "topic.does.not.exist." + (DateTime.Now.Ticks - 621355968000000000) / 10000;
            Topic  dynamicTopic = null;
            try
            {
                dynamicTopic = (Topic)lcxt.Lookup(dynamicName);

                // If the sample config was not altered, we should not get to
                // this line because lookup() should throw an exception.
                Console.Error.WriteLine("**Error: dynamic topic " + dynamicName + " found by lookup");
            }
            catch (NamingException)
            {
                // This is OK.
                Console.Error.WriteLine("OK - could not lookup dynamic topic " + dynamicName);
            }

            // Try to create it.
            try
            {
                dynamicTopic = session.CreateTopic(dynamicName);
                Console.WriteLine("OK - successfully created dynamic topic " + dynamicName);
            }
            catch (EMSException e)
            {
                // A few reasons are possible here. Maybe there is no > entry
                // in the topics configuration or the server security is
                // turned on. If the original sample configuration is used, this
                // should work.
                Console.Error.WriteLine("**EMSException occurred while creating topic " + dynamicName);
                Console.Error.WriteLine("  Please verify your topics configuration and security settings.");
                Console.Error.WriteLine(e.StackTrace);
                Environment.Exit(0);
            }

            connection.Close();

            Console.WriteLine("OK - Done.");
        }
        catch (EMSException e)
        {
            Console.Error.WriteLine(e.StackTrace);
            Environment.Exit(0);
        }
    }
コード例 #4
0
    public emsSSLGlobal(String[] args)
    {
        parseArgs(args);

        if (topicName == null)
        {
            System.Console.WriteLine("Error: must specify topic name");
            usage();
        }

        System.Console.WriteLine("Global SSL parameters sample.");

        try {
            EMSSSLFileStoreInfo storeInfo = new EMSSSLFileStoreInfo();

            // set trace for client-side operations, loading of certificates
            // and other
            if (ssl_trace)
            {
                EMSSSL.SetClientTracer(new System.IO.StreamWriter(System.Console.OpenStandardError()));
            }


            // set trusted certificates if specified
            int s = ssl_trusted.Count;
            for (int i = 0; i < s; i++)
            {
                String cert = (String)ssl_trusted[i];
                storeInfo.SetSSLTrustedCertificate(cert);
            }

            // set target host name in the sertificate if specified
            if (ssl_target_hostname != null)
            {
                EMSSSL.SetTargetHostName(ssl_target_hostname);
            }

            // only pkcs12 or pfx files are supported.
            if (ssl_identity != null)
            {
                if (ssl_password == null)
                {
                    System.Console.WriteLine("Error: must specify -ssl_password if identity is set");
                    System.Environment.Exit(-1);
                }
                storeInfo.SetSSLClientIdentity(ssl_identity);
                storeInfo.SetSSLPassword(ssl_password.ToCharArray());
            }

            EMSSSL.SetCertificateStoreType(EMSSSLStoreType.EMSSSL_STORE_TYPE_FILE, storeInfo);
        }
        catch (Exception e)
        {
            System.Console.WriteLine(e.StackTrace);

            if (e is EMSException)
            {
                EMSException je = (EMSException)e;

                if (je.LinkedException != null)
                {
                    System.Console.WriteLine("##### Linked Exception:");
                    System.Console.WriteLine(je.LinkedException.StackTrace);
                }
            }
            System.Environment.Exit(-1);
        }

        try
        {
            ConnectionFactory factory = new ConnectionFactory(serverUrl);

            Connection connection = factory.CreateConnection(userName, password);

            Session session = connection.CreateSession(false, TIBCO.EMS.SessionMode.AutoAcknowledge);

            Topic topic = session.CreateTopic(topicName);

            MessageProducer publisher  = session.CreateProducer(topic);
            MessageConsumer subscriber = session.CreateConsumer(topic);

            connection.Start();

            MapMessage message = session.CreateMapMessage();
            message.SetStringProperty("field", "SSL message");

            for (int i = 0; i < 3; i++)
            {
                publisher.Send(message);
                System.Console.WriteLine("\nPublished message: " + message);

                /* read same message back */
                message = (MapMessage)subscriber.Receive();
                if (message == null)
                {
                    System.Console.WriteLine("\nCould not receive message");
                }
                else
                {
                    System.Console.WriteLine("\nReceived message: " + message);
                }

                try {
                    System.Threading.Thread.Sleep(1000);
                }
                catch (Exception) {}
            }

            connection.Close();
        }
        catch (EMSException e)
        {
            System.Console.WriteLine("##### Exception:" + e.Message);
            System.Console.WriteLine(e.StackTrace);

            if (e.LinkedException != null)
            {
                System.Console.WriteLine("##### Linked Exception error msg:" + e.LinkedException.Message);
                System.Console.WriteLine("##### Linked Exception:");
                System.Console.WriteLine(e.LinkedException.StackTrace);
            }
            System.Environment.Exit(-1);
        }
    }
コード例 #5
0
        /// <summary>
        /// Listen for messages and consume when messages are received.
        /// </summary>
        public void Run()
        {
            try
            {
                if (string.IsNullOrEmpty(Uri))
                {
                    throw new ArgumentException("Uri can not be empty");
                }

                Logger.Info($"Uri : {Uri}");

                connectionFactory = new Spring.Messaging.Ems.Common.EmsConnectionFactory(Uri);
                if (!string.IsNullOrEmpty(User))
                {
                    connectionFactory.UserName = User;
                    Logger.Info($"User : {User}");
                }

                if (!string.IsNullOrEmpty(Pwd))
                {
                    connectionFactory.UserPassword = Pwd;
                    Logger.Info($"Pwd : {Pwd}");
                }

                if (!string.IsNullOrEmpty(TargetHostName))
                {
                    connectionFactory.TargetHostName = TargetHostName;
                    Logger.Info($"TargetHostName : {TargetHostName}");
                }

                if (UseSsl)
                {
                    if (!System.IO.File.Exists(SslClientCert))
                    {
                        throw new Exception("SslClientCert File is missing");
                    }

                    // Load client certificate from a file
                    var clientCert = new System.Security.Cryptography.X509Certificates.X509Certificate2(SslClientCert, SslClientCertPassword);
                    Logger.Info($"Certificate File:{SslClientCert}");
                    Logger.Info($"Certificate Subject:{clientCert.Subject}");
                    Logger.Info($"Certificate Public Key:{clientCert.PublicKey.Key}");
                    Logger.Info($"Certificate Has private key?:{(clientCert.HasPrivateKey ? "Yes" : "No")}");
                    var sslStore = new EMSSSLFileStoreInfo();
                    sslStore.SetSSLClientIdentity(clientCert);
                    connectionFactory.NativeConnectionFactory.SetCertificateStoreType(EMSSSLStoreType.EMSSSL_STORE_TYPE_FILE, sslStore);
                }

                // Check if we have established a connection since the TargetHostName, Uri, User, or Pwd could be incorrect
                if (connectionFactory == null)
                {
                    throw new Exception("connectionFactory has not been initialized");
                }

                connectionFactory.ClientID = "This needs to be set right";
                Logger.Debug("connectionFactory initialized");
                try
                {
                    Logger.Debug($"Destination - {DestinationName}");
                    using (var listenerContainer = new SimpleMessageListenerContainer())
                    {
                        listenerContainer.ConnectionFactory           = connectionFactory;
                        listenerContainer.DestinationName             = DestinationName;
                        listenerContainer.ConcurrentConsumers         = 1;
                        listenerContainer.PubSubDomain                = false;
                        listenerContainer.MessageListener             = new MessageListener();
                        listenerContainer.ExceptionListener           = new ExceptionListener();
                        listenerContainer.MaxRecoveryTime             = new TimeSpan(MaxRecoveryTimeInDays, 0, 0, 0);
                        listenerContainer.RecoveryInterval            = new TimeSpan(0, 0, 0, 10, 0); // set to 10 Minutes
                        listenerContainer.AcceptMessagesWhileStopping = false;
                        listenerContainer.SessionAcknowledgeMode      = AckMode;
                        listenerContainer.AfterPropertiesSet();
                        if (listenerContainer.IsRunning)
                        {
                            Logger.Debug("Listener IsRunning.");
                        }

                        // TODO: Block to stay in the using and keep on listening.
                        // What are other ways of performing this same action.
                        Console.WriteLine("Press <ENTER> to exit.");
                        Console.ReadLine();
                    }
                }
                catch (EMSException e)
                {
                    Logger.Error($"EMSException : {e.Message}");

                    if (e.LinkedException != null)
                    {
                        Logger.Error($"EMSException Linked Exception error msg : {e.LinkedException.Message}");
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error($"Exception : {ex.Message}");
                if (ex.InnerException != null)
                {
                    Logger.Error($"InnerException : {ex.InnerException.Message}");
                }
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: zyonet/tibcoems-tutorials
    string ssl_password        = null;          // password to decrypt client identity or key file {password}


    public tibemsSSL(string[] args)
    {
        ssl_trusted.Add("C:/tibco/ems/8.3/samples/certs/server_root.cert.pem");
        ssl_target_hostname = "localhost";
        ssl_identity        = "C:/tibco/ems/8.3/samples/certs/client_identity.p12";
        ssl_password        = "******";

        if (topicName == null)
        {
            System.Console.WriteLine("Error: must specify topic name");
            //usage();
        }


        if (topicName == null)
        {
            System.Console.WriteLine("Error: must specify topic name");
        }
        System.Console.WriteLine("SSL sample.");


        // initialize SSL environment
        Hashtable environment = new Hashtable();

        try
        {
            EMSSSLFileStoreInfo storeInfo = new EMSSSLFileStoreInfo();

            // set trace for client-side operations, loading of certificates
            // and other
            if (ssl_trace)
            {
                environment.Add(EMSSSL.TRACE, true);
            }

            // set trusted certificates if specified
            int s = ssl_trusted.Count;
            for (int i = 0; i < s; i++)
            {
                String cert = (String)ssl_trusted[i];
                storeInfo.SetSSLTrustedCertificate(cert);
            }

            // set expected host name in the certificate if specified
            if (ssl_target_hostname != null)
            {
                environment.Add(EMSSSL.TARGET_HOST_NAME, ssl_target_hostname);
            }

            // only pkcs12 or pfx files are supported.
            if (ssl_identity != null)
            {
                if (ssl_password == null)
                {
                    System.Console.WriteLine("Error: must specify -ssl_password if identity is set");
                    System.Environment.Exit(-1);
                }
                storeInfo.SetSSLClientIdentity(ssl_identity);
                storeInfo.SetSSLPassword(ssl_password.ToCharArray());
            }
            environment.Add(EMSSSL.STORE_INFO, storeInfo);
            environment.Add(EMSSSL.STORE_TYPE, EMSSSLStoreType.EMSSSL_STORE_TYPE_FILE);
        }
        catch (Exception e)
        {
            System.Console.WriteLine("ERROR MSG: " + e.Message);
            System.Console.WriteLine(e.StackTrace);

            if (e is EMSException)
            {
                EMSException je = (EMSException)e;
                if (je.LinkedException != null)
                {
                    System.Console.WriteLine("Linked Exception Error Msg: " + e.Message);
                    System.Console.WriteLine("##### Linked Exception:");
                    System.Console.WriteLine(je.LinkedException.StackTrace);
                }
            }
            //System.Environment.Exit(-1);
        }

        try
        {
            ConnectionFactory factory = new ConnectionFactory(serverUrl, null, environment);

            Connection connection = factory.CreateConnection(userName, password);

            Session session = connection.CreateSession(false, TIBCO.EMS.SessionMode.AutoAcknowledge);

            Topic topic = session.CreateTopic(topicName);

            MessageProducer publisher  = session.CreateProducer(topic);
            MessageConsumer subscriber = session.CreateConsumer(topic);

            connection.Start();

            MapMessage message = session.CreateMapMessage();
            message.SetStringProperty("field", "SSL message");

            for (int i = 0; i < 3; i++)
            {
                publisher.Send(message);
                System.Console.WriteLine("\nPublished message: " + message);

                /* read same message back */

                message = (MapMessage)subscriber.Receive();
                if (message == null)
                {
                    System.Console.WriteLine("\nCould not receive message");
                }
                else
                {
                    System.Console.WriteLine("\nReceived message: " + message);
                }

                try
                {
                    System.Threading.Thread.Sleep(1000);
                }
                catch (Exception) { }
            }

            connection.Close();
        }
        catch (EMSException e)
        {
            System.Console.WriteLine("ERROR MSG: " + e.Message);
            System.Console.WriteLine(e.StackTrace);

            if (e.LinkedException != null)
            {
                System.Console.WriteLine("Linked Exception Error Msg: " + e.Message);
                System.Console.WriteLine("##### Linked Exception:");
                System.Console.WriteLine(e.LinkedException.StackTrace);
            }
            //System.Environment.Exit(-1);
        }
    }