Skip to content

marcel-gepardec/api-demo

Repository files navigation

API TEST

Development environment

System wide

  • OpenJDK 21.0.3 LTS

  • Apache Maven 3.9.8

  • git

  • docker

Product wide

  • WildFly 33.0.0.Final

  • MySQL 8.1.0

Database setup (MySQL 8.1.0)

Run mysql docker

#Run mysql docker container
$ docker run --detach --name mysql-api-demo -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=ApiDemo -p 3306:3306 mysql:8.1.0

Configure mysql

#Connect to bash in container
$ docker exec -it mysql-api-demo mysql -u root -ppassword
#Create new user
MYSQL> CREATE USER 'TEST'@'%' IDENTIFIED BY 'password';

#Grant rights to new user
MYSQL> GRANT ALL ON `ApiDemo`.* TO 'TEST'@'%';
MYSQL> FLUSH PRIVILEGES;

#Exit mysql
MYSQL> exit
#Check if logging into new user works
$ docker exec -it mysql-api-demo mysql -u TEST -ppassword

Create ApiDemo-tables in local MySQL

(config data will also be inserted in the database)

$ cd flyway-db
#Clean database
$ mvn flyway:clean
#Migrate database
$ mvn flyway:migrate

Configure IntelliJ to work with MySQL

#Add datasource to IntelliJ
Host: localhost
Port: 3306
Authentication: User & Password
User: TEST
Password: password
URL should be: jdbc:mysql://localhost:3306/ApiDemo

Configurate DB Connection in Wildfly

$ cd /home/.../tools/wildfly-33.0.0.Final/bin/

#Linux
$ sh jboss-cli.sh --connect
#Windows
> .\jboss-cli.bat --connect


[standalone@localhost:9990 /] module add --name=com.mysql --resources=/home/.../api-demo/src/main/resources/wildfly/modules/com/mysql/main/mysql-connector-j-9.0.0.jar --dependencies=javax.api,javax.transaction.api

[standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=mysql:add(driver-name=mysql,driver-module-name=com.mysql,driver-xa-datasource-class-name=com.mysql.cj.jdbc.MysqlXADataSource)

[standalone@localhost:9990 /] data-source add --name=ApiDemoPersistenceDS --connection-url=jdbc:mysql://localhost:3306/ApiDemo --jndi-name=java:jboss/datasources/ApiDemoPersistenceDS --driver-name=mysql --user-name=TEST --password=password --transaction-isolation=TRANSACTION_READ_COMMITTED --min-pool-size=10 --max-pool-size=50 --pool-prefill=true --allocation-retry=3 --allocation-retry-wait-millis=100 --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker --validate-on-match=false --background-validation=true --background-validation-millis=30000 --stale-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLStaleConnectionChecker --exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter --enabled=true

[standalone@localhost:9990 /] /extension=org.wildfly.extension.microprofile.openapi-smallrye:add()

[standalone@localhost:9990 /] /subsystem=microprofile-openapi-smallrye:add()

After Configuration

Now you can start the WildFly server.

Or build and run Docker image locally

#Build docker image
$ docker build --platform linux/amd64 --build-arg DB_USER_NAME=TEST --build-arg DB_USER_PASSWORD=password -t wildfly .
#Run docker image
$ docker run --detach -p 8080:8080 wildfly

Deploy on own server

#Pull repository
$ git pull https://github.com/marcel-gepardec/api-demo.git
#Replace configuration for mysql database in the file docker-compose.yml
environment:          # Set Passwords, User and Database
  MYSQL_ROOT_PASSWORD: password  # Set the root password for MySQL
  MYSQL_DATABASE: ApiDemo  # Create a database named 'ApiDemo'
  MYSQL_USER: DB_USER_NAME  # Create a user with the specified username
  MYSQL_PASSWORD: DB_USER_PASSWORD  # Set the password for the user
#Attention!!! If you use Linux/ARM64, you need to add this to your /etc/hosts file
$ echo "172.17.0.1       host.docker.internal" | sudo tee -a /etc/hosts > /dev/null
#Run docker compose file
$ docker compose up -d

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages