Last active
August 29, 2015 14:01
-
-
Save alexcpn/bf97eb088613f17ac319 to your computer and use it in GitHub Desktop.
Minimal POM for JBOSS AS7.0 -MDB and a message producer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nokia.oss; | |
/* | |
* 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. | |
*/ | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import javax.annotation.Resource; | |
import javax.jms.Connection; | |
import javax.jms.ConnectionFactory; | |
import javax.jms.Destination; | |
import javax.jms.JMSException; | |
import javax.jms.MessageProducer; | |
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; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
/** | |
* <p> | |
* A simple servlet 3 as client that sends several messages to a queue or a topic. | |
* </p> | |
* | |
* <p> | |
* The servlet is registered and mapped to /HelloWorldMDBServletClient using the {@linkplain WebServlet | |
* @HttpServlet}. | |
* </p> | |
* | |
* @author Serge Pagop (spagop@redhat.com) | |
* | |
*/ | |
@WebServlet("/MessageSenderServlet") | |
public class MessageSenderServlet extends HttpServlet { | |
private static final long serialVersionUID = -8314035702649252239L; | |
private static final int MSG_COUNT = 5; | |
@Resource(mappedName = "java:/ConnectionFactory") | |
private ConnectionFactory connectionFactory; | |
@Resource(mappedName = "java:/queue/test") | |
private Queue queue; | |
@Resource(mappedName = "java:/topic/test") | |
private Topic topic; | |
@Override | |
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: This example demonstrates the use of <strong>JMS 1.1</strong> and <strong>EJB 3.1 Message-Driven Bean</strong> in JBoss Enterprise Application 6.</h1>"); | |
try { | |
Destination destination; | |
if (req.getParameterMap().keySet().contains("topic")) { | |
destination = topic; | |
} else { | |
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>"); | |
} | |
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>"); | |
} finally { | |
if (connection != null) { | |
try { | |
connection.close(); | |
} catch (JMSException e) { | |
e.printStackTrace(); | |
} | |
} | |
if (out != null) { | |
out.close(); | |
} | |
} | |
} | |
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
doGet(req, resp); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
And of course a Mavn module to build all the three | |
Dir --D:\Coding\JavaLearn\HardCoreJava\mdb_learn | |
--> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
<name>MDB Learn test</name> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.nokia.oss</groupId> | |
<artifactId>mdb_learn</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<packaging>pom</packaging> | |
<modules> | |
<module>com.nokia.oss.mdb2</module> | |
<module>com.nokia.oss</module> | |
<module>com.nokia.oss.servlet</module> | |
</modules> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Generated Manually for EAR file | |
Dir --D:\Coding\JavaLearn\HardCoreJava\mdb_learn\com.nokia.oss | |
--> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.nokia.oss</groupId> | |
<artifactId>com.nokia.oss.mdb2_ear</artifactId> | |
<version>1.0.0</version> | |
<packaging>ear</packaging> | |
<name>mdb2-ear</name> | |
<build> | |
<finalName>mdb2-ear</finalName> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<configuration> | |
<source>1.6</source> | |
<target>1.6</target> | |
</configuration> | |
</plugin> | |
<plugin> | |
<artifactId>maven-resources-plugin</artifactId> | |
<version>2.3</version> | |
<configuration> | |
<encoding>UTF-8</encoding> | |
</configuration> | |
</plugin> | |
<plugin> | |
<artifactId>maven-ear-plugin</artifactId> | |
<version>2.4.1</version> | |
<configuration> | |
<modules> | |
<webModule> | |
<groupId>com.nokia.oss</groupId> | |
<artifactId>com.nokia.oss.servlet</artifactId> | |
<bundleFileName>com.nokia.oss.servlet.war</bundleFileName> | |
</webModule> | |
<ejbModule> | |
<groupId>com.nokia.oss</groupId> | |
<artifactId>com.nokia.oss.mdb2</artifactId> | |
<bundleFileName>com.nokia.oss.mdb2.jar</bundleFileName> | |
</ejbModule> | |
</modules> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
<dependencies> | |
<dependency> | |
<groupId>com.nokia.oss</groupId> | |
<artifactId>com.nokia.oss.mdb2</artifactId> | |
<version>${ejb-version}</version> | |
<type>ejb</type> | |
</dependency> | |
<dependency> | |
<groupId>com.nokia.oss</groupId> | |
<artifactId>com.nokia.oss.servlet</artifactId> | |
<version>${ejb-version}</version> | |
<type>war</type> | |
</dependency> | |
</dependencies> | |
<properties> | |
<ejb-version>1.0-SNAPSHOT</ejb-version> | |
</properties> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Generated via | |
mvn archetype:generate -DarchetypeArtifactId=ejb-javaee6 -DarchetypeGroupId=org.codehaus.mojo.archetypes -DartifactId=com.nokia.oss.mdb2 -DgroupId=com.nokia.oss -DinteractiveMode=false | |
Dir -D:\Coding\JavaLearn\HardCoreJava\mdb_learn\com.nokia.oss.mdb2 | |
--> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<parent> | |
<groupId>com.nokia.oss</groupId> | |
<artifactId>mdb_learn</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
</parent> | |
<groupId>com.nokia.oss</groupId> | |
<artifactId>com.nokia.oss.mdb2</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<packaging>ejb</packaging> | |
<name>com.nokia.oss.mdb2</name> | |
<properties> | |
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>javax</groupId> | |
<artifactId>javaee-api</artifactId> | |
<version>6.0</version> | |
<scope>provided</scope> | |
</dependency> | |
<!--<dependency> | |
<groupId>org.jboss.spec</groupId> | |
<artifactId>jboss-javaee-6.0</artifactId> | |
<version>3.0.2.Final</version> | |
<type>pom</type> | |
<scope>import</scope> | |
</dependency> --> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-ejb-plugin</artifactId> | |
<version>2.3</version> | |
<configuration> | |
<ejbVersion>3.1</ejbVersion> | |
<archive> | |
<manifest> | |
<addClasspath>true</addClasspath> | |
</manifest> | |
</archive> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Genernarted via | |
mvn archetype:generate -DarchetypeArtifactId=webapp-javaee6 -DarchetypeGroupId=org.codehaus.mojo.archetypes -DartifactId=com.nokia.oss.servlet -DgroupId=com.nokia.oss -DinteractiveMode=false | |
Dir D:\Coding\JavaLearn\HardCoreJava\mdb_learn\com.nokia.oss.servlet | |
--> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<parent> | |
<artifactId>mdb_learn</artifactId> | |
<groupId>com.nokia.oss</groupId> | |
<version>1.0-SNAPSHOT</version> | |
</parent> | |
<groupId>com.nokia.oss</groupId> | |
<artifactId>com.nokia.oss.servlet</artifactId> | |
<packaging>war</packaging> | |
<version>1.0-SNAPSHOT</version> | |
<name>com.nokia.oss.servlet-Java EE 6 Webapp</name> | |
<dependencies> | |
<dependency> | |
<groupId>javax</groupId> | |
<artifactId>javaee-web-api</artifactId> | |
<version>6.0-RC1</version> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>javax</groupId> | |
<artifactId>javaee-api</artifactId> | |
<version>6.0</version> | |
<scope>provided</scope> | |
</dependency> | |
<!--dependency> | |
<groupId>org.jboss.spec</groupId> | |
<artifactId>jboss-javaee-6.0</artifactId> | |
<version>3.0.2.Final</version> | |
<type>pom</type> | |
<scope>import</scope> | |
</dependency!--> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>3.8.2</version> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>2.0.2</version> | |
<configuration> | |
<source>1.6</source> | |
<target>1.6</target> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-war-plugin</artifactId> | |
<version>2.1-beta-1</version> | |
<configuration> | |
<failOnMissingWebXml>false</failOnMissingWebXml> | |
</configuration> | |
</plugin> | |
</plugins> | |
<finalName>com.nokia.oss.servlet</finalName> | |
</build> | |
<profiles> | |
<profile> | |
<id>endorsed</id> | |
<activation> | |
<property> | |
<name>sun.boot.class.path</name> | |
</property> | |
</activation> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>2.0.2</version> | |
<configuration> | |
<!-- javaee6 contains upgrades of APIs contained within the JDK itself. | |
As such these need to be placed on the bootclasspath, rather than classpath of the | |
compiler. | |
If you don't make use of these new updated API, you can delete the profile. | |
On non-SUN jdk, you will need to create a similar profile for your jdk, with the similar property as sun.boot.class.path in Sun's JDK.--> | |
<compilerArguments> | |
<bootclasspath>${settings.localRepository}/javax/javaee-endorsed-api/6.0-RC1/javaee-endorsed-api-6.0-RC1.jar${path.separator}${sun.boot.class.path}</bootclasspath> | |
</compilerArguments> | |
</configuration> | |
<dependencies> | |
<dependency> | |
<groupId>javax</groupId> | |
<artifactId>javaee-endorsed-api</artifactId> | |
<version>6.0-RC1</version> | |
</dependency> | |
</dependencies> | |
</plugin> | |
</plugins> | |
</build> | |
</profile> | |
</profiles> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nokia.oss; | |
import java.util.logging.Logger; | |
import javax.ejb.ActivationConfigProperty; | |
import javax.ejb.MessageDriven; | |
import javax.jms.JMSException; | |
import javax.jms.Message; | |
import javax.jms.MessageListener; | |
import javax.jms.TextMessage; | |
@MessageDriven( | |
activationConfig = { | |
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"), | |
@ActivationConfigProperty(propertyName = "destination", propertyValue = "topic/test") | |
}) | |
public class SimpleMessageMDB implements MessageListener{ | |
private final static Logger LOGGER = Logger.getLogger(SimpleMessageMDB.class.toString()); | |
@Override | |
public void onMessage(Message rcvMessage) { | |
TextMessage msg = null; | |
try { | |
if (rcvMessage instanceof TextMessage) { | |
msg = (TextMessage) rcvMessage; | |
LOGGER.info("Received Message from topic: " + msg.getText()); | |
System.out.println("----Received Message from topic: " + msg.getText()); | |
} else { | |
LOGGER.warning("Message of wrong type: " + rcvMessage.getClass().getName()); | |
} | |
} catch (JMSException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Message Producer Servlet and an MDB that receives the message is from https://github.com/jboss-developer/jboss-eap-quickstarts/tree/6.3.x-develop/helloworld-mdb
What I wanted was a maven archetype to generate maven pom files that are JBOSS dependencies agnostic and that is what is above. It works for d;\jboss-as-7.1.1.Final\bin>standalone.bat -c standalone-full.xml as is
Only change is that the default queues and topics are used