我正在尝试使用RestTemplate使用rest api并将其保存在RxJava中。
@Scheduled(cron = "0 */5 11-14 * * SUN-THU", zone = "Asia/Kolkata")
public void getAndSaveData() throws ParseException {
RestTemplate restTemplate = new RestTemplate();
String date = CurrentDate.getSimpleDate();
boolean holiday = holidayController.isThisDayHoliday(date);
if (!holiday) {
Observable.just(restTemplate).observeOn(Schedulers.io()).subscribeOn(Schedulers.newThread()).unsubscribeOn(Schedulers.io()).subscribe(new Observer<RestTemplate>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(RestTemplate template) {
System.out.println("saving to database ");
HolidayData holidayData = template.getForObject(Constants.Holiday_API,
HolidayData.class); //getting the error here.
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onComplete() {
}
});
}
}
Rest Api运行正常,但是当Cron运行此方法时。我得到
io.reactivex.exceptions.UndeliverableException: org.springframework.web.client.HttpClientErrorException: 424 null
这指向注释中上面提到的类似内容。
我在这里做错了什么?任何帮助,将不胜感激。谢谢