From f04579d422790bfed81c843f093a58f15cd8eb2d Mon Sep 17 00:00:00 2001 From: Ravi Srinivasan <rsriniva@redhat.com> Date: Mon, 10 Sep 2018 09:36:48 +0200 Subject: [PATCH] Chap 3 labs --- labs/stateless-ejb/src/main/java/com/redhat/training/ui/Hello.java | 35 ++ labs/stateless-ejb/pom.xml | 137 ++++++++ solutions/stateless-ejb/src/main/webapp/index.html | 23 + labs/stateless-ejb/src/main/webapp/WEB-INF/beans.xml | 25 + labs/stateless-ejb/src/main/webapp/index.html | 23 + labs/stateless-ejb/src/main/webapp/resources/images/redhat.png | 0 solutions/stateless-ejb/src/main/webapp/WEB-INF/beans.xml | 25 + solutions/stateless-ejb/src/main/webapp/resources/images/redhat.png | 0 solutions/stateless-ejb/.gitignore | 5 solutions/stateless-ejb/src/main/webapp/index.xhtml | 32 ++ solutions/stateless-ejb/src/main/webapp/WEB-INF/faces-config.xml | 30 + solutions/stateless-ejb/pom.xml | 137 ++++++++ labs/stateless-ejb/README.md | 7 solutions/stateless-ejb/README.md | 7 solutions/stateless-ejb/src/main/java/com/redhat/training/ejb/HelloBean.java | 14 labs/stateless-ejb/src/main/webapp/resources/css/screen.css | 79 ++++ labs/stateless-ejb/src/test/java/com/redhat/training/ejb/EJBTest.java | 52 +++ labs/stateless-ejb/src/main/webapp/WEB-INF/faces-config.xml | 30 + solutions/stateless-ejb/src/test/java/com/redhat/training/ejb/EJBTest.java | 52 +++ solutions/stateless-ejb/src/main/webapp/resources/css/screen.css | 79 ++++ labs/stateless-ejb/.gitignore | 5 labs/stateless-ejb/src/main/java/com/redhat/training/ejb/HelloBean.java | 11 labs/stateless-ejb/src/main/webapp/WEB-INF/templates/default.xhtml | 34 ++ solutions/stateless-ejb/src/main/webapp/WEB-INF/templates/default.xhtml | 34 ++ solutions/stateless-ejb/src/main/java/com/redhat/training/ui/Hello.java | 35 ++ labs/stateless-ejb/src/main/webapp/index.xhtml | 32 ++ 26 files changed, 943 insertions(+), 0 deletions(-) diff --git a/labs/stateless-ejb/.gitignore b/labs/stateless-ejb/.gitignore new file mode 100644 index 0000000..d0152b8 --- /dev/null +++ b/labs/stateless-ejb/.gitignore @@ -0,0 +1,5 @@ +.classpath +.project +.tern-project +.settings +target diff --git a/labs/stateless-ejb/README.md b/labs/stateless-ejb/README.md new file mode 100644 index 0000000..486fb2a --- /dev/null +++ b/labs/stateless-ejb/README.md @@ -0,0 +1,7 @@ +# JB125 Java EE 7 Hello World web App + +##This app is composed of the following architecture: + +* Maven Project - builds a WAR +* Using JSF 2.2 for web interface, HTML5 facelets page, JSF backing beans, CDI scopes on beans, @Named +* Stateless EJB for Business Logic (sayHello) diff --git a/labs/stateless-ejb/pom.xml b/labs/stateless-ejb/pom.xml new file mode 100644 index 0000000..3a8ed73 --- /dev/null +++ b/labs/stateless-ejb/pom.xml @@ -0,0 +1,137 @@ +<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> + <artifactId>stateless-ejb</artifactId> + <packaging>war</packaging> + <name>Stateless EJB web app Project</name> + <description>This is the Stateless EJB project</description> + <parent> + <groupId>com.redhat.training</groupId> + <artifactId>parent-pom</artifactId> + <version>1.0</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + + <!-- First declare the APIs we depend on and need for compilation. All + of them are provided by JBoss EAP --> + + <!-- Import the CDI API, we use provided scope as the API is included in + JBoss EAP --> + <dependency> + <groupId>javax.enterprise</groupId> + <artifactId>cdi-api</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Import the EJB API, we use provided scope as the API is included in + JBoss EAP --> + <dependency> + <groupId>org.jboss.spec.javax.ejb</groupId> + <artifactId>jboss-ejb-api_3.2_spec</artifactId> + <scope>provided</scope> + </dependency> + + + <!-- Import the JSF API, we use provided scope as the API is included in + JBoss EAP --> + <dependency> + <groupId>org.jboss.spec.javax.faces</groupId> + <artifactId>jboss-jsf-api_2.2_spec</artifactId> + <scope>provided</scope> + </dependency> + + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.jboss.arquillian.junit</groupId> + <artifactId>arquillian-junit-container</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.jboss.arquillian.protocol</groupId> + <artifactId>arquillian-protocol-servlet</artifactId> + <scope>test</scope> + </dependency> + + <!-- Need to explicitly reference this version, or else there will be an exception + due to a bug in Arquilian --> + <dependency> + <groupId>org.wildfly.arquillian</groupId> + <artifactId>wildfly-arquillian-common</artifactId> + <version>2.0.0.Final</version> + </dependency> + + </dependencies> + + <build> + <finalName>stateless-ejb</finalName> + <plugins> + <plugin> + <artifactId>maven-war-plugin</artifactId> + <version>${version.war.plugin}</version> + <extensions>false</extensions> + <configuration> + <failOnMissingWebXml>false</failOnMissingWebXml> + <archive> + <manifestEntries> + <Dependencies>com.google.guava,org.slf4j + </Dependencies> + </manifestEntries> + </archive> + </configuration> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <!-- This profile skips all tests, though you can tune + it to run just unit tests based on a custom pattern --> + <!-- Separate profiles are provided for running all tests, including + Arquillian tests that execute in the specified container --> + <!-- Use this profile if you just want to build a WAR file without running any unit tests --> + <!-- Run like this: mvn clean package -Pdefault --> + <id>default</id> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>${version.surefire.plugin}</version> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + </plugins> + </build> + </profile> + <profile> + <!-- An optional Arquillian testing profile that + executes tests in a remote JBoss EAP instance --> + <!-- Run with: mvn clean test -Parq-wildfly-remote or, simply run: mvn test --> + <!-- To make it easy to run tests from within JBDS, this profile is set as active by default --> + <id>arq-wildfly-remote</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <dependencies> + <dependency> + <groupId>org.wildfly.arquillian</groupId> + <artifactId>wildfly-arquillian-container-remote</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + </profile> + </profiles> + +</project> diff --git a/labs/stateless-ejb/src/main/java/com/redhat/training/ejb/HelloBean.java b/labs/stateless-ejb/src/main/java/com/redhat/training/ejb/HelloBean.java new file mode 100644 index 0000000..6feb736 --- /dev/null +++ b/labs/stateless-ejb/src/main/java/com/redhat/training/ejb/HelloBean.java @@ -0,0 +1,11 @@ +package com.redhat.training.ejb; + + +public class HelloBean { + + public String sayHello(String name) { + + // respond back with Hello, {name}. + return "Hello, " + name; + } +} diff --git a/labs/stateless-ejb/src/main/java/com/redhat/training/ui/Hello.java b/labs/stateless-ejb/src/main/java/com/redhat/training/ui/Hello.java new file mode 100755 index 0000000..fd1e785 --- /dev/null +++ b/labs/stateless-ejb/src/main/java/com/redhat/training/ui/Hello.java @@ -0,0 +1,35 @@ +package com.redhat.training.ui; + +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.faces.application.FacesMessage; +import javax.faces.context.FacesContext; +import javax.inject.Named; + +import com.redhat.training.ejb.HelloBean; + +@RequestScoped +@Named("hello") +public class Hello { + private String name; + + @EJB + HelloBean helloEJB; + + public String greet() { + return helloEJB.sayHello(name); + } + public void sayHello() { + String response = greet(); + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(response)); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/labs/stateless-ejb/src/main/webapp/WEB-INF/beans.xml b/labs/stateless-ejb/src/main/webapp/WEB-INF/beans.xml new file mode 100755 index 0000000..adcbeda --- /dev/null +++ b/labs/stateless-ejb/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + JBoss, Home of Professional Open Source + Copyright 2014, 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. +--> +<!-- This file can be an empty text file (0 bytes) --> +<!-- We're declaring the schema to save you time if you do have to configure + this in the future --> +<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> diff --git a/labs/stateless-ejb/src/main/webapp/WEB-INF/faces-config.xml b/labs/stateless-ejb/src/main/webapp/WEB-INF/faces-config.xml new file mode 100755 index 0000000..d7054de --- /dev/null +++ b/labs/stateless-ejb/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + JBoss, Home of Professional Open Source + Copyright 2014, 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. +--> +<!-- This file is not required if you don't need any extra configuration. --> +<faces-config version="2.0" 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/web-facesconfig_2_0.xsd"> + + <!-- This descriptor activates the JSF 2.0 Servlet --> + + <!-- Write your navigation rules here. You are encouraged to use CDI + for creating @Named managed beans. --> + +</faces-config> diff --git a/labs/stateless-ejb/src/main/webapp/WEB-INF/templates/default.xhtml b/labs/stateless-ejb/src/main/webapp/WEB-INF/templates/default.xhtml new file mode 100755 index 0000000..2fe703c --- /dev/null +++ b/labs/stateless-ejb/src/main/webapp/WEB-INF/templates/default.xhtml @@ -0,0 +1,34 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:ui="http://java.sun.com/jsf/facelets"> +<h:head> + <title><ui:insert name="title"> + [Title will be inserted here] + </ui:insert> + </title> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <h:outputStylesheet name="css/screen.css" /> +</h:head> +<h:body> + + <header> + <h:graphicImage name="images/redhat.png" /> + <div class="right"> + Application: + <ui:insert name="application_name"> + [Application name will be inserted here] + </ui:insert> + </div> + </header> + <div id="content"> + <ui:insert name="content"> + [Template content will be inserted here] + </ui:insert> + </div> + <footer> + JB183 - Enterprise Java Development - Red Hat Training + </footer> +</h:body> +</html> diff --git a/labs/stateless-ejb/src/main/webapp/index.html b/labs/stateless-ejb/src/main/webapp/index.html new file mode 100755 index 0000000..684299b --- /dev/null +++ b/labs/stateless-ejb/src/main/webapp/index.html @@ -0,0 +1,23 @@ +<!-- + JBoss, Home of Professional Open Source + Copyright 2014, 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. +--> +<!-- Plain HTML page that kicks us into the app --> + +<html> +<head> +<meta http-equiv="Refresh" content="0; URL=index.jsf"> +</head> +</html> diff --git a/labs/stateless-ejb/src/main/webapp/index.xhtml b/labs/stateless-ejb/src/main/webapp/index.xhtml new file mode 100755 index 0000000..add53c5 --- /dev/null +++ b/labs/stateless-ejb/src/main/webapp/index.xhtml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<ui:composition xmlns="http://www.w3.org/1999/xhtml" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:h="http://java.sun.com/jsf/html" + template="/WEB-INF/templates/default.xhtml"> + <ui:define name="title"> + Hello World web app + </ui:define> + <ui:define name="application_name"> + Hello EJB web app + </ui:define> + <ui:define name="content"> + <h1>Hello EJB web app</h1> + <br class="clear"/> + <h:form id="form"> + <p class="input"> + <h:outputLabel value="Enter your name:" for="name" /> + <h:inputText value="#{hello.name}" id="name" required="true" requiredMessage="Name is required"/> + </p> + <br class="clear"/> + <br class="clear"/> + <p class="input"> + <h:commandButton action="#{hello.sayHello()}" value="Submit" styleClass="btn" /> + </p> + <br class="clear"/> + <br class="clear"/> + <h:messages styleClass="messages"/> + </h:form> + </ui:define> +</ui:composition> diff --git a/labs/stateless-ejb/src/main/webapp/resources/css/screen.css b/labs/stateless-ejb/src/main/webapp/resources/css/screen.css new file mode 100755 index 0000000..0e284d1 --- /dev/null +++ b/labs/stateless-ejb/src/main/webapp/resources/css/screen.css @@ -0,0 +1,79 @@ +body { + +} + +header { + background-color: #C40016; + height: 150px; + padding: 10px; + width: 95%; + margin: 0 auto; + border: 4px solid #000000; +} + +header .right { + display: inline-block; + float: right; + font-size: 40px; + font-weight: bolder; + height: 150px; + padding: 48px; + vertical-align: middle; +} + +#content { + background-color: #F2F2F2; + width: 91%; + margin: 0 auto; + padding: 100px 50px; + border: 2px solid #000000; +} + +footer { + border: 4px solid #000000; + background-color: #C40016; + height: 30px; + padding: 10px; + width: 95%; + margin: 0 auto; + text-align: center; + font-weight: bolder; + font-size: 27px; +} + +label{ + display: inline-block; + float: left; + clear: left; + width: 165px; +} +input { + display: inline-block; + float: left; + width: 362px; +} +select{ + display: inline-block; + float: left; + width: 371px; +} +textarea{ + display: inline-block; + float: left; +} + +.clear{ + clear: both; +} + +.messages{ + color: green; + font-weight: bolder; +} + +.btn{ + display: inline-block; + float: left; + clear: left; + width: 165px; +} \ No newline at end of file diff --git a/labs/stateless-ejb/src/main/webapp/resources/images/redhat.png b/labs/stateless-ejb/src/main/webapp/resources/images/redhat.png new file mode 100755 index 0000000..0984beb --- /dev/null +++ b/labs/stateless-ejb/src/main/webapp/resources/images/redhat.png Binary files differ diff --git a/labs/stateless-ejb/src/test/java/com/redhat/training/ejb/EJBTest.java b/labs/stateless-ejb/src/test/java/com/redhat/training/ejb/EJBTest.java new file mode 100644 index 0000000..de9a333 --- /dev/null +++ b/labs/stateless-ejb/src/test/java/com/redhat/training/ejb/EJBTest.java @@ -0,0 +1,52 @@ +/* + * 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.ejb; + +import static org.junit.Assert.assertEquals; + +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ArchivePaths; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.redhat.training.ui.Hello; + + +@RunWith(Arquillian.class) +public class EJBTest { + @Inject + private Hello hello; + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class,"stateless-ejb-test.war").addClass(HelloBean.class).addClass(Hello.class) + .addAsManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")); + } + + @Test + public void testHelloEJB() { + hello.setName("John Doe"); + String result = hello.greet(); + assertEquals("Hello, John Doe", result); + } +} diff --git a/solutions/stateless-ejb/.gitignore b/solutions/stateless-ejb/.gitignore new file mode 100644 index 0000000..d0152b8 --- /dev/null +++ b/solutions/stateless-ejb/.gitignore @@ -0,0 +1,5 @@ +.classpath +.project +.tern-project +.settings +target diff --git a/solutions/stateless-ejb/README.md b/solutions/stateless-ejb/README.md new file mode 100644 index 0000000..486fb2a --- /dev/null +++ b/solutions/stateless-ejb/README.md @@ -0,0 +1,7 @@ +# JB125 Java EE 7 Hello World web App + +##This app is composed of the following architecture: + +* Maven Project - builds a WAR +* Using JSF 2.2 for web interface, HTML5 facelets page, JSF backing beans, CDI scopes on beans, @Named +* Stateless EJB for Business Logic (sayHello) diff --git a/solutions/stateless-ejb/pom.xml b/solutions/stateless-ejb/pom.xml new file mode 100644 index 0000000..14f7d05 --- /dev/null +++ b/solutions/stateless-ejb/pom.xml @@ -0,0 +1,137 @@ +<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> + <artifactId>stateless-ejb-solution</artifactId> + <packaging>war</packaging> + <name>Stateless EJB web app Project</name> + <description>This is the Stateless EJB project</description> + <parent> + <groupId>com.redhat.training</groupId> + <artifactId>parent-pom</artifactId> + <version>1.0</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + + <!-- First declare the APIs we depend on and need for compilation. All + of them are provided by JBoss EAP --> + + <!-- Import the CDI API, we use provided scope as the API is included in + JBoss EAP --> + <dependency> + <groupId>javax.enterprise</groupId> + <artifactId>cdi-api</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Import the EJB API, we use provided scope as the API is included in + JBoss EAP --> + <dependency> + <groupId>org.jboss.spec.javax.ejb</groupId> + <artifactId>jboss-ejb-api_3.2_spec</artifactId> + <scope>provided</scope> + </dependency> + + + <!-- Import the JSF API, we use provided scope as the API is included in + JBoss EAP --> + <dependency> + <groupId>org.jboss.spec.javax.faces</groupId> + <artifactId>jboss-jsf-api_2.2_spec</artifactId> + <scope>provided</scope> + </dependency> + + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.jboss.arquillian.junit</groupId> + <artifactId>arquillian-junit-container</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.jboss.arquillian.protocol</groupId> + <artifactId>arquillian-protocol-servlet</artifactId> + <scope>test</scope> + </dependency> + + <!-- Need to explicitly reference this version, or else there will be an exception + due to a bug in Arquilian --> + <dependency> + <groupId>org.wildfly.arquillian</groupId> + <artifactId>wildfly-arquillian-common</artifactId> + <version>2.0.0.Final</version> + </dependency> + + </dependencies> + + <build> + <finalName>stateless-ejb</finalName> + <plugins> + <plugin> + <artifactId>maven-war-plugin</artifactId> + <version>${version.war.plugin}</version> + <extensions>false</extensions> + <configuration> + <failOnMissingWebXml>false</failOnMissingWebXml> + <archive> + <manifestEntries> + <Dependencies>com.google.guava,org.slf4j + </Dependencies> + </manifestEntries> + </archive> + </configuration> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <!-- This profile skips all tests, though you can tune + it to run just unit tests based on a custom pattern --> + <!-- Separate profiles are provided for running all tests, including + Arquillian tests that execute in the specified container --> + <!-- Use this profile if you just want to build a WAR file without running any unit tests --> + <!-- Run like this: mvn clean package -Pdefault --> + <id>default</id> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>${version.surefire.plugin}</version> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + </plugins> + </build> + </profile> + <profile> + <!-- An optional Arquillian testing profile that + executes tests in a remote JBoss EAP instance --> + <!-- Run with: mvn clean test -Parq-wildfly-remote or, simply run: mvn test --> + <!-- To make it easy to run tests from within JBDS, this profile is set as active by default --> + <id>arq-wildfly-remote</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <dependencies> + <dependency> + <groupId>org.wildfly.arquillian</groupId> + <artifactId>wildfly-arquillian-container-remote</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + </profile> + </profiles> + +</project> diff --git a/solutions/stateless-ejb/src/main/java/com/redhat/training/ejb/HelloBean.java b/solutions/stateless-ejb/src/main/java/com/redhat/training/ejb/HelloBean.java new file mode 100644 index 0000000..8da5b6f --- /dev/null +++ b/solutions/stateless-ejb/src/main/java/com/redhat/training/ejb/HelloBean.java @@ -0,0 +1,14 @@ +package com.redhat.training.ejb; + +import javax.ejb.Stateless; + + +@Stateless +public class HelloBean { + + public String sayHello(String name) { + + // respond back with Hello, {name}. + return "Hello, " + name; + } +} diff --git a/solutions/stateless-ejb/src/main/java/com/redhat/training/ui/Hello.java b/solutions/stateless-ejb/src/main/java/com/redhat/training/ui/Hello.java new file mode 100644 index 0000000..fd1e785 --- /dev/null +++ b/solutions/stateless-ejb/src/main/java/com/redhat/training/ui/Hello.java @@ -0,0 +1,35 @@ +package com.redhat.training.ui; + +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.faces.application.FacesMessage; +import javax.faces.context.FacesContext; +import javax.inject.Named; + +import com.redhat.training.ejb.HelloBean; + +@RequestScoped +@Named("hello") +public class Hello { + private String name; + + @EJB + HelloBean helloEJB; + + public String greet() { + return helloEJB.sayHello(name); + } + public void sayHello() { + String response = greet(); + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(response)); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/solutions/stateless-ejb/src/main/webapp/WEB-INF/beans.xml b/solutions/stateless-ejb/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000..adcbeda --- /dev/null +++ b/solutions/stateless-ejb/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + JBoss, Home of Professional Open Source + Copyright 2014, 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. +--> +<!-- This file can be an empty text file (0 bytes) --> +<!-- We're declaring the schema to save you time if you do have to configure + this in the future --> +<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> diff --git a/solutions/stateless-ejb/src/main/webapp/WEB-INF/faces-config.xml b/solutions/stateless-ejb/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000..d7054de --- /dev/null +++ b/solutions/stateless-ejb/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + JBoss, Home of Professional Open Source + Copyright 2014, 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. +--> +<!-- This file is not required if you don't need any extra configuration. --> +<faces-config version="2.0" 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/web-facesconfig_2_0.xsd"> + + <!-- This descriptor activates the JSF 2.0 Servlet --> + + <!-- Write your navigation rules here. You are encouraged to use CDI + for creating @Named managed beans. --> + +</faces-config> diff --git a/solutions/stateless-ejb/src/main/webapp/WEB-INF/templates/default.xhtml b/solutions/stateless-ejb/src/main/webapp/WEB-INF/templates/default.xhtml new file mode 100644 index 0000000..2fe703c --- /dev/null +++ b/solutions/stateless-ejb/src/main/webapp/WEB-INF/templates/default.xhtml @@ -0,0 +1,34 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:ui="http://java.sun.com/jsf/facelets"> +<h:head> + <title><ui:insert name="title"> + [Title will be inserted here] + </ui:insert> + </title> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <h:outputStylesheet name="css/screen.css" /> +</h:head> +<h:body> + + <header> + <h:graphicImage name="images/redhat.png" /> + <div class="right"> + Application: + <ui:insert name="application_name"> + [Application name will be inserted here] + </ui:insert> + </div> + </header> + <div id="content"> + <ui:insert name="content"> + [Template content will be inserted here] + </ui:insert> + </div> + <footer> + JB183 - Enterprise Java Development - Red Hat Training + </footer> +</h:body> +</html> diff --git a/solutions/stateless-ejb/src/main/webapp/index.html b/solutions/stateless-ejb/src/main/webapp/index.html new file mode 100644 index 0000000..684299b --- /dev/null +++ b/solutions/stateless-ejb/src/main/webapp/index.html @@ -0,0 +1,23 @@ +<!-- + JBoss, Home of Professional Open Source + Copyright 2014, 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. +--> +<!-- Plain HTML page that kicks us into the app --> + +<html> +<head> +<meta http-equiv="Refresh" content="0; URL=index.jsf"> +</head> +</html> diff --git a/solutions/stateless-ejb/src/main/webapp/index.xhtml b/solutions/stateless-ejb/src/main/webapp/index.xhtml new file mode 100644 index 0000000..add53c5 --- /dev/null +++ b/solutions/stateless-ejb/src/main/webapp/index.xhtml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<ui:composition xmlns="http://www.w3.org/1999/xhtml" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:h="http://java.sun.com/jsf/html" + template="/WEB-INF/templates/default.xhtml"> + <ui:define name="title"> + Hello World web app + </ui:define> + <ui:define name="application_name"> + Hello EJB web app + </ui:define> + <ui:define name="content"> + <h1>Hello EJB web app</h1> + <br class="clear"/> + <h:form id="form"> + <p class="input"> + <h:outputLabel value="Enter your name:" for="name" /> + <h:inputText value="#{hello.name}" id="name" required="true" requiredMessage="Name is required"/> + </p> + <br class="clear"/> + <br class="clear"/> + <p class="input"> + <h:commandButton action="#{hello.sayHello()}" value="Submit" styleClass="btn" /> + </p> + <br class="clear"/> + <br class="clear"/> + <h:messages styleClass="messages"/> + </h:form> + </ui:define> +</ui:composition> diff --git a/solutions/stateless-ejb/src/main/webapp/resources/css/screen.css b/solutions/stateless-ejb/src/main/webapp/resources/css/screen.css new file mode 100644 index 0000000..0e284d1 --- /dev/null +++ b/solutions/stateless-ejb/src/main/webapp/resources/css/screen.css @@ -0,0 +1,79 @@ +body { + +} + +header { + background-color: #C40016; + height: 150px; + padding: 10px; + width: 95%; + margin: 0 auto; + border: 4px solid #000000; +} + +header .right { + display: inline-block; + float: right; + font-size: 40px; + font-weight: bolder; + height: 150px; + padding: 48px; + vertical-align: middle; +} + +#content { + background-color: #F2F2F2; + width: 91%; + margin: 0 auto; + padding: 100px 50px; + border: 2px solid #000000; +} + +footer { + border: 4px solid #000000; + background-color: #C40016; + height: 30px; + padding: 10px; + width: 95%; + margin: 0 auto; + text-align: center; + font-weight: bolder; + font-size: 27px; +} + +label{ + display: inline-block; + float: left; + clear: left; + width: 165px; +} +input { + display: inline-block; + float: left; + width: 362px; +} +select{ + display: inline-block; + float: left; + width: 371px; +} +textarea{ + display: inline-block; + float: left; +} + +.clear{ + clear: both; +} + +.messages{ + color: green; + font-weight: bolder; +} + +.btn{ + display: inline-block; + float: left; + clear: left; + width: 165px; +} \ No newline at end of file diff --git a/solutions/stateless-ejb/src/main/webapp/resources/images/redhat.png b/solutions/stateless-ejb/src/main/webapp/resources/images/redhat.png new file mode 100644 index 0000000..0984beb --- /dev/null +++ b/solutions/stateless-ejb/src/main/webapp/resources/images/redhat.png Binary files differ diff --git a/solutions/stateless-ejb/src/test/java/com/redhat/training/ejb/EJBTest.java b/solutions/stateless-ejb/src/test/java/com/redhat/training/ejb/EJBTest.java new file mode 100644 index 0000000..de9a333 --- /dev/null +++ b/solutions/stateless-ejb/src/test/java/com/redhat/training/ejb/EJBTest.java @@ -0,0 +1,52 @@ +/* + * 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.ejb; + +import static org.junit.Assert.assertEquals; + +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ArchivePaths; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.redhat.training.ui.Hello; + + +@RunWith(Arquillian.class) +public class EJBTest { + @Inject + private Hello hello; + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class,"stateless-ejb-test.war").addClass(HelloBean.class).addClass(Hello.class) + .addAsManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")); + } + + @Test + public void testHelloEJB() { + hello.setName("John Doe"); + String result = hello.greet(); + assertEquals("Hello, John Doe", result); + } +} -- Gitblit v1.9.3