3

I want to get the Capabilities of a WCS using Geotools (16.2) net.opengis.wcs20.GetCapabilitiesType. I found a WCS 2.0 test class on GitHub but was not able to use the code in the same way because this part:

GetCapabilitiesType caps = (GetCapabilitiesType) parser.parse(getClass()
                .getResourceAsStream(capRequestPath));

throws

Exception in thread "main" java.net.MalformedURLException [...] Caused by: java.lang.NullPointerException

I wrote this method to overcome the exception:

GetCapabilitiesType getCapabilitiesType(String capRequestPath)
        throws IOException, SAXException, ParserConfigurationException {
    Parser parser = new Parser(new WCSConfiguration());
    FileInputStream fis = new FileInputStream(capRequestPath);
    GetCapabilitiesType capabilitiesType = (GetCapabilitiesType) parser.parse(fis);
    return capabilitiesType;
}

This throws

Exception in thread "main" java.lang.ClassCastException: java.util.HashMap cannot be cast to net.opengis.wcs20.GetCapabilitiesType

which I wasn't able to resolve. I also found a WCS 1.1 test class on GitHub.

This approach works:

HashMap<String, Object> getCapabilitiesMap(String capRequestPath)
        throws IOException, SAXException, ParserConfigurationException {
    Parser parser = new Parser(new WCSConfiguration());
    FileInputStream fis = new FileInputStream(capRequestPath);
    HashMap<String, Object> capabilitiesMap = (HashMap<String, Object>) parser.parse(fis);
    return capabilitiesMap;
}

but this way I do not have a net.opengis.wcs20.GetCapabilitiesType object.

Then I found the class net.opengis.wcs20.impl.Wcs20FactoryImpl on GitHub which has a createCapabilitiesType() method to create a net.opengis.wcs20.GetCapabilitiesType object. I created my GetCapabilitiesType like this:

String wcsURL = "https://www.wcs.nrw.de/geobasis/wcs_nw_dgm";    
Wcs20Factory factory = Wcs20FactoryImpl.init();
GetCapabilitiesType wcsGetCapabilities = factory.createGetCapabilitiesType();
wcsGetCapabilities.setBaseUrl(wcsURL); 

But when I want to use getters like:

List<String> versions = wcsGetCapabilities.getAcceptVersions().getVersion();

or

List<String> sections = wcsGetCapabilities.getSections().getSection();

they throw

java.lang.NullPointerException

What is the best way to get a net.opengis.wcs20.GetCapabilitiesType object?

1

When using your code I get an exception that the returned capabilities document is invalid.

  public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException {
    String baseurl = "https://www.wcs.nrw.de/geobasis/wcs_nw_dgm?service=wcs&request=getcapabilities";
    WCSTest me = new WCSTest();
    me.getCapabilitiesType(baseurl);

  }

  GetCapabilitiesType getCapabilitiesType(String capRequestPath)
      throws IOException, SAXException, ParserConfigurationException {
    Parser parser = new Parser(new WCSConfiguration());
    URL url = new URL(capRequestPath);
    GetCapabilitiesType capabilitiesType = (GetCapabilitiesType) parser.parse(url.openStream());
    return capabilitiesType;
  }

The "offending" line is, GeoTools feels that simple is invalid:

<ows:OnlineResource xlink:type="simple" xlink:href="http://www.geobasis.nrw.de"/> 

That seems to be a bug as that is a required type in an XLink simpleLink which is what an OnlineResource should be.

  • I got the exception (java.lang.ClassCastException: java.util.HashMap cannot be cast to net.opengis.wcs20.GetCapabilitiesType) already before returning the capabilitiesType in this line: GetCapabilitiesType capabilitiesType = (GetCapabilitiesType) parser.parse(url.openStream()); Which line throws the invalid capabilities document exception? I will report the issue at OsGeo. – Lars Jun 19 '17 at 7:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.