2013-08-27 4 views
0

MapQuest REST API를 통해 지오 코딩을 사용하여 위도/경도 좌표 집합의 주소를 가져 오려고합니다. 이 데이터를 가져 오기 위해 서버 쪽에서 Jersey 클라이언트를 사용하고 있습니다.MapQuest 요청시 저지 클라이언트가 응답하지 않음

GET이 실행될 때 어떤 이유로 인해 절대로 반환되지 않고 결국 시간 초과됩니다. 처음에 나는 존재하지도 않은 어떤 자료에 접근하려고 노력하고 있다고 생각했습니다. 그러나 액세스하는 리소스의 문자열 값을 브라우저 창에 붙여 넣으면 지정한 좌표에 대해 올바른 JSON이 반환됩니다. 내 기록에 문제가 될 수있는 점을 지적하지 않습니다.

private void getLocation(UserTemplate template) throws ConnectException 
{  
    double lon = template.getLocation().getCoordinates()[0]; 
    double lat = template.getLocation().getCoordinates()[1]; 

    Client c = Client.create(); 
    WebResource resource = c.resource(Adapter.geocodeUrl + "?key=" + 
     Adapter.mapquestKey + "&location=" + lat + "," + lon); 

    ClientResponse response = 
     resource.accept(MediaType.APPLICATION_JSON) 
     .type(MediaType.APPLICATION_JSON) 
     .get(ClientResponse.class); 
} 

왜이 타이밍이 밖으로 :

여기 내 코드입니까?

도움이 될 것입니다.

답변

0

가 시간 초과 이유는 모르겠지만, 나는 WebResource보다는 WebTarget를 사용하여 성공을 거두었 :

Client client = ClientBuilder.newClient(); 

WebTarget target = client.target("http://open.mapquestapi.com/elevation/v1/profile" 
     + "?key=" + MAPQUEST_API_KEY + "&latLngCollection=" + "39.74012,-104.9849,39.7995,-105.7237,39.6404,-106.3736"); 

Invocation.Builder invocationBuilder = 
     target.request(MediaType.APPLICATION_JSON_TYPE); 
Response response = 
     invocationBuilder.get(); 
System.out.println(response.getStatus()); 
System.out.println(response.readEntity(String.class)); 

당신이 당신의 문제에 대한 해결책을 찾았나요?