0

I just executed the below script :

import io.restassured.RestAssured;
import static io.restassured.RestAssured.given;
public class Basics {
 public static void main(String[] args) 
 { 
  RestAssured.baseURI="https://maps.googleapis.com";
  given().
  param("location","-33.8670522,151.1957362").
  param("radius","500").
  param("types","food").
  param("key","AIzaSyDXR2YGnRu3-112ttezUsQ-T2zOkb6aafE").
  when().
  get("/maps/api/place/nearbysearch/json").then().assertThat().statusCode(200);  
 }
}

But I am getting an exception while running the script.

Exception in thread "main" java.net.UnknownHostException: maps.googleapis.com
 at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
 at java.net.InetAddress$2.lookupAllHostAddr(Unknown Source)
 at java.net.InetAddress.getAddressesFromNameService(Unknown Source)
 at java.net.InetAddress.getAllByName0(Unknown Source)
 at java.net.InetAddress.getAllByName(Unknown Source)
 at java.net.InetAddress.getAllByName(Unknown Source)
 at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
 at org.apache.http.impl.conn.DefaultClientConnectionOperator.resolveHostname(DefaultClientConnectionOperator.java:263)
 at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:162)
 at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:326)
 at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)

Could someone help me to resolve this issue ?

Baburaj V
  • 63
  • 1
  • 2
  • 12
  • do you have an internet connection? are you using a proxy or filter or firewall etc? – SteelToe Apr 04 '18 at 05:44
  • An `UnknownHostException` means that your machine cannot resolve the given hostname, `maps.googleapis.com`, to an IP address. More likely than not, it's a DNS problem. Can you do an `nslookup maps.googleapis.com` from the machine on which the application runs? This is not necessarily the machine on which you are developing. – SeverityOne Apr 04 '18 at 05:44
  • @SteelToe Yes I am working in my office machine. Proxy or filter exits – Baburaj V Apr 04 '18 at 06:29
  • @SeverityOne I just checked nslookup maps.googleapis.com and I could see Server: questgedctvm.com Address: 10.197.72.16 Name: maps.googleapis.com – Baburaj V Apr 04 '18 at 06:31

2 Answers2

3

You probably have a problem with your DNS. If you do nslookup maps.googleapis.com, you should see more or less the following:

Server:  questgedctvm.com
Address:  10.197.72.16 

Non-authoritative answer:
Name:    googleapis.l.google.com
Addresses:  2a00:1450:4002:805::200a
          216.58.205.74
          216.58.205.106
          216.58.205.138
          216.58.205.170
          216.58.205.202
          216.58.198.10
          216.58.198.42
          172.217.23.106
          216.58.205.42
Aliases:  maps.googleapis.com

If this is not what you're seeing (the actual IP addresses may differ, but you should get a bunch) then you have a DNS issue that you need to solve. It's not a Java issue.

SeverityOne
  • 2,476
  • 12
  • 25
1

I'm able to get the response from host https://maps.googleapis.com through your code.

you can launch a UNIX terminal and use the nslookup command (among others) to see if your DNS server can resolve the host name to an IP address successfully.

try $ nslookup https://maps.googleapis.com

RestAssured.baseURI = "https://maps.googleapis.com";
RequestSpecification httpRequest = given();

Response response = httpRequest.
        param("location", "-33.8670522,151.1957362").
        param("radius", "500").
        param("types", "food").
        param("key", "AIzaSyDXR2YGnRu3-112ttezUsQ-T2zOkb6aafE").
        when().
        get("/maps/api/place/nearbysearch/json"); 

System.out.println("Response Body is =>  " + response.asString());

Update

$ nslookup https://maps.googleapis.com

Server: questgedctvm.com
Address: 10.197.72.16

Non-authoritative answer:
Name:    googleapis.l.google.com
Addresses: <IP_Addresses>

Aliases:  https://maps.googleapis.com

check the IP_Address, if you are able to get the IP_Address for host https://maps.googleapis.com than everything is Okay. You can try my code and check the coming response.

eigenharsha
  • 2,051
  • 1
  • 23
  • 32