Skip to content

Commit e23a734

Browse files
author
Arthur Gregorio
committed
fix #68
1 parent 8e1acac commit e23a734

File tree

6 files changed

+874
-258
lines changed

6 files changed

+874
-258
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import java.net.*;
17+
import java.io.*;
18+
import java.nio.channels.*;
19+
import java.util.Properties;
20+
21+
public class MavenWrapperDownloader {
22+
23+
private static final String WRAPPER_VERSION = "0.5.6";
24+
/**
25+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26+
*/
27+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29+
30+
/**
31+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32+
* use instead of the default one.
33+
*/
34+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35+
".mvn/wrapper/maven-wrapper.properties";
36+
37+
/**
38+
* Path where the maven-wrapper.jar will be saved to.
39+
*/
40+
private static final String MAVEN_WRAPPER_JAR_PATH =
41+
".mvn/wrapper/maven-wrapper.jar";
42+
43+
/**
44+
* Name of the property which should be used to override the default download url for the wrapper.
45+
*/
46+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47+
48+
public static void main(String args[]) {
49+
System.out.println("- Downloader started");
50+
File baseDirectory = new File(args[0]);
51+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52+
53+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
54+
// wrapperUrl parameter.
55+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56+
String url = DEFAULT_DOWNLOAD_URL;
57+
if(mavenWrapperPropertyFile.exists()) {
58+
FileInputStream mavenWrapperPropertyFileInputStream = null;
59+
try {
60+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61+
Properties mavenWrapperProperties = new Properties();
62+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64+
} catch (IOException e) {
65+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66+
} finally {
67+
try {
68+
if(mavenWrapperPropertyFileInputStream != null) {
69+
mavenWrapperPropertyFileInputStream.close();
70+
}
71+
} catch (IOException e) {
72+
// Ignore ...
73+
}
74+
}
75+
}
76+
System.out.println("- Downloading from: " + url);
77+
78+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79+
if(!outputFile.getParentFile().exists()) {
80+
if(!outputFile.getParentFile().mkdirs()) {
81+
System.out.println(
82+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83+
}
84+
}
85+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86+
try {
87+
downloadFileFromURL(url, outputFile);
88+
System.out.println("Done");
89+
System.exit(0);
90+
} catch (Throwable e) {
91+
System.out.println("- Error downloading");
92+
e.printStackTrace();
93+
System.exit(1);
94+
}
95+
}
96+
97+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99+
String username = System.getenv("MVNW_USERNAME");
100+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101+
Authenticator.setDefault(new Authenticator() {
102+
@Override
103+
protected PasswordAuthentication getPasswordAuthentication() {
104+
return new PasswordAuthentication(username, password);
105+
}
106+
});
107+
}
108+
URL website = new URL(urlString);
109+
ReadableByteChannel rbc;
110+
rbc = Channels.newChannel(website.openStream());
111+
FileOutputStream fos = new FileOutputStream(destination);
112+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113+
fos.close();
114+
rbc.close();
115+
}
116+
117+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

README.md

Lines changed: 92 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -3,90 +3,29 @@
33
A simple demo application to show how to work with the default technologies of JavaEE version 8 (or higher). This conceptual
44
architecture makes use of the following technologies:
55

6-
- Java 11 and Java EE 8 with Wildfly 14+ and PostgreSQL 10+
7-
- Hibernate 5 for JPA 2.2
6+
- Java 13+
7+
- JavaEE 8 with Thorntail 2.6
8+
- PostgreSQL 11+
9+
- Hibernate 5 and JPA 2.2
810
- Weld 3.0 for CDI 2.0
9-
- Mojarra for JSF 2.3 + Primefaces 7 + AdminLTE 2.4 + Bootstrap 3
10-
- Apache Delta Spike JPA and Data Module for database querying and repositories management
11-
- Apache Shiro 1.4 through [ShiroEE](https://github.com/arthurgregorio/shiro-ee) for Security with LDAP/AD and database
12-
authentication support
11+
- Mojarra for JSF 2.3 + Primefaces 7 + [AdminLTE](https://adminlte.io/) 2.4 + Bootstrap 3
12+
- Apache Delta Spike JPA + QueryDSL
13+
- Apache Shiro 1.4 provided by [ShiroEE](https://github.com/arthurgregorio/shiro-ee) extension
14+
- LDAP and Active Diretory integration for user authentication
1315
- Maven for dependency management and build
14-
- Flyway 5.2 for database migrations
16+
- Flyway 6 for database migrations
1517
- Database audit with Hibernate Envers 5
16-
- Hibernate Validator for Bean Validation
17-
- Omnifaces 3 and PrimefacesExt for JSF utilities
18-
- Jackson for JSON support
18+
- Hibernate Validator 6 for Bean Validation
19+
- Omnifaces 3 and Primefaces Extensions for JSF utilities
1920
- Lombok, Google Guava and Apache Commons-lang for class level utilities
2021
- Mustache for e-mail templating
2122
- Webservices with JAX-RS (RestEasy)
2223

23-
The demo makes use of a custom implementation of [AdminLTE](https://adminlte.io/) integrated with Boostrap 3 and
24-
Primefaces for a better UI experience, modern features and mobile support.
24+
It's not much say that if you want a **production ready architecture**, this is the project you are looking for.
2525

26-
Also, inside the application you can find (already functional) a simple CRUD of Users and User Groups with authentication,
27-
permission based authorization, all integrated with LDAP/AD and/or local accounts.
26+
### Create the database
2827

29-
It's not much say, that if you want a **production ready architecture**, this is the project you are looking for.
30-
31-
## How to: configure
32-
33-
First of all, you will need to download the latest version of Wildfly application server. This is the homologated version,
34-
maybe, with a little bit of changes ~~or no~~ you can run this on Payara, Glassfish or any other JEE 7+ server.
35-
36-
Download Wildfly [here](http://wildfly.org/downloads/) and configure the datasource for the application by editing the
37-
``` standalone.xml``` or ```standalone-full.xml``` (you will know which one to change) to add this lines to the
38-
datasource section in the file:
39-
40-
```xml
41-
<datasource jta="true" jndi-name="java:/datasources/LibraryDS" pool-name="LibraryDS" enabled="true" use-ccm="false">
42-
<connection-url>jdbc:postgresql://localhost:5432/library</connection-url>
43-
<driver-class>org.postgresql.Driver</driver-class>
44-
<driver>postgresql</driver>
45-
<pool>
46-
<min-pool-size>10</min-pool-size>
47-
<initial-pool-size>5</initial-pool-size>
48-
<max-pool-size>30</max-pool-size>
49-
<prefill>true</prefill>
50-
<flush-strategy>AllInvalidIdleConnections</flush-strategy>
51-
</pool>
52-
<security>
53-
<user-name>sa_library</user-name>
54-
<password>sa_library</password>
55-
</security>
56-
<validation>
57-
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
58-
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
59-
<background-validation>true</background-validation>
60-
<use-fast-fail>true</use-fast-fail>
61-
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
62-
</validation>
63-
</datasource>
64-
```
65-
66-
> **Quick note**: the datasource will not work if you don't have the PostgreSQL driver enabled in the wildfly modules.
67-
To do this, follow [this blog post](https://bok.stenusys.com/index.php/2018/02/12/how_to_setup_postgresql_datasource_with_wildfly/).
68-
69-
70-
If you want to send e-mails, these lines should be added to the mail subsystem (search for ```mail-session```):
71-
72-
> **Quick note**: if you are looking for a good fake/development e-mail provider, I can indicate [mailtrap](https://mailtrap.io/)
73-
74-
```xml
75-
<mail-session name="my-email" debug="true" jndi-name="java:/mail/library" from="no-reply@my-email-account.com">
76-
<smtp-server outbound-socket-binding-ref="my-email-socket" username="my@email-account.com" password="my-secret"/>
77-
</mail-session>
78-
```
79-
80-
And the e-mail socket to the ```socket-binding-group``` at the end of the file:
81-
82-
```xml
83-
<outbound-socket-binding name="my-email-socket">
84-
<remote-destination host="my-email-server.com" port="587"/>
85-
</outbound-socket-binding>
86-
```
87-
88-
After this, create the database on you local instance of PostgreSQL 10+ to match the Wildfly configurations and enable
89-
the deployment of the application:
28+
Before the configuration step, create the database to used by the application:
9029

9130
```sql
9231
-- the user
@@ -99,7 +38,7 @@ CREATE USER sa_library WITH
9938
NOREPLICATION
10039
ENCRYPTED PASSWORD 'sa_library';
10140

102-
-- the databse
41+
-- the database
10342
CREATE DATABASE library
10443
WITH
10544
OWNER = sa_library
@@ -112,37 +51,95 @@ CREATE USER sa_library WITH
11251

11352
The tables and the initial data (default user, group and authorizations) should be created by Flyway with the migrations
11453
strategy. If you want to run this application in development mode, Hibernate will create the tables, but you must create
115-
the schemes by hands on PgAdmin or other similar software:
54+
the schemes manually on PgAdmin or other similar software:
11655

11756
```sql
11857
CREATE SCHEMA configuration AUTHORIZATION sa_library;
11958
CREATE SCHEMA registration AUTHORIZATION sa_library;
120-
CREATE SCHEMA configuration_audit AUTHORIZATION sa_library;
121-
CREATE SCHEMA registration_audit AUTHORIZATION sa_library;
12259
```
12360

124-
## How to: run on IDE
61+
### Configure the application
62+
63+
The application provides three profiles to build and configure the application:
64+
65+
- *ALPHA* -for development environments
66+
- *BETA* - for testing environments
67+
- *RELEASE_CANDIDATE* - for validation and final testing (approval of changes)
68+
- *RELEASE* - used in production environments
12569

126-
Just import the maven project and deploy to you (already configured) Wildfly server. Remember: first configure the
127-
datasource because application will not start if it is missing.
70+
Every profile has his own configurations, it means that you can have separated environments and to activate them you
71+
just need to build the application again.
12872

129-
## How to: run by hands
73+
Below we will configure the RELEASE profile and build a production artifact:
13074

131-
Build the project. On the root folder run:
75+
```xml
76+
<profile>
77+
<id>release</id>
78+
<properties>
79+
<application.version>${project.version}-RELEASE</application.version>
80+
<application.base-url>https://localhost:8443/</application.base-url>
81+
<skip.tests>false</skip.tests>
82+
<project.stage>Production</project.stage>
83+
<mail.host>my-mail-host</mail.host>
84+
<mail.port>587</mail.port>
85+
<mail.debug>false</mail.debug>
86+
<mail.from-address>noreply@your-domain.com</mail.from-address>
87+
<mail.username>my@account.com</mail.username>
88+
<mail.password>secret</mail.password>
89+
<database.host>localhost</database.host>
90+
<database.port>5432</database.port>
91+
<database.name>library</database.name>
92+
<database.username>sa_library</database.username>
93+
<database.password>sa_library</database.password>
94+
<orm.show_sql>false</orm.show_sql>
95+
<orm.ddl_auto>none</orm.ddl_auto>
96+
<ws.base-url>https://my-webservice-server.com</ws.base-url>
97+
<ws.username>admin</ws.username>
98+
<ws.password>admin</ws.password>
99+
<ws.client-name>admin</ws.client-name>
100+
<ldap.enabled>false</ldap.enabled>
101+
<ldap.url>ldap://localhost</ldap.url>
102+
<ldap.baseDn>OU=Users,DC=arthurgregorio,DC=eti,DC=br</ldap.baseDn>
103+
<ldap.user>CN=bind-user,OU=Applications,DC=arthurgregorio,DC=eti,DC=br</ldap.user>
104+
<ldap.password>my-bind-password</ldap.password>
105+
</properties>
106+
</profile>
107+
```
132108

133-
```shell
134-
mvn clean package -Prelease
109+
As you can see, just fill the properties with your configurations and build with the command below:
110+
111+
```shell script
112+
mvnw clean package -Prelease
135113
```
136114

137-
If no profile is used, this will tell maven to build the development version with no migrations and the database need
138-
to be initialized manually like said above.
115+
> **Quick tip**!
116+
>
117+
> If you are on Windows, used ```mvnw.bat``` and if you are on a linux system, use ```./mvnw```
118+
119+
After the build process, a folder called ```target``` should appear and inside you will find the artifacts
120+
```library-x.x.x-RELEASE-thorntail.jar``` and ```library-x.x.x-RELEASE.war```, it means that you are ready to run the
121+
application.
122+
123+
To do that, just use:
124+
125+
```shell script
126+
java -jar target/library-x.x.x-RELEASE-thorntail.jar
127+
```
128+
129+
If you have Java JDK installed, the application will start and should be available on ```http://localhost:8080/```, the
130+
username and password to access are ```admin```.
131+
132+
> **Quick tip!**
133+
>
134+
> You can run the application directly from the build process using Thorntail Maven Plugin, just use
135+
> ```mvn clean package -Prelease thorntail:run```
136+
137+
### Running inside the IDE
138+
139+
We use maven to build the application and almost all the IDE on the market have a feature to import maven projects.
139140

140-
The build configuration also have other profiles for you to configure according your need:
141+
By that, just import the project and you are ready to go!
141142

142-
- *BETA* for beta releases, testing the software
143-
- *RC* for candidate releases, feature validation/approving purpose
144-
- *RELEASE* for the final, production ready, releases
143+
### Contact
145144

146-
After the build, open the wildfly admin console on the web browser and in the deployments section, upload the war file
147-
created by the build in the target folder (named *library-1.0.0-(selected-profile)*) inside the project and access it on
148-
the default URL: https://localhost:8443/, and you're done! Enjoy the demo.
145+
If you have any problem or want to contact me, send me an e-mail at: contato@arthurgregorio.eti.br

0 commit comments

Comments
 (0)