Issue
I want to send link Request Parameters in Spring WebClient request link. For example:
https://www.test.com/notification?con=41280440000097&sec=1232
WebClient client;
Map<String, String> map = new HashMap<>();
public Mono<Response> execute(Transaction transaction) {
map.put("some_key", "some_value");
Mono<PaymentTransaction> transactionMono = Mono.just(transaction);
return client.post().uri("/notification", token)
.accept(MediaType.APPLICATION_XML)
.contentType(MediaType.APPLICATION_XML)
.body(transactionMono, Transaction.class)
.attributes(Consumer<map>)
.retrieve()
.bodyToMono(Response.class);
}
But when I try to set the map I get Syntax error on token ">"
, Expression expected after this
What is the proper way to implement this without hardcoding the values into the address?
Solution
Does this work?
public Mono<PaymentResponse> execute(PaymentTransaction transaction, WebClient client) {
long conn = 1L;
int sec = 1232;
Mono<PaymentTransaction> transactionMono = Mono.just(transaction);
return client.post()
.uri(uriBuilder -> uriBuilder.scheme("https").host("www.test.com")
.path("notification")
.queryParam("con", conn)
.queryParam("sec", sec)
.build())
.accept(MediaType.APPLICATION_XML)
.contentType(MediaType.APPLICATION_XML)
.body(transactionMono, PaymentTransaction.class)
.retrieve()
.bodyToMono(PaymentResponse.class);
}
Answered By - Munish Chandel
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)