Select to view content in your preferred language

Export Web Map Task Error: "Unable to connect to map server..."

11878
22
05-02-2012 05:53 AM
AR
by
Occasional Contributor
I receive this error anytime I try to print any base map from http://services.arcgisonline.com.

If I remove the base map from my code, it prints fine.

(From Firebug console:)
"Error executing tool.: Layer "layer0": Unable to connect to map server at http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer. Failed to execute (Export Web Map). Failed to execute (Export Web Map Task)."

I get a gut-feeling it has something to do with my server's proxy, but I'm not sure.

Any thoughts?

Here is the proxy I'm using:

<%@page session="false"%>
<%@page import="java.net.*,java.io.*" %>
<%!
String[] serverUrls = {
  //"<url>[,<token>]"
  //For ex. (secured server): "http://myserver.mycompany.com/arcgis/rest/services,ayn2C2iPvqjeqWoXwV6rjmr43kyo23mhIPnXz2CEiMA6rVu0xR0St8gKsd0olv8a"
  //For ex. (non-secured server): "http://sampleserver1.arcgisonline.com/arcgis/rest/services"
  "http://sampleserver1.arcgisonline.com/arcgis/rest/services",
  "http://***/arcgis/rest/services, username=***",// username=***
  "http://server.arcgisonline.com/ArcGIS/rest/services",
  "http://***/ArcGIS/rest/services, username=***&password=***",
  "http://servicesbeta4.esri.com/arcgis/rest/services/",
  "http://sampleserver2.arcgisonline.com/arcgis/rest/services" 
};
%>
<%
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);
}
%>


22 Replies
KyleDixon
Deactivated User
Desktop is installed and I can access server.arcgisonline from ArcCatalog and a web browser.

In ArcCatalog: Customize... Arccatalog Options... Connections the proxy URL and Port is displayed correctly. The error in the server log (below) suggests it is not using the proxy setting to access AGOL.

Layer "layer0":  Unable to connect to map server at http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer
Cannot connect to this server.
Failed to execute (Export Web Map).
0 Kudos
RandallWilliams
Esri Regular Contributor
This issue can be addressed by ensuring the service account that ArcGIS Server runs under could access ArcGISOnline through the network proxy. See:

Using a proxy server to connect to the Internet
http://resourcesbeta.arcgis.com/en/help/main/10.1/index.html#/Using_a_proxy_server_to_connect_to_the...

In this case, it looks like the print task runs server side, so the basemap layers had to be accessible by ArcGIS Server.

~r
0 Kudos
SharonGin1
Occasional Contributor
I'm getting the exact same error with the export web map function. We have implemented an intranet flex web application on ArcGIS Server for .Net 10.1. We're using 4.6 SDK and Viewer 3.0. We get this error message when we try to run the print widget and the map service which the error message points to is our basemap cached map service.

The architecture is a reverse proxy, so the web app code actually resides on the ArcGIS server. The web server forwards the request to the app server. We have also installed Web Adaptor on our arcgis server.

What could be causing this error message?
0 Kudos
AndyLarkin1
Emerging Contributor
Hello, how you resolved this problem?
0 Kudos
SharonGin1
Occasional Contributor
We did figure it out eventually. We realised that we had to point the domain name to the GIS server's IP address in the host file of the GIS server. We do that by adding 1 line in the host file which contained the GIS server IP address and space, followed by the domain url.
0 Kudos
AndyLarkin1
Emerging Contributor
Thanx, May you show your host file, please
I configurated my host file C:\WINDOWS\system32\drivers\etc\hosts
127.0.0.1       localhost
172.20.12.21    oiv.gis....ru
but in total i get local address http://hv-ogv-app:6080/arcgis/rest/directories/arcgisoutput/Print/PrintingServices_GPServer/_ags_d51...
0 Kudos
SharonGin1
Occasional Contributor
I'm not able to show my host file as there is sensitive information. but from what you provided, the entry of your host file should look like this

172.20.12.21 hv-ogv-app

Just to confirm the info, could you provide the rest link to your map service which throws this error?
0 Kudos
AndyLarkin1
Emerging Contributor
Sample with my printing tools http://jsfiddle.net/KZvyM/
error on arcgis server log
SEVERE 15.05.2013 14:15:04 Error executing tool. Print/PrintingServices.GPServer
SEVERE 15.05.2013 14:15:04 Layer "Ocean_Basemap_5301": Unable to connect to map server at http://services.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer. Layer "LOJIC_LandRecords_Louisville_3326": Unable to connect to map server at http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/M.... Failed to execute (ExportWebMap). Failed to execute (Export Web Map). Print/PrintingServices.GPServer
0 Kudos
KyleDixon
Deactivated User
I was able to resolve the issue by logging in as agsadmin, the service account running the server then attempt to access arcgisonline via browser. Turns out, in our domain, service accounts aren't configured to be able to access the internet. All I had to do was open internet options and fill in proxy information.
AndyLarkin1
Emerging Contributor
thanx,
may show to your service?
0 Kudos