Skip to content

martin-kuba/muni-chat-service

Repository files navigation

muni-chat-service

Example of a web service with OpenAPI description implemented using Spring Boot.

This project demonstrates the following features:

  • a multimodule Maven project
    • parent project chat-service-parent and multiple modules:
    • module aggregation, where a command executed in the parent project gets executed also in all modules
    • module inheritance, where the parent project inherits from org.springframework.boot:spring-boot-starter-parent and each module inherits from the parent
  • a Spring Boot application (ChatApplication.java)
  • a Spring MVC's REST controller (ChatRestController.java)
  • application with multiple layers
    • facade - a stable API for the outside world
    • service layer - internal business logic
    • persistence layer is omitted for the sake of simplicity
  • OpenAPI description of the app's API (openapi.yaml) generated from annotated Java code in the REST controller and facade classes
  • unit tests executed when the command mvn test is issued (ChatRestControllerUnitTests.java)
  • integration tests executed when the command mvn verify is issued (ChatIT.java)

Installation

Prerequisites: git, Apache Maven and JDK 21+

Download and compile:

git clone https://github.com/martin-kuba/muni-chat-service.git
cd muni-chat-service
mvn install

Run server

cd chat-server
mvn spring-boot:run

Then visit the service with your browser: http://localhost:8080/

Run client

cd chat-client-java
mvn spring-boot:run

Advanced usage

Running the server with TLS enabled

Create a PKCS12 keystore with:

openssl pkcs12 -export -name "mycert" -inkey key.pem -in cert.pem -certfile chain.pem -out mykeystore.p12

then run with the following options:

java -jar target/chat_service.jar \
     --server.port=8443 \
     --server.ssl.key-store-type=pkcs12 \
     --server.ssl.key-store=mykeystore.p12 \
     --server.ssl.key-store-password=password

Running the server behind Apache web server

java -jar target/chat_service.jar \
     --server.tomcat.ajp.port=8009 \
     --server.tomcat.ajp.enabled=true \
     --server.tomcat.ajp.secret=5ecr3t