Google Maps - AEM Servlet
I have a doGet servlet which has rest call for Google map. Its, working as expected in my local instance, but when it goes to dev environment the servlet is keep on loading and after 1or 2 minutes its responding 200 status with no results. I have verified the cross origin, referrer filter & csrf filter and seems okay. There is no error's in logs too. Also, checked this configuration https://taylor.callsen.me/security-and-java-servlets-in-aem-6-1/ and nothing suspicious. Below is my full code,
@8220494(service = { Servlet.class })
@ServiceDescription("Google Geo Code API Servlet")
@SlingServletPaths("/bin/project/googlemap")
public class GoogleGeoCodeApiServlet extends BaseServlet {
private static final long serialVersionUID = -3445319565752648418L;
private static final Logger LOGGER = LoggerFactory.getLogger(GoogleGeoCodeApiServlet.class);
@3214626
private APIService apiService;
@9944223
protected void doGet (final SlingHttpServletRequest request,
final SlingHttpServletResponse response) {
try {
LOGGER.info("== Inside GoogleGeoCodeApiServlet ==");
String cords = request.getParameter("latlng");
String lang = request.getParameter("language");
String sensor = request.getParameter("sensor");
String url = https://xx.xx.xx.xx/bin/project/googlemap?language=en&latlng=24.538797297972213,46.49644320266542&sensor=false&lang=en
URL requestUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) requestUrl.openConnection();
conn.setRequestMethod(HttpConstants.METHOD_GET);
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
String res = new BufferedReader(new InputStreamReader(conn.getInputStream())).lines().collect(Collectors.joining());
Gson gson = new Gson();
JsonObject json = gson.fromJson( res, JsonObject.class);
response.setContentType("application/json;charset=UTF-8");
response.getWriter().write(json.toString());
conn.disconnect();
} catch (Exception e) {
LOGGER.error("== Error in GoogleGeoCodeApiServlet ==", e);
}
}
}
Can someone please let me know what's wrong here?
Regards,
Vijay