Skip to content

Instantly share code, notes, and snippets.

@Abhi-Codes
Abhi-Codes / RequestHeaderInterceptor.java
Last active March 2, 2024 08:24
RequestHeaderInterceptor
import io.micrometer.context.ContextRegistry;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.slf4j.MDC;
import org.springframework.graphql.server.WebGraphQlInterceptor;
import org.springframework.graphql.server.WebGraphQlRequest;
import org.springframework.graphql.server.WebGraphQlResponse;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import reactor.util.context.Context;
@Abhi-Codes
Abhi-Codes / Test.java
Created October 14, 2023 06:33
Print1To10UsingVolatileBoolean
public class Test {
private static Object object = new Object();
//private static AtomicBoolean isOddTurn = new AtomicBoolean(true);
private volatile Boolean isOddTurn = Boolean.TRUE;
public static void main(String[] args) {
Test test = new Test();
test.runDemo();
@Abhi-Codes
Abhi-Codes / pom.xml
Last active February 11, 2023 04:40
Pom.xml for Spring Boot 2.7.6
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.6</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.github</groupId>
<artifactId>ldap-service</artifactId>
<version>1.0.0</version>
<name>ldap-service</name>
@Abhi-Codes
Abhi-Codes / RoleService.java
Created November 20, 2022 08:02
Use Custom SQL function in QueryDSL
QRoles userRolesPath = QRoles.roles1;
BooleanExpression exp = Expressions
.booleanTemplate("json_contains_key({0}, {1})", userRolesPath.roles, Expressions.constant(role))
.isTrue();
Iterable<Roles> lr = rr.findAll(exp);
@Abhi-Codes
Abhi-Codes / SQLFunctionContributor.java
Created November 20, 2022 07:47
Implement MetadataBuilderContributor interface
public class SQLFunctionContributor implements MetadataBuilderContributor {
@Override
public void contribute(MetadataBuilder metadataBuilder) {
metadataBuilder.applySqlFunction("json_contains_key",
new SQLFunctionTemplate(BooleanType.INSTANCE, "JSON_CONTAINS(?1, JSON_QUOTE(?2))"));
}
}
@Abhi-Codes
Abhi-Codes / crashreport.txt
Created November 11, 2022 08:40
crashreport sts
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------
Process: SpringToolSuite4 [83191]
Path: /Applications/SpringToolSuite4.app/Contents/MacOS/SpringToolSuite4
Identifier: org.springframework.boot.ide.branding.sts4
Version: 4.16.1 (4.16.1.202210240748)
Code Type: X86-64 (Native)
Parent Process: launchd [1]
@Abhi-Codes
Abhi-Codes / layers.xml
Created November 6, 2022 04:52
Create custom layers in spring Boot
<layers xmlns="http://www.springframework.org/schema/boot/layers" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/boot/layers
https://www.springframework.org/schema/boot/layers/layers-2.7.xsd">
<application>
<into layer="spring-boot-loader">
<include>org/springframework/boot/loader/**</include>
</into>
<into layer="application" />
</application>
<dependencies>
<into layer="snapshot-dependencies">
@Abhi-Codes
Abhi-Codes / Dockerfile
Created November 6, 2022 03:49
Dockerfile to build optimized OCI image in Spring Boot
#Multi Stage Docker Build
#STAGE 1 - Build the layered jar
#Use Maven base image
FROM maven-3.8.3-openjdk-17 AS builder
COPY src /home/app/src
COPY pom.xml /home/app
#Build an uber jar
RUN mvn -f /home/app/pom.xml package
WORKDIR /home/app/target
@Abhi-Codes
Abhi-Codes / TestController.java
Created October 23, 2022 04:15
Controller where custom annotation is applied on Request Parameter
@RestController
@RequestMapping("/api/opportunity")
@Validated
public class OpportunityController {
@GetMapping("/vendors/list")
public String getVendorpage(@RequestParam(required = false) String term,
@RequestParam(required = false) Integer page, @RequestParam(required = false) Integer size,
@ValuesAllowed(propName = "orderBy", values = { "OpportunityCount", "OpportunityPublishedCount", "ApplicationCount",
"ApplicationsApprovedCount" }) @RequestParam(required = false) String orderBy, @RequestParam(required = false) String sortDir) {
return "success";
@Abhi-Codes
Abhi-Codes / ValuesAllowed.java
Created October 23, 2022 03:54
Custom Annotation
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.List;
import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.Payload;