Print templates with esri.request issue

2566
16
Jump to solution
10-31-2013 08:13 AM
SaqibAmin1
New Contributor
When I use the ESRI sample Print templates with esri.request (https://developers.arcgis.com/en/javascript/jssamples/widget_print_esri_request.html), I copy the code into a local html file, the "print" button doesn't display, however when I put an alert box in line 79, this somehow causes it to work in FireFox. To make debugging easier, I have replaced the original console.log() method to alert().

Any ideas?


<!doctype html> <html>   <head>     <meta charset="utf-8">     <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">     <title></title>     <link rel="stylesheet" href="http://js.arcgis.com/3.7/js/dojo/dijit/themes/tundra/tundra.css">     <link rel="stylesheet" href="http://js.arcgis.com/3.7/js/esri/css/esri.css">     <style>       html, body { height: 100%; width: 100%; margin: 0; padding: 0; }       h3 { margin: 0 0 5px 0; border-bottom: 1px solid #444; padding: 0 0 5px 0; text-align: center; }       .shadow {         -moz-box-shadow: 0 0 5px #888;         -webkit-box-shadow: 0 0 5px #888;         box-shadow: 0 0 5px #888;       }       #map{ margin: 0; padding: 0; }       #feedback {         background: #fff;         color: #000;         position: absolute;         font-family: arial;         height: auto;         right: 20px;         margin: 5px;         padding: 10px;         top: 20px;         width: 300px;         z-index: 40;       }       #feedback a {         border-bottom: 1px solid #888;         color: #444;         text-decoration: none;       }       #feedback a:hover, #feedback a:active, #feedback a:visited {         border: none;         color: #444;         text-decoration: none;       }       #note { font-size: 80%; font-weight: 700; padding: 0 0 10px 0; }       #info { padding: 10px 0 0 0; }     </style>      <script src="http://js.arcgis.com/3.7/"></script>     <script>       var app = {};       require([         "esri/map", "esri/layers/FeatureLayer",          "esri/dijit/Print", "esri/tasks/PrintTemplate",          "esri/request", "esri/config",         "dojo/_base/array", "dojo/dom", "dojo/parser",          "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"       ], function(         Map, FeatureLayer,          Print, PrintTemplate,          esriRequest, esriConfig,         arrayUtils, dom, parser       ) {         parser.parse();          app.printUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";          esriConfig.defaults.io.proxyUrl = "/proxy";                  app.map = new esri.Map("map", {           basemap: "hybrid",           center: [-117.447, 33.906],           zoom: 17,           slider: false         });          // add graphics for pools with permits         var permitUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/PoolPermits/MapServer/1";         var poolFeatureLayer = new FeatureLayer(permitUrl, {           "mode": FeatureLayer.MODE_SNAPSHOT         });   alert("Test"); // This is Line 79 ! This will work in FireFox, after commenting out, it will break         app.map.addLayer(poolFeatureLayer);          // get print templates from the export web map task         var printInfo = esriRequest({           "url": app.printUrl,           "content": { "f": "json" }         });         printInfo.then(handlePrintInfo, handleError);          function handlePrintInfo(resp) {           var layoutTemplate, templateNames, mapOnlyIndex, templates;            layoutTemplate = arrayUtils.filter(resp.parameters, function(param, idx) {             return param.name === "Layout_Template";           });                      if ( layoutTemplate.length == 0 ) {             alert("print service parameters name for templates must be \"Layout_Template\"");             return;           }           templateNames = layoutTemplate[0].choiceList;            // remove the MAP_ONLY template then add it to the end of the list of templates            mapOnlyIndex = arrayUtils.indexOf(templateNames, "MAP_ONLY");           if ( mapOnlyIndex > -1 ) {             var mapOnly = templateNames.splice(mapOnlyIndex, mapOnlyIndex + 1)[0];             templateNames.push(mapOnly);           }                      // create a print template for each choice           templates = arrayUtils.map(templateNames, function(ch) {             var plate = new PrintTemplate();             plate.layout = plate.label = ch;             plate.format = "PDF";             plate.layoutOptions = {                "authorText": "Made by:  Esri's JS API Team",               "copyrightText": "<copyright info here>",               "legendLayers": [],                "titleText": "Pool Permits",                "scalebarUnit": "Miles"              };             return plate;           });            // create the print dijit           app.printer = new Print({             "map": app.map,             "templates": templates,             url: app.printUrl           }, dom.byId("print_button"));           app.printer.startup();         }          function handleError(err) {           alert("Something broke: ", err);         }       });     </script>   </head>    <body class="tundra">     <div data-dojo-type="dijit/layout/BorderContainer"          data-dojo-props="design:'headline',gutters:false"          style="width: 100%; height: 100%; margin: 0;">       <div id="map"            data-dojo-type="dijit/layout/ContentPane"            data-dojo-props="region:'center'">          <div id="feedback" class="shadow">           <h3>             Print Templates Created from Info Returned by the Print Service using              <a href="https://developers.arcgis.com/en/javascript/jsapi/namespace_esri.html#request">esri.request</a>           </h3>           <div id="info">             <div id="note">               Note:  This sample uses an ArcGIS Server version 10.1 export web map task.             </div>                          <!-- that will be used for the print dijit -->             <div id="print_button"></div>              <div id="info">               <a href="https://developers.arcgis.com/en/javascript/jsapi/printtemplate.html">Print templates</a> are generated                from the Export Web Map Task's <a href="http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task">Layout_Template parameter</a>. This info is retrieved from the service                using <a href="https://developers.arcgis.com/en/javascript/jsapi/namespace_esri.html#request">esri.request</a>.              </div>            </div>         </div>       </div>     </div>   </body> </html>
0 Kudos
16 Replies
DonCaviness
New Contributor III
I have tried what you have mentioned with little success.  What I usually get is "Proxy.config file does not exist at application root, or is not readable."  The proxy.config file is located in the same directory that the proxy.ashx file is located in.  What would be blocking access to this file?  I have tried hosting the proxy page in several different locations/servers and this is the consistent error.
0 Kudos
JohnGravois
Frequent Contributor
@don
tough to say.  could be a restriction set in IIS or other network specific security setting.  perhaps your IT staff can provide some insight?

my only other suggestion is to use a text editor that supports color highlighting (like Notepad++) to ensure that no problems with the XML tags in the proxy.config are keeping it from being read successfully.
0 Kudos
SaqibAmin1
New Contributor
John,

I have used your link (http://localhost/proxy/proxy.ashx?http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utiliti...) and in the attached are the results I'm getting in Chrome. I have also replaced from sampleserver6 to Task with my own print task and the same results are retrieved as the attachment.

Does this mean the proxy is defined and fully working? If so, how do I get this to work with my own site? I think more specifically my question is how do I find out which external url is the same as http://localhost/ ?

The URL I thought localhost/proxy/proxy.ashx was pointing to doesn't exist externally. Our IT people don't have a clue either!

Additionally, when I try your url (http://localhost/proxy/proxy.ashx?http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utiliti...) from my machine, the attachment is what I get, when I try your url from a "test" server, I get a 403 forbidden error and from the "live" server I get a 404 not found in the Network stats.
0 Kudos
DonCaviness
New Contributor III
@John

I reviewed the proxy.config file in notepad++ and it appears that everything looks good.  Also, I have tried to set up the proxy locally as well as on networks outside of my local network.  The error I am receiving stays consistent. Are there any tricks to setting up a proxy page to work within my application?  I have embedded the proxy in my application as  well as followed the steps laid out by Esri for setting up a proxy via IIS.
0 Kudos
JohnGravois
Frequent Contributor
@sadiq,
the url i referenced was a hypothetical example based on the location of the proxy.ashx file on my own machine.  the error you are seeing is proof that yours is stored somewhere else.

@don,
it could be any number of things.  if you know for a fact that you can log onto the web server with your own credentials and view the page in question in the browser, you might try creating a new application pool in IIS and set its identity to be you instead of the generic IIS User.  doing this has two benefits:

1. your permissions may be greater, allowing the proxy to function (and giving your IT a clearer picture of what to modify)
2. if the proxy still doesn't work, you can launch fiddler as the same user and see the actual request that the proxy is making for the resource in question.
0 Kudos
SaqibAmin1
New Contributor
Finally it is working! The proxy.ashx files was finally located and after the amendment was made in the proxy.config file, printing started to work in my project on IE, FireFox, Safari and Chrome!

Many thanks @John, @Don and @Chris for your help and contributions. 🙂

Saqib.
0 Kudos
JohnGravois
Frequent Contributor
glad to hear it Saqib.  please consider marking this thread as 'answered'.
0 Kudos