Skip to content

Commit

Permalink
update helloworld-mdb for WildFly 8
Browse files Browse the repository at this point in the history
  • Loading branch information
jmesnil committed Feb 3, 2014
1 parent 2f82aad commit 2cb2cc4
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 70 deletions.
38 changes: 18 additions & 20 deletions helloworld-mdb/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
---
Author: Serge Pagop, Andy Taylor, Jeff Mesnil
Level: Intermediate
Technologies: JMS, EJB, MDB
Summary: Demonstrates the use of JMS and EJB Message-Driven Bean
Target Product: WildFly
Source: https://github.com/wildfly/quickstart/
---

helloworld-mdb: Helloword Using an MDB (Message-Driven Bean)
============================================================
Author: Serge Pagop, Andy Taylor, Jeff Mesnil
Level: Intermediate
Technologies: JMS, EJB, MDB
Summary: Demonstrates the use of JMS 1.1 and EJB 3.1 Message-Driven Bean
Target Product: EAP
Source: <https://github.com/jboss-jdf/jboss-as-quickstart/>

What is it?
-----------

This example demonstrates the use of *JMS 1.1* and *EJB 3.1 Message-Driven Bean* in JBoss Enterprise Application Platform 6 or JBoss AS 7.1.0.
This example demonstrates the use of *JMS 2.0* and *EJB 3.2 Message-Driven Bean* in WildFly 8.

This project creates two JMS resources:

Expand All @@ -21,18 +24,18 @@ This project creates two JMS resources:
System requirements
-------------------

All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better.
All you need to build this project is Java 7.0 (Java SDK 1.7) or better, Maven 3.0 or better.

The application this project produces is designed to be run on JBoss Enterprise Application Platform 6 or JBoss AS 7.
The application this project produces is designed to be run on WildFly 8.


Configure Maven
---------------

If you have not yet done so, you must [Configure Maven](../README.md#mavenconfiguration) before testing the quickstarts.
If you have not yet done so, you must [Configure Maven](../README.md#configure-maven-) before testing the quickstarts.


Start JBoss Enterprise Application Platform 6 or JBoss AS 7 with the Full Profile
Start WildFly 8 with the Full Profile
---------------

1. Open a command line and navigate to the root of the JBoss server directory.
Expand Down Expand Up @@ -91,11 +94,6 @@ Undeploy the Archive
mvn jboss-as:undeploy


Run the Quickstart in JBoss Developer Studio or Eclipse
-------------------------------------
You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see [Use JBoss Developer Studio or Eclipse to Run the Quickstarts](../README.md#useeclipse)


Debug the Application
------------------------------------

Expand All @@ -114,13 +112,13 @@ If you do not yet have an OpenShift account and domain, [Sign in to OpenShift](h

### Create the OpenShift Application

Open a shell command prompt and change to a directory of your choice. Enter the following command, replacing APPLICATION_TYPE with `jbosseap-6.0` for quickstarts running on JBoss Enterprise Application Platform 6, or `jbossas-7` for quickstarts running on JBoss AS 7:
Open a shell command prompt and change to a directory of your choice. Enter the following command for quickstarts running on WildFLy 8:

rhc app create -a hellworldmdb -t APPLICATION_TYPE
rhc app create helloworldmdb https://raw.github.com/openshift-cartridges/openshift-wildfly-cartridge/master/metadata/manifest.yml

The domain name for this application will be `helloworldmdb-YOUR_DOMAIN_NAME.rhcloud.com`. Here we use the _quickstart_ domain. You will need to replace it with your own OpenShift domain name.

This command creates an OpenShift application called `helloworldmdb` and will run the application inside the `jbosseap-6.0` or `jbossas-7` container. You should see some output similar to the following:
This command creates an OpenShift application called `helloworldmdb` and will run the application inside the `wildfly-8` container. You should see some output similar to the following:

Creating application: helloworldmdb
Now your new domain name is being propagated worldwide (this might take a minute)...
Expand Down Expand Up @@ -173,7 +171,7 @@ If the application has run succesfully you should see some output in the browser

Now you can look at the output of the server by running the following command:

rhc app status -a helloworldmdb
rhc tail -a helloworldmdb

This will show the tail of the servers log which should show something like the following.

Expand Down
34 changes: 17 additions & 17 deletions helloworld-mdb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@

<version.jboss.maven.plugin>7.3.Final</version.jboss.maven.plugin>

<version.jboss.spec.javaee.6.0>3.0.2.Final</version.jboss.spec.javaee.6.0>
<!-- Alternatively, comment out the above line, and un-comment the
line below to use version 3.0.2.Final-redhat-2 which is a release certified
to work with JBoss EAP 6. It requires you have access to the JBoss EAP 6
maven repository. -->
<!-- <version.jboss.spec.javaee.6.0>3.0.2.Final-redhat-2</version.jboss.spec.javaee.6.0> -->
<version.jboss.spec.javaee.all.7.0>1.0.0.Final</version.jboss.spec.javaee.all.7.0>

<!-- other plugin versions -->
<version.compiler.plugin>2.3.1</version.compiler.plugin>
Expand All @@ -63,18 +58,18 @@

<dependencyManagement>
<dependencies>
<!-- Define the version of JBoss' Java EE 6 APIs we want to use -->
<!-- JBoss distributes a complete set of Java EE 6 APIs including
<!-- Define the version of JBoss' Java EE 7 APIs we want to use -->
<!-- JBoss distributes a complete set of Java EE 7 APIs including
a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or
a collection) of artifacts. We use this here so that we always get the correct
versions of artifacts. Here we use the jboss-javaee-6.0 stack (you can read
this as the JBoss stack of the Java EE 6 APIs). You can actually use this
stack with any version of JBoss AS that implements Java EE 6, not just JBoss
AS 7! -->
this as the JBoss stack of the Java EE 7 APIs). You can actually use this
stack with any version of JBoss AS that implements Java EE 7, not just WildFly 8!
-->
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>${version.jboss.spec.javaee.6.0}</version>
<artifactId>jboss-javaee-all-7.0</artifactId>
<version>${version.jboss.spec.javaee.all.7.0}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -83,20 +78,25 @@

<dependencies>
<!-- Import the Servlet API, we use provided scope as the API is
included in JBoss EAP 6/JBoss AS 7 -->
included in WildFly 8 -->
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
<artifactId>jboss-servlet-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.jms</groupId>
<artifactId>jboss-jms-api_1.1_spec</artifactId>
<artifactId>jboss-jms-api_2.0_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@
import java.io.PrintWriter;

import javax.annotation.Resource;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.inject.Inject;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.JMSContext;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
Expand All @@ -37,7 +33,7 @@

/**
* <p>
* A simple servlet 3 as client that sends several messages to a queue or a topic.
* A simple servlet 3 as client that sends several messages to a queue or a topic.
* </p>
*
* <p>
Expand All @@ -55,8 +51,8 @@ public class HelloWorldMDBServletClient extends HttpServlet {

private static final int MSG_COUNT = 5;

@Resource(mappedName = "java:/ConnectionFactory")
private ConnectionFactory connectionFactory;
@Inject
private JMSContext context;

@Resource(mappedName = "java:/queue/HELLOWORLDMDBQueue")
private Queue queue;
Expand All @@ -68,8 +64,7 @@ public class HelloWorldMDBServletClient extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
Connection connection = null;
out.write("<h1>Quickstart: Example demonstrates the use of <strong>JMS 1.1</strong> and <strong>EJB 3.1 Message-Driven Bean</strong> in JBoss Enterprise Application 6 or JBoss AS 7.1.0.</h1>");
out.write("<h1>Quickstart: Example demonstrates the use of <strong>JMS 2.0</strong> and <strong>EJB 3.2 Message-Driven Bean</strong> in WildFly 8.</h1>");
try {
Destination destination;
if (req.getParameterMap().keySet().contains("topic")) {
Expand All @@ -78,32 +73,14 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
destination = queue;
}
out.write("<p>Sending messages to <em>" + destination + "</em></p>");
connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(destination);
connection.start();
out.write("<h2>Following messages will be send to the destination:</h2>");
TextMessage message = session.createTextMessage();
for (int i = 0; i < MSG_COUNT; i++) {
message.setText("This is message " + (i + 1));
messageProducer.send(message);
out.write("Message (" + i + "): " + message.getText() + "</br>");
String text = "This is message " + (i + 1);
context.createProducer().send(destination, text);
out.write("Message (" + i + "): " + text + "</br>");
}
out.write("<p><i>Go to your JBoss Application Server console or Server log to see the result of messages processing</i></p>");

} catch (JMSException e) {
e.printStackTrace();
out.write("<h2>A problem occurred during the delivery of this message</h2>");
out.write("</br>");
out.write("<p><i>Go your the JBoss Application Server console or Server log to see the error stack trace</i></p>");
out.write("<p><i>Go to your WildFly Server console or Server log to see the result of messages processing</i></p>");
} finally {
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {
e.printStackTrace();
}
}
if (out != null) {
out.close();
}
Expand Down
22 changes: 22 additions & 0 deletions helloworld-mdb/src/main/webapp/WEB-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
JBoss, Home of Professional Open Source
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.
Licensed 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.
-->
<!-- Marker file indicating CDI should be enabled -->
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

0 comments on commit 2cb2cc4

Please sign in to comment.