@Test public void testReadingDriverConfiguration() throws Exception { Map<String, DatabaseHandler.DriverInfo> drivers = new HashMap<>(); int expectedDrivers = 12; try (InputStream is = DatabaseHandler.class.getClassLoader().getResourceAsStream("drivers.mapping")) { DatabaseHandler.loadDrivers(is, drivers); JsonArray values = new JsonArray(); Collection<Map.Entry<String, DatabaseHandler.DriverInfo>> entries = drivers.entrySet(); for (Map.Entry<String, DatabaseHandler.DriverInfo> driver : entries) { JsonObject object = new JsonObject(); object.addProperty("class", driver.getKey()); object.addProperty("label", driver.getValue().getName()); String shortTag = driver.getValue().getTag(); object.addProperty("tag", shortTag); object.addProperty("name", shortTag); object.addProperty("default.port", driver.getValue().getPort()); values.add(object); } Assert.assertEquals(expectedDrivers, values.size()); } Assert.assertEquals(expectedDrivers, drivers.size()); }
@VisibleForTesting static void loadDrivers(InputStream is, Map<String, DriverInfo> drivers) throws IOException { try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { String line; while ((line = br.readLine()) != null) { String[] columns = line.split(","); if (columns.length == 6) { DriverInfo info = new DriverInfo(columns[0], columns[1], columns[2], columns[3], columns[4], Boolean.parseBoolean(columns[5])); if (drivers.containsKey(info.tag)) { throw new IllegalStateException( "Wrangler's allowed JDBC plugins has been misconfigured. " + "Please make sure the driver plugin names in the drivers.mapping file are unique."); } drivers.put(info.tag, info); } } } }
DatabaseHandler extends AbstractWranglerHandler { @VisibleForTesting static void loadDrivers(InputStream is, Map<String, DriverInfo> drivers) throws IOException { try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { String line; while ((line = br.readLine()) != null) { String[] columns = line.split(","); if (columns.length == 6) { DriverInfo info = new DriverInfo(columns[0], columns[1], columns[2], columns[3], columns[4], Boolean.parseBoolean(columns[5])); if (drivers.containsKey(info.tag)) { throw new IllegalStateException( "Wrangler's allowed JDBC plugins has been misconfigured. " + "Please make sure the driver plugin names in the drivers.mapping file are unique."); } drivers.put(info.tag, info); } } } } }
DatabaseHandler extends AbstractWranglerHandler { @VisibleForTesting static void loadDrivers(InputStream is, Map<String, DriverInfo> drivers) throws IOException { try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { String line; while ((line = br.readLine()) != null) { String[] columns = line.split(","); if (columns.length == 6) { DriverInfo info = new DriverInfo(columns[0], columns[1], columns[2], columns[3], columns[4], Boolean.parseBoolean(columns[5])); if (drivers.containsKey(info.tag)) { throw new IllegalStateException( "Wrangler's allowed JDBC plugins has been misconfigured. " + "Please make sure the driver plugin names in the drivers.mapping file are unique."); } drivers.put(info.tag, info); } } } }  }
DatabaseHandler extends AbstractWranglerHandler { @VisibleForTesting static void loadDrivers(InputStream is, Map<String, DriverInfo> drivers) throws IOException { try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { String line; while ((line = br.readLine()) != null) { String[] columns = line.split(","); if (columns.length == 6) { DriverInfo info = new DriverInfo(columns[0], columns[1], columns[2], columns[3], columns[4], Boolean.parseBoolean(columns[5])); if (drivers.containsKey(info.tag)) { throw new IllegalStateException( "Wrangler's allowed JDBC plugins has been misconfigured. " + "Please make sure the driver plugin names in the drivers.mapping file are unique."); } drivers.put(info.tag, info); } } } }  @Override void initialize(SystemHttpServiceContext context); @GET @Path("contexts/{context}/jdbc/drivers") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listDrivers(HttpServiceRequest request, HttpServiceResponder responder,
                          @PathParam("context") String namespace); @GET @Path("contexts/{context}/jdbc/allowed") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listAvailableDrivers(HttpServiceRequest request, HttpServiceResponder responder,
                                   @PathParam("context") String namespace); @POST @Path("contexts/{context}/connections/jdbc/test") @TransactionPolicy(value = TransactionControl.EXPLICIT) void testConnection(HttpServiceRequest request, HttpServiceResponder responder,
                             @PathParam("context") String namespace); @POST @Path("contexts/{context}/connections/databases") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listDatabases(HttpServiceRequest request, HttpServiceResponder responder,
                            @PathParam("context") String namespace); @GET @Path("contexts/{context}/connections/{id}/tables") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listTables(HttpServiceRequest request, HttpServiceResponder responder,
                         @PathParam("context") String namespace, @PathParam("id") String id); @GET @Path("contexts/{context}/connections/{id}/tables/{table}/read") @TransactionPolicy(value = TransactionControl.EXPLICIT) void read(HttpServiceRequest request, HttpServiceResponder responder,
                   @PathParam("context") String namespace, @PathParam("id") String id, @PathParam("table") String table,
                   @QueryParam("lines") int lines,
                   @QueryParam("scope") @DefaultValue(WorkspaceDataset.DEFAULT_SCOPE) String scope); @GET @Path("contexts/{context}/connections/{id}/tables/{table}/specification") @TransactionPolicy(value = TransactionControl.EXPLICIT) void specification(HttpServiceRequest request, HttpServiceResponder responder,
                            @PathParam("context") String namespace, @PathParam("id") String id,
                            @PathParam("table") String table); }
DatabaseHandler extends AbstractWranglerHandler { @VisibleForTesting static void loadDrivers(InputStream is, Map<String, DriverInfo> drivers) throws IOException { try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { String line; while ((line = br.readLine()) != null) { String[] columns = line.split(","); if (columns.length == 6) { DriverInfo info = new DriverInfo(columns[0], columns[1], columns[2], columns[3], columns[4], Boolean.parseBoolean(columns[5])); if (drivers.containsKey(info.tag)) { throw new IllegalStateException( "Wrangler's allowed JDBC plugins has been misconfigured. " + "Please make sure the driver plugin names in the drivers.mapping file are unique."); } drivers.put(info.tag, info); } } } }  @Override void initialize(SystemHttpServiceContext context); @GET @Path("contexts/{context}/jdbc/drivers") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listDrivers(HttpServiceRequest request, HttpServiceResponder responder,
                          @PathParam("context") String namespace); @GET @Path("contexts/{context}/jdbc/allowed") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listAvailableDrivers(HttpServiceRequest request, HttpServiceResponder responder,
                                   @PathParam("context") String namespace); @POST @Path("contexts/{context}/connections/jdbc/test") @TransactionPolicy(value = TransactionControl.EXPLICIT) void testConnection(HttpServiceRequest request, HttpServiceResponder responder,
                             @PathParam("context") String namespace); @POST @Path("contexts/{context}/connections/databases") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listDatabases(HttpServiceRequest request, HttpServiceResponder responder,
                            @PathParam("context") String namespace); @GET @Path("contexts/{context}/connections/{id}/tables") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listTables(HttpServiceRequest request, HttpServiceResponder responder,
                         @PathParam("context") String namespace, @PathParam("id") String id); @GET @Path("contexts/{context}/connections/{id}/tables/{table}/read") @TransactionPolicy(value = TransactionControl.EXPLICIT) void read(HttpServiceRequest request, HttpServiceResponder responder,
                   @PathParam("context") String namespace, @PathParam("id") String id, @PathParam("table") String table,
                   @QueryParam("lines") int lines,
                   @QueryParam("scope") @DefaultValue(WorkspaceDataset.DEFAULT_SCOPE) String scope); @GET @Path("contexts/{context}/connections/{id}/tables/{table}/specification") @TransactionPolicy(value = TransactionControl.EXPLICIT) void specification(HttpServiceRequest request, HttpServiceResponder responder,
                            @PathParam("context") String namespace, @PathParam("id") String id,
                            @PathParam("table") String table);  }