2.4. DomiSMP as a Spring Boot application

2.4.1. Purpose of the guide

This guide provides instructions for starting the DomiSMP application using Spring Boot, aiming to simplify the process for demonstrations and testing. It is intended for project’s technical decision-makers, developers and testers interested in using DomiSMP for Access-Point development.

2.4.1.1. What you will achieve

By following this guide, you will learn how to set up and start the DomiSMP as a Spring Boot application.

2.4.1.2. What you will need
  • About 20 minutes of your time.

  • A basic understanding of the Dynamic Discovery process.

  • Java 8 or higher installed.

  • MySQL 8.x+ database server or Docker with the pre-downloaded MySQL 8.3.0 image.

  • Access to a Bash shell.

2.4.1.3. How to complete this guide

This guide will walk you through the steps to start DomiSMP with Spring Boot.

2.4.2. Step-by-step guide

2.4.2.1. Step 1: Download DomiSMP application & deployment bundle

Create a working folder referred to as ${SMP_HOME}. Then, navigate to it. This folder will store the DomiSMP application and deployment bundle.

Download DomiSMP from one of the following sources:

wget -O smp.jar https://ec.europa.eu/digital-building-blocks/artifact/repository/eDelivery/eu/europa/ec/edelivery/smp-springboot/5.0.1/smp-springboot-5.0.1-exec.jar

Download the DomiSMP deployment bundle from one of the following sources:

wget -O smp-5.0.1-setup.zip https://ec.europa.eu/digital-building-blocks/artifact/repository/eDelivery/eu/europa/ec/edelivery/smp/5.0.1/smp-5.0.1-setup.zip
2.4.2.2. Step 2: Start the Docker MySQL database

Skip this step if using a local MySQL database.

If using Docker, pull and start the MySQL 8.3.0 image with the following commands:

docker pull mysql:8.0.23
docker run --name domismp-mysql -e MYSQL_ROOT_PASSWORD=root -p 3307:3306 -d mysql:8.3.0

To connect to the MySQL database:

docker exec -it domismp-mysql mysql -uroot -proot

The command starts the MySQL database with the following parameters:

  • --name domismp-mysql: Name of the container.

  • -e MYSQL_ROOT_PASSWORD=root: Root password of the MySQL database.

  • -p 3307:3306: Port mapping of the MySQL database. Port 3307 of the host is mapped to port 3306 of the container.

  • -d: Starts the container in the background.

2.4.2.3. Step 3: Initialise the database

In this step, we will initialise the database with the DomiSMP database schema and initial data. We will execute the database commands manually. In the next chapter, we will provide Bash scripts that can be used to initialise the database.

To initialize the database, we will use script files that are part of the DomiSMP deployment bundle.

Unzip smp-5.0.1-setup.zip to ${SMP_HOME}. Navigate to the ${SMP_HOME}/smp-5.0.1/database-scripts/ folder, which contains the mysql5innodb.ddl file with the DomiSMP database schema and the mysql5innodb-data.sql file with the initial data for the DomiSMP database.

To create DomiSMP, we will use the following variables:

  • Database schema: smpdb

  • Database user: smp

  • Database user password: smp

  • Database root user: root

  • Database root user password: root

2.4.2.3.1. Step 3.1: Initialise the database schema

If using a local MySQL database, connect to it and execute the following command:

mysql -h localhost -u root --password=root -e "drop schema if exists smpdb;DROP USER IF EXISTS smp;create schema smpdb;alter database smpdb charset=utf8;create user smp identified by 'smp';grant all on smpdb.* to smp"

If using a Docker MySQL database, the same can be done with the following command:

docker exec -it domismp-mysql mysql -h localhost -u root --password=root -e "drop schema if exists smpdb;DROP USER IF EXISTS smp;create schema smpdb;alter database smpdb charset=utf8;create user smp identified by 'smp';grant all on smpdb.* to smp"

When using a Docker MySQL database, the command is prepended by docker exec -it domismp-mysql which executes the mysql command inside the Docker container. Moving forward, we will provide here only the mysql command.

2.4.2.3.2. Step 3.2 Create the DomiSMP database schema objects

Execute the following command (replace ${SMP_HOME} with the actual path to the smp-5.0.1-setup’s parent folder):

mysql -u smp --password=smp smpdb < ${SMP_HOME}/smp-5.0.1/database-scripts/mysql5innodb.ddl

When script is executed, the DomiSMP database schema is created and we can validate the schema with the following:

mysql -u smp --password=smp smpdb -e "show tables"

The command should return the list of the tables in the smpdb database.

2.4.2.3.3. Step 3.3: Insert the initial data

Execute the following:

mysql -u smp --password=smp smpdb < ${SMP_HOME}/smp-5.0.1/database-scripts/mysql5innodb-data.sql

The main purpose of the script is to insert demo users:

  • system/123456 with the SYSTEM_ADMIN role

  • user/123456 with the USER role

To check if the data is inserted, execute the following:

    mysql -u smp --password=smp smpdb -e "select * from SMP_USER"
2.4.2.4. Step 4: Initialise the database (scripts)

For the testing and demo purposes, we would like to have a clean database each time we start the DomiSMP application. In this step we will provide the Bash script that can be used to initialise the database. The script is provided as an example and should be adjusted to meet the local environment requirements.

To run the script, ensure the following:

  • Correct command-line emulator (example uses /bin/sh).

  • Locally installed MySQL database.

  • Clone DomiSMP repository and check out the right branch (for example, check out the development branch for development). The reposistory contains the database DDL scripts.

Before executing the sample script, set the following variables:

  • PROJECT_HOME: The DomiSMP code/project home (for example, /code/smp).

  • DATABASE: smp database schema.

  • DB_ADMIN: MySQL database root username.

  • DB_ADMIN_PASSWORD: MySQL database root password.

  • DB_USERNAME: DomiSMP MySQL database username.

  • DB_PASSWORD: DomiSMP MySQL database username.

Explanation of the script: The script connects to MySQL database using mysql (CLI tool) and deletes database/schema and user defined in the variables DATABASE and DB_USERNAME. The DomiSMP schema is generated from the following script:

${SMP_HOME}/smp-5.0.1/database-scripts/mysql5innodb.ddl

and the initial data is inserted from the following script:

${SMP_HOME}/smp-5.0.1/database-scripts/mysql5innodb-data.sql

Linux OS:

#!/bin/sh

PROJECT_HOME=/cef/code/smp

DATABASE=smpdb
DB_ADMIN=root
DB_ADMIN_PASSWORD=root
DB_USERNAME=smp;
DB_PASSWORD=smp;
DB_CREATE_SCRIP=${PROJECT_HOME}/smp-5.0.1/database-scripts/mysql5innodb.ddl
DB_INIT_SCRIPT=${PROJECT_HOME}/smp-5.0.1/database-scripts/mysql5innodb-data.sql

# recreate database
echo "clean the database $DATABASE if exists "
mysql -h localhost -u $DB_ADMIN --password=$DB_ADMIN_PASSWORD -e "drop schema if exists $DATABASE;DROP USER IF EXISTS $DB_USERNAME;  create schema $DATABASE;alter database $DATABASE charset=utf8; create user $DB_USERNAME identified by '$DB_PASSWORD';grant all on $DATABASE.* to $DB_USERNAME;"

# create new database
echo "create database"
mysql -h localhost -u $DB_ADMIN --password=$DB_ADMIN_PASSWORD $DATABASE < "$DB_CREATE_SCRIP"
echo "init database for soapui tests"
mysql -h localhost -u $DB_ADMIN --password=$DB_ADMIN_PASSWORD $DATABASE < "$DB_INIT_SCRIPT"

Windows OS:

@echo off


set PROJECT_HOME=C:\\cef\\code\\smp
set DATABASE=smpdb
set DB_ADMIN=root
set DB_ADMIN_PASSWORD=
set DB_USERNAME=smp
set DB_PASSWORD=smp
set DB_CREATE_SCRIP=${PROJECT_HOME}\\smp-5.0.1\\database-scripts\\mysql5innodb.ddl
set DB_INIT_SCRIPT=${PROJECT_HOME}\\smp-5.0.1\\database-scripts\\mysql5innodb-data.sql

REM recreate database
echo "clean the database %DATABASE% if exists "
mysql -h localhost -u %DB_ADMIN% --password=%DB_ADMIN_PASSWORD% -e "drop schema if exists %DATABASE%;DROP USER IF EXISTS %DB_USERNAME%;create schema %DATABASE%;alter database %DATABASE% charset=utf8;create user %DB_USERNAME% identified by '%DB_PASSWORD%';grant all on %DATABASE%.* to %DB_USERNAME%;"


REM create new database
echo "create database"
mysql -h localhost -u %DB_ADMIN% --password=%DB_ADMIN_PASSWORD% %DATABASE% < "%DB_CREATE_SCRIP%"
echo "init database for soapui tests"
mysql -h localhost -u %DB_ADMIN% --password=%DB_ADMIN_PASSWORD% %DATABASE% < "%DB_INIT_SCRIPT%"
2.4.2.5. Step 5: Prepare the application.properties

For the DomiSMP database configuration, set the following properties:

  • smp.jdbc.hibernate.dialect: Database hibernate dialect name.

  • jdbc.driver: jdbc driver. The MySQL driver is embedded by default. In case of other drivers, add them to pom.xml and rebuild the Spring Boot application.

    • smp.jdbc.url: URL of the database.

    • smp.jdbc.user: Database username

    • smp.jdbc.password: Database password.

To set/change other Spring Boot parameters (for example, server.port), refer to the Spring Boot documentation.

The configuration properties must be set in the application.properties file and placed in the working directory of the DomiSMP Spring Boot application.

For alternatives on how to set Spring Boot properties, refer to the Spring Boot documentation.

For DomiSMP startup properties, refer to DomiSMP Administration Guide.

Only the "java property type" of the Spring Boot properties format is supported (JSON or YAML types are not supported!).

Example of Spring Boot configuration in the application.properties file (adapt the properties to your local MySQL installation configuration):

# the tomcat server port
server.port=8084

# Database configuration
smp.jdbc.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

# *********************************
#  Custom defined datasource
# *********************************
# mysql database example
smp.jdbc.driver=com.mysql.jdbc.Driver
# in case of the docker mysql database the url is jdbc:mysql://localhost:3307/smpdb
smp.jdbc.url=jdbc:mysql://localhost:3306/smpdb
smp.jdbc.user=smp
smp.jdbc.password=smp
2.4.2.6. Step 6: Start the application

Start the application with the following command in the working directory of the DomiSMP Spring Boot application:

 java -jar smp.jar

If configured to use port 8084, the application will be accessible at http://localhost:8084/smp/.

2.4.3. Further reading

Review the concepts covered in this guide and explore further documentation for advanced features and next steps. :toc: