@Override public void setServletContext(ServletContext servletContext) { String data = GeoServerResourceLoader.lookupGeoServerDataDirectory(servletContext); if (data != null) { this.baseDirectory = new File(data); } else { throw new IllegalStateException("Unable to determine data directory"); } } }
@Override public void setServletContext(ServletContext servletContext) { String data = GeoServerResourceLoader.lookupGeoServerDataDirectory(servletContext); if (data != null) { root = new File(data); } else { throw new IllegalStateException("Unable to determine data directory"); } }
@Override public void setServletContext(ServletContext servletContext) { if (baseDirectory == null) { String data = lookupGeoServerDataDirectory(servletContext); if (data != null) { this.baseDirectory = new File(data); } else { throw new IllegalStateException("Unable to determine data directory"); } } if (resources == ResourceStore.EMPTY && baseDirectory != null) { // lookup the configuration resources resources = new FileSystemResourceStore(baseDirectory); } }
/** * processed parameters with relative URLs resolved against data directory. * * @param m * @param sc Context used to create GeoServerResourceLoader if required * @return processed parameters with relative URLs resolved against data directory * @deprecated Unused, call {@link ResourcePool#getParams(Map, GeoServerResourceLoader)} * directly. */ public static <K, V> Map<K, V> getParams(Map<K, V> m, ServletContext sc) { GeoServerResourceLoader loader; if (sc != null) { String basePath = GeoServerResourceLoader.lookupGeoServerDataDirectory(sc); File baseDir = new File(basePath); loader = new GeoServerResourceLoader(baseDir); } else { loader = GeoServerExtensions.bean(GeoServerResourceLoader.class); } return ResourcePool.getParams(m, loader); }
/** * Test {@link GeoServerResourceLoader#lookupGeoServerDataDirectory(ServletContext)} with a * single required file that exists specified in the Java environment. */ @Test public void testLookupRequireExistingFileJava() { Assume.assumeThat(System.getenv("GEOSERVER_DATA_DIR"), CoreMatchers.nullValue()); ServletContext context = EasyMock.createMock(ServletContext.class); EasyMock.expect(context.getInitParameter("GEOSERVER_REQUIRE_FILE")).andReturn(null); EasyMock.expect(context.getInitParameter("GEOSERVER_DATA_DIR")).andReturn(null); EasyMock.expect(context.getInitParameter("GEOSERVER_DATA_ROOT")).andReturn(null); EasyMock.expect(context.getRealPath("/data")).andReturn("data"); EasyMock.replay(context); System.setProperty("GEOSERVER_REQUIRE_FILE", "pom.xml"); System.clearProperty("GEOSERVER_DATA_DIR"); try { Assert.assertEquals( "data", GeoServerResourceLoader.lookupGeoServerDataDirectory(context)); } finally { System.clearProperty("GEOSERVER_REQUIRE_FILE"); } }
/** * Test {@link GeoServerResourceLoader#lookupGeoServerDataDirectory(ServletContext)} with a * single required file that does not exist specified in the Java environment. */ @Test public void testLookupRequireMissingFileJava() { ServletContext context = EasyMock.createMock(ServletContext.class); EasyMock.expect(context.getInitParameter("GEOSERVER_REQUIRE_FILE")).andReturn(null); EasyMock.expect(context.getInitParameter("GEOSERVER_DATA_DIR")).andReturn(null); EasyMock.expect(context.getInitParameter("GEOSERVER_DATA_ROOT")).andReturn(null); EasyMock.expect(context.getRealPath("/data")).andReturn("data"); EasyMock.replay(context); expected.expect(IllegalArgumentException.class); expected.expectMessage( "Missing required file: does-not-exist " + "From: Java environment variable GEOSERVER_REQUIRE_FILE: does-not-exist"); System.setProperty("GEOSERVER_REQUIRE_FILE", "does-not-exist"); try { GeoServerResourceLoader.lookupGeoServerDataDirectory(context); } finally { System.clearProperty("GEOSERVER_REQUIRE_FILE"); } }
/** * Test {@link GeoServerResourceLoader#lookupGeoServerDataDirectory(ServletContext)} with a * single required file that does not exist specified in the servlet context. */ @Test public void testLookupRequireMissingFileServlet() { ServletContext context = EasyMock.createMock(ServletContext.class); EasyMock.expect(context.getInitParameter("GEOSERVER_REQUIRE_FILE")) .andReturn("does-not-exist"); EasyMock.expect(context.getInitParameter("GEOSERVER_DATA_DIR")).andReturn(null); EasyMock.expect(context.getInitParameter("GEOSERVER_DATA_ROOT")).andReturn(null); EasyMock.expect(context.getRealPath("/data")).andReturn("data"); EasyMock.replay(context); expected.expect(IllegalArgumentException.class); expected.expectMessage( "Missing required file: does-not-exist " + "From: Servlet context parameter GEOSERVER_REQUIRE_FILE: does-not-exist"); GeoServerResourceLoader.lookupGeoServerDataDirectory(context); }
try { Assert.assertEquals( "data", GeoServerResourceLoader.lookupGeoServerDataDirectory(context)); } finally { System.clearProperty("GEOSERVER_REQUIRE_FILE");
try { File baseDir = new File(GeoServerResourceLoader.lookupGeoServerDataDirectory(context)); GeoServerResourceLoader loader = new GeoServerResourceLoader(baseDir);
@Override public void setServletContext(ServletContext servletContext) { String data = GeoServerResourceLoader.lookupGeoServerDataDirectory(servletContext); if (data != null) { this.base = new File(data); } else { throw new IllegalStateException("Unable to determine data directory"); } } }
/** * Test {@link GeoServerResourceLoader#lookupGeoServerDataDirectory(ServletContext)} with a * single required file that exists specified in the Java environment. */ @Test public void testLookupRequireExistingFileJava() { Assume.assumeThat(System.getenv("GEOSERVER_DATA_DIR"), CoreMatchers.nullValue()); ServletContext context = EasyMock.createMock(ServletContext.class); EasyMock.expect(context.getInitParameter("GEOSERVER_REQUIRE_FILE")).andReturn(null); EasyMock.expect(context.getInitParameter("GEOSERVER_DATA_DIR")).andReturn(null); EasyMock.expect(context.getInitParameter("GEOSERVER_DATA_ROOT")).andReturn(null); EasyMock.expect(context.getRealPath("/data")).andReturn("data"); EasyMock.replay(context); System.setProperty("GEOSERVER_REQUIRE_FILE", "pom.xml"); System.clearProperty("GEOSERVER_DATA_DIR"); try { Assert.assertEquals( "data", GeoServerResourceLoader.lookupGeoServerDataDirectory(context)); } finally { System.clearProperty("GEOSERVER_REQUIRE_FILE"); } }
/** * Test {@link GeoServerResourceLoader#lookupGeoServerDataDirectory(ServletContext)} with a * single required file that does not exist specified in the servlet context. */ @Test public void testLookupRequireMissingFileServlet() { ServletContext context = EasyMock.createMock(ServletContext.class); EasyMock.expect(context.getInitParameter("GEOSERVER_REQUIRE_FILE")) .andReturn("does-not-exist"); EasyMock.expect(context.getInitParameter("GEOSERVER_DATA_DIR")).andReturn(null); EasyMock.expect(context.getInitParameter("GEOSERVER_DATA_ROOT")).andReturn(null); EasyMock.expect(context.getRealPath("/data")).andReturn("data"); EasyMock.replay(context); expected.expect(IllegalArgumentException.class); expected.expectMessage( "Missing required file: does-not-exist " + "From: Servlet context parameter GEOSERVER_REQUIRE_FILE: does-not-exist"); GeoServerResourceLoader.lookupGeoServerDataDirectory(context); }
/** * Test {@link GeoServerResourceLoader#lookupGeoServerDataDirectory(ServletContext)} with a * single required file that does not exist specified in the Java environment. */ @Test public void testLookupRequireMissingFileJava() { ServletContext context = EasyMock.createMock(ServletContext.class); EasyMock.expect(context.getInitParameter("GEOSERVER_REQUIRE_FILE")).andReturn(null); EasyMock.expect(context.getInitParameter("GEOSERVER_DATA_DIR")).andReturn(null); EasyMock.expect(context.getInitParameter("GEOSERVER_DATA_ROOT")).andReturn(null); EasyMock.expect(context.getRealPath("/data")).andReturn("data"); EasyMock.replay(context); expected.expect(IllegalArgumentException.class); expected.expectMessage( "Missing required file: does-not-exist " + "From: Java environment variable GEOSERVER_REQUIRE_FILE: does-not-exist"); System.setProperty("GEOSERVER_REQUIRE_FILE", "does-not-exist"); try { GeoServerResourceLoader.lookupGeoServerDataDirectory(context); } finally { System.clearProperty("GEOSERVER_REQUIRE_FILE"); } }
try { Assert.assertEquals( "data", GeoServerResourceLoader.lookupGeoServerDataDirectory(context)); } finally { System.clearProperty("GEOSERVER_REQUIRE_FILE");