From 4682c83fc81338c490eedde4372db9a68514c813 Mon Sep 17 00:00:00 2001 From: Ravi Srinivasan <rsriniva@redhat.com> Date: Fri, 07 Sep 2018 18:05:56 +0200 Subject: [PATCH] Chap 2 GE code --- labs/hello-web/.gitignore | 5 labs/hello-web/src/main/webapp/resources/images/redhat.png | 0 labs/hello-web/src/main/webapp/index.html | 23 + settings.xml | 71 ++++ labs/pom.xml | 82 +++++ labs/hello-web/src/main/java/com/redhat/training/servlet/PingServlet.java | 60 ++++ labs/hello-web/src/main/webapp/resources/css/screen.css | 79 +++++ labs/hello-web/src/main/java/com/redhat/training/ui/Hello.java | 51 +++ labs/hello-web/README.md | 12 labs/hello-web/src/main/resources/META-INF/persistence.xml | 15 + labs/hello-web/src/main/webapp/WEB-INF/templates/default.xhtml | 34 ++ labs/hello-web/src/main/webapp/WEB-INF/beans.xml | 25 + labs/hello-web/pom.xml | 148 +++++++++ labs/hello-web/src/main/webapp/index.xhtml | 32 ++ labs/hello-web/src/main/java/com/redhat/training/rest/Service.java | 9 labs/hello-web/src/main/webapp/WEB-INF/faces-config.xml | 30 ++ labs/hello-web/src/main/java/com/redhat/training/rest/PersonService.java | 134 ++++++++ labs/hello-web/src/main/java/com/redhat/training/model/Person.java | 62 ++++ 18 files changed, 872 insertions(+), 0 deletions(-) diff --git a/labs/hello-web/.gitignore b/labs/hello-web/.gitignore new file mode 100644 index 0000000..d0152b8 --- /dev/null +++ b/labs/hello-web/.gitignore @@ -0,0 +1,5 @@ +.classpath +.project +.tern-project +.settings +target diff --git a/labs/hello-web/README.md b/labs/hello-web/README.md new file mode 100644 index 0000000..56cae66 --- /dev/null +++ b/labs/hello-web/README.md @@ -0,0 +1,12 @@ +# 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 +* Statelss EJB for services - uses JPA entity beans - exposes appropriate method as REST API using JAX-RS annotations +* JAX-RS Application class +* JPA entity bean to store names - uses H2 in-memory database +* Use EJB Singleton to lookup messaging connection and queue destination and inject into stateless EJB - lookup should only occur once on startup +* Servlet that returns "OK" - this is a health check - path should be [context]/health +* H2 (embedded in-memory DB) backend diff --git a/labs/hello-web/pom.xml b/labs/hello-web/pom.xml new file mode 100644 index 0000000..0da6bb0 --- /dev/null +++ b/labs/hello-web/pom.xml @@ -0,0 +1,148 @@ +<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>hello-web</artifactId> + <packaging>war</packaging> + <name>Hello World web app Project</name> + <description>This is the hello-web 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 Common Annotations API (JSR-250), we use provided scope + as the API is included in JBoss EAP --> + <dependency> + <groupId>org.jboss.spec.javax.annotation</groupId> + <artifactId>jboss-annotations-api_1.2_spec</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Import the JAX-RS API, we use provided scope as the API is included + in JBoss EAP --> + <dependency> + <groupId>org.jboss.spec.javax.ws.rs</groupId> + <artifactId>jboss-jaxrs-api_2.0_spec</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Import the JPA API, we use provided scope as the API is included in + JBoss EAP --> + <dependency> + <groupId>org.hibernate.javax.persistence</groupId> + <artifactId>hibernate-jpa-2.1-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> + + <dependency> + <groupId>org.jboss.spec.javax.jms</groupId> + <artifactId>jboss-jms-api_2.0_spec</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Bean Validation Implementation --> + <!-- Provides portable constraints such as @Email --> + <!-- Hibernate Validator is shipped in JBoss EAP --> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-validator</artifactId> + <scope>provided</scope> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-search-orm</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-entitymanager</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>org.jboss.spec.javax.servlet</groupId> + <artifactId>jboss-servlet-api_3.1_spec</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Annotation processor to generate the JPA metamodel classes for + typesafe criteria queries --> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-jpamodelgen</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Annotation processor that raising compilation errors whenever constraint + annotations are incorrectly used. --> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-validator-annotation-processor</artifactId> + <scope>provided</scope> + </dependency> + + </dependencies> + + <build> + <finalName>hello-web</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> + +</project> diff --git a/labs/hello-web/src/main/java/com/redhat/training/model/Person.java b/labs/hello-web/src/main/java/com/redhat/training/model/Person.java new file mode 100644 index 0000000..163204a --- /dev/null +++ b/labs/hello-web/src/main/java/com/redhat/training/model/Person.java @@ -0,0 +1,62 @@ +package com.redhat.training.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +@Entity +public class Person { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @NotNull + @Size(min=2,max=50) + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Person other = (Person) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + + +} diff --git a/labs/hello-web/src/main/java/com/redhat/training/rest/PersonService.java b/labs/hello-web/src/main/java/com/redhat/training/rest/PersonService.java new file mode 100644 index 0000000..c4ff188 --- /dev/null +++ b/labs/hello-web/src/main/java/com/redhat/training/rest/PersonService.java @@ -0,0 +1,134 @@ +package com.redhat.training.rest; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; + +import javax.annotation.Resource; +import javax.ejb.EJBException; +import javax.ejb.Stateless; +import javax.ejb.TransactionManagement; +import javax.ejb.TransactionManagementType; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.TypedQuery; +import javax.transaction.UserTransaction; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.ResponseBuilder; + +import com.redhat.training.model.Person; + +@Stateless +@Path("persons") +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +@TransactionManagement(TransactionManagementType.BEAN) +public class PersonService { + + @PersistenceContext + private EntityManager entityManager; + + @Resource + UserTransaction tx; + + // Simple non-RESTy method for JSF bean invocation + public String hello(String name) { + try { + try { + // start a new transaction + tx.begin(); + + // let's grab the current date and time on the server + LocalDateTime today = LocalDateTime.now(); + + // format it nicely for on-screen display + DateTimeFormatter format = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mm:ss a"); + String fdate = today.format(format); + + // Create a new Person object and persist to database + Person p = new Person(); + p.setName(name); + entityManager.persist(p); + + // respond back with Hello and convert the name to UPPERCASE. Also, send the + // current time on the server. + return "Hello " + name.toUpperCase() + "!. " + "Time on the server is: " + fdate; + } finally { + // commit the transaction + tx.commit(); + } + } catch (Exception e) { + throw new EJBException(e); + } + } + + // CRUD RESTful methods below + + // fetch result by Person id + public Person getPerson(@PathParam("id") Long id) { + return entityManager.find(Person.class, id); + } + + // Dump all Person objects in the Database + @GET + public List<Person> getAllPersons() { + TypedQuery<Person> query = entityManager.createQuery("SELECT p FROM Person p", Person.class); + List<Person> persons = query.getResultList(); + + return persons; + } + + // delete an object by Person id + @DELETE + @Path("{id}") + public void deletePerson(@PathParam("id") Long id) { + try { + try { + tx.begin(); + entityManager.remove(getPerson(id)); + } finally { + tx.commit(); + } + } catch (Exception e) { + throw new EJBException(); + } + } + + // Save a Person object to Database + @POST + public Response savePerson(Person person) { + try { + try { + ResponseBuilder builder; + if (person.getId() == null) { + Person newPerson = new Person(); + newPerson.setName(person.getName()); + tx.begin(); + entityManager.persist(newPerson); + builder = Response.ok(); + } else { + Person uPerson; + Person updatePerson = getPerson(person.getId()); + updatePerson.setName(person.getName()); + uPerson = entityManager.merge(updatePerson); + builder = Response.ok(uPerson); + } + + return builder.build(); + }finally { + tx.commit(); + } + }catch (Exception e) { + throw new EJBException(e); + } + } + +} diff --git a/labs/hello-web/src/main/java/com/redhat/training/rest/Service.java b/labs/hello-web/src/main/java/com/redhat/training/rest/Service.java new file mode 100644 index 0000000..0b01d7e --- /dev/null +++ b/labs/hello-web/src/main/java/com/redhat/training/rest/Service.java @@ -0,0 +1,9 @@ +package com.redhat.training.rest; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("/api") +public class Service extends Application { + +} diff --git a/labs/hello-web/src/main/java/com/redhat/training/servlet/PingServlet.java b/labs/hello-web/src/main/java/com/redhat/training/servlet/PingServlet.java new file mode 100644 index 0000000..d413cdf --- /dev/null +++ b/labs/hello-web/src/main/java/com/redhat/training/servlet/PingServlet.java @@ -0,0 +1,60 @@ +/* + * 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.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +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 taking advantage of features added in 3.0. + * </p> + * + * <p> + * The servlet is registered and mapped to /HelloServlet using the {@linkplain WebServlet + * @HttpServlet}. + * </p> + * + * @author Pete Muir + * + */ +@SuppressWarnings("serial") +@WebServlet("/health") +public class PingServlet extends HttpServlet { + + static String PAGE_HEADER = "<html><head><title>Ping Servlet</title></head><body>"; + + static String PAGE_FOOTER = "</body></html>"; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("text/html"); + PrintWriter writer = resp.getWriter(); + writer.println(PAGE_HEADER); + writer.println("<h1>OK.</h1>"); + writer.println("It is now " + new java.util.Date().toString() + " at the server."); + writer.println(PAGE_FOOTER); + writer.close(); + } + +} diff --git a/labs/hello-web/src/main/java/com/redhat/training/ui/Hello.java b/labs/hello-web/src/main/java/com/redhat/training/ui/Hello.java new file mode 100755 index 0000000..fd1d43f --- /dev/null +++ b/labs/hello-web/src/main/java/com/redhat/training/ui/Hello.java @@ -0,0 +1,51 @@ +package com.redhat.training.ui; + +import javax.enterprise.context.RequestScoped; +import javax.faces.application.FacesMessage; +import javax.faces.context.FacesContext; +import javax.inject.Named; +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; +import javax.inject.Inject; + +import com.redhat.training.rest.PersonService; + +@RequestScoped +@Named("hello") +public class Hello { + private String name; + + @Inject + private PersonService personService; + + public void sayHello() { + try { + String response = personService.hello(name); + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(response)); + }catch(Exception e){ + System.out.println(e.getCause()); + if(e.getCause() != null && e.getCause() instanceof ConstraintViolationException) { + ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); + String violations = ""; + for(ConstraintViolation<?> cv: ex.getConstraintViolations()) { + + violations += cv.getMessage() + "\n"; + + System.out.println("Violations: "+violations); + } + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(violations)); + } + + } + + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/labs/hello-web/src/main/resources/META-INF/persistence.xml b/labs/hello-web/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..41466e2 --- /dev/null +++ b/labs/hello-web/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<persistence version="2.1" + xmlns="http://xmlns.jcp.org/xml/ns/persistence" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> + <persistence-unit name="hello" transaction-type="JTA"> + <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> + <properties> + <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" /> + <property name="hibernate.hbm2ddl.auto" value="create-drop" /> + <property name="hibernate.show_sql" value="true" /> + <property name="hibernate.format_sql" value="true" /> + </properties> + </persistence-unit> +</persistence> diff --git a/labs/hello-web/src/main/webapp/WEB-INF/beans.xml b/labs/hello-web/src/main/webapp/WEB-INF/beans.xml new file mode 100755 index 0000000..adcbeda --- /dev/null +++ b/labs/hello-web/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/hello-web/src/main/webapp/WEB-INF/faces-config.xml b/labs/hello-web/src/main/webapp/WEB-INF/faces-config.xml new file mode 100755 index 0000000..d7054de --- /dev/null +++ b/labs/hello-web/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/hello-web/src/main/webapp/WEB-INF/templates/default.xhtml b/labs/hello-web/src/main/webapp/WEB-INF/templates/default.xhtml new file mode 100755 index 0000000..2fe703c --- /dev/null +++ b/labs/hello-web/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/hello-web/src/main/webapp/index.html b/labs/hello-web/src/main/webapp/index.html new file mode 100755 index 0000000..684299b --- /dev/null +++ b/labs/hello-web/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/hello-web/src/main/webapp/index.xhtml b/labs/hello-web/src/main/webapp/index.xhtml new file mode 100755 index 0000000..f17e997 --- /dev/null +++ b/labs/hello-web/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 World web app + </ui:define> + <ui:define name="content"> + <h1>Hello World 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/hello-web/src/main/webapp/resources/css/screen.css b/labs/hello-web/src/main/webapp/resources/css/screen.css new file mode 100755 index 0000000..0e284d1 --- /dev/null +++ b/labs/hello-web/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/hello-web/src/main/webapp/resources/images/redhat.png b/labs/hello-web/src/main/webapp/resources/images/redhat.png new file mode 100755 index 0000000..0984beb --- /dev/null +++ b/labs/hello-web/src/main/webapp/resources/images/redhat.png Binary files differ diff --git a/labs/pom.xml b/labs/pom.xml new file mode 100644 index 0000000..3dd9361 --- /dev/null +++ b/labs/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> diff --git a/settings.xml b/settings.xml new file mode 100644 index 0000000..7f20f20 --- /dev/null +++ b/settings.xml @@ -0,0 +1,71 @@ +<?xml version="1.0"?> +<settings> + + <profiles> + <profile> + <id>jboss-eap-repos</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <repositories> + <repository> + <id>redhat-ga-repository</id> + <url>https://maven.repository.redhat.com/ga</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + <repository> + <id>redhat-ea-repository</id> + <url>https://maven.repository.redhat.com/earlyaccess/all</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + <repository> + <id>jboss-public</id> + <name>JBoss Public Repository Group</name> + <url>https://repository.jboss.org/nexus/content/groups/public/</url> + </repository> + </repositories> + <pluginRepositories> + <pluginRepository> + <id>redhat-ga-repository</id> + <url>https://maven.repository.redhat.com/ga</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </pluginRepository> + <pluginRepository> + <id>redhat-ea-repository</id> + <url>https://maven.repository.redhat.com/earlyaccess/all</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </pluginRepository> + <pluginRepository> + <id>jboss-public</id> + <name>JBoss Public Repository Group</name> + <url>https://repository.jboss.org/nexus/content/groups/public</url> + </pluginRepository> + </pluginRepositories> + </profile> + </profiles> + + <activeProfiles> + <activeProfile>jboss-eap-repos</activeProfile> + </activeProfiles> + +</settings> -- Gitblit v1.9.3