'Is there a reason why, when my resource path is called it doesn't run the storeJson method

Below is an example of my code the resource GETS json from the random.org api and store it as a an object. I want the json to be cached temporarily am i on the right track? Any advice would help. Thank you in advance !

'''

@GET
    @Produces(MediaType.APPLICATION_JSON)
    public RandomCls getJson() throws IOException {
        GenerateRandom run = new GenerateRandom();
        RandomCls random = new RandomCls();
        
        Gson gson = new Gson();
        URL test = new URL("https://www.random.org/integers/?num=1&min=1&max=1000&col=1&base=10&format=plain&rnd=new");//https://www.random.org/sequences/?min=1&max=52&format=plain&rnd=new
        URL test2 = new URL("https://www.random.org/sequences/?min=1&max=52&format=plain&rnd=new");
        HttpURLConnection con = (HttpURLConnection) test.openConnection();
        con.setRequestMethod("GET");
    
        BufferedReader br = null;
        String jsonString = null;
        
        
        if (con.getResponseCode() == 200) {
        
            
        br = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String strCurrentLine;
        int tempid = 0;
        
            while (((strCurrentLine = br.readLine()) != null )) {
                
                tempid = Integer.parseInt(strCurrentLine);
            }
            random.setRandomid(tempid);
            run.storeJson(random);
            br.close();
            } 
        
        else {
            
        br = new BufferedReader(new InputStreamReader(con.getErrorStream()));
        String strCurrentLine;
       
        
            while (((strCurrentLine = br.readLine()) != null )) {
                
                int tempid = Integer.parseInt(strCurrentLine);
                
           }  br.close();        
        }
        
     
    return random; 
    }
    '''

The method below is what i want to carry out in order to save the json in a file.

   ''' 
    public void storeJson(RandomCls r) throws IOException{
      GsonBuilder builder = new GsonBuilder(); 
      Gson gson = builder.create(); 
      FileWriter writer = new FileWriter("random.json");   
      writer.write(gson.toJson(r));   
      writer.close();
    
    }
'''


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source