Select to view content in your preferred language

Unusual Problem with Print Widget

1511
10
Jump to solution
05-09-2013 12:00 PM
DanielTrone
Deactivated User
I have a small problem in my code, but it is resulting in a big headache.

I am using the Print Widget (w/ a proxy).  If you press the button once, a couple of errors are thrown (in Firebug), and the process fails.  However, the next time the button is pressed (and forever after), it works.

Interestingly enough, if you don't select a layer in the dropdown, the print process will work the first time.

I have stripped down the code to the bare minimum to illustrate the problem.  I would be thankful for any suggestions.

http://jsfiddle.net/DanielTrone/zjNjx/
0 Kudos
1 Solution

Accepted Solutions
JianHuang
Deactivated User
As John pointed out, it fails when it goes through proxy. Please check the proxy is valid.
The first time, it has to go through proxy because it doesn't know if it's CORS supported.

View solution in original post

0 Kudos
10 Replies
JohnGravois
Deactivated User
are you seeing an identity manager prompt when the first call fails?  i am.

i still don't understand why, but it is the calls that go through the proxy specifically that are failing.  for some reason the second request is executed as a POST (across domains, without a proxy) even in IE (which doesn't support CORS).

when you don't have a census layer in the map, the request is short enough to send as a GET, so the proxy is never utilized.
0 Kudos
JohnGravois
Deactivated User
the same error is not reproducible when you use http://servicesbeta2.esri.com/arcgis/rest/services/Utilities...

strange.

i tested with my own proxy (which fails in your sample app, and I couldn't reproduce the error directly from REST with sampleserver6
0 Kudos
JianHuang
Deactivated User
As John pointed out, it fails when it goes through proxy. Please check the proxy is valid.
The first time, it has to go through proxy because it doesn't know if it's CORS supported.
0 Kudos
JohnGravois
Deactivated User
that makes a lot of sense Jian.  i added the following line of code to identify sampleserver6 as supporting CORS and no longer see a problem

esri.config.defaults.io.corsEnabledServers.push("sampleserver6.arcgisonline.com");


i was confused initially about the CORS support in IE, but i just realized i upgraded to 10, where CORS is finally fully supported!

i still don't understand why the proxy is failing for that particular server though...
0 Kudos
DanielTrone
Deactivated User
Thanks for looking into this.  I'm not an advanced programmer, and dealing with proxy pages is definitely new to me. 

If this is only now working due to CORS, I'm guessing I still need to fix my proxy file to support older browsers.

I got the proxy from here: http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jshelp_start.htm#jshelp/...  (The PHP version).

I looked through the proxy instructions (in the file) and checked my configuration locally (where it also fails), and everything was already set correctly. (I don't have any control over the settings on the public servers).  I am curious about the $mustMatch variable, and the allowed serverUrls:

  $serverUrls = array(
    array( 'url' => 'http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/', 'matchAll' => true, 'token' => '' ),
    array( 'url' => 'http://sampleserver2.arcgisonline.com/ArcGIS/rest/services/', 'matchAll' => true, 'token' => '' ),
    array( 'url' => 'http://sampleserver1a.arcgisonline.com/arcgisoutput/',        'matchAll' => true, 'token' => '' ),
    array( 'url' => 'http://sampleserver1b.arcgisonline.com/arcgisoutput/',        'matchAll' => true, 'token' => '' ),
    array( 'url' => 'http://sampleserver1c.arcgisonline.com/arcgisoutput/',        'matchAll' => true, 'token' => '' )
  );

I've set $mustMatch to false and true, but it doesn't seem to make a difference either way (though I may need to clear my cache to know for certain).

I'm going to try messing with the proxy code, maybe adding a line such as this could be the solution :

    array( 'url' => 'http://sampleserver6.arcgisonline.com/ArcGIS/rest/services/', 'matchAll' => true, 'token' => '' ),


Thanks for all your help so far.  Please chime in again if you can think of anything that might help.
0 Kudos
JohnGravois
Deactivated User
its failing with my ASP.NET proxy as well, so i don't think the problem is your proxy, but rather the server.  Why not just point at the print service on servicesbeta2.esri.com instead?  i didn't see any errors there, even when using my proxy.
0 Kudos
DanielTrone
Deactivated User
Simple enough.  Thanks again for your help!
0 Kudos
JohnGravois
Deactivated User
finally solved the problem with my own proxy by removing an old invalid token which was stored in the proxy.config.  probably not the same thing causing your problems though....
0 Kudos
DanielTrone
Deactivated User
It was my proxy.  Adding the proper servers to my 'Whitelist' was the solution.
0 Kudos