3
Good morning guys.
I’m looking to retrieve some geographic information using latitude and longitude as parameters.
To recover such information I am trying to make a request via URL through this link: Google Maps Geolocation API. It returns me an XML where I can work on it.
When creating this service on my web service, I went up to the Weblogic server under development (Running on Linux System) and it returns me the following error while running it:
java.io.FileNotFoundException: Response: '502: Bad Gateway' for url: 'http://maps.google.com/maps/api/geocode/xml?latlng=-15.8040195453225%2C-47.8799401993617'
I’ve tried several ways, but you keep making the same mistake. I’m using Google’s own code to consume the information, below:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
public class GeocodeProcessor {
private static final String GEOCODE_REQUEST_PREFIX = "http://maps.google.com/maps/api/geocode/xml";
private static final int PROXY_PORT = 3128;
private static final String PROXY_HOST = "vampre.funasa.gov";
private static final int TIMEOUT = 30000;
public static void main() throws IOException,
URISyntaxException, ParserConfigurationException, SAXException {
String urlString = null;
urlString = GEOCODE_REQUEST_PREFIX + "?latlng=" + URLEncoder.encode("-15.8040195453225,-47.8799401993617", "UTF-8");
System.out.println(urlString);
// Convert the string to a URL so we can parse it
URL url = new URL(urlString);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
PROXY_HOST, PROXY_PORT));
HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);
conn.setConnectTimeout(TIMEOUT);
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/xml");
try {
// open the connection and get results as InputSource.
conn.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(),
"UTF-8"));
String line = null;
StringBuilder ab = new StringBuilder();
while( ( line = reader.readLine() ) != null ) {
ab.append(line);
}
reader.close();
System.out.println(ab.toString());
} finally {
conn.disconnect();
}
}
}
A help would be extremely useful now. Vlw galley.
By coincidence, I am working on a project that will also need to use this API. If I can solve, I put a response.
– Victor Stafusa
It’s OK, probably your proxy or server access to the external network. Include the stack trace complete.
– Bruno César