KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > appclient > MessageReplierBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.test.appclient;
23
24 import javax.annotation.Resource;
25 import javax.ejb.ActivationConfigProperty JavaDoc;
26 import javax.ejb.EJBException JavaDoc;
27 import javax.ejb.MessageDriven JavaDoc;
28 import javax.jms.Connection JavaDoc;
29 import javax.jms.ConnectionFactory JavaDoc;
30 import javax.jms.Destination JavaDoc;
31 import javax.jms.JMSException JavaDoc;
32 import javax.jms.Message JavaDoc;
33 import javax.jms.MessageListener JavaDoc;
34 import javax.jms.MessageProducer JavaDoc;
35 import javax.jms.Session JavaDoc;
36
37 import org.jboss.logging.Logger;
38
39 /**
40  * This message bean will just reply the message.
41  *
42  * @author <a HREF="mailto:carlo.dewolf@jboss.com">Carlo de Wolf</a>
43  * @version $Revision: $
44  */

45 @MessageDriven JavaDoc(activationConfig = {
46    @ActivationConfigProperty JavaDoc(propertyName="destinationType", propertyValue="javax.jms.Queue"),
47    @ActivationConfigProperty JavaDoc(propertyName="destination", propertyValue="queue/messageReplier")
48 })
49 public class MessageReplierBean implements MessageListener JavaDoc
50 {
51    private static final Logger log = Logger.getLogger(MessageReplierBean.class);
52    
53    @Resource(mappedName="java:ConnectionFactory")
54    private ConnectionFactory JavaDoc connectionFactory;
55    
56    public void onMessage(Message JavaDoc message)
57    {
58       try
59       {
60          if(message.getJMSReplyTo() != null)
61          {
62             Destination JavaDoc destination = message.getJMSReplyTo();
63             
64             Connection JavaDoc conn = connectionFactory.createConnection();
65             try
66             {
67                Session JavaDoc session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
68                MessageProducer JavaDoc producer = session.createProducer(destination);
69                producer.send(destination, message);
70                producer.close();
71                session.close();
72             }
73             finally
74             {
75                conn.close();
76             }
77          }
78          else
79             log.info("no reply to specified");
80       }
81       catch(JMSException JavaDoc e)
82       {
83          throw new EJBException JavaDoc(e);
84       }
85    }
86 }
87
Popular Tags