facebook

jndi-name lookup config-problem

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #252798 Reply

    Lance Drake
    Member

    Hi MyEclipse Support and J2EE-Folks,

    A HUGE amount of time was spent this weekend – to no avail – trying to get a JNDI lookup call to work so I could send a message to my MDbean.

    WEB.XML particulars:
    <resource-ref>
    <description>Default Queue Factory</description>
    <res-ref-name>jms/QueueFactory</res-ref-name>
    <res-type>javax.jms.QueueConnectionFactory</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>

    <resource-ref>
    <description>TableMsg Queue</description>
    <res-ref-name>jms/TableMsg</res-ref-name>
    <res-type>javax.jms.Queue</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>

    JBOSS-WEB.XML particulars:
    <resource-ref>
    <res-ref-name>jms/QueueFactory</res-ref-name>
    <jndi-name>QueueConnectionFactory</jndi-name>
    </resource-ref>

    <resource-ref>
    <res-ref-name>jms/TableMsg</res-ref-name>
    <jndi-name>jms/TableMsg</jndi-name>
    </resource-ref>

    REFERRING SOURCE-CODE:

    Context jndiContext = new InitialContext();
    QueueConnectionFactory queueConnectionFactory =
    (QueueConnectionFactory) jndiContext.lookup(“QueueConnectionFactory”);
    queueConnection = queueConnectionFactory.createQueueConnection();
    queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    queue = (Queue) jndiContext.lookup(“jms/TableMsg”);

    <NAMING EXCEPTION HAPPENS AT LINE ABOVE>

    This SHOULD be such a simple thing – but I can’t get the secret incantations properly aligned. Any suggestions?

    THANK YOU!

    #252817 Reply

    Riyad Kalla
    Member

    Moving to OT > Soft Dev

    #252833 Reply

    Lance Drake
    Member

    So said the King of Siam, “Is a puzzlement!”

    Well – this problems continues to cause me to want to reach for my wallet, buy into JBuilder-world and get on with the actual ‘work’ involved in this assignment. The tags that appear to be the solution to the problem are marked as errors when added into the XML file, they are ignored by XDoclet, and the documentation has really not been much of a help.

    Nowhere was I able to find anything resembling sample code for a simple basic project where there’s a servlet that passes off a message into a MDbean. There’s ALL sorts of “this is along the lines of what you need to do…” chatter – but this primary, basic, fundamentally important connection mechanism is not ‘actually’; demonstrated anywhere (I can find). And, taking ALL of the suggestions and Java docs into account, I was not able to get it to work. I am not stupid – I am not a dilettante – I seriously tried to slug thru this and MyEclipse (and Eclipse) either fought me or just layed there the whole time.

    There are LOTS of things about MyEclipse which are encouraging, but I spent the weekend in a loop consisting of “read-try-fail-tweak-guess-look-try-fail-think-fail-comeback-read-spin-fail” mode.

    Where’s my wallet… I need to get crankin’….

    #252834 Reply

    Riyad Kalla
    Member

    Try using:

    
    queue = (Queue)jndiContext.lookup("java:comp/env/jms/TableMsg");
    

    I just googled for some JNDI JMS queue examples, not sure really what that means necessarily, but if that’s worth $3500 to you, then you gotta get the tools that make your life easier. I would point out that for 1 copy of JBuilder Enterprise you could buy almost 117 copies of MyEclipse.

    #252835 Reply

    Lance Drake
    Member

    Oh golly – Will I EVER learn NOT to complain!?!

    First off… I’ve been down the “java:com/env/jms/TableMsg” path. But will go there AGAIN! Thanks for the encouragement.

    Secondly – you are absolutely correct that it’s a $3500 (versus $500) ticket to ride the JBuilder/JBoss express – as I just found out MOMENTS AGO! So, it looks like the wallet is NOT coming out, after all – I’ll need to buckle down and make this thing happen for me.

    Thirdly, I apologize for the sad state of my Eclipse/J2EE experience and am grateful for your kind consideration of my frustrating problem.

    Thanks very much!

    #252836 Reply

    Riyad Kalla
    Member

    First off… I’ve been down the “java:com/env/jms/TableMsg” path. But will go there AGAIN! Thanks for the encouragement.

    I know how you feel, every time I do Hibernate I can’t remember if I need the java:comp crap or if I just need the path part… I still don’t know to this day, I always trial-and-error it.

    Is there such a think as a JNDI explorer that can connect to your running app server and explore your directory to see what IS in it? I’m not versed in the ways of JNDI.

    Thirdly, I apologize for the sad state of my Eclipse/J2EE experience and am grateful for your kind consideration of my frustrating problem.

    No problem, the reason I didn’t pitch in earlier was because I had absolutely no idea. But then you sounded really frustrated, so I asked my good friend Google. He’s pretty good at a lot of things 😉

    #252837 Reply

    Lance Drake
    Member

    For some person’s future reference when searching the archives for a similar answer and looking for an opportunity to compare what they have (that doesn’t work) with something that’s working for me – here’re the pieces of the “Send a message to an MDbean “puzzle which – now that everything is working – seem quite reasonable. It’s quite possible I have left out some important configuration details. What this config represents is a set of details that allow the thing to work. Apologies to all super-code-wonks who may not find it terse (or verbose) enough or especially well-formed. The snips below would sure have been welcomed by ME acouple of days ago. Here’s hoping it has a positive effect for somebody else.

    FROM WEB.XML
    <servlet-mapping>
    <servlet-name>Trident</servlet-name>
    <url-pattern>/servlet/Trident</url-pattern>
    </servlet-mapping>

    <resource-ref>
    <description>Default Queue Factory</description>
    <res-ref-name>jms/QueueFactory</res-ref-name>
    <res-type>javax.jms.QueueConnectionFactory</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>

    <resource-ref>
    <description>TableMsg Queue</description>
    <res-ref-name>java:comp/env/jms/TableMsg</res-ref-name>
    <res-type>javax.jms.Queue</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>

    FROM JBOSS-WEB.XML
    <jboss-web>
    <security-domain>java:/jaas/Trident</security-domain>
    <resource-ref>
    <res-ref-name>jms/QueueFactory</res-ref-name>
    <jndi-name>QueueConnectionFactory</jndi-name>
    </resource-ref>

    <resource-ref>
    <res-ref-name>java:comp/env/jms/TableMsg</res-ref-name>
    <jndi-name>java:comp/env/jms/TableMsg</jndi-name>
    </resource-ref>
    </jboss-web>

    FROM JBOSS.XML
    <message-driven>
    <ejb-name>TableMsg</ejb-name>
    <destination-jndi-name>queue/TableMsg</destination-jndi-name>
    </message-driven>

    FROM EJB-JAR.XML
    <message-driven>
    <description><![CDATA[Message-Driven TableMsgBean]]></description>
    <display-name>Table Messages Bean</display-name>
    <ejb-name>TableMsg</ejb-name>
    <ejb-class>ejb.TableMsgBean</ejb-class>
    <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
    <transaction-type>Container</transaction-type>
    <message-driven-destination>
    <destination-type>javax.jms.Queue</destination-type>
    </message-driven-destination>
    <res-ref-name>jms/TableMsg</res-ref-name>
    </message-driven>

    JBOSS DEPLOYMENT MESSAGES:
    00:02:51,878 INFO [EJBDeployer] Undeploying: file:/Developer/JBOSS/server/default/deploy/ejb.jar/
    00:02:51,926 INFO [EjbModule] Undeployed TableMsg
    00:02:51,928 INFO [ProxyFactory] Unbind EJB Home ‘Table’ from jndi ‘ejb/Table’
    00:02:51,930 INFO [EjbModule] Undeployed Table
    00:02:52,064 INFO [EjbModule] Deploying Table
    00:02:52,076 INFO [EjbModule] Deploying TableMsg

    00:02:52,137 INFO [ProxyFactory] Bound EJB Home ‘Table’ to jndi ‘ejb/Table’
    00:02:52,165 INFO [EJBDeployer] Deployed: file:/Developer/JBOSS/server/default/deploy/ejb.jar/

    NOTE LACK OF AN ENTRY LIKE:

    00:09:28,409 WARN [JMSContainerInvoker] Could not find the queue destination-jndi-name=jms/TableMsg

    Global JNDI Namespace seen at the JBoss JMX Console -> service JNDIview -> List

    …Listing SNIPPED for brevity…
    +- queue (class: org.jnp.interfaces.NamingContext)
    | +- D (class: org.jboss.mq.SpyQueue)
    | +- C (class: org.jboss.mq.SpyQueue)
    | +- TableMsg (class: org.jboss.mq.SpyQueue)

    | +- B (class: org.jboss.mq.SpyQueue)
    | +- A (class: org.jboss.mq.SpyQueue)
    | +- testQueue (class: org.jboss.mq.SpyQueue)
    | +- javax.jms.Queue (class: org.jboss.mq.SpyQueue)
    | +- env (class: org.jnp.interfaces.NamingContext)
    | | +- jms (class: org.jnp.interfaces.NamingContext)
    | | | +- TableMsg (class: org.jboss.mq.SpyQueue)
    | +- ex (class: org.jboss.mq.SpyQueue)
    | +- DLQ (class: org.jboss.mq.SpyQueue)
    +- topic (class: org.jnp.interfaces.NamingContext)
    | +- testDurableTopic (class: org.jboss.mq.SpyTopic)
    | +- testTopic (class: org.jboss.mq.SpyTopic)
    | +- securedTopic (class: org.jboss.mq.SpyTopic)
    … and so on…

    The code that actually gets the message into the queue:
    (nothing new or even clever here – just included for completeness)


    private int sendMsg(String msg)
    {
    int result = -1;
    Queue queue = null;
    QueueSession queueSession = null;
    QueueSender queueSender = null;
    QueueConnection queueConnection = null;

    try
    {
    Context jndiContext = new InitialContext();

    QueueConnectionFactory queueConnectionFactory =
    (QueueConnectionFactory) jndiContext.lookup(“QueueConnectionFactory”);
    System.out.println(“GOT PAST: jndiContext.lookup(‘QueueConnectionFactory’)”);

    queueConnection = queueConnectionFactory.createQueueConnection();
    System.out.println(“GOT PAST: queueConnectionFactory.createQueueConnection()”);

    queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    System.out.println(“GOT PAST: queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE)”);

    queue = (Queue) jndiContext.lookup(queueName); // derived elsewhere
    System.out.println(“GOT PAST: (Queue) jndiContext.lookup(‘queue/TableMsg’)”);

    queueSender = queueSession.createSender(queue);

    // programmer’s paranoia
    if((null != queueConnection) && (null != queueSession) && (null != queueSender))
    {
    try {
    TextMessage message = queueSession.createTextMessage();
    message.setText(msg);
    queueSender.send(message);
    result = 0; // success
    }
    catch (JMSException ex)
    {
    System.out.println(“Message Send Exception”);
    }

    if (null != queueConnection)
    {
    try {
    queueConnection.close();
    }
    catch (JMSException e)
    {
    System.out.println(“Close Queue Connection Exception”);
    }
    }

    queueConnection = null;
    queue = null;
    queueSession = null;
    queueSender = null;
    }
    }

    catch (NamingException e)
    {
    System.out.println(“Naming Exception”);
    }
    catch (JMSException e)
    {
    System.out.println(“JMS Exception”);
    }
    return(result);
    } // sendMsg

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: jndi-name lookup config-problem

You must be logged in to post in the forum log in