Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-4805

InitialContextFactory.getHAContext() should not use hardcoded localhost for lookup

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • JBossAS-4.2.3.GA
    • JBossAS-5.0.0.Beta2, JBossAS-4.2.1.GA
    • EJB
    • None
    • Low
    • Hide

      + Workaround for injecting ConnectionFactory instances - Inject JmsXA instead of ConnectionFactory

      @Resource(mappedName="java:/JmsXA", type=javax.jms.ConnectionFactory.class)
      private ConnectionFactory factory;

      + Workarounds for injecting Queue/Topic instances:

      1.- Not to inject Queue and instead, assuming the queue name is "queue/A" use the
      following code to initialise it the first time you use the Queue instance variable:

      String bindAddress = System.getProperty("jboss.bind.address") == null ? "localhost" : System.getProperty("jboss.bind.address");
      InitialContext ic = new InitialContext();
      Queue queueA = (Queue)ic.lookup("jnp://" + bindAddress + ":1100/queue/A");

      2.- For this second option, let's assume the queue name is "queue/B". In this case,
      you can add META-INF/jboss.xml to your EJB jar deployment, which looks like this:

      <?xml version="1.0"?>
      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN"
      "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
      <jboss>
      <enterprise-beans>
      <session>
      <ejb-name>InhaltPruefungVerwaltungBean</ejb-name>
      <resource-ref>
      <res-ref-name>queue/ref/B</res-ref-name>
      <jndi-name>jnp://${jboss.bind.address:localhost}:1100/queue/B</jndi-name>
      </resource-ref>
      </session>
      </enterprise-beans>
      </jboss>

      And inject the Queue in your EJB this way:

      @Resource(mappedName="java:comp/env/queue/ref/B")
      private Queue queueB;

      Show
      + Workaround for injecting ConnectionFactory instances - Inject JmsXA instead of ConnectionFactory @Resource(mappedName="java:/JmsXA", type=javax.jms.ConnectionFactory.class) private ConnectionFactory factory; + Workarounds for injecting Queue/Topic instances: 1.- Not to inject Queue and instead, assuming the queue name is "queue/A" use the following code to initialise it the first time you use the Queue instance variable: String bindAddress = System.getProperty("jboss.bind.address") == null ? "localhost" : System.getProperty("jboss.bind.address"); InitialContext ic = new InitialContext(); Queue queueA = (Queue)ic.lookup("jnp://" + bindAddress + ":1100/queue/A"); 2.- For this second option, let's assume the queue name is "queue/B". In this case, you can add META-INF/jboss.xml to your EJB jar deployment, which looks like this: <?xml version="1.0"?> <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd"> <jboss> <enterprise-beans> <session> <ejb-name>InhaltPruefungVerwaltungBean</ejb-name> <resource-ref> <res-ref-name>queue/ref/B</res-ref-name> <jndi-name>jnp://${jboss.bind.address:localhost}:1100/queue/B</jndi-name> </resource-ref> </session> </enterprise-beans> </jboss> And inject the Queue in your EJB this way: @Resource(mappedName="java:comp/env/queue/ref/B") private Queue queueB;

      org.jboss.ejb3.InitialContextFactory.getHAContext() contains:

      env.put(Context.PROVIDER_URL, "localhost:" + getHaJndiPort());
      InitialContext haCtx = new InitialContext(env);

      The code should not have hardcoded localhost because as soon as someone binds JBoss
      to something different, a localhost lookup will fail.

      This could should instead check HAJNDI service's BindAddress attribute and use that.

            wdecoste1@redhat.com William Decoste (Inactive)
            rh-ee-galder Galder ZamarreƱo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: