/// <summary> /// <see cref="IExceptionListener"/> implementation, invoked by the EMS provider in /// case of connection failures. Re-initializes this listener container's /// shared connection and its sessions and consumers. /// </summary> /// <param name="exception">The reported connection exception.</param> public void OnException(EMSException exception) { // First invoke the user-specific ExceptionListener, if any. InvokeExceptionListener(exception); // now try to recover the shared Connection and all consumers... if (logger.IsInfoEnabled) { logger.Info("Trying to recover from EMS Connection exception: " + exception); } try { lock (consumersMonitor) { sessions = null; consumers = null; } RefreshConnectionUntilSuccessful(); InitializeConsumers(); logger.Info("Successfully refreshed EMS Connection"); } catch (RecoveryTimeExceededException) { throw; } catch (EMSException recoverEx) { logger.Debug("Failed to recover EMS Connection", recoverEx); logger.Error("Encountered non-recoverable EMSException", exception); } }
/// <summary> /// Called when an exception occurs in message processing. /// </summary> /// <param name="exception">The exception.</param> public void OnException(EMSException exception) { foreach (IExceptionListener listener in listeners) { listener.OnException(exception); } }
static EMSQueueConnection() /* Static Constructor for creating Connection at Start-up */ { try { SetEnvironment(); Hashtable Environment = LC.Settings; /* Username , password and targetHostname were already retrieved in SetEnv.At present , we are assuming that lookup JNDI and connectiing QCF are of same provider */ String username = Environment[LookupContext.SECURITY_PRINCIPAL].ToString(); String password = Environment[LookupContext.SECURITY_CREDENTIALS].ToString(); /*QCF and CLient-ID are not required for SetEnv/Lookup obviously. Hence now retriving from config. */ string ClientID = System.Configuration.ConfigurationManager.ConnectionStrings["Client-ID"].ConnectionString; string QueueConnectionFactory = System.Configuration.ConfigurationManager.ConnectionStrings["QueueConnectionFactory"].ConnectionString; QueueConnectionFactory QCF = (QueueConnectionFactory)LC.Lookup(QueueConnectionFactory); QCF.SetClientID(ClientID); if (Environment[LookupContext.SECURITY_PROTOCOL].ToString().Equals("ssl")) { Console.WriteLine("########### QCF=" + QCF.ToString()); QCF.SetTargetHostName(Environment[LookupContext.SSL_TARGET_HOST_NAME].ToString()); } connection = (QueueConnection)QCF.CreateQueueConnection(username, password); connection.ExceptionHandler += new EMSExceptionHandler(_HandleException); connection.Start(); } catch (Exception E) { Console.WriteLine("\n###############\nERROR thrown in EMSQueueConnection Constructor :" + E.ToString()); if (E is EMSException) { EMSException je = (EMSException)E; if (je.LinkedException != null) { System.Console.WriteLine("##### Linked Exception:"); System.Console.WriteLine(je.LinkedException.StackTrace); } } } }
/// <summary> /// Invokes the registered exception listener, if any. /// </summary> /// <param name="ex">The exception that arose during EMS processing.</param> /// <see cref="ExceptionListener"/> protected virtual void InvokeExceptionListener(EMSException ex) { IExceptionListener exListener = ExceptionListener; if (exListener != null) { exListener.OnException(ex); } }
public void _HandleException(object sender, EMSExceptionEventArgs arg) { EMSException e = arg.Exception; // print the connection exception status Console.WriteLine("Connection Exception: " + e.Message); Console.WriteLine(e.StackTrace); lock (stateLock) { stop = true; } }
/// <inheritdoc /> /// <summary> /// The on exception. /// </summary> /// <param name="exception"> /// The exception. /// </param> public void OnException(EMSException exception) { Logger.Debug($"OnException : {exception.Message}"); if (exception.LinkedException != null) { Logger.Debug($"OnException Linked Exception error msg : {exception.LinkedException.Message}"); } if (exception.InnerException != null) { Logger.Debug($"OnException InnerException : {exception.InnerException.Message}"); } }
public static void _HandleException(object sender, EMSExceptionEventArgs arg) { EMSException e = arg.Exception; // print the connection exception status Console.WriteLine("\n\n********** On EMSExceptionEvent **********\n\n********** ThreadName:" + Thread.CurrentThread.Name + "\n\n********** Exception Message: " + e.Message + "\n\n********** Sender Object:" + sender.ToString() + "\n\n********** Stacktrace:" + e.StackTrace + "\n\n********** Source:" + e.Source + "\n\n********** TargetSite:" + e.TargetSite ); }
/// <inheritdoc /> /// <summary> /// The on exception. /// </summary> /// <param name="exception"> /// The exception. /// </param> public void OnException(EMSException exception) { Logger.Error($"OnException : {exception.Message}"); if (exception.LinkedException != null) { Logger.Error($"OnException Linked Exception error msg : {exception.LinkedException.Message}"); } if (exception.InnerException != null) { Logger.Error($"OnException InnerException : {exception.InnerException.Message}"); } Logger.Error($"OnException Time : {DateTime.Now:O}"); }
public void RegisteredExceptionListenerIsInvokedOnException() { SimpleMessageConsumer messageConsumer = new SimpleMessageConsumer(); ISession session = (ISession)mocks.CreateMock(typeof(ISession)); Expect.Call(session.CreateQueue(DESTINATION_NAME)).Return(QUEUE_DESTINATION); Expect.Call(session.CreateConsumer(QUEUE_DESTINATION, null)).Return(messageConsumer); // an exception is thrown, so the rollback logic is being applied here... Expect.Call(session.Transacted).Return(false); IConnection connection = (IConnection)mocks.CreateMock(typeof(IConnection)); //connection.ExceptionListener += container.OnException; connection.ExceptionListener = container; Expect.Call(connection.CreateSession(false, container.SessionAcknowledgeMode)).Return(session); connection.Start(); IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory)); Expect.Call(connectionFactory.CreateConnection()).Return(connection); EMSException theException = new EMSException(EXCEPTION_MESSAGE); IExceptionListener exceptionListener = (IExceptionListener)mocks.CreateMock(typeof(IExceptionListener)); exceptionListener.OnException(theException); //IMessage message = (IMessage) mocks.CreateMock(typeof (IMessage)); TextMessage message = new TextMessage(null, "hello"); mocks.ReplayAll(); container.ConnectionFactory = connectionFactory; container.DestinationName = DESTINATION_NAME; container.MessageListener = new BadSessionAwareMessageListener(theException); container.ExceptionListener = exceptionListener; container.AfterPropertiesSet(); // manually trigger an Exception with the above bad MessageListener... messageConsumer.SendMessage(message); mocks.VerifyAll(); }
public void FireExcpetionEvent(EMSException e) { exceptionListener.OnException(e); }
public void OnException(EMSException e) { // print the connection exception status Console.Error.WriteLine("Connection Exception: " + e.Message); }
public void OnException(EMSException exception) { logger.Info("********* Caught exception *************", exception); }
public void OnException(EMSException exception) { _log.Error("An exception occurred on the endpoint. Uri = " + _uri, exception); }
public emsSSLSampleClient(string[] args) { if (topicName == null) { System.Console.WriteLine("Error: must specify topic name"); usage(); } System.Console.WriteLine("Global SSL parameters sample with Microsoft Certificate Store."); try { EMSSSLSystemStoreInfo storeInfo = new EMSSSLSystemStoreInfo(); //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 target host name in the sertificate if specified if (ssl_target_hostname != null) { EMSSSL.SetTargetHostName(ssl_target_hostname); } if (ssl_cert_store_location != null) { if (ssl_cert_store_location.Equals("currentuser")) { storeInfo.SetCertificateStoreLocation(StoreLocation.CurrentUser); } else if (ssl_cert_store_location.Equals("localmachine")) { storeInfo.SetCertificateStoreLocation(StoreLocation.LocalMachine); } } if (ssl_cert_store_name != null) { storeInfo.SetCertificateStoreName(ssl_cert_store_name); } if (ssl_cert_name != null) { storeInfo.SetCertificateNameAsFullSubjectDN(ssl_cert_name); } EMSSSL.SetCertificateStoreType(EMSSSLStoreType.EMSSSL_STORE_TYPE_SYSTEM, 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); //factory.SetSSLTrace(true); factory.SetConnAttemptCount(1); factory.SetConnAttemptDelay(1000); factory.SetConnAttemptTimeout(1000); 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 Connect:" + 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); } }
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); } }
/// <summary> /// Exception listener callback that renews the underlying single Connection. /// </summary> /// <param name="exception">The exception from the messaging infrastructure.</param> public void OnException(EMSException exception) { ResetConnection(); }
public emsSSLSampleClient(string[] args) { if (topicName == null) { System.Console.WriteLine("Error: must specify topic name"); } System.Console.WriteLine("Global SSL parameters sample with Microsoft Cerrtificate Store."); try { // System Store Info object to be used while setting the store type for a connection factory via the // ConnectionFactory.SetCertificateStoreType. The store info consists of the store location, store name, // the certificate name (to look for in the specified store name at the specified store location). // The default store location is StoreLocation.CurrentUser and the default store name is 'my' store as defined by the .NET framework. // The search criteria to find the certificate in the store name at the store location is X509FindType.FindBySubjectDistinguishedName. EMSSSLSystemStoreInfo storeInfo = new EMSSSLSystemStoreInfo(); // set trace for client-side operations, loading of certificates // and other if (ssl_trace) { EMSSSL.SetClientTracer(new System.IO.StreamWriter(System.Console.OpenStandardError())); } // Set the target host name. // This is a required parameter for all.NET SSL connections.Because System.Net.Security.SslStream // requires a target host, this value is required. // // The name of the server as defined in the server's certificate. Usually the server's HostName // is specified as the CN in the server's certificate. This value must match the name on the // server's certificate server name. if (ssl_target_hostname != null) { EMSSSL.SetTargetHostName(ssl_target_hostname); } // Set location of the certificate store // The certificate store location indicates where to lookup the certificate by name. If no store name is specified, // then the default store name is "My" store name within this store location. // storeLocation Location in which to lookup certificate by name. For example, "CurrentUser" or "LocalMachine." if (ssl_cert_store_location != null) { if (ssl_cert_store_location.Equals("currentuser")) { storeInfo.SetCertificateStoreLocation(StoreLocation.CurrentUser); } else if (ssl_cert_store_location.Equals("localmachine")) { storeInfo.SetCertificateStoreLocation(StoreLocation.LocalMachine); } } // Set the certificate store name // This is the name of the store in which certificates are stored. During the SSL handshake, // this is where the client library looks for the certificates. if (ssl_cert_store_name != null) { storeInfo.SetCertificateStoreName(ssl_cert_store_name); } // Set the name of the certificate as a full subject DN // This method sets the name of the certificate. The certificate name is the subject distinguished name of the certificate. // During the SSL handshake, the server searches for the named certificate in the store specified by SetCertificateStoreName // at the location specified by SetCertificateStoreLocation. The search criteria to find the certificate in the store name // at the store location is X509FindType.FindBySubjectDistinguishedName. // A subject DN sample // [email protected], CN=client, OU=client Unit, O=Test Company, L=us-english, S=California, C=US if (ssl_cert_name != null) { storeInfo.SetCertificateNameAsFullSubjectDN(ssl_cert_name); } // Set the store type for ALL the connection factories // If the store type is EMSSSL_STORE_TYPE_SYSTEM, then storeInfo must be an EMSSSLSystemStoreInfo object. If the store type is // EMSSSL_STORE_TYPE_FILE, then storeInfo must be an EMSSSLFileStoreInfo object. // The type of certificate store. Can be either EMSSSL_STORE_TYPE_SYSTEM or EMSSSL_STORE_TYPE_FILE. See EMSSSLStoreType details. EMSSSL.SetCertificateStoreType(EMSSSLStoreType.EMSSSL_STORE_TYPE_SYSTEM, 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); } } } try { ConnectionFactory factory = new ConnectionFactory(serverUrl); //How can I wrap this to ignore self signed certs mistrust // this does not work for our issues.... ServicePointManager.ServerCertificateValidationCallback = delegate( object obj, X509Certificate certificate, X509Chain chain, System.Net.Security.SslPolicyErrors errors) { return(true); }; 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); } } }
public BadSessionAwareMessageListener(EMSException exception) { this.exception = exception; }
public void OnException(EMSException exception) { count++; }
public virtual void OnException(EMSException e) { }
public void OnException(EMSException e) { LOG.Error("Exception processing message", e); }
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); } }