xmlinternet-explorergwtopenlayersgwt-openlayers

Malformed WFS XMLHttpRequest from GWT-openlayers in IE11


I have tried reproducing one of GWT-openlayers showcase examples involving WFS requests (this one). I kept the code and just modified it to be a simple Composite instead of an Abstract Example, like this:

public class Example extends Composite {

public Example() {
    buildPanel();
}

public void buildPanel() {        
    OpenLayers.setProxyHost("olproxy?targetURL=");         
    //create some MapOptions        
    MapOptions defaultMapOptions = new MapOptions();        
    defaultMapOptions.setNumZoomLevels(16);         
    MapWidget mapWidget = new MapWidget("500px", "500px", defaultMapOptions);        
    Map map = mapWidget.getMap();        
    WMSParams wmsParams = new WMSParams();        
    wmsParams.setFormat("image/png");        
    wmsParams.setLayers("topp:states");        
    wmsParams.setStyles("");         
    WMSOptions wmsLayerParams = new WMSOptions();       
    wmsLayerParams.setUntiled();        
    wmsLayerParams.setTransitionEffect(TransitionEffect.RESIZE);
    String wmsUrl = "http://demo.opengeo.org/geoserver/wms";         
    WMS wmsLayer = new WMS("Basic WMS", wmsUrl, wmsParams, wmsLayerParams);         
    //Create a WFS layer        
    WFSProtocolOptions wfsProtocolOptions = new WFSProtocolOptions();        
    wfsProtocolOptions.setUrl("http://demo.opengeo.org/geoserver/wfs");       
    wfsProtocolOptions.setFeatureType("states");        
    wfsProtocolOptions.setFeatureNameSpace("http://www.openplans.org/topp");        
    //if your wms is in a different projection use wfsProtocolOptions.setSrsName(LAMBERT72);         
    WFSProtocol wfsProtocol = new WFSProtocol(wfsProtocolOptions);         
    VectorOptions vectorOptions = new VectorOptions();        
    vectorOptions.setProtocol(wfsProtocol);        
    vectorOptions.setStrategies(new Strategy[]{new BBoxStrategy()});        
    //if your wms is in a different projection use vectorOptions.setProjection(LAMBERT72);         
    final Vector wfsLayer = new Vector("wfsExample", vectorOptions);       
    wfsLayer.setFilter(new FeatureIdFilter(new String[]{"states.30"})); 
    //note that you can request the FID of a VectorFeature using getFID()   
    map.addLayer(wmsLayer);    
    map.addLayer(wfsLayer);      
    //Lets add some default controls to the map    
    map.addControl(new LayerSwitcher()); //+ sign in the upperright corner to display the layer switcher    
    map.addControl(new OverviewMap()); //+ sign in the lowerright to display the overviewmap  
    map.addControl(new ScaleLine()); //Display the scaleline     
    //Center and zoom to a location    
    map.setCenter(new LonLat(-100, 40), 4);        
    initWidget(mapWidget);      
    mapWidget.getElement().getFirstChildElement().getStyle().setZIndex(0); //force the map to fall behind popups
}
}

I deployed my GWT application containing this panel and ran it on Internet Explorer 11. Using the developer tools, I examined the WFS XMLHttpRequest that asks for the feature with the specified id. The XML request was as follows:

<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd">
<wfs:Query typeName="feature:states" xmlns:NS1="" NS1:xmlns:feature="http://www.openplans.org/topp">
    <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
        <ogc:And>
            <ogc:FeatureId fid="states.30" />
            <ogc:BBOX>
                <ogc:PropertyName>the_geom</ogc:PropertyName>
                <gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
                    <gml:coordinates decimal="." cs="," ts=" ">-143.9453125,-3.9453125 -56.0546875,83.9453125</gml:coordinates>
                </gml:Box>
            </ogc:BBOX>
        </ogc:And>
    </ogc:Filter>
</wfs:Query>
</wfs:GetFeature>

The same request, originating from the showcase example, is like this instead:

<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd">
<wfs:Query typeName="feature:states" xmlns:feature="http://www.openplans.org/topp">
    <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
        <ogc:And>
            <ogc:FeatureId fid="states.30"/>
            <ogc:BBOX>
                <ogc:PropertyName>the_geom</ogc:PropertyName>
                <gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
                    <gml:coordinates decimal="." cs="," ts=" ">-143.9453125,-3.9453125 -56.0546875,83.9453125</gml:coordinates>
                </gml:Box>
            </ogc:BBOX>
        </ogc:And>
    </ogc:Filter>
</wfs:Query>
</wfs:GetFeature>

They are the same, except for this bit on line 2: ...xmlns:NS1="" NS1:xmlns:feature=... This is a problem, since it makes my request unparseable by Geoserver (it says org.xml.sax.SAXParseException: The value of the attribute "prefix="xmlns",localpart="ns1",rawname="xmlns:ns1"" is invalid. Prefixed namespace bindings may not be empty). This seems to happen also for different kinds of WFS feature filters (i.e. logical). Moreover, this only happens on IE11. The request is correctly built when running on Firefox and Chrome. I am using GWT 2.5.1 and GWT-openlayers 1.0.
I need to make it work, but I could not find out what causes this anomalous behaviour on IE...


Solution

  • This seems to be a know bug in IE11.

    Source : http://osgeo-org.1560.x6.nabble.com/WFS-and-IE-11-td5090636.html

    The workaround is to overwrite OpenLayers.Format.XML.write method with one which removes some rogue text (author: Stephen Battey with modification from krooole):

    var _class = OpenLayers.Format.XML;
    var originalWriteFunction = _class.prototype.write;
    
    var patchedWriteFunction = function() {
        var child = originalWriteFunction.apply( this, arguments );
    
        // NOTE: Remove the rogue namespaces as one block of text.
        child = child.replace(new RegExp('xmlns:NS\\d+="" NS\\d+:', 'g'), '');
    
        return child;
    }
    
    _class.prototype.write = patchedWriteFunction;