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

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: JBossAS-5.0.0.Beta2, JBossAS-4.2.1.GA
    • Fix Version/s: JBossAS-4.2.3.GA
    • Component/s: EJB
    • Labels:
      None
    • Workaround Description:
      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;
    • Estimated Difficulty:
      Low

      Description

      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.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  bdecoste William DeCoste
                  Reporter:
                  galder.zamarreno Galder ZamarreƱo
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: