List of usage examples for javax.naming NamingException toString
public String toString()
From source file:io.datalayer.activemq.consumer.SimpleConsumer.java
/** * @param args the queue used by the example */// www. j a v a 2 s. co m public static void main(String... args) { String destinationName = null; Context jndiContext = null; ConnectionFactory connectionFactory = null; Connection connection = null; Session session = null; Destination destination = null; MessageConsumer consumer = null; /* * Read destination name from command line and display it. */ if (args.length != 1) { LOG.info("Usage: java SimpleConsumer <destination-name>"); System.exit(1); } destinationName = args[0]; LOG.info("Destination name is " + destinationName); /* * Create a JNDI API InitialContext object */ try { jndiContext = new InitialContext(); } catch (NamingException e) { LOG.info("Could not create JNDI API " + "context: " + e.toString()); System.exit(1); } /* * Look up connection factory and destination. */ try { connectionFactory = (ConnectionFactory) jndiContext.lookup("ConnectionFactory"); destination = (Destination) jndiContext.lookup(destinationName); } catch (NamingException e) { LOG.info("JNDI API lookup failed: " + e.toString()); System.exit(1); } /* * Create connection. Create session from connection; false means * session is not transacted. Create receiver, then start message * delivery. Receive all text messages from destination until a non-text * message is received indicating end of message stream. Close * connection. */ try { connection = connectionFactory.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); consumer = session.createConsumer(destination); connection.start(); while (true) { Message m = consumer.receive(1); if (m != null) { if (m instanceof TextMessage) { TextMessage message = (TextMessage) m; LOG.info("Reading message: " + message.getText()); } else { break; } } } } catch (JMSException e) { LOG.info("Exception occurred: " + e); } finally { if (connection != null) { try { connection.close(); } catch (JMSException e) { } } } }
From source file:io.datalayer.activemq.consumer.SimpleQueueReceiver.java
/** * Main method.//ww w . j a va 2 s.c o m * * @param args the queue used by the example */ public static void main(String... args) { String queueName = null; Context jndiContext = null; QueueConnectionFactory queueConnectionFactory = null; QueueConnection queueConnection = null; QueueSession queueSession = null; Queue queue = null; QueueReceiver queueReceiver = null; TextMessage message = null; /* * Read queue name from command line and display it. */ if (args.length != 1) { LOG.info("Usage: java " + "SimpleQueueReceiver <queue-name>"); System.exit(1); } queueName = args[0]; LOG.info("Queue name is " + queueName); /* * Create a JNDI API InitialContext object if none exists yet. */ try { jndiContext = new InitialContext(); } catch (NamingException e) { LOG.info("Could not create JNDI API " + "context: " + e.toString()); System.exit(1); } /* * Look up connection factory and queue. If either does not exist, exit. */ try { queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("QueueConnectionFactory"); queue = (Queue) jndiContext.lookup(queueName); } catch (NamingException e) { LOG.info("JNDI API lookup failed: " + e.toString()); System.exit(1); } /* * Create connection. Create session from connection; false means * session is not transacted. Create receiver, then start message * delivery. Receive all text messages from queue until a non-text * message is received indicating end of message stream. Close * connection. */ try { queueConnection = queueConnectionFactory.createQueueConnection(); queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); queueReceiver = queueSession.createReceiver(queue); queueConnection.start(); while (true) { Message m = queueReceiver.receive(1); if (m != null) { if (m instanceof TextMessage) { message = (TextMessage) m; LOG.info("Reading message: " + message.getText()); } else { break; } } } } catch (JMSException e) { LOG.info("Exception occurred: " + e.toString()); } finally { if (queueConnection != null) { try { queueConnection.close(); } catch (JMSException e) { } } } }
From source file:io.datalayer.activemq.producer.SimpleQueueSender.java
/** * Main method./*from w ww. j ava 2 s. com*/ * * @param args the queue used by the example and, optionally, the number of * messages to send */ public static void main(String... args) { String queueName = null; Context jndiContext = null; QueueConnectionFactory queueConnectionFactory = null; QueueConnection queueConnection = null; QueueSession queueSession = null; Queue queue = null; QueueSender queueSender = null; TextMessage message = null; final int numMsgs; if ((args.length < 1) || (args.length > 2)) { LOG.info("Usage: java SimpleQueueSender " + "<queue-name> [<number-of-messages>]"); System.exit(1); } queueName = args[0]; LOG.info("Queue name is " + queueName); if (args.length == 2) { numMsgs = (new Integer(args[1])).intValue(); } else { numMsgs = 1; } /* * Create a JNDI API InitialContext object if none exists yet. */ try { jndiContext = new InitialContext(); } catch (NamingException e) { LOG.info("Could not create JNDI API context: " + e.toString()); System.exit(1); } /* * Look up connection factory and queue. If either does not exist, exit. */ try { queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("QueueConnectionFactory"); queue = (Queue) jndiContext.lookup(queueName); } catch (NamingException e) { LOG.info("JNDI API lookup failed: " + e); System.exit(1); } /* * Create connection. Create session from connection; false means * session is not transacted. Create sender and text message. Send * messages, varying text slightly. Send end-of-messages message. * Finally, close connection. */ try { queueConnection = queueConnectionFactory.createQueueConnection(); queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); queueSender = queueSession.createSender(queue); message = queueSession.createTextMessage(); for (int i = 0; i < numMsgs; i++) { message.setText("This is message " + (i + 1)); LOG.info("Sending message: " + message.getText()); queueSender.send(message); } /* * Send a non-text control message indicating end of messages. */ queueSender.send(queueSession.createMessage()); } catch (JMSException e) { LOG.info("Exception occurred: " + e.toString()); } finally { if (queueConnection != null) { try { queueConnection.close(); } catch (JMSException e) { } } } }
From source file:io.datalayer.activemq.producer.SimpleProducer.java
/** * @param args the destination name to send to and optionally, the number of * messages to send// w ww.ja va 2 s . c o m */ public static void main(String... args) { Context jndiContext = null; ConnectionFactory connectionFactory = null; Connection connection = null; Session session = null; Destination destination = null; MessageProducer producer = null; String destinationName = null; final int numMsgs; if ((args.length < 1) || (args.length > 2)) { LOG.info("Usage: java SimpleProducer <destination-name> [<number-of-messages>]"); System.exit(1); } destinationName = args[0]; LOG.info("Destination name is " + destinationName); if (args.length == 2) { numMsgs = (new Integer(args[1])).intValue(); } else { numMsgs = 1; } /* * Create a JNDI API InitialContext object */ try { jndiContext = new InitialContext(); } catch (NamingException e) { LOG.info("Could not create JNDI API context: " + e.toString()); System.exit(1); } /* * Look up connection factory and destination. */ try { connectionFactory = (ConnectionFactory) jndiContext.lookup("ConnectionFactory"); destination = (Destination) jndiContext.lookup(destinationName); } catch (NamingException e) { LOG.info("JNDI API lookup failed: " + e); System.exit(1); } /* * Create connection. Create session from connection; false means * session is not transacted. Create sender and text message. Send * messages, varying text slightly. Send end-of-messages message. * Finally, close connection. */ try { connection = connectionFactory.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(destination); TextMessage message = session.createTextMessage(); for (int i = 0; i < numMsgs; i++) { message.setText("This is message " + (i + 1)); LOG.info("Sending message: " + message.getText()); producer.send(message); } /* * Send a non-text control message indicating end of messages. */ producer.send(session.createMessage()); } catch (JMSException e) { LOG.info("Exception occurred: " + e); } finally { if (connection != null) { try { connection.close(); } catch (JMSException e) { } } } }
From source file:eu.planets_project.tb.impl.persistency.CommentPersistencyImpl.java
/** * A Factory method to build a reference to this interface. * @return/* w w w . ja v a 2s. com*/ */ public static CommentPersistencyRemote getInstance() { Log log = LogFactory.getLog(CommentPersistencyImpl.class); try { Context jndiContext = new javax.naming.InitialContext(); CommentPersistencyRemote dao_r = (CommentPersistencyRemote) PortableRemoteObject.narrow( jndiContext.lookup("testbed/CommentPersistencyImpl/remote"), CommentPersistencyRemote.class); return dao_r; } catch (NamingException e) { log.error("Failure in getting PortableRemoteObject: " + e.toString()); return null; } }
From source file:eu.planets_project.tb.impl.system.TestbedStatelessAdminBean.java
/** * @return A reference to this EJB.//ww w . ja v a 2s .co m */ public static TestbedStatelessAdmin getTestbedAdminBean() { try { Context jndiContext = new javax.naming.InitialContext(); TestbedStatelessAdmin um = (TestbedStatelessAdmin) jndiContext .lookup("planets-project.eu/tb/TestbedAdminBean"); return um; } catch (NamingException e) { log.error("Failure during lookup of the local TestbedStatelessAdmin: " + e.toString()); return null; } }
From source file:eu.planets_project.tb.impl.persistency.ServiceRecordPersistencyImpl.java
/** * A Factory method to build a reference to this interface. * @return/*from w ww.j av a 2s. c om*/ */ public static ServiceRecordPersistencyRemote getInstance() { Log log = LogFactory.getLog(ServiceRecordPersistencyImpl.class); try { Context jndiContext = new javax.naming.InitialContext(); ServiceRecordPersistencyRemote dao_r = (ServiceRecordPersistencyRemote) PortableRemoteObject.narrow( jndiContext.lookup("testbed/ServiceRecordPersistencyImpl/remote"), ServiceRecordPersistencyRemote.class); return dao_r; } catch (NamingException e) { log.error("Failure in getting PortableRemoteObject: " + e.toString()); return null; } }
From source file:eu.planets_project.tb.impl.persistency.TestbedServiceTemplatePersistencyImpl.java
/** * A Factory method to build a reference to this interface. * @return//from w w w . ja v a 2s .c o m */ public static TestbedServiceTemplatePersistencyRemote getInstance() { Log log = LogFactory.getLog(TestbedServiceTemplatePersistencyImpl.class); try { Context jndiContext = new javax.naming.InitialContext(); TestbedServiceTemplatePersistencyRemote dao_r = (TestbedServiceTemplatePersistencyRemote) PortableRemoteObject .narrow(jndiContext.lookup("testbed/TestbedServiceTemplatePersistencyImpl/remote"), TestbedServiceTemplatePersistencyRemote.class); return dao_r; } catch (NamingException e) { log.error("Failure in getting PortableRemoteObject: " + e.toString()); return null; } }
From source file:de.griffel.confluence.plugins.plantuml.DatasourceHelper.java
/** * Determines data sources configured in Tomcat. * * @return List of data source names/* w w w .j a va 2s . c om*/ */ public static List<String> listAvailableDataSources() { final List<String> results = new LinkedList<String>(); // Workaround for classloader problems, see https://answers.atlassian.com/questions/6374/how-do-i-access-jndi-from-a-version-2-osgi-plugin final ClassLoader origCL = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(ComponentManager.class.getClassLoader()); final InitialContext jndiContext = new InitialContext(); final NamingEnumeration<Binding> bindings = jndiContext.listBindings(JDBC_CONTEXT); while (bindings != null && bindings.hasMore()) { results.add(bindings.next().getName()); } } catch (NamingException e) { log.debug("NamingException listBindings", e); results.add(e.toString()); } finally { Thread.currentThread().setContextClassLoader(origCL); } return results; }
From source file:eu.planets_project.tb.gui.UserBean.java
/** * Create a user manager://from w w w . j a v a2s . com * @return */ public static UserManager getUserManager() { try { Context jndiContext = getInitialContext(); UserManager um = (UserManager) PortableRemoteObject .narrow(jndiContext.lookup("planets-project.eu/UserManager/remote"), UserManager.class); return um; } catch (NamingException e) { log.error("Failure in getting PortableRemoteObject: " + e.toString()); return null; } }