private void readConfigFiles( File[] files ) { for (File file: files) { try { String fileContent = _configService.replaceProperties(file); JSONArray contents = new JSONArray( new JSONTokener(fileContent) ); for ( int i=0; i<contents.length(); i++ ) { if( contents.get(i) instanceof JSONObject ) { JSONObject layerJSON = contents.getJSONObject(i); layerJSON = addLayerContext(layerJSON); _layersById.put( layerJSON.getString( LayerConfiguration.LAYER_ID.getName() ), layerJSON ); _layers.add( layerJSON ); } } } catch (JSONException e) { LOGGER.error("Layer configuration file {} was not valid JSON.", file, e); } catch (ConfigException e) { LOGGER.error("Unable to replace properties in layer file {}.", file, e); } } }
private void withMockConfigService() throws URISyntaxException, IOException, ConfigException { File configFile = new File(this.getClass().getClassLoader().getResource(UNIT_TEST_CONFIG_JSON).toURI()); String configFileContent = new String(Files.readAllBytes(Paths.get(configFile.getPath())), StandardCharsets.UTF_8); when(_configService.replaceProperties(any(File.class))).thenReturn(configFileContent); }
private void withMockConfigService() throws URISyntaxException, IOException, ConfigException { File configFile = new File(this.getClass().getClassLoader().getResource(UNIT_TEST_CONFIG_JSON).toURI()); String configFileContent = new String(Files.readAllBytes(Paths.get(configFile.getPath())), StandardCharsets.UTF_8); when(_configService.replaceProperties(any(File.class))).thenReturn(configFileContent); }
@Get public Representation getConfig() { try { String result = "{}"; String name = ( String ) getRequest().getAttributes().get( "name" ); File matchingFile = _service.findResourceConfig(name); if (matchingFile != null) { result = _service.replaceProperties(matchingFile); } setStatus(Status.SUCCESS_OK); return new JsonRepresentation( result ); } catch ( Exception e ) { throw new ResourceException( Status.SERVER_ERROR_INTERNAL, "Unable to get configuration", e ); } } }