[GIS] GeoExt and Mapfish print on other domain: can’t get how to proxy

ext-jsgeoextmapfishprinting

I have OpenLayers ProxyHost configured

OpenLayers.ProxyHost= "form/proxy?url=";

, the url config of Mapfish Print Provider is configured as http://path/to/mapfish/print, and the doc tells that I can do that as it is accessible throug the proxy

This property requires that the print service is at the same origin as the application (or accessible via proxy).

, but the lib still tries to go to other origin directly and fails.

I cannot find where to configure GeoExt or ExtJS to go there through proxy.

The Mapfish Print doc tells to set some parameter of a mapfish variable, I did that but obviously with no success.

Please, help!

(Actually, it's GeoExt 2 for ExtJS 4, where the PrintProvider seems being renamed as GeoExt.data.MapfishPrintProvider)

Best Answer

Adding the OpenLayers.ProxyHost will only proxy requests that OpenLayers itself makes and won't proxy requests from the GeoExt framework. But actually you do not need to use a proxy as you can put the request for the Print Capabilities into your page's header as a script tag like this:

<script src="http://path/to/mapfish/print/info.json?var=printCapabilities type="text/javascript"></script>

Then all you need to do in your print provider is reference the printCapabilities variable like this:

// The printProvider that connects us to the print service
var printProvider = new GeoExt.data.PrintProvider({
    method: "GET", // "POST" recommended for production use
    capabilities: printCapabilities, // from the info.json script in the html
    customParams: {
        mapTitle: "Printing Demo",
        comment: "This is a simple map printed from GeoExt."
    }
});

Then all requests for printing should work as the url is stored in the printCapabilities object. This is the approach I use for printing from my web appications.

Related Question