AnsweredAssumed Answered

Require a method to call a URL  World_Imagery (MapServer) from client site without redirecting request to proxy.jsp file at server

Question asked by adarsh2402 on Jul 28, 2016

 

we are using proxy for token services but our web application server not having a internet connectivity because of which it is unable to call URL World_Imagery (MapServer)

 

Please suggest a method to call this URL World_Imagery (MapServer) without using proxy.jsp & other URL is (10.131.5.244:6080/arcgis/rest/services).

 

NOTE- we cannot allow internet to our hosting server for security reasons.

 

Call proxy in my javascript :-

esri.config.defaults.io.proxyUrl = "proxy.jsp";

esri.config.defaults.io.alwaysUseProxy = true; 

esriConfig.defaults.io.corsDetection = false; 

 

 

proxy.jsp :-

<%@page session="false"%>

<%@page import="java.net.*,java.io.*" %>

<%!

String[] serverUrls = {

"http://myserver.mycompany.com/arcgis/rest/services,ayn2C2iPvqjeqWoXwV6rjmr43kyo23mhIPnXz2CEiMA6rVu0xR0St8gKsd0olv8a"

"https://server.arcgisonline.com/ArcGIS/rest/services", 

  "http://10.131.4.244:6080/arcgis/rest/services,55diNsb4PSZW1pf9MDkTJ1ZGfLDUhc6rn81rg-bIszh9RRN3mi6ImwjrLzQesnI9"

};

%>

<%

try {

  String reqUrl = request.getQueryString();

  boolean allowed = false;

  String token = null;

  for(String surl : serverUrls) {

    String[] stokens = surl.split("\\s*,\\s*");

    if(reqUrl.toLowerCase().contains(stokens[0].toLowerCase())) {

      allowed = true;

      if(stokens.length >= 2 && stokens[1].length() > 0)

        token = stokens[1];

      break;

    }

  }

  if(!allowed) {

    response.setStatus(403);

    return;

  }

  if(token != null) {

    reqUrl = reqUrl + (reqUrl.indexOf("?") > -1 ? "&" : "?") + "token=" + token;

  }

  URL url = new URL(reqUrl);

  HttpURLConnection con = (HttpURLConnection)url.openConnection();

  con.setDoOutput(true);

  con.setRequestMethod(request.getMethod());

  if(request.getContentType() != null) {

   con.setRequestProperty("Content-Type", request.getContentType());

  }

  con.setRequestProperty("Referer", request.getHeader("Referer"));

  int clength = request.getContentLength();

  if(clength > 0) {

  con.setDoInput(true);

  InputStream istream = request.getInputStream();

  OutputStream os = con.getOutputStream();

  final int length = 5000;

   byte[] bytes = new byte[length];

   int bytesRead = 0;

   while ((bytesRead = istream.read(bytes, 0, length)) > 0) {

     os.write(bytes, 0, bytesRead);

   }

  }

  else {

    con.setRequestMethod("GET");

  }

  out.clear();

  out = pageContext.pushBody();

  OutputStream ostream = response.getOutputStream();

  response.setContentType(con.getContentType());

  InputStream in = con.getInputStream();

  final int length = 5000;

  byte[] bytes = new byte[length];

  int bytesRead = 0;

  while ((bytesRead = in.read(bytes, 0, length)) > 0) {

    ostream.write(bytes, 0, bytesRead);

  }

} catch(Exception e) {

  response.setStatus(500);

}

%>

Outcomes