[jboss-user] [EJB 3.0 Users] - Re: How to load external parameters in ejb?
mnenchev
do-not-reply at jboss.com
Tue Nov 17 12:51:48 EST 2009
Hi, here is the whole stateles bean class:
|
| @Stateless
| public class QueueSenderBean implements ISenderLocal {
|
| private static final Logger log = Logger.getLogger(QueueSenderBean.class);
|
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| public void send(final Serializable obj, String queueName, String cf) {
| sendToQueue(obj, queueName, cf);
| }
|
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| private void sendToQueue(Serializable obj, String queueName, String cf) {
| Connection queueConnection = null;
| Session queueSession = null;
| Queue queue = null;
| MessageProducer sender = null;
| try {
| final Context initCtx = new InitialContext();
| final ConnectionFactory qFactory = (ConnectionFactory) initCtx.lookup(cf);
| queueConnection = qFactory.createConnection();
| queueSession = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
| queue = (Queue) initCtx.lookup(queueName);
| sender = queueSession.createProducer(queue);
| log.debug("Sending message to " + queue);
| final Message msg = queueSession.createTextMessage((String) obj);
| sender.send(msg);
| } catch (final javax.jms.JMSException e) {
| log.error("send() -> JMS Error: ", e);
| } catch (final NamingException e) {
| log.error("sendToQueue() -> JNI Error: ", e);
| } catch (final Exception e) {
| log.error("sendToQueue() -> Error: ", e);
| } finally {
| try {
| if (queueConnection != null) {
| queueConnection.close();
| }
| if (queueSession != null) {
| queueSession.close();
| }
| queue = null;
| if (sender != null) {
| sender.close();
| }
| } catch (final Exception e) {
| log.error("sendToQueue() -> Error while closing resources: ", e);
| }
| }
| }
|
| }
|
I use TransactionAttributeType.NOT_SUPPORTED because i send messages to websphere in CLIENT transportType, which throws exceptions if this is done in transaction scope, so i added this attribute.
Regards.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4266153#4266153
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4266153
More information about the jboss-user
mailing list