You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jl...@apache.org on 2019/01/02 21:18:16 UTC
[05/12] tomee git commit: converting simple mdb and cdi from md to
adoc
converting simple mdb and cdi from md to adoc
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/f8be7469
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/f8be7469
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/f8be7469
Branch: refs/heads/master
Commit: f8be746996a360fd1237626fec3bc597838d17f3
Parents: 2dbfc56
Author: ivanjunckes <ij...@tomitribe.com>
Authored: Wed Jan 2 12:25:05 2019 -0200
Committer: ivanjunckes <ij...@tomitribe.com>
Committed: Wed Jan 2 12:25:05 2019 -0200
----------------------------------------------------------------------
examples/simple-mdb-and-cdi/README.adoc | 195 +++++++++++++++++++++++++++
examples/simple-mdb-and-cdi/README.md | 189 --------------------------
2 files changed, 195 insertions(+), 189 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/f8be7469/examples/simple-mdb-and-cdi/README.adoc
----------------------------------------------------------------------
diff --git a/examples/simple-mdb-and-cdi/README.adoc b/examples/simple-mdb-and-cdi/README.adoc
new file mode 100644
index 0000000..c0e2c45
--- /dev/null
+++ b/examples/simple-mdb-and-cdi/README.adoc
@@ -0,0 +1,195 @@
+= Simple MDB and CDI
+:index-group: JMS and MDBs
+:jbake-type: page
+:jbake-status: published
+
+_Help us document this example! Click the blue pencil icon in the upper right to edit this page._
+
+== ChatBean
+
+....
+package org.superbiz.mdb;
+
+import javax.annotation.Resource;
+import javax.ejb.MessageDriven;
+import javax.inject.Inject;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+@MessageDriven
+public class ChatBean implements MessageListener {
+
+ @Resource
+ private ConnectionFactory connectionFactory;
+
+ @Resource(name = "AnswerQueue")
+ private Queue answerQueue;
+
+ @Inject
+ private ChatRespondCreator responder;
+
+ public void onMessage(Message message) {
+ try {
+
+ final TextMessage textMessage = (TextMessage) message;
+ final String question = textMessage.getText();
+ final String response = responder.respond(question);
+
+ if (response != null) {
+ respond(response);
+ }
+ } catch (JMSException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ private void respond(String text) throws JMSException {
+
+ Connection connection = null;
+ Session session = null;
+
+ try {
+ connection = connectionFactory.createConnection();
+ connection.start();
+
+ // Create a Session
+ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // Create a MessageProducer from the Session to the Topic or Queue
+ MessageProducer producer = session.createProducer(answerQueue);
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ // Create a message
+ TextMessage message = session.createTextMessage(text);
+
+ // Tell the producer to send the message
+ producer.send(message);
+ } finally {
+ // Clean up
+ if (session != null) session.close();
+ if (connection != null) connection.close();
+ }
+ }
+}
+....
+
+== ChatRespondCreator
+
+....
+package org.superbiz.mdb;
+
+public class ChatRespondCreator {
+ public String respond(String question) {
+ if ("Hello World!".equals(question)) {
+ return "Hello, Test Case!";
+ } else if ("How are you?".equals(question)) {
+ return "I'm doing well.";
+ } else if ("Still spinning?".equals(question)) {
+ return "Once every day, as usual.";
+ }
+ return null;
+ }
+}
+....
+
+== beans.xml
+
+....
+<!--
+
+ 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.
+-->
+
+<beans/>
+....
+
+== ChatBeanTest
+
+....
+package org.superbiz.mdb;
+
+import junit.framework.TestCase;
+
+import javax.annotation.Resource;
+import javax.ejb.embeddable.EJBContainer;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+public class ChatBeanTest extends TestCase {
+
+ @Resource
+ private ConnectionFactory connectionFactory;
+
+ @Resource(name = "ChatBean")
+ private Queue questionQueue;
+
+ @Resource(name = "AnswerQueue")
+ private Queue answerQueue;
+
+ public void test() throws Exception {
+ EJBContainer.createEJBContainer().getContext().bind("inject", this);
+
+
+ final Connection connection = connectionFactory.createConnection();
+
+ connection.start();
+
+ final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ final MessageProducer questions = session.createProducer(questionQueue);
+
+ final MessageConsumer answers = session.createConsumer(answerQueue);
+
+
+ sendText("Hello World!", questions, session);
+
+ assertEquals("Hello, Test Case!", receiveText(answers));
+
+
+ sendText("How are you?", questions, session);
+
+ assertEquals("I'm doing well.", receiveText(answers));
+
+
+ sendText("Still spinning?", questions, session);
+
+ assertEquals("Once every day, as usual.", receiveText(answers));
+ }
+
+ private void sendText(String text, MessageProducer questions, Session session) throws JMSException {
+
+ questions.send(session.createTextMessage(text));
+ }
+
+ private String receiveText(MessageConsumer answers) throws JMSException {
+
+ return ((TextMessage) answers.receive(1000)).getText();
+ }
+}
+....
http://git-wip-us.apache.org/repos/asf/tomee/blob/f8be7469/examples/simple-mdb-and-cdi/README.md
----------------------------------------------------------------------
diff --git a/examples/simple-mdb-and-cdi/README.md b/examples/simple-mdb-and-cdi/README.md
deleted file mode 100644
index 68b9b25..0000000
--- a/examples/simple-mdb-and-cdi/README.md
+++ /dev/null
@@ -1,189 +0,0 @@
-index-group=Unrevised
-type=page
-status=published
-title=Simple MDB and CDI
-~~~~~~
-
-*Help us document this example! Click the blue pencil icon in the upper right to edit this page.*
-
-## ChatBean
-
- package org.superbiz.mdb;
-
- import javax.annotation.Resource;
- import javax.ejb.MessageDriven;
- import javax.inject.Inject;
- import javax.jms.Connection;
- import javax.jms.ConnectionFactory;
- import javax.jms.DeliveryMode;
- import javax.jms.JMSException;
- import javax.jms.Message;
- import javax.jms.MessageListener;
- import javax.jms.MessageProducer;
- import javax.jms.Queue;
- import javax.jms.Session;
- import javax.jms.TextMessage;
-
- @MessageDriven
- public class ChatBean implements MessageListener {
-
- @Resource
- private ConnectionFactory connectionFactory;
-
- @Resource(name = "AnswerQueue")
- private Queue answerQueue;
-
- @Inject
- private ChatRespondCreator responder;
-
- public void onMessage(Message message) {
- try {
-
- final TextMessage textMessage = (TextMessage) message;
- final String question = textMessage.getText();
- final String response = responder.respond(question);
-
- if (response != null) {
- respond(response);
- }
- } catch (JMSException e) {
- throw new IllegalStateException(e);
- }
- }
-
- private void respond(String text) throws JMSException {
-
- Connection connection = null;
- Session session = null;
-
- try {
- connection = connectionFactory.createConnection();
- connection.start();
-
- // Create a Session
- session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- // Create a MessageProducer from the Session to the Topic or Queue
- MessageProducer producer = session.createProducer(answerQueue);
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- // Create a message
- TextMessage message = session.createTextMessage(text);
-
- // Tell the producer to send the message
- producer.send(message);
- } finally {
- // Clean up
- if (session != null) session.close();
- if (connection != null) connection.close();
- }
- }
- }
-
-## ChatRespondCreator
-
- package org.superbiz.mdb;
-
- public class ChatRespondCreator {
- public String respond(String question) {
- if ("Hello World!".equals(question)) {
- return "Hello, Test Case!";
- } else if ("How are you?".equals(question)) {
- return "I'm doing well.";
- } else if ("Still spinning?".equals(question)) {
- return "Once every day, as usual.";
- }
- return null;
- }
- }
-
-## beans.xml
-
- <!--
-
- 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.
- -->
-
- <beans/>
-
-
-## ChatBeanTest
-
- package org.superbiz.mdb;
-
- import junit.framework.TestCase;
-
- import javax.annotation.Resource;
- import javax.ejb.embeddable.EJBContainer;
- import javax.jms.Connection;
- import javax.jms.ConnectionFactory;
- import javax.jms.JMSException;
- import javax.jms.MessageConsumer;
- import javax.jms.MessageProducer;
- import javax.jms.Queue;
- import javax.jms.Session;
- import javax.jms.TextMessage;
-
- public class ChatBeanTest extends TestCase {
-
- @Resource
- private ConnectionFactory connectionFactory;
-
- @Resource(name = "ChatBean")
- private Queue questionQueue;
-
- @Resource(name = "AnswerQueue")
- private Queue answerQueue;
-
- public void test() throws Exception {
- EJBContainer.createEJBContainer().getContext().bind("inject", this);
-
-
- final Connection connection = connectionFactory.createConnection();
-
- connection.start();
-
- final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- final MessageProducer questions = session.createProducer(questionQueue);
-
- final MessageConsumer answers = session.createConsumer(answerQueue);
-
-
- sendText("Hello World!", questions, session);
-
- assertEquals("Hello, Test Case!", receiveText(answers));
-
-
- sendText("How are you?", questions, session);
-
- assertEquals("I'm doing well.", receiveText(answers));
-
-
- sendText("Still spinning?", questions, session);
-
- assertEquals("Once every day, as usual.", receiveText(answers));
- }
-
- private void sendText(String text, MessageProducer questions, Session session) throws JMSException {
-
- questions.send(session.createTextMessage(text));
- }
-
- private String receiveText(MessageConsumer answers) throws JMSException {
-
- return ((TextMessage) answers.receive(1000)).getText();
- }
- }