Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3630

To develop scheduling rest client

$
0
0

I am trying to develop scheduling rest client.The task is:

  1. There is Rest API
  2. I would like to send GET requests on schedule

I created the Spring boot application:

import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class IntegrationApplication {    public static void main(String[] args) throws IOException {        SpringApplication.run(IntegrationApplication.class, args);    }}

I created the scheduler config:

import org.springframework.context.annotation.Configuration;import org.springframework.scheduling.annotation.EnableAsync;import org.springframework.scheduling.annotation.EnableScheduling;import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;@Configuration@EnableScheduling@EnableAsync@ConditionalOnProperty(name = "scheduler.enabled", matchIfMissing = true)public class SchedulerConfig { }

I created java class which send requests to rest API:

import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Component;@Servicepublic class GetAllData {    @Value("${server.url}")    private String serverUrl;    @Value("${security.oauth2.client.clientSecret}")    private String clientSecret;    private static RestClientGetExecute restClientGetExecute;    public void get() {        // Do send request     }}

Finally, I created java class which initiates request sending, as I am expecting:

import org.springframework.scheduling.annotation.Scheduled;import org.springframework.stereotype.Component;import java.time.ZonedDateTime;@Componentpublic class TestEngine {    private static GetAllData getAllData;    @Scheduled(fixedDelay = 2000)    public void getLocalDateTimeFixedDelay() throws InterruptedException {        getAllData.get();    }}

But it doesn't work. The error is:

java.lang.NullPointerException: Cannot invoke GetAllData.get()" because "TestEngine.getAllData" is null

Could you help me please to find out how to run schedule sending requests to REST API?


Viewing all articles
Browse latest Browse all 3630

Trending Articles