Skip to content

Commit

Permalink
Update tps-messaging-service til spring 3.2
Browse files Browse the repository at this point in the history
#deploy-tps-messaging-service
  • Loading branch information
stigus committed Jan 11, 2024
1 parent a32027c commit 8b23e17
Show file tree
Hide file tree
Showing 44 changed files with 121 additions and 139 deletions.
12 changes: 10 additions & 2 deletions apps/budpro-service/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.1'
id 'io.spring.dependency-management' version '1.1.3'
id 'io.spring.dependency-management' version '1.1.4'
id "jacoco"
id "org.sonarqube" version "4.0.0.2929"
id("org.openrewrite.rewrite") version("6.6.4")
}

bootJar {
archiveFileName = "app.jar"
mainClass = 'no.nav.dolly.budpro.BudproServiceApplication'
}

rewrite {
activeRecipe("org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2")
}

configurations {
compileOnly {
extendsFrom annotationProcessor
Expand Down Expand Up @@ -39,11 +44,13 @@ repositories {
dependencyManagement {
applyMavenExclusions = false
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:2022.0.4"
mavenBom "org.springframework.cloud:spring-cloud-dependencies:2023.0.0"
}
}

dependencies {
rewrite("org.openrewrite.recipe:rewrite-spring:5.2.0")

annotationProcessor 'org.projectlombok:lombok'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'

Expand Down Expand Up @@ -73,6 +80,7 @@ dependencies {

testAnnotationProcessor 'org.projectlombok:lombok'

testImplementation "org.junit.jupiter:junit-jupiter:5.10.1"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.testcontainers:junit-jupiter'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public String next() {
var a = random.nextInt(99);
var b = random.nextInt(99);
var c = random.nextInt(99);
generated = String.format("%02d%02d%02d", a, b, c);
generated = "%02d%02d%02d".formatted(a, b, c);
} while (assigned.contains(generated));
assigned.add(generated);
return generated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BudproControllerTest {
private AutoCloseable closeable;

@BeforeEach
public void before() {
void before() {
closeable = MockitoAnnotations.openMocks(this);

var names = new ArrayList<String>(100);
Expand All @@ -56,12 +56,12 @@ public void before() {
}

@AfterEach
public void after() throws Exception {
void after() throws Exception {
closeable.close();
}

@Test
void testThatNoSeedGivesDifferentResults()
void thatNoSeedGivesDifferentResults()
throws Exception {
var result1 = mockMvc
.perform(get("/api/random?limit={limit}", 50))
Expand All @@ -80,7 +80,7 @@ void testThatNoSeedGivesDifferentResults()
}

@Test
void testThatSameSeedGivesSameResults()
void thatSameSeedGivesSameResults()
throws Exception {
var result1 = mockMvc
.perform(get("/api/random?seed={seed}&limit={limit}", 123L, 50))
Expand All @@ -99,7 +99,7 @@ void testThatSameSeedGivesSameResults()
}

@Test
void testThatOverrideWorksAsIntended()
void thatOverrideWorksAsIntended()
throws Exception {
var override = new BudproRecord(
"OVERRIDE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;

Expand All @@ -16,25 +18,23 @@ public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {

httpSecurity.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().csrf().disable()
.authorizeHttpRequests()
.requestMatchers(
"/internal/**",
"/webjars/**",
"/h2/**",
"/swagger-resources/**",
"/v3/api-docs/**",
"/swagger-ui/**",
"/swagger",
"/error",
"/swagger-ui.html"
).permitAll()
.requestMatchers("/api/**").fullyAuthenticated()
.and()
.oauth2ResourceServer()
.jwt();
httpSecurity.sessionManagement(managementConfigurer ->
managementConfigurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(matcherRegistry -> matcherRegistry.requestMatchers(
"/internal/**",
"/webjars/**",
"/h2/**",
"/swagger-resources/**",
"/v3/api-docs/**",
"/swagger-ui/**",
"/swagger",
"/error",
"/swagger-ui.html")
.permitAll()
.requestMatchers("/api/**").fullyAuthenticated())
.oauth2ResourceServer(httpSecurityOAuth2ResourceServerConfigurer -> httpSecurityOAuth2ResourceServerConfigurer
.jwt(Customizer.withDefaults()));

return httpSecurity.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.oauth2.jwt.ReactiveJwtDecoder;
Expand All @@ -21,12 +22,10 @@ public class SecurityConfig {
@Bean
public SecurityWebFilterChain configure(ServerHttpSecurity http) {

http.cors()
.and().csrf().disable()
.authorizeExchange()
.anyExchange()
.permitAll()
.and().oauth2ResourceServer().jwt(jwt -> jwtDecoder());
http.cors(Customizer.withDefaults())
.csrf(ServerHttpSecurity.CsrfSpec::disable)
.authorizeExchange(authorizeExchangeSpec -> authorizeExchangeSpec.anyExchange().permitAll())
.oauth2ResourceServer(oAuth2ResourceServerSpec -> oAuth2ResourceServerSpec.jwt(jwtSpec -> jwtDecoder()));
return http.build();
}

Expand Down
25 changes: 16 additions & 9 deletions apps/tps-messaging-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ plugins {
id 'org.springframework.boot' version "3.2.1"
id 'io.spring.dependency-management' version "1.1.4"
id "jacoco"
id("org.openrewrite.rewrite") version("6.6.4")
}

test {
useJUnitPlatform()
jvmArgs '--add-opens', 'java.base/java.lang=ALL-UNNAMED'
}

rewrite {
activeRecipe("org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2")
}

jacocoTestReport {
reports {
xml.required = true
Expand All @@ -34,6 +39,7 @@ sonarqube {
}

bootJar {
duplicatesStrategy(DuplicatesStrategy.INCLUDE)
archiveFileName = "app.jar"
}

Expand Down Expand Up @@ -69,6 +75,7 @@ configurations.implementation {
}

dependencies {
rewrite("org.openrewrite.recipe:rewrite-spring:5.2.0")
implementation 'no.nav.testnav.libs:security-core'
implementation 'no.nav.testnav.libs:servlet-core'
implementation 'no.nav.testnav.libs:servlet-security'
Expand All @@ -81,16 +88,14 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'


implementation 'com.fasterxml.jackson.core:jackson-annotations'
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.ibm.mq:mq-jms-spring-boot-starter:3.0.3'
implementation 'com.ibm.icu:icu4j:72.1'

implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'javax.json.bind:javax.json.bind-api:1.0'
implementation 'javax.activation:activation:1.1.1'
implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.0'
implementation 'com.sun.xml.bind:jaxb-core:2.3.0.1'
implementation 'com.ibm.mq:mq-jms-spring-boot-starter:3.2.1'
implementation 'com.ibm.icu:icu4j:74.2'

implementation 'jakarta.xml.bind:jakarta.xml.bind-api'
implementation 'com.sun.xml.bind:jaxb-core'
implementation 'org.glassfish.jaxb:jaxb-runtime'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'

Expand All @@ -102,7 +107,7 @@ dependencies {
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'ma.glasnost.orika:orika-core:1.5.4'
implementation 'org.hibernate.validator:hibernate-validator'
implementation 'org.aspectj:aspectjweaver:1.9.7'
implementation 'org.aspectj:aspectjweaver:1.9.19'

implementation 'net.logstash.logback:logstash-logback-encoder:7.4'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'
Expand All @@ -112,4 +117,6 @@ dependencies {
implementation 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'

testImplementation "org.junit.jupiter:junit-jupiter:5.10.1"
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import no.nav.testnav.apps.tpsmessagingservice.factory.ConnectionFactoryFactory;
import org.springframework.stereotype.Service;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import java.io.StringWriter;

import static org.apache.commons.lang3.StringUtils.isBlank;
Expand All @@ -29,7 +29,7 @@ public EndringsmeldingConsumer(ConnectionFactoryFactory connectionFactoryFactory
protected String getQueueName(String queue, String miljoe) {

return isBlank(queue) ?
String.format("%s%s_%s", PREFIX_MQ_QUEUES, miljoe.toUpperCase(),
"%s%s_%s".formatted(PREFIX_MQ_QUEUES, miljoe.toUpperCase(),
XML_REQUEST_QUEUE_ENDRINGSMELDING_ALIAS) :
queue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import no.nav.testnav.apps.tpsmessagingservice.factory.ConnectionFactoryFactory;
import org.springframework.stereotype.Service;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import java.io.StringWriter;

import static org.apache.commons.lang3.StringUtils.isBlank;
Expand All @@ -28,7 +28,7 @@ public ServicerutineConsumer(ConnectionFactoryFactory connectionFactoryFactory)
protected String getQueueName(String queue, String miljoe) {

return isBlank(queue) ?
String.format("%s%s_%s", PREFIX_MQ_QUEUES, miljoe.toUpperCase(),
"%s%s_%s".formatted(PREFIX_MQ_QUEUES, miljoe.toUpperCase(),
XML_REQUEST_QUEUE_SERVICE_RUTINE_ALIAS) :
queue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.xml.bind.JAXBException;
import jakarta.xml.bind.JAXBException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public String call() throws JMSException, JmqiException {
producer.send(requestMessage);
}
} catch (JMSException e) {
log.warn(String.format("%s: %s", FEIL_KOENAVN, e.getMessage()), e);
log.warn("%s: %s".formatted(FEIL_KOENAVN, e.getMessage()), e);
return e.getMessage();
}

TextMessage responseMessage;

/* Wait for response */
String attributes = String.format("JMSCorrelationID='%s'", requestMessage.getJMSMessageID());
String attributes = "JMSCorrelationID='%s'".formatted(requestMessage.getJMSMessageID());

try (MessageConsumer consumer = session.createConsumer(responseDestination, attributes)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;

@Data
@SuperBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import javax.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlRootElement;

@Data
@SuperBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;

@Data
@SuperBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import javax.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlRootElement;

@Data
@SuperBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;

@Data
@SuperBuilder
Expand Down
Loading

0 comments on commit 8b23e17

Please sign in to comment.