public QLender(String queuecf, String requestQueue) { try { // Connect to the provider and get the JMS connection Context ctx = new InitialContext(); QueueConnectionFactory qFactory = (QueueConnectionFactory) ctx.lookup(queuecf); qConnect = qFactory.createQueueConnection(); // Create the JMS Session qSession = qConnect.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); // Lookup the request queue requestQ = (Queue) ctx.lookup(requestQueue); // Now that setup is complete, start the Connection qConnect.start(); // Create the message listener QueueReceiver qReceiver = qSession.createReceiver(requestQ); qReceiver.setMessageListener(this); System.out.println("Waiting for loan requests..."); } catch (JMSException jmse) { jmse.printStackTrace(); System.exit(1); } catch (NamingException jne) { jne.printStackTrace(); System.exit(1); } }
private void initSFSB(String[] args) { System.out.println("[apiClient] Inside init...."); try { Context ic = null; Object objref = null; if ((args[0] == null) || (args[1] == null)) { ic = new InitialContext(); System.out.println("[apiClient] Lookingup Bean apiClient "); objref = ic.lookup("java:comp/env/ejb/apiSecurity"); } else { Properties env = new Properties(); env.put("java.naming.provider.url", args[0]); env.put("java.naming.factory.initial", args[1]); ic = new InitialContext(env); objref = ic.lookup(args[2]); } RpaHome home = (RpaHome) PortableRemoteObject.narrow(objref, RpaHome.class); hr = home.create("LizHurley"); System.out.println("[passivateactivate] Initalization done"); // stat.addStatus("init apiClient", stat.PASS); } catch (Exception e) { e.printStackTrace(); System.out.println("[apiClient] Exception in init...."); e.printStackTrace(); // stat.addStatus("client initSFSB", stat.FAIL); } }
public void ejbCreate() { System.out.println("In SimpleMessageBean.ejbCreate()"); try { jndiContext = new InitialContext(); queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("java:comp/env/jms/QCFactory"); queue = (Queue) jndiContext.lookup("java:comp/env/jms/clientQueue"); } catch (NamingException e) { System.out.println("JNDI lookup failed: " + e.toString()); } }
private void initSLSB() { System.out.println("[txtests] Inside init...."); try { Context ic = new InitialContext(); Object objref = ic.lookup("java:comp/env/ejb/SLSBHome"); this.home = (SLSBHome) PortableRemoteObject.narrow(objref, SLSBHome.class); System.out.println("[txtests] Initalization done"); } catch (Exception e) { System.out.println("[txtests] Exception in init...."); e.printStackTrace(); } }
public boolean inicializaCola() { try { if (contexto == null) { // Aun no se ha realizado la inicializacion. Una vez realizada // no tiene sentido volver a realizarla. contexto = new InitialContext(); // Obtiene contexto JNDI // Obtiene factoria de conexion a colas (ha debido ser creada externamente) factoria = (QueueConnectionFactory) contexto.lookup("jms/factoria"); // Obtiene la cola (ha debido ser creada externamente) cola = (Queue) contexto.lookup(nombreCola); // Ahora crea la conexion a la cola conexionCola = factoria.createQueueConnection(); // Crea la sesion sesionCola = conexionCola.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); conexionCola.start(); // Hay que activar la conexion para empezar. } } catch (NamingException | JMSException ex) { contexto = null; return false; } return true; }
/** * Creates a JNDI InitialContext object if none exists yet. Then looks up the string argument and * returns the associated object. * * @param name the name of the object to be looked up * @return the object bound to <code>name</code> * @throws javax.naming.NamingException if name cannot be found */ public static Object jndiLookup(String name) throws NamingException { Object obj = null; if (jndiContext == null) { try { jndiContext = new InitialContext(); } catch (NamingException e) { System.out.println("Could not create JNDI context: " + e.toString()); throw e; } } try { obj = jndiContext.lookup(name); } catch (NamingException e) { System.out.println("JNDI lookup failed: " + e.toString()); throw e; } return obj; }