• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Servlets, MDB and OC4J

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
Little Help Needed here, You tips would be helpful.

I am sending a messgae from the Servlet to the Queue and have configured QueueConnectionFactory and Queue in the jms.xml file in OC4J.

A MDB has been deployed within the same EAR. Servlet can successfully send the messages to the queue but for some reason MDB is not responding or seems to be doing anything in response. I tried to write some console output but seems like messages are not being delivered to the MDB.

I have doubt on configuration. Do i have to add any entry for the Queue in the MDB deployment desctriptors!

Regards
Salman

<?xml version = '1.0' encoding = 'windows-1252'?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<message-driven>
<description>Message Driven Bean</description>
<display-name>MessageDrivenEJB</display-name>
<ejb-name>MessageDrivenEJB</ejb-name>
<ejb-class>voa.rsa.messaging.MessageDrivenEJBBean</ejb-class>
<transaction-type>Container</transaction-type>
<acknowledge-mode>Auto-acknowledge</acknowledge-mode>
<message-driven-destination>
<destination-type>javax.jms.Queue</destination-type>
<subscription-durability>Durable</subscription-durability>
</message-driven-destination>
<security-identity/>
</message-driven>
</enterprise-beans>
<assembly-descriptor/>
</ejb-jar>


Servlet Call:

private void sendMessageToQueue(String msg) {
TextMessage message;
try {
InitialContext ic = new InitialContext();

QueueConnectionFactory qcf = ( QueueConnectionFactory)ic.lookup("jms/MyQueueConnectionFactory");
Queue queue = (Queue)ic.lookup("jms/MyQueue");

QueueConnection qc = qcf.createQueueConnection();
QueueSession qs = qc.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
QueueSender qSender = qs.createSender(queue);

message = qs.createTextMessage();

for (int x = 0 ; x < 6; x++) {
message.setText(" Sending This Message: " + msg + " : "+(x + 1 ));
System.out.println("Sending message: " + message.getText());
qSender.send(message);
}


} catch(NamingException ne) {
System.out.println("NamingException in JMSQueueServlet: " + ne.getMessage());
ne.printStackTrace();
} catch(Exception ex) {
System.out.println("Exception in JMSQueueServlet: " + ex.getMessage());
ex.printStackTrace();
}
}
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Salman,
your not defining any JNDI name(s) in your descriptor file for your connection factory and queue, but you are acceesing the Queue and connection factories by using some JNDI name..

<resource-description>
<res-ref-name>jms/QCF</res-ref-name>
<jndi-name>weblogic.jms.ConnectionFactory</jndi-name>
</resourcedescription>

Do some thing like this ..

thanks,
Ugender
 
Salman Riaz
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ugender,
But could you please explain if i need to provide description for Queue only! as i dont think i would have to provide res-ref for the QueueConnectionFactory!

thanks in advance

salman
 
Ugender Rekulampally
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi salman,

you have to provide both, Connection Factory as well as Queue JNDI references in the descriptor file.

In your client program, you actually referencing them.

do some thing like this in your descriptor file:

<resource-ref>
<res-ref-name>jms/QCF</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

This element declares that a JMS QueueConnectionFactory object will be bound into JNDI, at the location:

java:comp/env/jms/QCF


<resource-description>
<res-ref-name>jms/QCF</res-ref-name>
<jndi-name>weblogic.jms.ConnectionFactory</jndi-name>
</resource-description>




for further help, look this bea site http://edocs.bea.com/wls/docs81/jms/j2ee_components.html

Hope that helps.

Ugender
 
Salman Riaz
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ugender.
I Can access the destination and send the messages to the queue from my servlet. But my MDB is not receiving any messages from the Queue.

I do not know here i am doing wrong as i have added the entry in the ejb-jar.xml and also in orion-ejb-jar.xml(OC4J in my case :-).

<?xml version = '1.0' encoding = 'windows-1252'?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>

<message-driven>
<description>Message Driven Bean</description>
<display-name>MessageDrivenEJB</display-name>
<ejb-name>MessageDrivenEJB</ejb-name>
<ejb-class>voa.rsa.messaging.MessageDrivenEJBBean</ejb-class>
<transaction-type>Container</transaction-type>
<acknowledge-mode>Auto-acknowledge</acknowledge-mode>

<message-driven-destination>
<destination-type>javax.jms.Queue</destination-type>
</message-driven-destination>

<resource-ref>
<res-ref-name>jms/MyQueueConnectionFactory</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-env-ref>
<resource-env-ref-name>jms/MyQueue</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>

<security-identity/>
</message-driven>

</enterprise-beans>
<assembly-descriptor/>
</ejb-jar>

orion-ejb-jar.xml

<enterprise-beans>
<message-driven-deployment name="MessageDrivenEJB"
connection-factory-location="jms/MyQueueConnectionFactory"
destination-location="jms/MyQueue"/>
</enterprise-beans>

onMessage method:
public void onMessage(Message inMessage)
{
TextMessage msg = null;

try {
if (inMessage instanceof TextMessage) {
msg = (TextMessage) inMessage;
System.out.println
("MESSAGE BEAN: Message received: "
+ msg.getText());
} else {
System.out.println
("Message of wrong type: "
+ inMessage.getClass().getName());
}
} catch (JMSException e) {
e.printStackTrace();
System.out.println("JMSException from onMessage() " + e.getMessage() );

context.setRollbackOnly();
} catch (Throwable te) {
te.printStackTrace();
System.out.println("JMSException from onMessage() " + te.getMessage() );
}

}
 
Ugender Rekulampally
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Salman,
I have no idea why your MDB not connected to your QUEUE. it seems you did everything right (ejb-jar file JNDI entries and client access those JNDI entries) but I dont know about OC4 thing .....

sorry for not helping you out in this problem...

Ugender
 
Salman Riaz
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ugender,
Thanks for your help. It worked finally. I had jms connection defined in jms.xml file(oc4j specific)wrongly. just made the changes in jms.xml and it worked

thanks once again.
salman
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic