Select to view content in your preferred language

Printing Secured Service

2674
4
02-12-2013 12:18 PM
JillianStanford
Frequent Contributor
Hi,
I haven't seen a satisfactory answer to this issue but maybe somebody has some fresh ideas.

I have some secured services hosted in Server 10.1 that use long term tokens. In order to facilitate printing I published a custom Export Web Map tool according to these instructions - Printing maps that contain secured services .

I can successfully use this custom service to print map containing all unsecured layers but as soon as I add a layer from the secured service I get: {"error":{"code":400,"message":"Unable to complete operation.","details":["Error executing tool."]}}.

If I paste all of the same parameters into the REST Service Directory interface I receive the same error, so I don't think it's a problem with the proxy page.

Here is the content of the Web_Map_as_JSON parameter:
{"mapOptions":{"showAttribution":true,"extent":{"xmin":-13074789.94993775,"ymin":4015647.8563408996,"xmax":-13073490.52045701,"ymax":4016726.33503677,"spatialReference":{"wkid":102100}},"spatialReference":{"wkid":102100}},"operationalLayers":[{"id":"layer0","title":"layer0","opacity":1,"minScale":591657527.591555,"maxScale":1128.497176,"url":"http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"},{"id":"layer2","title":"layer2","opacity":1,"minScale":0,"maxScale":0,"url":"http://ec2-54-243-148-157.compute-1.amazonaws.com/be/rest/services/v2/BERides/MapServer?token=MY_TOK...","visibleLayers":null,"layers":[]},{"id":"layer1","title":"layer1","opacity":1,"minScale":591657527.591555,"maxScale":1128.497176,"url":"http://services.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServe..."}],"exportOptions":{"outputSize":[800,1100],"dpi":96}}

I'm using the same token to add the layers to the map and am having no display problems.

Not sure what to troubleshoot next. Any ideas?

Thanks!
0 Kudos
4 Replies
ChetEgbert
New Contributor
I am experiencing the same issue described here.  Has a solution been supplied?  Thanks.
0 Kudos
MattLane
Frequent Contributor
I tackled this issue earlier and hope my solution applies here. The source of the issue is the long-term token. When you add the layer to the map like so:
map.addLayer(new esri.layers.ArcGISDynamicMapServiceLayer("http://ec2-54-243-148-157.compute-1.amazonaws.com/be/rest/services/v2/BERides/MapServer?token=MY_TOKEN_GOES_HERE"));

the token is passed in the URL. BUT, that token is only good from the referral URL. You'll see that the token is in the URL in the webmap_as_json request. The server that the printservice is on can not access that url with that token because it is not that 'referrer'.

What I did was strip the token from the webmap_as_json before it goes to the server. There may be a more elegant way, and I'm open to improvements.
//This goes in the original map initialization function
esri.setRequestPreCallback(function (e) {
  if (e.content && e.content.Web_Map_as_JSON) {
    e.content.Web_Map_as_JSON = e.content.Web_Map_as_JSON.replace(/\?token\=MY_TOKEN_GOES_HERE/g, "")
  }
  return e;
});
0 Kudos
MattLane
Frequent Contributor
Oh, and if you try that code, make sure you escape any special characters in your token with a \. Regular expressions information.
0 Kudos
gpei_ahuang
Emerging Contributor

Are you using enterprise or just ArcGIS server to do your user management? Depends on which one there, there is a generateToken service that you can use to create a short-term token.

Use a POST request and use the referral to create a token for the specific secure service that requires it.

Than in your operational layer definition, add a <token> parameter with the generate token as it's value.

You can find the specific JSON format how of to incorporate tokens into the operationalLayer in the ExportWebMap specification—ArcGIS Server
https://enterprise.arcgis.com/en/server/latest/publish-services/windows/exportwebmap-specification.h...

0 Kudos