I'm trying to generate a pdf file to print a map using GeoExt but have run into a problem. On Chrome I get the error message:
XMLHttpRequest cannot load http://Howard:8080/geoserver/pdf/create.json. Origin http://localhost:55608 is not allowed by Access-Control-Allow-Origin.
I think the error message tells me that its to do with the proxy so I have tried adding the following to the Config.yaml but not luck:
- !localMatch
dummy: true
- !ipMatch
host: 0.0.0.0
mask: 0.0.0.0
This should have allowed all local ip addresses and all hosts to access the create.json in Howard:8080 but for some reason I still get the error message.
However, on Firefox I get a slighly different behaviour. I dont get any error message but I end up triggering a printexception with an error message "Communication failure.
I'm stuck and out of ideas, can anyone help?
Here is the code:
var printProvider = new GeoExt.data.PrintProvider({
//method: "GET", // "POST" recommended for production use
method: "POST", // "POST" recommended for production use
//capabilities: g_printCapabilities, // provide url instead for lazy loading
url: OpenLayers.ProxyHost + "http://Howard:8080/geoserver/pdf/",
//url: "http://Howard:8080/geoserver/pdf/",
autoLoad: true,
customParams: {
mapTitle: "GeoExt Printing Demo",
comment: "This demo shows how to use GeoExt.PrintMapPanel with OSM"
}
});
var printPage = new GeoExt.data.PrintPage({
printProvider: printProvider
});
var mapPanel = new GeoExt.MapPanel({
title: "Map",
region: "center",
height: 400,
width: 600,
map: map,
bbar: ["->", {
text: "Print",
handler: function() {
// convenient way to fit the print page to the visible map area
printPage.fit(mapPanel, true);
printProvider.print(mapPanel, printPage);
}
}]
});
// create a panel and add the map panel and grid panel
// inside it
var mainPanel = new Ext.Panel({
renderTo: "mainpanel",
layout: "border",
height: 800,
width: 600,
items: [mapPanel]
});
edit:
I have added the following code in javascript:
var invocation = new XMLHttpRequest();
var url = 'http://Howard:8080/geoserver/pdf/create.json';
function callOtherDomain() {
if(invocation) {
invocation.open('POST', url, true);
invocation.onreadystatechange = function (){
alert("invocation.onreadystatechange");
}
invocation.send();
}
}
callOtherDomain();
But I still get the error message. Do I add Access-Control-Allow-Origin header at the Howard server? If so how do I do that?
Edit 2:
I have added the following in code behind:
Response.AddHeader("Access-Control-Allow-Origin", "*");
Response.AddHeader("Access-Control-Allow-Headers", "POST");
Response.AddHeader("Access-Control-Allow-Headers", "GET");
I have also placed the following:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
Both code blocks added on the machine that will call the pdf file in my web.config file and still no luck.
Edit 3.
The pdf file seems to generate correctly if I don't include any vector layers. That works for Firefox and chrome. I have separate issues with IE so can't test it there.