diff options
| author | Rajith Muditha Attapattu <rajith@apache.org> | 2012-02-01 23:56:28 +0000 |
|---|---|---|
| committer | Rajith Muditha Attapattu <rajith@apache.org> | 2012-02-01 23:56:28 +0000 |
| commit | 0dcfedb9a055a5ec9175a13cdce8667104cd799a (patch) | |
| tree | d195069c3d429ef502f3514d8b1faf82eba0f651 /qpid/java/jca/example/src | |
| parent | 08b3d439ce5cdcd127d14489ba4730ae3f2c7724 (diff) | |
| download | qpid-python-0dcfedb9a055a5ec9175a13cdce8667104cd799a.tar.gz | |
QPID-3734 Commiting patch by Weston Price.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1239411 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/jca/example/src')
6 files changed, 82 insertions, 120 deletions
diff --git a/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidGoodByeSubscriberBean.java b/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidGoodByeSubscriberBean.java index 8ad8aaa482..64e0effb1f 100644 --- a/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidGoodByeSubscriberBean.java +++ b/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidGoodByeSubscriberBean.java @@ -1,9 +1,35 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ package org.apache.qpid.jca.example.ejb; +import java.util.Date; + import javax.ejb.ActivationConfigProperty; import javax.ejb.MessageDriven; import javax.jms.Message; import javax.jms.MessageListener; +import javax.jms.TextMessage; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), @@ -17,11 +43,25 @@ import javax.jms.MessageListener; public class QpidGoodByeSubscriberBean implements MessageListener { + private static final Logger _log = LoggerFactory.getLogger(QpidGoodByeSubscriberBean.class); @Override public void onMessage(Message message) { - System.out.println(message); + try + { + if(message instanceof TextMessage) + { + String content = ((TextMessage)message).getText(); + + _log.info("Received text message with contents: [" + content + "] at " + new Date()); + } + } + catch(Exception e) + { + _log.error(e.getMessage(), e); + } + } } diff --git a/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidHelloListenerBean.java b/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidHelloListenerBean.java index d6d08d1557..0056e7b0b8 100644 --- a/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidHelloListenerBean.java +++ b/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidHelloListenerBean.java @@ -23,6 +23,7 @@ package org.apache.qpid.jca.example.ejb; import java.util.Date; import javax.annotation.PostConstruct; +import javax.annotation.Resource; import javax.ejb.ActivationConfigProperty; import javax.ejb.MessageDriven; import javax.jms.Connection; @@ -49,33 +50,12 @@ public class QpidHelloListenerBean implements MessageListener { private static final Logger _log = LoggerFactory.getLogger(QpidHelloListenerBean.class); + @Resource(@jndi.scheme@="@qpid.xacf.jndi.name@") private ConnectionFactory _connectionFactory; + @Resource(@jndi.scheme@="GoodByeQueue") private Destination _queue; - @PostConstruct - public void init() - { - InitialContext context = null; - - try - { - context = new InitialContext(); - _connectionFactory = (ConnectionFactory)context.lookup("java:comp/env/QpidJMSXA"); - _queue = (Destination)context.lookup("@qpid.goodbye.queue.jndi.name@"); - - } - catch(Exception e) - { - _log.error(e.getMessage(), e); - } - finally - { - QpidUtil.closeResources(context); - } - - } - @Override public void onMessage(Message message) { diff --git a/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidHelloSubscriberBean.java b/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidHelloSubscriberBean.java index 43ccf9defd..560de36e48 100644 --- a/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidHelloSubscriberBean.java +++ b/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidHelloSubscriberBean.java @@ -22,7 +22,7 @@ package org.apache.qpid.jca.example.ejb; import java.util.Date; -import javax.annotation.PostConstruct; +import javax.annotation.Resource; import javax.ejb.ActivationConfigProperty; import javax.ejb.MessageDriven; import javax.jms.Connection; @@ -52,35 +52,14 @@ public class QpidHelloSubscriberBean implements MessageListener { private static final Logger _log = LoggerFactory.getLogger(QpidHelloSubscriberBean.class); + @Resource(@jndi.scheme@="@qpid.xacf.jndi.name@") private ConnectionFactory _connectionFactory; + @Resource(@jndi.scheme@="GoodByeTopic") private Destination _topic; - @PostConstruct - public void init() - { - InitialContext context = null; - - try - { - context = new InitialContext(); - _connectionFactory = (ConnectionFactory)context.lookup("java:comp/env/QpidJMSXA"); - _topic = (Destination)context.lookup("@qpid.goodbye.topic.jndi.name@"); - - } - catch(Exception e) - { - _log.error(e.getMessage(), e); - } - finally - { - QpidUtil.closeResources(context); - } - - } - @Override - public void onMessage(Message message) + public void onMessage(Message message) { Connection connection = null; Session session = null; diff --git a/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidJMSResponderBean.java b/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidJMSResponderBean.java index 74d6fb6d89..e7b44e10ca 100644 --- a/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidJMSResponderBean.java +++ b/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidJMSResponderBean.java @@ -1,8 +1,28 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ package org.apache.qpid.jca.example.ejb; import java.util.Date; -import javax.annotation.PostConstruct; +import javax.annotation.Resource; import javax.ejb.ActivationConfigProperty; import javax.ejb.MessageDriven; import javax.jms.Connection; @@ -29,30 +49,9 @@ public class QpidJMSResponderBean implements MessageListener private static final Logger _log = LoggerFactory.getLogger(QpidJMSResponderBean.class); + @Resource(@jndi.scheme@="@qpid.xacf.jndi.name@") private ConnectionFactory _connectionFactory; - @PostConstruct - public void init() - { - InitialContext context = null; - - try - { - context = new InitialContext(); - _connectionFactory = (ConnectionFactory)context.lookup("java:comp/env/QpidJMSXA"); - - } - catch(Exception e) - { - _log.error(e.getMessage(), e); - } - finally - { - QpidUtil.closeResources(context); - } - - } - @Override public void onMessage(Message message) { diff --git a/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidTestBean.java b/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidTestBean.java index 17e37b9475..014b459699 100644 --- a/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidTestBean.java +++ b/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/ejb/QpidTestBean.java @@ -21,6 +21,7 @@ package org.apache.qpid.jca.example.ejb; import javax.annotation.PostConstruct; +import javax.annotation.Resource; import javax.ejb.Stateless; import javax.jms.Connection; import javax.jms.ConnectionFactory; @@ -39,35 +40,15 @@ public class QpidTestBean implements QpidTestRemote, QpidTestLocal private static final Logger _log = LoggerFactory.getLogger(QpidTestBean.class); + @Resource(@jndi.scheme@="@qpid.xacf.jndi.name@") private ConnectionFactory _connectionFactory; + @Resource(@jndi.scheme@="HelloQueue") private Destination _queue; + @Resource(@jndi.scheme@="HelloTopic") private Destination _topic; - @PostConstruct - public void init() - { - InitialContext context = null; - - try - { - context = new InitialContext(); - _connectionFactory = (ConnectionFactory)context.lookup("java:comp/env/QpidJMSXA"); - _queue = (Destination)context.lookup("@qpid.hello.queue.jndi.name@"); - _topic = (Destination)context.lookup("@qpid.hello.topic.jndi.name@"); - - } - catch(Exception e) - { - _log.error(e.getMessage(), e); - } - finally - { - QpidUtil.closeResources(context); - } - - } @Override public void testQpidAdapter(String content) throws Exception { diff --git a/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/web/QpidTestServlet.java b/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/web/QpidTestServlet.java index 71289b22c3..11a61e762c 100644 --- a/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/web/QpidTestServlet.java +++ b/qpid/java/jca/example/src/main/java/org/apache/qpid/jca/example/web/QpidTestServlet.java @@ -22,6 +22,8 @@ package org.apache.qpid.jca.example.web; import java.io.IOException; +import javax.annotation.Resource; +import javax.ejb.EJB; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.Destination; @@ -36,7 +38,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.transaction.UserTransaction; -import org.apache.qpid.jca.example.ejb.QpidTest; +import org.apache.qpid.jca.example.ejb.QpidTestLocal; import org.apache.qpid.jca.example.ejb.QpidUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,35 +54,17 @@ public class QpidTestServlet extends HttpServlet private static final boolean DEFAULT_XA = false; private static final boolean DEFAULT_SAY_GOODBYE = true; + @Resource(@jndi.scheme@="@qpid.xacf.jndi.name@") private ConnectionFactory _connectionFactory; + @Resource(@jndi.scheme@="HelloQueue") private Destination _queue; + @Resource(@jndi.scheme@="HelloTopic") private Destination _topic; - public void init(ServletConfig config) throws ServletException - { - - InitialContext context = null; - - try - { - context = new InitialContext(); - _connectionFactory = (ConnectionFactory)context.lookup("java:comp/env/QpidJMSXA"); - _queue = (Destination)context.lookup("@qpid.hello.queue.jndi.name@"); - _topic = (Destination)context.lookup("@qpid.hello.topic.jndi.name@"); - - } - catch(Exception e) - { - _log.error(e.getMessage(), e); - throw new ServletException(e.getMessage(), e); - } - finally - { - QpidUtil.closeResources(context); - } - } + @EJB + private QpidTestLocal ejb; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException @@ -127,7 +111,6 @@ public class QpidTestServlet extends HttpServlet if(useEJB) { - QpidTest ejb = (QpidTest)ctx.lookup("java:comp/env/QpidTestBean"); ejb.testQpidAdapter(content, count, useTopic, false, sayGoodBye); } else |
