Forwardings Requests to static content in Spring Boot Webflux

The following WebFilter redirects incoming requests for / to a static HTML file, index.html. ToIndexPageRedirection.java package com.hascode.tutorial; import org.springframework.stereotype.Component; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilter; import org.springframework.web.server.WebFilterChain; import reactor.core.publisher.Mono; @Component public class ToIndexPageRedirection implements WebFilter { @Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { if (exchange.getRequest().getURI().getPath().equals("/")) { return chain.filter( exchange.mutate().request( exchange.getRequest().mutate().path("/index.html").build() ).build() ); } return chain.filter(exchange); } } Ressources: JavaDocs WebFilter

August 16, 2022 · 1 min · 59 words · Micha Kops

Logback and Spring Boot - Change Log Level to custom format

Create a custom converter This class converts the well known log levels to a custom format CustomLogLevelConverter.java package com.hascode; public class CustomLogLevelConverter extends ClassicConverter { @Override public String convert(ILoggingEvent event) { switch (event.getLevel().toInt()) { case Level.ERROR_INT: return "ERROR!!!"; case Level.WARN_INT: return "WARN!!"; case Level.INFO_INT: return "INFO!"; case Level.TRACE_INT: return "DEBUG"; default: return event.getLevel().toString(); } } } Register the converter The following Logback config includes some defaults and registers our custom converter. ...

August 19, 2021 · 1 min · 165 words · Micha Kops

Package a Spring Boot App as RPM

Goals Package a Spring Boot Service as RPM Package Configure systemd integration Add install/uninstall hooks to create users, directories etc. Maven Setup <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.2</version> <relativePath/> </parent> <groupId>com.hascode</groupId> <artifactId>sample-app</artifactId> <version>1.0.0-SNAPSHOT</version> <name>sample-app</name> <properties> <java.version>11</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> (1) <groupId>de.dentrassi.maven</groupId> <artifactId>rpm</artifactId> <version>1.5.0</version> <executions> <execution> <goals> <goal>rpm</goal> </goals> </execution> </executions> <configuration> <packageName>sample-app</packageName> <skipSigning>true</skipSigning> <group>Application/Misc</group> <requires> <require>java-11-openjdk-headless</require> (2) </requires> <entries> <entry> (3) <name>/opt/sample-app</name> <directory>true</directory> <user>root</user> <group>root</group> <mode>0755</mode> </entry> <entry> (4) <name>/opt/sample-app/log</name> <directory>true</directory> <user>sample-app</user> <group>sample-app</group> <mode>0750</mode> </entry> <entry> (5) <name>/opt/sample-app/sample-app.jar</name> <file>${project.build.directory}/${project.build.finalName}.jar</file> <user>root</user> <group>root</group> <mode>0644</mode> </entry> <entry> (6) <name>/usr/lib/systemd/system/sample-app.service</name> <file>${project.basedir}/src/main/dist/sample-app.service</file> <mode>0644</mode> </entry> </entries> <beforeInstallation> (7) <file>${project.basedir}/src/main/dist/preinstall.sh</file> </beforeInstallation> <afterInstallation> <file>${project.basedir}/src/main/dist/postinstall.sh</file> </afterInstallation> <beforeRemoval> <file>${project.basedir}/src/main/dist/preuninstall.sh</file> </beforeRemoval> <license>All rights reserved</license> </configuration> </plugin> </plugins> </build> </project> ...

May 14, 2021 · 3 min · 567 words · Micha Kops