Skip to content

Commit 14a4de6

Browse files
Merge branch 'pr/553-lukasz-deltaspike'
Conflicts: pom.xml
2 parents 683f176 + 9dc1784 commit 14a4de6

38 files changed

Lines changed: 1747 additions & 0 deletions

‎deltaspike/.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.idea
2+
baeldung-jee7-seed.iml
3+
/target

‎deltaspike/pom.xml‎

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.baeldung</groupId>
6+
<artifactId>deltaspike</artifactId>
7+
<version>1.0</version>
8+
<packaging>war</packaging>
9+
<name>deltaspike</name>
10+
<description>A starter Java EE 7 webapp which uses DeltaSpike</description>
11+
12+
<url>http://wildfly.org</url>
13+
<licenses>
14+
<license>
15+
<name>Apache License, Version 2.0</name>
16+
<distribution>repo</distribution>
17+
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
18+
</license>
19+
</licenses>
20+
21+
<properties>
22+
<!-- Explicitly declaring the source encoding eliminates the following
23+
message: -->
24+
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
25+
resources, i.e. build is platform dependent! -->
26+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
27+
28+
<!-- JBoss dependency versions -->
29+
<version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>
30+
31+
<!-- Define the version of the JBoss BOMs we want to import to specify
32+
tested stacks. -->
33+
<version.jboss.bom>8.2.1.Final</version.jboss.bom>
34+
35+
<!-- other plugin versions -->
36+
<version.compiler.plugin>3.1</version.compiler.plugin>
37+
<version.surefire.plugin>2.16</version.surefire.plugin>
38+
<version.war.plugin>2.5</version.war.plugin>
39+
40+
<!-- maven-compiler-plugin -->
41+
<maven.compiler.target>1.7</maven.compiler.target>
42+
<maven.compiler.source>1.7</maven.compiler.source>
43+
</properties>
44+
45+
46+
<dependencyManagement>
47+
<dependencies>
48+
<!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill
49+
of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
50+
of artifacts. We use this here so that we always get the correct versions
51+
of artifacts. Here we use the jboss-javaee-7.0-with-tools stack (you can
52+
read this as the JBoss stack of the Java EE 7 APIs, with some extras tools
53+
for your project, such as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate
54+
stack you can read this as the JBoss stack of the Java EE 7 APIs, with extras
55+
from the Hibernate family of projects) -->
56+
<dependency>
57+
<groupId>org.wildfly.bom</groupId>
58+
<artifactId>jboss-javaee-7.0-with-tools</artifactId>
59+
<version>${version.jboss.bom}</version>
60+
<type>pom</type>
61+
<scope>import</scope>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.wildfly.bom</groupId>
65+
<artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
66+
<version>${version.jboss.bom}</version>
67+
<type>pom</type>
68+
<scope>import</scope>
69+
</dependency>
70+
</dependencies>
71+
</dependencyManagement>
72+
73+
<dependencies>
74+
75+
<!-- First declare the APIs we depend on and need for compilation. All
76+
of them are provided by JBoss WildFly -->
77+
78+
<!-- Import the CDI API, we use provided scope as the API is included in
79+
JBoss WildFly -->
80+
<dependency>
81+
<groupId>javax.enterprise</groupId>
82+
<artifactId>cdi-api</artifactId>
83+
<scope>provided</scope>
84+
</dependency>
85+
86+
<!-- Import the Common Annotations API (JSR-250), we use provided scope
87+
as the API is included in JBoss WildFly -->
88+
<dependency>
89+
<groupId>org.jboss.spec.javax.annotation</groupId>
90+
<artifactId>jboss-annotations-api_1.2_spec</artifactId>
91+
<scope>provided</scope>
92+
</dependency>
93+
94+
<!-- Import the JAX-RS API, we use provided scope as the API is included
95+
in JBoss WildFly -->
96+
<dependency>
97+
<groupId>org.jboss.resteasy</groupId>
98+
<artifactId>jaxrs-api</artifactId>
99+
<scope>provided</scope>
100+
</dependency>
101+
102+
<!-- Import the JPA API, we use provided scope as the API is included in
103+
JBoss WildFly -->
104+
<dependency>
105+
<groupId>org.hibernate.javax.persistence</groupId>
106+
<artifactId>hibernate-jpa-2.1-api</artifactId>
107+
<scope>provided</scope>
108+
</dependency>
109+
110+
<!-- Import the EJB API, we use provided scope as the API is included in
111+
JBoss WildFly -->
112+
<dependency>
113+
<groupId>org.jboss.spec.javax.ejb</groupId>
114+
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
115+
<scope>provided</scope>
116+
</dependency>
117+
118+
<!-- JSR-303 (Bean Validation) Implementation -->
119+
<!-- Provides portable constraints such as @Email -->
120+
<!-- Hibernate Validator is shipped in JBoss WildFly -->
121+
<dependency>
122+
<groupId>org.hibernate</groupId>
123+
<artifactId>hibernate-validator</artifactId>
124+
<scope>provided</scope>
125+
<exclusions>
126+
<exclusion>
127+
<groupId>org.slf4j</groupId>
128+
<artifactId>slf4j-api</artifactId>
129+
</exclusion>
130+
</exclusions>
131+
</dependency>
132+
133+
<!-- Import the JSF API, we use provided scope as the API is included in
134+
JBoss WildFly -->
135+
<dependency>
136+
<groupId>org.jboss.spec.javax.faces</groupId>
137+
<artifactId>jboss-jsf-api_2.2_spec</artifactId>
138+
<scope>provided</scope>
139+
</dependency>
140+
141+
<!-- Now we declare any tools needed -->
142+
143+
<!-- Annotation processor to generate the JPA 2.0 metamodel classes for
144+
typesafe criteria queries -->
145+
<dependency>
146+
<groupId>org.hibernate</groupId>
147+
<artifactId>hibernate-jpamodelgen</artifactId>
148+
<scope>provided</scope>
149+
</dependency>
150+
151+
<!-- Annotation processor that raising compilation errors whenever constraint
152+
annotations are incorrectly used. -->
153+
<dependency>
154+
<groupId>org.hibernate</groupId>
155+
<artifactId>hibernate-validator-annotation-processor</artifactId>
156+
<scope>provided</scope>
157+
</dependency>
158+
159+
<!-- Needed for running tests (you may also use TestNG) -->
160+
<dependency>
161+
<groupId>junit</groupId>
162+
<artifactId>junit</artifactId>
163+
<scope>test</scope>
164+
</dependency>
165+
166+
<!-- Optional, but highly recommended -->
167+
<!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA)
168+
JPA from JUnit/TestNG -->
169+
<dependency>
170+
<groupId>org.jboss.arquillian.junit</groupId>
171+
<artifactId>arquillian-junit-container</artifactId>
172+
<scope>test</scope>
173+
</dependency>
174+
175+
<dependency>
176+
<groupId>org.jboss.arquillian.protocol</groupId>
177+
<artifactId>arquillian-protocol-servlet</artifactId>
178+
<scope>test</scope>
179+
</dependency>
180+
181+
<dependency>
182+
<groupId>org.jboss.shrinkwrap.resolver</groupId>
183+
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
184+
<scope>test</scope>
185+
</dependency>
186+
187+
<dependency>
188+
<groupId>org.apache.deltaspike.modules</groupId>
189+
<artifactId>deltaspike-data-module-api</artifactId>
190+
<version>1.7.1</version>
191+
<scope>compile</scope>
192+
</dependency>
193+
194+
<dependency>
195+
<groupId>org.apache.deltaspike.modules</groupId>
196+
<artifactId>deltaspike-data-module-impl</artifactId>
197+
<version>1.7.1</version>
198+
<scope>runtime</scope>
199+
</dependency>
200+
201+
<!-- querydsl libraries -->
202+
<dependency>
203+
<groupId>com.mysema.querydsl</groupId>
204+
<artifactId>querydsl-apt</artifactId>
205+
<version>3.7.4</version>
206+
<scope>provided</scope>
207+
</dependency>
208+
209+
<dependency>
210+
<groupId>com.mysema.querydsl</groupId>
211+
<artifactId>querydsl-jpa</artifactId>
212+
<version>3.7.4</version>
213+
</dependency>
214+
215+
<dependency>
216+
<groupId>org.slf4j</groupId>
217+
<artifactId>slf4j-log4j12</artifactId>
218+
<version>1.6.1</version>
219+
</dependency>
220+
</dependencies>
221+
222+
<build>
223+
<!-- Maven will append the version to the finalName (which is the name
224+
given to the generated war, and hence the context root) -->
225+
<finalName>${project.artifactId}</finalName>
226+
<plugins>
227+
<plugin>
228+
<artifactId>maven-war-plugin</artifactId>
229+
<version>${version.war.plugin}</version>
230+
<configuration>
231+
<!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
232+
<failOnMissingWebXml>false</failOnMissingWebXml>
233+
</configuration>
234+
</plugin>
235+
<plugin>
236+
<groupId>com.mysema.maven</groupId>
237+
<artifactId>apt-maven-plugin</artifactId>
238+
<version>1.0.9</version>
239+
<executions>
240+
<execution>
241+
<goals>
242+
<goal>process</goal>
243+
</goals>
244+
<configuration>
245+
<outputDirectory>target/generated-sources/java</outputDirectory>
246+
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
247+
</configuration>
248+
</execution>
249+
</executions>
250+
</plugin>
251+
<!-- The WildFly plugin deploys your war to a local WildFly container -->
252+
<!-- To use, run: mvn package wildfly:deploy -->
253+
<plugin>
254+
<groupId>org.wildfly.plugins</groupId>
255+
<artifactId>wildfly-maven-plugin</artifactId>
256+
<version>${version.wildfly.maven.plugin}</version>
257+
</plugin>
258+
</plugins>
259+
</build>
260+
261+
<profiles>
262+
<profile>
263+
<!-- The default profile skips all tests, though you can tune it to run
264+
just unit tests based on a custom pattern -->
265+
<!-- Seperate profiles are provided for running all tests, including Arquillian
266+
tests that execute in the specified container -->
267+
<id>default</id>
268+
<activation>
269+
<activeByDefault>true</activeByDefault>
270+
</activation>
271+
<build>
272+
<plugins>
273+
<plugin>
274+
<artifactId>maven-surefire-plugin</artifactId>
275+
<version>${version.surefire.plugin}</version>
276+
<configuration>
277+
<skip>true</skip>
278+
</configuration>
279+
</plugin>
280+
</plugins>
281+
</build>
282+
</profile>
283+
284+
<profile>
285+
286+
<!-- An optional Arquillian testing profile that executes tests
287+
in your WildFly instance -->
288+
<!-- This profile will start a new WildFly instance, and execute the
289+
test, shutting it down when done -->
290+
<!-- Run with: mvn clean test -Parq-wildfly-managed -->
291+
<id>arq-wildfly-managed</id>
292+
<dependencies>
293+
<dependency>
294+
<groupId>org.wildfly</groupId>
295+
<artifactId>wildfly-arquillian-container-managed</artifactId>
296+
<scope>test</scope>
297+
</dependency>
298+
</dependencies>
299+
</profile>
300+
</profiles>
301+
</project>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
4+
* contributors by the @authors tag. See the copyright.txt in the
5+
* distribution for a full listing of individual contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package baeldung.controller;
18+
19+
import javax.annotation.PostConstruct;
20+
import javax.enterprise.inject.Model;
21+
import javax.enterprise.inject.Produces;
22+
import javax.faces.application.FacesMessage;
23+
import javax.faces.context.FacesContext;
24+
import javax.inject.Inject;
25+
import javax.inject.Named;
26+
27+
import baeldung.model.Member;
28+
import baeldung.service.MemberRegistration;
29+
30+
// The @Model stereotype is a convenience mechanism to make this a request-scoped bean that has an
31+
// EL name
32+
// Read more about the @Model stereotype in this FAQ:
33+
// http://www.cdi-spec.org/faq/#accordion6
34+
@Model
35+
public class MemberController {
36+
37+
@Inject
38+
private FacesContext facesContext;
39+
40+
@Inject
41+
private MemberRegistration memberRegistration;
42+
43+
@Produces
44+
@Named
45+
private Member newMember;
46+
47+
@PostConstruct
48+
public void initNewMember() {
49+
newMember = new Member();
50+
}
51+
52+
public void register() throws Exception {
53+
try {
54+
memberRegistration.register(newMember);
55+
FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_INFO, "Registered!", "Registration successful");
56+
facesContext.addMessage(null, m);
57+
initNewMember();
58+
} catch (Exception e) {
59+
String errorMessage = getRootErrorMessage(e);
60+
FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, "Registration unsuccessful");
61+
facesContext.addMessage(null, m);
62+
}
63+
}
64+
65+
private String getRootErrorMessage(Exception e) {
66+
// Default to general error message that registration failed.
67+
String errorMessage = "Registration failed. See server log for more information";
68+
if (e == null) {
69+
// This shouldn't happen, but return the default messages
70+
return errorMessage;
71+
}
72+
73+
// Start with the exception and recurse to find the root cause
74+
Throwable t = e;
75+
while (t != null) {
76+
// Get the message from the Throwable class instance
77+
errorMessage = t.getLocalizedMessage();
78+
t = t.getCause();
79+
}
80+
// This is the root cause message
81+
return errorMessage;
82+
}
83+
84+
}

0 commit comments

Comments
 (0)