From a37070c239d87ec5f0b0a0544351a57ed06f489b Mon Sep 17 00:00:00 2001
From: Ravi Srinivasan <rsriniva@redhat.com>
Date: Fri, 14 Sep 2018 06:31:06 +0200
Subject: [PATCH] Fixes for Chap 6 on REST

---
 /dev/null                                                                      |   59 -------------------
 labs/hello-rest/src/main/java/com/redhat/training/rest/PersonService.java      |    7 --
 solutions/pom.xml                                                              |   82 +++++++++++++++++++++++++++
 solutions/hello-rest/src/main/java/com/redhat/training/rest/PersonService.java |    7 --
 4 files changed, 82 insertions(+), 73 deletions(-)

diff --git a/labs/hello-rest/src/main/java/com/redhat/training/messaging/JMSUtil.java b/labs/hello-rest/src/main/java/com/redhat/training/messaging/JMSUtil.java
deleted file mode 100644
index 14c1421..0000000
--- a/labs/hello-rest/src/main/java/com/redhat/training/messaging/JMSUtil.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.redhat.training.messaging;
-
-import javax.ejb.Singleton;
-import javax.ejb.Startup;
-import javax.annotation.Resource;
-import javax.jms.Queue;
-import javax.jms.JMSContext;
-import javax.inject.Inject;
-
-@Startup
-@Singleton
-public class JMSUtil {
-
-    @Resource(mappedName = "java:jboss/jms/queue/helloWorldQueue")
-    private Queue helloWorldQueue;
-
-    @Inject
-    JMSContext context;
-
-    public void sendMessage(String msg) {
-        try {
-            context.createProducer().send(helloWorldQueue, msg);
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-}
diff --git a/labs/hello-rest/src/main/java/com/redhat/training/messaging/QueueListener.java b/labs/hello-rest/src/main/java/com/redhat/training/messaging/QueueListener.java
deleted file mode 100644
index 169c4be..0000000
--- a/labs/hello-rest/src/main/java/com/redhat/training/messaging/QueueListener.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2015, 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.
- */
-package com.redhat.training.messaging;
-
-import org.jboss.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;
-
-/**
- * <p>
- * A simple Message Driven Bean that asynchronously receives and processes the messages that are sent to the queue.
- * </p>
- *
- * @author Serge Pagop (spagop@redhat.com)
- *
- */
-@MessageDriven(name = "QueueListener", activationConfig = {
-    @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "queue/helloWorldQueue"),
-    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
-    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
-public class QueueListener implements MessageListener {
-
-    private final static Logger LOGGER = Logger.getLogger(QueueListener.class.getName());
-
-    /**
-     * @see MessageListener#onMessage(Message)
-     */
-    public void onMessage(Message rcvMessage) {
-        TextMessage msg = null;
-        try {
-            if (rcvMessage instanceof TextMessage) {
-                msg = (TextMessage) rcvMessage;
-                LOGGER.info("Received Message from helloWorldQueue ===> " + msg.getText());
-            } else {
-                LOGGER.warn("Message of wrong type: " + rcvMessage.getClass().getName());
-            }
-        } catch (JMSException e) {
-            throw new RuntimeException(e);
-        }
-    }
-}
diff --git a/labs/hello-rest/src/main/java/com/redhat/training/rest/PersonService.java b/labs/hello-rest/src/main/java/com/redhat/training/rest/PersonService.java
index 0c309c3..0e26941 100644
--- a/labs/hello-rest/src/main/java/com/redhat/training/rest/PersonService.java
+++ b/labs/hello-rest/src/main/java/com/redhat/training/rest/PersonService.java
@@ -25,7 +25,6 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 
-import com.redhat.training.messaging.JMSUtil;
 import com.redhat.training.model.Person;
 
 //TODO Add the stateless annotation
@@ -45,9 +44,6 @@
 	@Resource
 	UserTransaction tx;
 
-	@Inject
-	JMSUtil jmsUtil;
-
 	// Simple non-RESTy method for JSF bean invocation
 	public String hello(String name) {
 		try {
@@ -66,9 +62,6 @@
 				Person p = new Person();
 				p.setName(name);
 				entityManager.persist(p);
-
-				// Send a JMS message to the 'helloWorldQueue'
-				jmsUtil.sendMessage("Said Hello to " + name.toUpperCase() + " at " + fdate);
 
 				// respond back with Hello and convert the name to UPPERCASE. Also, send the
 				// current time on the server.
diff --git a/solutions/hello-rest/src/main/java/com/redhat/training/messaging/JMSUtil.java b/solutions/hello-rest/src/main/java/com/redhat/training/messaging/JMSUtil.java
deleted file mode 100644
index 14c1421..0000000
--- a/solutions/hello-rest/src/main/java/com/redhat/training/messaging/JMSUtil.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.redhat.training.messaging;
-
-import javax.ejb.Singleton;
-import javax.ejb.Startup;
-import javax.annotation.Resource;
-import javax.jms.Queue;
-import javax.jms.JMSContext;
-import javax.inject.Inject;
-
-@Startup
-@Singleton
-public class JMSUtil {
-
-    @Resource(mappedName = "java:jboss/jms/queue/helloWorldQueue")
-    private Queue helloWorldQueue;
-
-    @Inject
-    JMSContext context;
-
-    public void sendMessage(String msg) {
-        try {
-            context.createProducer().send(helloWorldQueue, msg);
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-}
diff --git a/solutions/hello-rest/src/main/java/com/redhat/training/messaging/QueueListener.java b/solutions/hello-rest/src/main/java/com/redhat/training/messaging/QueueListener.java
deleted file mode 100644
index 169c4be..0000000
--- a/solutions/hello-rest/src/main/java/com/redhat/training/messaging/QueueListener.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2015, 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.
- */
-package com.redhat.training.messaging;
-
-import org.jboss.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;
-
-/**
- * <p>
- * A simple Message Driven Bean that asynchronously receives and processes the messages that are sent to the queue.
- * </p>
- *
- * @author Serge Pagop (spagop@redhat.com)
- *
- */
-@MessageDriven(name = "QueueListener", activationConfig = {
-    @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "queue/helloWorldQueue"),
-    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
-    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
-public class QueueListener implements MessageListener {
-
-    private final static Logger LOGGER = Logger.getLogger(QueueListener.class.getName());
-
-    /**
-     * @see MessageListener#onMessage(Message)
-     */
-    public void onMessage(Message rcvMessage) {
-        TextMessage msg = null;
-        try {
-            if (rcvMessage instanceof TextMessage) {
-                msg = (TextMessage) rcvMessage;
-                LOGGER.info("Received Message from helloWorldQueue ===> " + msg.getText());
-            } else {
-                LOGGER.warn("Message of wrong type: " + rcvMessage.getClass().getName());
-            }
-        } catch (JMSException e) {
-            throw new RuntimeException(e);
-        }
-    }
-}
diff --git a/solutions/hello-rest/src/main/java/com/redhat/training/rest/PersonService.java b/solutions/hello-rest/src/main/java/com/redhat/training/rest/PersonService.java
index 9a76af5..efa4a32 100644
--- a/solutions/hello-rest/src/main/java/com/redhat/training/rest/PersonService.java
+++ b/solutions/hello-rest/src/main/java/com/redhat/training/rest/PersonService.java
@@ -25,7 +25,6 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 
-import com.redhat.training.messaging.JMSUtil;
 import com.redhat.training.model.Person;
 
 @Stateless
@@ -40,9 +39,6 @@
 
 	@Resource
 	UserTransaction tx;
-
-	@Inject
-	JMSUtil jmsUtil;
 
 	// Simple non-RESTy method for JSF bean invocation
 	public String hello(String name) {
@@ -62,9 +58,6 @@
 				Person p = new Person();
 				p.setName(name);
 				entityManager.persist(p);
-
-				// Send a JMS message to the 'helloWorldQueue'
-				jmsUtil.sendMessage("Said Hello to " + name.toUpperCase() + " at " + fdate);
 
 				// respond back with Hello and convert the name to UPPERCASE. Also, send the
 				// current time on the server.
diff --git a/solutions/pom.xml b/solutions/pom.xml
new file mode 100644
index 0000000..3dd9361
--- /dev/null
+++ b/solutions/pom.xml
@@ -0,0 +1,82 @@
+<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>
+	<groupId>com.redhat.training</groupId>
+	<artifactId>parent-pom</artifactId>
+	<version>1.0</version>
+	<packaging>pom</packaging>
+	<name>JB125 Parent Project</name>
+	<description>This is the parent project</description>
+
+	<properties>
+		<!-- Explicitly declaring the source encoding eliminates the following
+            message: -->
+		<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
+            resources, i.e. build is platform dependent! -->
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+		<!-- JBoss dependency versions -->
+
+		<version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>
+
+		<!-- Define the version of the JBoss BOMs we want to import to specify tested stacks. -->
+		<version.jboss.bom.eap>7.0.2.GA</version.jboss.bom.eap>
+
+		<!-- other plug-in versions -->
+		<version.surefire.plugin>2.10</version.surefire.plugin>
+		<version.war.plugin>2.1.1</version.war.plugin>
+
+		<!-- maven-compiler-plugin -->
+		<maven.compiler.target>1.8</maven.compiler.target>
+		<maven.compiler.source>1.8</maven.compiler.source>
+	</properties>
+
+	<dependencyManagement>
+		<dependencies>
+			<dependency>
+				<groupId>org.jboss.bom</groupId>
+				<artifactId>jboss-eap-javaee7-with-tools</artifactId>
+				<version>${version.jboss.bom.eap}</version>
+				<type>pom</type>
+				<scope>import</scope>
+			</dependency>
+
+			<dependency>
+				<groupId>org.jboss.eap</groupId>
+				<artifactId>wildfly-ejb-client-bom</artifactId>
+				<version>7.0.2.GA-redhat-1</version>
+				<type>pom</type>
+				<scope>import</scope>
+			</dependency>
+
+		</dependencies>
+	</dependencyManagement>
+
+	<build>
+		<finalName>${project.artifactId}</finalName>
+		<plugins>
+			<plugin>
+				<artifactId>maven-war-plugin</artifactId>
+				<version>${version.war.plugin}</version>
+				<configuration>
+					<!-- Java EE doesn't require web.xml, Maven needs to catch
+                        up! -->
+					<failOnMissingWebXml>false</failOnMissingWebXml>
+				</configuration>
+			</plugin>
+			<!-- Surefire plug-in is responsible for running tests
+                as part of project build -->
+			<plugin>
+				<artifactId>maven-surefire-plugin</artifactId>
+				<version>${version.surefire.plugin}</version>
+			</plugin>
+			<!-- The WildFly plug-in deploys the WAR to a local JBoss EAP container -->
+			<!-- To use, run: mvn package wildfly:deploy -->
+			<plugin>
+				<groupId>org.wildfly.plugins</groupId>
+				<artifactId>wildfly-maven-plugin</artifactId>
+				<version>${version.wildfly.maven.plugin}</version>
+			</plugin>
+		</plugins>
+	</build>
+
+</project>

--
Gitblit v1.9.3