Re-write usage of Spring WebClient from Java to Scala

40 views Asked by At

I am using IntelliJ with Maven as Build Tool. In my project there is a mix of Scala (2.13) and Java (11) sources. Now I am trying to re-write the following Snippet from Java to Scala:


import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.reactive.function.client.WebClient;
//...

 String response = webClient
            .get()
            .uri(uri)
            .accept(MediaType.APPLICATION_JSON)
            .retrieve()
            .onStatus(HttpStatus::isError, clientResponse -> {
              logger.error("...");
              return Mono.error(new HttpClientErrorException(clientResponse.statusCode()));
            })
            .bodyToMono(String.class)
            .block();

Facing troubles, as in Scala, IntelliJ can't resolve the accept-Method call, as it doesn't recognize the return-Value of the uri-Method... So far it looks like this:


    val response: String = webClient
      .get()
      .uri(uri)
      .accept(MediaType.APPLICATION_JSON) // Cannot resolve symbol accept
      .retrieve()
      .onStatus(s => s.isError() // Cannot resolve symbol isError
    , clientResponse => {
        logger.error("...")
        Mono.error(new HttpClientErrorException(clientResponse.statusCode())) //Cannot resolve symbol statusCode
      })
      .bodyToMono(classOf[String])
      .block()

What is the reason, the IDE can't resolve the symbols? Whenever I use mvn compile, it works fine, so I assume it's an IDE setup issue.

Thanks for your input :)

0

There are 0 answers