Example #1
0
  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);
    }
  }
 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());
   }
 }
Example #3
0
  /**
   * 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;
  }