Ошибка Connection TimeOut через java.net

Вот часть кода. Дело в том, что, если напрямую в браузере забить URL https://maps.googleapis.com/maps/api/geocode/json?latlng="+lat+","+lng+"&key=mykey , то все открывается ( грузятся данные в JSON формате). А если тот же URL получить через класс Coordinate, то Coonnection time out выдает. URL абсолютно тот же самый , через дебаг проверил.

package RestExample.MainPack.Controller;

import RestExample.MainPack.model.Coordinate;
import RestExample.MainPack.repos.SalesPointRepos;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;

@RestController
public class GreetingController {

    @Autowired
    SalesPointRepos salesPointRepos;



    @GetMapping(value = "/salespoints")
    @ResponseBody
    public String greeting( @RequestParam(required = false) String lat, @RequestParam(required = false) String lng ) throws IOException {


      if(lat==null || lng==null){

          return "Hello, please  fill parameters latitude and longtitude";

      }

        Coordinate coordinate= new Coordinate(Double.parseDouble(lat),Double.parseDouble(lng));
        String inline="";
        URL newURL= new URL(coordinate.getURL());
        HttpURLConnection conn=(HttpURLConnection) newURL.openConnection();
        conn.setRequestMethod("GET");
        conn.connect();
        int responseCode=conn.getResponseCode();
        if (responseCode!=200){
            throw  new RuntimeException("HttpResponseCode: "+responseCode);
        }
        else {
            Scanner sc=new Scanner(newURL.openStream());
            while (sc.hasNext()){
                inline+=sc.nextLine();
            }
            sc.close();
        }

        JSONObject jsonObject= new JSONObject(inline);
        JSONObject object= jsonObject.getJSONObject("plus_code");

        return  object.toString();

    }
}

Здесь получаем URL

package RestExample.MainPack.model;

public class Coordinate {


    private double  lat;
    private double  lng;

    public Coordinate(double lat, double lng ){
        this.lat=lat;
        this.lng=lng;

    }

    public double getLat() {
        return lat;
    }

    public void setLat(double lat) {
        this.lat = lat;
    }

    public double getLng() {
        return lng;
    }

    public void setLng(double lng) {
        this.lng = lng;
    }



    public String getURL() {
        return "https://maps.googleapis.com/maps/api/geocode/json?latlng="+lat+","+lng+"&key=mykey" ;
    }
}

На скриншоте видно, что формируется точно такой же URL, что я вводил вручную, но проблема сохраняется. Ниже скрин дебага.

Скрин дебага

введите сюда описание изображения


Ответы (0 шт):