Solved! Go to Solution.
Not sure if you've seen it, but there is a help topic in the server help that talks about "Printing maps that contain secured services":
http://resources.arcgis.com/en/help/main/10.2/index.html#/Printing_maps_that_contain_secured_service...
if (ioArgs && ioArgs.content && ioArgs.content.Web_Map_as_JSON) { var webmapJson = dojo.fromJson(ioArgs.content.Web_Map_as_JSON); if (webmapJson.operationalLayers.length) { arrayUtils.forEach(webmapJson.operationalLayers, function (lyr) { if (lyr.url) { try { var reString = '[a-z]+.myserver.com'; var re = new RegExp(reString, "g"); var newUrl = lyr.url.replace(re, 'someservername'); lyr.url = newUrl; } catch (e) { console.log(e); } } }, this); ioArgs.content.Web_Map_as_JSON = dojo.toJson(webmapJson); } }
...Both of those are awfully complex workarounds for something that REALLY should be a part of the platform.
I really hope somebody has been able to use the JSAPI's PrintTask to print a layer from a secured service.
Not sure if you've seen it, but there is a help topic in the server help that talks about "Printing maps that contain secured services":
http://resources.arcgis.com/en/help/main/10.2/index.html#/Printing_maps_that_contain_secured_service...
if (ioArgs && ioArgs.content && ioArgs.content.Web_Map_as_JSON) { var webmapJson = dojo.fromJson(ioArgs.content.Web_Map_as_JSON); if (webmapJson.operationalLayers.length) { arrayUtils.forEach(webmapJson.operationalLayers, function (lyr) { if (lyr.url) { try { var reString = '[a-z]+.myserver.com'; var re = new RegExp(reString, "g"); var newUrl = lyr.url.replace(re, 'someservername'); lyr.url = newUrl; } catch (e) { console.log(e); } } }, this); ioArgs.content.Web_Map_as_JSON = dojo.toJson(webmapJson); } }
Thanks for that link, Bjorn. I had seen that before, I went through it, and that's what got me rolling in the beginning. But, my secured services were still not working.
After your suggestion, I went back to the help, and banged my head to see what was wrong. The problem was the connections that I was using to connect to the secured services. Get ready for it...
The URL for the connection must precisely match the URL in the webmap json.
Duh? Yes, but in our case, we are using subdomains. So, if the connection is set to http://subdomain1.myserver.com/argis but the webmap json points to a service at http://subdomain2.myserver.com/arcgis then you will not get a match. If the connection is set to http://someservername/arcgis but the webmap json points to a service at http://subdomain1.myserver.com/argis then you will not get a match.
Since we have about 100 subdomains, it's impractical to create 100 connection in ArcCatalog for the Print toolbox. My solution was to create the connection with the server name like http://someservername/arcgis. Then, add a preRequestCallback that changed any subdomain to the server name:if (ioArgs && ioArgs.content && ioArgs.content.Web_Map_as_JSON) { var webmapJson = dojo.fromJson(ioArgs.content.Web_Map_as_JSON); if (webmapJson.operationalLayers.length) { arrayUtils.forEach(webmapJson.operationalLayers, function (lyr) { if (lyr.url) { try { var reString = '[a-z]+.myserver.com'; var re = new RegExp(reString, "g"); var newUrl = lyr.url.replace(re, 'someservername'); lyr.url = newUrl; } catch (e) { console.log(e); } } }, this); ioArgs.content.Web_Map_as_JSON = dojo.toJson(webmapJson); } }
I ran into this same problem using the new JS API resource proxy. Currently, the proxy does not support wildcard subdomains. So, I had to create an entry for each subdomain in the proxy config. That wasn't a big deal for a text file, but much harder in ArcCatalog. So, wildcard subdomains would a nice addition here, too.
I've created a basic proxy that will insert tokens into the webmap_as_json request parameter. It's using NancyFx and the code is on GitHub if you want to take a look.