/nstat

Primary LanguageJava

Backend: JavaEE RESTEasy App

Tested on Wildfly 10.0.10.Final

Create database

CREATE DATABASE IF NOT EXISTS `nstat` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `nstat`;

CREATE TABLE IF NOT EXISTS `entry` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `amount` decimal(15,2) NOT NULL,
  `currency` char(50) NOT NULL,
  `comment` varchar(1000) DEFAULT NULL,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;

Add MySQL driver to JBoss

Put mysql-connector-java-6.0.3.jar to \wildfly-10.0.0.Final\modules\system\layers\base\com\mysql\main

Put module.xml with following contents to the same directory:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.mysql">
  <resources>
    <resource-root path="mysql-connector-java-6.0.3.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
  </dependencies>
</module>

In jboss-cli.bat:

/subsystem=datasources/jdbc-driver=com.mysql:add(driver-name=com.mysql,driver-module-name=com.mysql,driver-xa-datasource-class-name=com.mysql.cj.jdbc.MysqlXADataSource)

Add datasource to JBoss

In jboss-cli.bat:

data-source add \
--name=NStatDS \
--driver-name=com.mysql \
--connection-url=jdbc:mysql://localhost:3306/nstat \
--jndi-name=java:jboss/datasources/NStatDS \
--jta=true \
--use-ccm=false \
--transaction-isolation=TRANSACTION_READ_COMMITTED \
--user-name=foo \
--password=bar \
--max-pool-size=25 \
--pool-prefill=true \
--valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker \
--check-valid-connection-sql="SELECT 1" \
--background-validation=true \
--background-validation-millis=60000 \
--exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter \
--blocking-timeout-wait-millis=5000 \
--idle-timeout-minutes=60
data-source enable --name=NStatDS

Add security domain to JBoss

<security-domain name="nstatSecurityDomain" cache-type="default">
        <authentication>
            <login-module code="Database" flag="required">
                <module-option name="dsJndiName" value="java:jboss/datasources/NStatDS"/>
                <module-option name="principalsQuery" value="SELECT password_hash FROM user WHERE username=?"/>
                <module-option name="rolesQuery" value="SELECT ur.role_name, 'Roles' FROM user u INNER JOIN user_role ur on ur.user_id = u.id WHERE u.username=?"/>
                <module-option name="hashAlgorithm" value="SHA-256"/>
                <module-option name="hashEncoding" value="base64"/>
            </login-module>
        </authentication>
    </security-domain>

POSTMan collection

Run in Postman