GeoTools getFeature请求401未经授权的错误

时间:2015-09-08 07:45:44

标签: java geotools

我在尝试向WFS服务器发出getFeature请求时遇到了问题。我可以提出getCapabilitiesdescribeFeatureType请求。

 String getCapabilities = "http://cbsservis.tkgm.gov.tr/tkgm.ows/wfs?SERVICE=WFS&REQUEST=Getcapabilities";
    Map<String, String> connectionParameters = new HashMap<String, String>();
    connectionParameters.put("WFSDataStoreFactory:USERNAME", "cbsdemouser");
    connectionParameters.put("WFSDataStoreFactory:PASSWORD", "lp+12345");
    connectionParameters.put("WFSDataStoreFactory:GET_CAPABILITIES_URL",
            getCapabilities);
    try {
        DataStore data = DataStoreFinder.getDataStore(connectionParameters);
        String typeNames[] = null;
        typeNames = data.getTypeNames();
        String typeName = typeNames[0];
        SimpleFeatureType schema = data.getSchema(typeName);
        System.out.println("Schema Attributes:"
                + schema.getAttributeCount());

        SimpleFeatureSource source = data.getFeatureSource(typeName);
        System.out.println("Metadata Bounds:" + source.getBounds());

        FilterFactory ff = CommonFactoryFinder.getFilterFactory(GeoTools
                .getDefaultHints());

        DefaultQuery query = new DefaultQuery(typeName, Filter.INCLUDE);
        query.setMaxFeatures(2);

        SimpleFeatureCollection features = source.getFeatures(query);

        String fid = null;

        Iterator<SimpleFeature> iterator = (Iterator<SimpleFeature>) features
                .features();

        while (iterator.hasNext()) {
            SimpleFeature feature = (SimpleFeature) iterator.next();
            fid = feature.getID();
            System.out.println(fid);
        }

但是当我尝试发出getFeature请求时,我收到了这个错误:

WARNING: Unexpected response "401 Unauthorized" while downloading http://cbsservis.tkgm.gov.tr/tkgm.ows/wfs?service=WFS&version=1.0.0&request=DescribeFeatureType&typeName=TKGM%3Aadalar
Eyl 08, 2015 10:23:45 AM org.geotools.data.wfs.v1_0_0.NonStrictWFSStrategy createFeatureReaderGET
WARNING: java.io.IOException: org.xml.sax.SAXException: Failed to resolve 
Eyl 08, 2015 10:23:45 AM org.geotools.data.wfs.v1_0_0.NonStrictWFSStrategy createFeatureReaderPOST
WARNING: java.io.IOException: Server returned HTTP response code: 500 for URL: 

0 个答案:

没有答案