Skip to content

Instantly share code, notes, and snippets.

View aoudiamoncef's full-sized avatar
🏠
Working from home

Moncef AOUDIA aoudiamoncef

🏠
Working from home
View GitHub Profile
@aoudiamoncef
aoudiamoncef / SerdeConfig.java
Last active January 28, 2024 21:31
Spring Boot specify Jackson module(s) to register with the ObjectMapper
package com.maoudia;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.hibernate6.Hibernate6Module;
import com.fasterxml.jackson.module.blackbird.BlackbirdModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
@aoudiamoncef
aoudiamoncef / LoggingAspect.java
Last active February 5, 2024 08:53
Spring Boot with Spring AOP Logging (Use for debugging only)
package com.maoudia.app;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@aoudiamoncef
aoudiamoncef / pom.xml
Created January 29, 2021 12:26
Rest-assured 4+ dependencies conflict solution
<?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>
<groupId>com.lahzouz</groupId>
<artifactId>rest-assured-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<groovy.version>3.0.7</groovy.version>
@aoudiamoncef
aoudiamoncef / logback-spring.xml
Last active July 4, 2019 15:47
Spring Logback heavy JSON logging with size and time based rolling policy
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="APPLICATION_NAME" value="lahzouz"/>
<property name="LOG_PATH" value="/var/log/lahzouz/${APPLICATION_NAME}"/>
<property name="FILE_PREFIX" value="${APPLICATION_NAME}"/>
<property name="PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %magenta([%thread]) %highlight(%level) %cyan(%logger{36}) - %message%n%xException"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<withJansi>true</withJansi>
<encoder>
@aoudiamoncef
aoudiamoncef / OkHttp3SslByPass.java
Created June 26, 2019 11:01
OkHttp3 Ssl ByPass
private static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain,
String authType) {
}
@aoudiamoncef
aoudiamoncef / CacheProvider.java
Last active May 11, 2021 10:00
GraphQL Java Spring Boot 2 configuration with queries cache(Caffeine)
@Component
public class CacheProvider implements PreparsedDocumentProvider {
@Autowired
private AppProperties appProps;
@Override
public PreparsedDocumentEntry getDocument(ExecutionInput executionInput, Function<ExecutionInput, PreparsedDocumentEntry> computeFunction) {
final Cache<String, PreparsedDocumentEntry> cache = Caffeine.newBuilder()
.maximumSize(appProps.getCache()
@aoudiamoncef
aoudiamoncef / MavenJacocoSonarQube.xml
Last active April 30, 2024 11:20
Maven Jacoco(0.8.3) && SonarQube(7.7) integration with unit && integration tests
...
<properties>
...
<sonar.scanner.maven.version>3.6.0.1398</sonar.scanner.maven.version>
<sonar.host.url>http://localhost:9000</sonar.host.url>
<sonar.projectName>lahzouz</sonar.projectName>
<sonar.language>java</sonar.language>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
@aoudiamoncef
aoudiamoncef / DataLoaderConfig.java
Last active January 9, 2023 11:00
GraphQL Java Dataloader Redis generic Cachemap (Spring Boot 2 )
@Configuration
public class DataLoaderConfig {
@Autowired
private RedisCacheRepository<String, ObjectId, Home> homeByObjectIdCacheMapRepository;
@Autowired
private RedisCacheRepository<String, String, Home> homeByStringCacheMapRepository;
@Bean
public DataLoaderRegistry dataLoaderRegistry() {
@aoudiamoncef
aoudiamoncef / getResourceFileAsString.java
Last active June 11, 2023 09:36
Spring Boot read file from resources
public String loadFile(final String pathResource) {
try (final InputStream is = new ClassPathResource(pathResource).getInputStream()) {
// To be customized
return IOUtils.toString(is, "UTF-8");
} catch (final Exception e) {
final String errorMessage = "Error loading file ";
// Could be more specific
throw new RuntimeException(errorMessage + e);
}
}
@aoudiamoncef
aoudiamoncef / introspection-query.graphql
Created January 27, 2019 02:20
GraphQL schema introspection query.
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {