Skip to content

Commit ac3476f

Browse files
committed
Fix some WebFluxClient deprecations
The rest `.exchange()` usages require significant code overhaul
1 parent 272497d commit ac3476f

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/main/kotlin/io/spring/github/api/WebClientGitHubApi.kt

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package io.spring.github.api
1818

1919
import org.springframework.http.HttpHeaders
2020
import org.springframework.http.HttpStatus
21-
import org.springframework.stereotype.Component
2221
import org.springframework.web.reactive.function.client.ClientResponse
2322
import org.springframework.web.reactive.function.client.WebClient
2423
import org.springframework.web.reactive.function.client.bodyToFlux
@@ -28,7 +27,6 @@ import reactor.core.publisher.Flux
2827
import reactor.core.publisher.Mono
2928
import java.io.ByteArrayInputStream
3029
import java.io.InputStream
31-
import java.lang.IllegalStateException
3230
import java.lang.RuntimeException
3331
import java.net.URI
3432
import java.util.*
@@ -65,8 +63,7 @@ class WebClientGitHubApi(val webClient: WebClient = WebClient.create(), val base
6563
return webClient.get()
6664
.uri("$baseGitHubUrl/teams/$teamId/memberships/$username")
6765
.headers { h -> h.setBearerAuth(accessToken) }
68-
.exchange()
69-
.flatMap { response ->
66+
.exchangeToMono { response ->
7067
val status = response.statusCode()
7168
if (status == HttpStatus.OK) {
7269
Mono.just(true)
@@ -94,9 +91,8 @@ class WebClientGitHubApi(val webClient: WebClient = WebClient.create(), val base
9491
.toUri()
9592
return webClient.patch()
9693
.uri(uri)
97-
.syncBody(body)
98-
.exchange()
99-
.flatMap { clientResponse ->
94+
.bodyValue(body)
95+
.exchangeToMono { clientResponse ->
10096
val status = clientResponse.statusCode()
10197
if (status.is2xxSuccessful)
10298
clientResponse.bodyToMono<String>()
@@ -117,9 +113,8 @@ class WebClientGitHubApi(val webClient: WebClient = WebClient.create(), val base
117113
.toUri()
118114
return webClient.post()
119115
.uri(uri)
120-
.syncBody(mapOf(Pair("body", comment)))
121-
.exchange()
122-
.flatMap { clientResponse ->
116+
.bodyValue(mapOf(Pair("body", comment)))
117+
.exchangeToMono { clientResponse ->
123118
val status = clientResponse.statusCode()
124119
if (status.is2xxSuccessful)
125120
clientResponse.bodyToMono<String>()
@@ -172,8 +167,7 @@ class WebClientGitHubApi(val webClient: WebClient = WebClient.create(), val base
172167
.toUri()
173168
return webClient.get()
174169
.uri(uri)
175-
.exchange()
176-
.flatMap { clientResponse ->
170+
.exchangeToMono { clientResponse ->
177171
val status = clientResponse.statusCode()
178172
if (status.is2xxSuccessful)
179173
clientResponse.bodyToMono<GithubContents>()
@@ -192,9 +186,8 @@ class WebClientGitHubApi(val webClient: WebClient = WebClient.create(), val base
192186
.toUri()
193187
return webClient.post()
194188
.uri(uri)
195-
.syncBody(issue)
196-
.exchange()
197-
.flatMap { clientResponse ->
189+
.bodyValue(issue)
190+
.exchangeToMono { clientResponse ->
198191
val status = clientResponse.statusCode()
199192
if (status.is2xxSuccessful)
200193
clientResponse.bodyToMono<CreateIssueResponse>().map { r -> r.number }
@@ -211,8 +204,7 @@ class WebClientGitHubApi(val webClient: WebClient = WebClient.create(), val base
211204
.toUri()
212205
return webClient.get()
213206
.uri(uri)
214-
.exchange()
215-
.flatMap { clientResponse ->
207+
.exchangeToMono { clientResponse ->
216208
val status = clientResponse.statusCode()
217209
if (status.is2xxSuccessful)
218210
clientResponse.bodyToMono<Issue>()

src/main/kotlin/io/spring/github/event/DefaultBackportService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,11 +24,11 @@ import reactor.core.publisher.Mono
2424
import java.util.*
2525
import javax.xml.parsers.DocumentBuilderFactory
2626
import javax.xml.xpath.XPath
27-
import javax.xml.xpath.XPathConstants
2827
import javax.xml.xpath.XPathFactory
2928

3029
/**
3130
* @author Rob Winch
31+
* @author Artem Bilan
3232
*/
3333
@Component
3434
class DefaultBackportService(val github: GitHubApi) : BackportService {

0 commit comments

Comments
 (0)