Title: RE: Orion and JMS: javax.naming.NameNotFoundException]
Daniel,
 
This my second reply to your question. Apperantly my first was lost since another reply submitted after yours appeared on the list yesterday but not yours.
 
In addition, you might want to apply the following edits to jms.xml:
 
> > > .- Configure jms.xml with this content:
> > >         <jms-server port="9127" host="">
> > >                 <queue name="Demo Queue" location="jms/demoQueue">
> > >                         <description>A dummy queue</description>
> > >                 </queue>
> > >                 <log>
> > >                         <file path="../logs/jms.log" />
> > >                 </log>
> > >         </jms-server>
This class might simplify your use of messaging:
 
public class MessageSender implements Serializable
{
    public MessageSender(String queueName, String topicName) throws MagnetException
    {
        this.queueName = queueName;
        this.topicName = topicName;
        initMessaging();
    }
 
    private void initMessaging()
    {
        try
        {
            if (queueName == null && topicName == null)
            {
                throw new IllegalArgumentException("MessageSender: initMessaging: No topic name or queue name");
            }
            InitialContext jndiEnc = new InitialContext();
            if (queueName != null)
            {
                QueueConnectionFactory factory = (QueueConnectionFactory)
                    jndiEnc.lookup(JNDINames.QUEUE_CONNECTION_FACTORY);
                qConnect = factory.createQueueConnection();
                qConnect.start();
                qSession = qConnect.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                try
                {
                    requestQ = (Queue)jndiEnc.lookup(JNDINames.JMS_DIRECTORY + queueName);
                }
                catch (NameNotFoundException nnfex)
                {
                    requestQ = qSession.createQueue(queueName);
                }
                qSender = qSession.createSender(requestQ);
            }
            if (topicName != null)
            {
                TopicConnectionFactory factory = (TopicConnectionFactory)
                    jndiEnc.lookup(JNDINames.TOPIC_CONNECTION_FACTORY);
                System.out.println("MessageSender: initMessaging: got connection factory " + factory);
                tConnect = factory.createTopicConnection();
                tConnect.start();
                tSession = tConnect.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
                try
                {
                    requestT = (Topic)jndiEnc.lookup(JNDINames.JMS_DIRECTORY + topicName);
                }
                catch (NameNotFoundException nnfex)
                {
                    requestT = tSession.createTopic(queueName);
                }
                publisher = tSession.createPublisher(requestT);
            }
        }
        catch (JMSException jmsex)
        {
            throw new UndeclaredThrowableException(jmsex, "MessageSender: initMessaging: " + jmsex.getMessage());
        }
        catch (NamingException nex)
        {
            throw new UndeclaredThrowableException(nex,
                "MessageSender: initMessaging: Problem looking up JmsQueueConnectionFactory");
        }
   }
 
    protected void finalize()
    {
        try
        {
         if (qConnect != null)
             qConnect.close();
         qConnect = null;
         qSession = null;
         qSender = null;
         requestQ = null;
 
         if (tConnect != null)
             tConnect.close();
         tConnect = null;
         tSession = null;
         publisher = null;
         requestT = null;
        }
        catch (JMSException jex)
        {
        }
    }
 

 private void writeObject(java.io.ObjectOutputStream out) throws IOException
    {
        try
        {
         if (qConnect != null)
             qConnect.close();
         qConnect = null;
         qSession = null;
         qSender = null;
         requestQ = null;
 
         if (tConnect != null)
             tConnect.close();
         tConnect = null;
         tSession = null;
         publisher = null;
         requestT = null;
        }
        catch (JMSException jex)
        {
            throw new IOException("MessageSender:  writeObject:  " + jex.getMessage());
        }
    }
 
    protected String queueName = null;
    protected transient QueueConnection qConnect = null;
    protected transient QueueSession qSession    = null;
    protected transient QueueSender qSender      = null;
    protected transient Queue requestQ   = null;
 
    protected String topicName = null;
    protected transient TopicConnection tConnect = null;
    protected transient TopicSession tSession    = null;
    protected transient TopicPublisher publisher      = null;
    protected transient Topic requestT   = null;
}
 
You will need to define the JNDINames interface with the appropriate values for its attributes.
Then any class that needs to send messages can extend MessageSender and use the appropriate attributes
This works for me. Let me know if you still have problems or questions

Dave


-----Original Message-----
From: Kesav Kumar [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 22, 2001 3:17 PM
To: Orion-Interest
Subject: RE: Orion and JMS: javax.naming.NameNotFoundException]

If you want to get any resource in your Servlet/jsp you got define resource-ref in your web.xml. 
One basic information as long as you are in the same container you don't need any parameters to JDNI context. 
You need jndi.properties only when you try to access from outside the container.  Your servlets/jsp/ejb/applicationclient

are in the same orion container so in all these components you can directly get JNDI context by
Context ctx = new InitialContext();
As long as you are in the same container there is no need for jndi.properties.

Regarding the JMS you got define resource-ref in your web.xml.  Any container resource of ejb resource you want to use in web tier i.e in servlets/jsp you have to define resource-ref and ejb-ref correspondingly. For JMS which is a resource so you have to declare resource-ref in your web.xml like the following.

        <resource-ref>
                <res-ref-name>jms/theQueueConnectionFactory</res-ref-name>
                <res-type>javax.jms.QueueConnectionFactory</res-type>
                <res-auth>Container</res-auth>
        </resource-ref>
        <resource-ref>
                <res-ref-name>jms/myQueue</res-ref-name>
                <res-type>javax.jms.Queue</res-type>
                <res-auth>Container</res-auth>
        </resource-ref>

Inside your servlet/jsp for connection factory lookup for jms/theQueueConnectionFactory and for queue lookup for jms/myQueue.



> ----- Original Message -----
> From: "Daniel Lopez" <[EMAIL PROTECTED]>
> To: "Orion-Interest" <[EMAIL PROTECTED]>
> Sent: Wednesday, August 22, 2001 8:48 AM
> Subject: [Fwd: Re: Orion and JMS: javax.naming.NameNotFoundException]
>
>
> > Hi (third try to the list, first ones didn't make it),
> >
> > I haven't got a single answer, so I'm wondering if nobody
> is using Orion
> >
> > JMS or this mailing list is playing funny with me. Has anybody
> > configured and used Orion JMS? Could somebody please
> elaborate on the
> > steps necessary to get this thing working?
> > Thanks in advance,
> > D.
> >
> > Daniel López wrote:
> > >
> > > Hi,
> > >
> > > I know this topic has been discussed a lot in here, but I
> haven't been
> >
> > > able to find the answer in the archive or in the
> documentation. The
> > > problem is: I decided to have a go with JMS but I can't
> even start to
> > > play with it, as all I get is
> "javax.naming.NameNotFoundException".
> > > These are the steps I have followed:
> > > .- Configure server.xml with the following line:
> > >         ...
> > >         <jms-config path="./jms.xml" />
> > >         ...
> > > .- Configure jms.xml with this content:
> > >         <jms-server port="9127" host="localhost">
> > >                 <queue-connection-factory
> > >                         location="jms/QueueConnectionFactory"/>
> > >                 <queue name="Demo Queue" location="jms/demoQueue">
> > >                         <description>A dummy queue</description>
> > >                 </queue>
> > >                 <log>
> > >                         <file path="../logs/jms.log" />
> > >                 </log>
> > >         </jms-server>
> > > .- Add jndi.properties to my application's
> classes(WEB-INF/classes),
> > > with the following content:
> > >
> > >
> >
> java.naming.factory.initial=com.evermind.server.ApplicationCli
> entInitialCont
> extFactory
> >
> > >         java.naming.provider.url=ormi://localhost/
> > >         java.naming.security.principal=admin
> > > .- Then in my servlet, I just try to see if the objects are there:
> > >         ...
> > >         Context ctx = new InitialContext();
> > >         QueueConnectionFactory queueConnectionFactory =
> > >                 (QueueConnectionFactory)
> > > ctx.lookup("java:comp/env/jms/QueueConnectionFactory");
> > >         // Exception is thrown in the line above
> > >         ...
> > > The facts:
> > >         .- JMS Server seems to have been started, as I can see the
> > jms.log file
> > > and reads (Date 1.4.5 Started)
> > >         .- I have tried with various names, with and without
> > java:comp/env, and
> > > with various methods (list, listBindings...) with no
> look. I cannot
> > get
> > > a single object to be looked up.
> > >         .- Platform is WinNt 4.0, JDK1.3.0-c hotspot,
> Orion 1.4.5 (I
> > also tried
> > > 1.5.2 with the same results)
> > >
> > > So, what have I forgotten to do? It seems like I just forgot to do
> > some
> > > essential step. I tried to find the JMS how to by Kesav
> Kumar but I
> > > couldn't find it. Anybody, please?
> > > Thank you in advance,
> > > D.
> > >
> > > PD: On a side note, I have seen man people trying to use
> external JMS
> > > providers with Orion, is that so because Orion JMS is
> buggy? Would it
> > be
> > > better to use some external tool like OpenJMS or so? I
> had thought it
> > > would be nice to have everything in the same place, this
> way you just
> > > have to take care of one server. Comments?
> >
>
>

Reply via email to