Hej,
próbuję wysłać sms z użyciem tego serwisu https://dev.serwersms.pl/https-api-v2/wprowadzenie
stworzyłem takiego Beana aby nie tworzyć ciągle nowego WebClienta
@Configuration
public class WebClientConfiguration {
@Bean
public WebClient.Builder getWebClientBuilder() {
return WebClient.builder();
}
}
na razie taki zaczątek serwisu
@Service
public class SmsService {
@Autowired
private WebClient.Builder webClientBuilder;
private static String URI = "https://api2.serwersms.pl/messages/send_sms";
public SmsResponseDto send(String phone) {
SmsGateway smsGateway = new SmsGateway();
smsGateway.setLogin("mojUser");
smsGateway.setHaslo("mojeHaslo");
smsGateway.setNadawca("nadawcaTekst");
smsGateway.setNumer(phone);
smsGateway.setWiadomosc("this is the test message");
return webClientBuilder.build()
.post()
.uri(URI)
.contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromValue(smsGateway))
.retrieve()
.bodyToMono(SmsResponseDto.class)
.retryWhen(Retry.fixedDelay(2, Duration.ofMillis(100)))
.block();
}
a tak wygląda smsGateway
@Data
public class SmsGateway {
@JsonProperty
String login;
@JsonProperty
String haslo;
@JsonProperty
String nadawca;
@JsonProperty
String wiadomosc;
@JsonProperty
String numer;
}
skrypt działa ok 3 sekund. Brak błędów w konsoli. Brak sms.
Chcialbym użyć WebClient - na internetach doczytałem, że restTemplate zniknie i rekomendują WebClient.