authTopic = (Topic) initialContext.lookup("topic/topicAuth");
authTopic = (Topic) initialContext.lookup(BeanConfig.PrefixTopicName+"topicAuth");
  public String getCategories(String regionName, String username, String password) throws RemoteException  {    StringBuffer html = new StringBuffer();    Connection        conn = null;    PreparedStatement stmt = null;    ResultSet rs           = null;    String categoryName;    int categoryId;    int regionId = -1;    int userId = -1;    if (regionName != null && !regionName.equals(""))    {      // get the region ID      try       {        conn = dataSource.getConnection();        stmt = conn.prepareStatement("SELECT id FROM regions WHERE name=?");        stmt.setString(1, regionName);        rs = stmt.executeQuery();        stmt.close();      }      catch (SQLException e)      {        try        {          if (stmt != null) stmt.close();          if (conn != null) conn.close();        }        catch (Exception ignore)        {        }        throw new RemoteException("Failed to get region Id " +e);      }      try      {        if (rs.first())        {          regionId = rs.getInt("id");        }      }      catch (Exception e)      {        try        {          if (conn != null) conn.close();        }        catch (Exception ignore)        {        }        throw new EJBException(" Region "+regionName+" does not exist in the database!<br>(got exception: " +e+")");      }    }    else    {      // Authenticate the user who wants to sell items      if ((username != null && !username.equals("")) || (password != null && !password.equals("")))      {        TopicConnection authConnection;        TopicSession authSession;        Topic authTopic;        try         {          // create a connection          authConnection = connectionFactory.createTopicConnection();          // lookup the destination          authTopic = (Topic) initialContext.lookup("topic/topicAuth");          // create a session          authSession  = authConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); // no transaction and auto ack        }         catch (Exception e)        {          throw new EJBException("Cannot connect to message bean MDB_Auth : " +e+"<br>");        }        try         {          // create a requestor to receive the reply          TopicRequestor requestor = new TopicRequestor(authSession, authTopic);          // create a message          MapMessage m = authSession.createMapMessage();          // set parameters          m.setStringProperty("nickname", username);          m.setStringProperty("password", password);          m.setJMSCorrelationID("auth");          // send the message and receive the reply          authConnection.start(); // allows message to be delivered (default is connection stopped)          MapMessage authReply = (MapMessage)requestor.request(m);          authConnection.stop();          // read the reply          userId = authReply.getInt("userId");          // close connection and session          requestor.close(); // also close the session          authConnection.close();        }         catch (Exception e)        {          throw new EJBException("user authentication failed: " +e+"<br>");        }        if (userId == -1)        {           html.append(" You don't have an account on RUBiS!<br>You have to register first.<br>");           return html.toString();        }      }    }    try     {      if (conn == null)        conn = dataSource.getConnection();      stmt = conn.prepareStatement("SELECT name, id FROM categories");      rs = stmt.executeQuery();    }    catch (SQLException e)    {      try      {        if (stmt != null) stmt.close();        if (conn != null) conn.close();      }      catch (Exception ignore)      {      }      throw new EJBException("Failed to get categories list " +e);    }    try     {      if (!rs.first())        html.append("<h2>Sorry, but there is no category available at this time. Database table is empty</h2><br>");      else      {        do        {          categoryName = rs.getString("name");          categoryId = rs.getInt("id");          if (regionId != -1)          {            html.append(printCategoryByRegion(categoryName, categoryId, regionId));          }          else          {            if (userId != -1)              html.append(printCategoryToSellItem(categoryName, categoryId, userId));            else              html.append(printCategory(categoryName, categoryId));          }        }        while (rs.next());      }      if (stmt != null) stmt.close();      if (conn != null) conn.close();    }     catch (Exception e)     {      try      {        if (stmt != null) stmt.close();        if (conn != null) conn.close();      }      catch (Exception ignore)      {      }      throw new EJBException("Exception getting category list: " + e);    }    return html.toString();  }