@Test public void testUriErrors() throws Exception { Configuration conf = new Configuration(); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, "unkn@own:/x/y"); try { List<CredentialProvider> providers = CredentialProviderFactory.getProviders(conf); assertTrue("should throw!", false); } catch (IOException e) { assertEquals("Bad configuration of " + CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH + " at unkn@own:/x/y", e.getMessage()); } }
public static List<CredentialProvider> getProviders(Configuration conf ) throws IOException { List<CredentialProvider> result = new ArrayList<CredentialProvider>(); for(String path: conf.getStringCollection(CREDENTIAL_PROVIDER_PATH)) { try { URI uri = new URI(path); boolean found = false; for(CredentialProviderFactory factory: serviceLoader) { CredentialProvider kp = factory.createProvider(uri, conf); if (kp != null) { result.add(kp); found = true; break; } } if (!found) { throw new IOException("No CredentialProviderFactory for " + uri + " in " + CREDENTIAL_PROVIDER_PATH); } } catch (URISyntaxException error) { throw new IOException("Bad configuration of " + CREDENTIAL_PROVIDER_PATH + " at " + path, error); } } return result; }
CredentialProviderFactory { public static List<CredentialProvider> getProviders(Configuration conf ) throws IOException { List<CredentialProvider> result = new ArrayList<CredentialProvider>(); for(String path: conf.getStringCollection(CREDENTIAL_PROVIDER_PATH)) { try { URI uri = new URI(path); boolean found = false; for(CredentialProviderFactory factory: serviceLoader) { CredentialProvider kp = factory.createProvider(uri, conf); if (kp != null) { result.add(kp); found = true; break; } } if (!found) { throw new IOException("No CredentialProviderFactory for " + uri + " in " + CREDENTIAL_PROVIDER_PATH); } } catch (URISyntaxException error) { throw new IOException("Bad configuration of " + CREDENTIAL_PROVIDER_PATH + " at " + path, error); } } return result; } }
CredentialProviderFactory { public static List<CredentialProvider> getProviders(Configuration conf ) throws IOException { List<CredentialProvider> result = new ArrayList<CredentialProvider>(); for(String path: conf.getStringCollection(CREDENTIAL_PROVIDER_PATH)) { try { URI uri = new URI(path); boolean found = false; for(CredentialProviderFactory factory: serviceLoader) { CredentialProvider kp = factory.createProvider(uri, conf); if (kp != null) { result.add(kp); found = true; break; } } if (!found) { throw new IOException("No CredentialProviderFactory for " + uri + " in " + CREDENTIAL_PROVIDER_PATH); } } catch (URISyntaxException error) { throw new IOException("Bad configuration of " + CREDENTIAL_PROVIDER_PATH + " at " + path, error); } } return result; }  }
CredentialProviderFactory { public static List<CredentialProvider> getProviders(Configuration conf ) throws IOException { List<CredentialProvider> result = new ArrayList<CredentialProvider>(); for(String path: conf.getStringCollection(CREDENTIAL_PROVIDER_PATH)) { try { URI uri = new URI(path); boolean found = false; for(CredentialProviderFactory factory: serviceLoader) { CredentialProvider kp = factory.createProvider(uri, conf); if (kp != null) { result.add(kp); found = true; break; } } if (!found) { throw new IOException("No CredentialProviderFactory for " + uri + " in " + CREDENTIAL_PROVIDER_PATH); } } catch (URISyntaxException error) { throw new IOException("Bad configuration of " + CREDENTIAL_PROVIDER_PATH + " at " + path, error); } } return result; }  abstract CredentialProvider createProvider(URI providerName,
                                             Configuration conf
                                             ); static List<CredentialProvider> getProviders(Configuration conf
                                               ); }
CredentialProviderFactory { public static List<CredentialProvider> getProviders(Configuration conf ) throws IOException { List<CredentialProvider> result = new ArrayList<CredentialProvider>(); for(String path: conf.getStringCollection(CREDENTIAL_PROVIDER_PATH)) { try { URI uri = new URI(path); boolean found = false; for(CredentialProviderFactory factory: serviceLoader) { CredentialProvider kp = factory.createProvider(uri, conf); if (kp != null) { result.add(kp); found = true; break; } } if (!found) { throw new IOException("No CredentialProviderFactory for " + uri + " in " + CREDENTIAL_PROVIDER_PATH); } } catch (URISyntaxException error) { throw new IOException("Bad configuration of " + CREDENTIAL_PROVIDER_PATH + " at " + path, error); } } return result; }  abstract CredentialProvider createProvider(URI providerName,
                                             Configuration conf
                                             ); static List<CredentialProvider> getProviders(Configuration conf
                                               ); static final String CREDENTIAL_PROVIDER_PATH; }