Thanks for the reply,
Indeed the problem in our case was due to incorrect GetCapabilities and
DescribeFeatureType responses.
If someone encounters this same situation, you should check GetCapabilities
responses for remote server e.g. with browser:

http://{URL}?SERVICE=WFS&VERSION=1.1.0&REQUEST=GetCapabilities
After that, ensure that <ows:Operation> elements contain urls that actually
work.

If someone is "more interested", we have also customized how schemas are
located.
I do not know if this is GeoTools endorsed way but this is how we do it:

1) Background
We wanted to customize how XML Schemas are located in our web portal that is
integrated to multiple WFS services.
Some of remote WFS services require authentication, some don't. We also need
to use http proxy for our XML schema requests.
Our project is built with Ant and bundled with GeoTools binaries.

2) In order to create custom SchemaLocator we start with configuration like
so:

    GMLConfiguration configuration = new GMLConfiguration() {

        @Override
        public void configureContext(final MutablePicoContainer container) {
            super.configureContext(container);
            String username = "{DEPENDS ON SERVICE}";
            String password = "{DEPENDS ON SERVICE}";
            Boolean useProxy = {DEPENDS ON SERVICE};
            XSDSchemaLocator locator = new CachingSchemaLocator(username,
password, useProxy);
            QName key = new QName("mycustom", "schemaLocator");
            container.registerComponentInstance(key, locator);
        }
    };

Notice that CachingSchemaLocator is our own class that is implemented like
this:

    public class CachingSchemaLocator implements XSDSchemaLocator {

        @Override
        public XSDSchema locateSchema(XSDSchema schema, String namespaceURI,
String rawSchemaLocationURI, String resolvedSchemaLocationURI) {

             ... Implementation ...

        }
    }

3) After we have configuration ready, we simply pass that to Parser:

    Parser parser = new Parser(configuration);
    parser.setValidating(false);
    parser.setFailOnValidationError(false);
    parser.setStrict(false);
    FeatureCollection<SimpleFeatureType, SimpleFeature> features =
parser.parse(... WFS response InputStream Here ...);


4) That's it.

This has worked for us.

On Mon, Apr 18, 2011 at 3:32 PM, Jody Garnett <[email protected]>wrote:

> That happens when your WFS does not set up its DescribeFeatureType
> correctly; you may need to configure the parser to be able to resolve to the
> schema correctly? Or check the xml output and make sure to correctly
> references the wfs DescribeFeatureType; and then check the results of
> DescribeFeatureType to make sure it makes sense...
>
> In the GML utility class I have some extra processing that will attempt to
> fake things; but looking at the HashMaps returned and building a feature
> type that matches that kind of contents; and then building features that
> match that FeatureType. This is similar to the approach taken by OGR; OGR
> figures out where the "geometry" is; and then goes up two levels and assumes
> those things are features.
>
> We actually use the XMLSchema; so when it is not correct we run into
> trouble.
>
> For more information; here is my attempt at updating the xml docs....
> - http://docs.geotools.org/latest/userguide/library/xml/index.html
>
> Jody
>
> On Mon, Apr 18, 2011 at 9:20 PM, Oskari Avoin <[email protected]>wrote:
>
>> Hi,
>> We are having a slight problem when trying to read WFS 1.1 response that
>> is returned in GML 3.2.1. (GeoTools 2.7-M4)
>> Currently, we are reading all WFS responses using GeoTools like so:
>>
>>     Parser parser = new Parser(...);
>>     parser.setValidating(false);
>>     parser.setFailOnValidationError(false);
>>     parser.setStrict(false);
>>     FeatureCollection<SimpleFeatureType, SimpleFeature> features =
>> (FeatureCollection<SimpleFeatureType, SimpleFeature>)
>> parser.parse(response.getResponseAsInputStream());
>>
>> but now are getting ClassCastException "java.util.HashMap cannot be cast
>> to FeatureCollection".
>> XML response contains multisurface object like this:
>>
>>     <gml:MultiSurface gml:id="XXX.MultiSurface" srsName="EPSG:3067">
>>        <gml:surfaceMember>
>>             <gml:Surface gml:id="XXX.Surface" srsName="EPSG:3067">
>>                 <gml:patches>
>>                     <gml:PolygonPatch>
>>                         <gml:exterior>
>>                             <gml:LinearRing>
>>                                 <gml:posList>xx yy ...</gml:posList>
>>                             </gml:LinearRing>
>>                         </gml:exterior>
>>                         <gml:interior>
>>                             <gml:LinearRing>
>>                                 <gml:posList>xx yy ...</gml:posList>
>>                             </gml:LinearRing>
>>                         </gml:interior>
>>                     </gml:PolygonPatch>
>>                 </gml:patches>
>>             </gml:Surface>
>>         </gml:surfaceMember>
>>     </gml:MultiSurface>
>>
>> Now, is there an easy way to convert HashMap WFS GetFeature result to a
>> "Layer" that could be render into an image something like this:
>>
>>     String style = "...";
>>     FeatureCollection<SimpleFeatureType, SimpleFeature> features = {magic
>> conversion from HashMap to FeatureCollection }
>>     MapContext mapContext = buildMapContext();
>>     mapContext.addLayer(features, style);
>>
>> Cheers.
>>
>>
>> ------------------------------------------------------------------------------
>> Benefiting from Server Virtualization: Beyond Initial Workload
>> Consolidation -- Increasing the use of server virtualization is a top
>> priority.Virtualization can reduce costs, simplify management, and improve
>> application availability and disaster protection. Learn more about
>> boosting
>> the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
>> _______________________________________________
>> Geotools-gt2-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>
>>
>
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload 
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve 
application availability and disaster protection. Learn more about boosting 
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to