class WMSEnvoyHelper {

    public static WMSServerCapabilities requestCapabilitiesFromServer(ServerConnectionParams serverConf, Toolbox toolbox)
        throws IOException, GeneralSecurityException, InterruptedException, URISyntaxException
    {
        /* Request a 1.3.0 doc and if that fails, request a 1.1.1 doc */
        byte[] bytes;
        try
        {
            bytes = requestCapabilities(serverConf, toolbox, "1.3.0", false);
        }
        catch (IOException | InterruptedException e)
        {
            bytes = requestCapabilities(serverConf, toolbox, "1.1.1", true);
        }
        final InputStream stream = new ByteArrayInputStream(bytes);

        /* Regardless of the request, try to parse it both ways. */
        WMSCapabilities caps130;
        try
        {
            caps130 = getXmlObject(stream, WMSCapabilities.class, handler -> new NamespaceContentHandler(handler));
        }
        catch (final IOException e)
        {
            caps130 = null;
        }
        if (caps130 != null && caps130.getCapability() != null && "1.3.0".equals(caps130.getVersion()))
        {
            return new WMS130Capabilities(caps130);
        }

        stream.reset();

        final WMTMSCapabilities caps111 = getXmlObject(stream, WMTMSCapabilities.class, null);
        if (caps111 != null && caps111.getCapability() != null)
        {
            return new WMS111Capabilities(caps111);
        }

        return null;
    }

    private  WMSEnvoyHelper();

}