@Test public void testEmptyErrorPageDirectoryProperty() throws Exception { final Mockery mockery = new Mockery() { { setImposteriser(ClassImposteriser.INSTANCE); } }; final ServiceContext serviceContext = mockery.mock(ServiceContext.class); final File webDir = new File("." + File.pathSeparator); final TestServiceProperties properties = new TestServiceProperties(); properties.put("directory", "/"); properties.put("error-page-directory", ""); mockery.checking(new Expectations() { { allowing(serviceContext).getWebDirectory(); will(returnValue(webDir)); allowing(serviceContext).getProperties(); will(returnValue(properties)); allowing(serviceContext).getAccepts(); will(returnValue(Collections.<URI> emptyList())); } }); HttpDirectoryService service = (HttpDirectoryService)ServiceFactory.newServiceFactory().newService("directory"); service.init(serviceContext); mockery.assertIsSatisfied(); }
@Override public void init(ServiceContext serviceContext) throws Exception { this.serviceContext = serviceContext; handler = new HttpDirectoryServiceHandler(); File webDir = serviceContext.getWebDirectory(); ServiceProperties properties = serviceContext.getProperties(); Collection<String> accepts = serviceContext.getAccepts(); Collection<String> failedAccepts = new HashSet<>(); for (String accept : accepts) { String path = URIUtils.getPath(accept); if (path == null || path.isEmpty()) { failedAccepts.add(accept); } } if (!failedAccepts.isEmpty()) { throw new IllegalArgumentException( "The following directory service accept elements are missing the URL path. You may need to add a trailing slash): " + failedAccepts); } String directory = properties.get("directory"); if (directory == null) { throw new IllegalArgumentException("Missing required property: directory"); } File directoryFile = toFile(webDir, directory); String welcomeFile = properties.get("welcome-file"); if (welcomeFile != null) { String pathSeparator = File.pathSeparator; if (welcomeFile.contains(pathSeparator)) { throw new IllegalArgumentException("Unexpected character \"" + pathSeparator + "\" in welcome file: " + welcomeFile); } } File errorPagesDir = toFile(webDir.getParentFile(), properties.get("error-pages-directory")); File clientAccessPolicyXml = new File(directoryFile, "/clientaccesspolicy.xml"); if (clientAccessPolicyXml.exists()) { for (String accept : accepts) { logger.warn( "Ignoring user-defined file contents for {}clientaccesspolicy.xml, please modify configuration instead", accept); } } handler.setServiceContext(serviceContext); handler.setBaseDir(directoryFile); handler.setWelcomeFile(welcomeFile); handler.setErrorPagesDir(errorPagesDir); handler.setPatterns(buildPatternsList(properties)); String indexes = properties.get("options"); if ((indexes != null) && "indexes".equalsIgnoreCase(indexes)) { handler.setIndexes(true); } }
HttpDirectoryService implements Service { @Override public void init(ServiceContext serviceContext) throws Exception { this.serviceContext = serviceContext; handler = new HttpDirectoryServiceHandler(); File webDir = serviceContext.getWebDirectory(); ServiceProperties properties = serviceContext.getProperties(); Collection<String> accepts = serviceContext.getAccepts(); Collection<String> failedAccepts = new HashSet<>(); for (String accept : accepts) { String path = URIUtils.getPath(accept); if (path == null || path.isEmpty()) { failedAccepts.add(accept); } } if (!failedAccepts.isEmpty()) { throw new IllegalArgumentException( "The following directory service accept elements are missing the URL path. You may need to add a trailing slash): " + failedAccepts); } String directory = properties.get("directory"); if (directory == null) { throw new IllegalArgumentException("Missing required property: directory"); } File directoryFile = toFile(webDir, directory); String welcomeFile = properties.get("welcome-file"); if (welcomeFile != null) { String pathSeparator = File.pathSeparator; if (welcomeFile.contains(pathSeparator)) { throw new IllegalArgumentException("Unexpected character \"" + pathSeparator + "\" in welcome file: " + welcomeFile); } } File errorPagesDir = toFile(webDir.getParentFile(), properties.get("error-pages-directory")); File clientAccessPolicyXml = new File(directoryFile, "/clientaccesspolicy.xml"); if (clientAccessPolicyXml.exists()) { for (String accept : accepts) { logger.warn( "Ignoring user-defined file contents for {}clientaccesspolicy.xml, please modify configuration instead", accept); } } handler.setServiceContext(serviceContext); handler.setBaseDir(directoryFile); handler.setWelcomeFile(welcomeFile); handler.setErrorPagesDir(errorPagesDir); handler.setPatterns(buildPatternsList(properties)); String indexes = properties.get("options"); if ((indexes != null) && "indexes".equalsIgnoreCase(indexes)) { handler.setIndexes(true); } } }
HttpDirectoryService implements Service { @Override public void init(ServiceContext serviceContext) throws Exception { this.serviceContext = serviceContext; handler = new HttpDirectoryServiceHandler(); File webDir = serviceContext.getWebDirectory(); ServiceProperties properties = serviceContext.getProperties(); Collection<String> accepts = serviceContext.getAccepts(); Collection<String> failedAccepts = new HashSet<>(); for (String accept : accepts) { String path = URIUtils.getPath(accept); if (path == null || path.isEmpty()) { failedAccepts.add(accept); } } if (!failedAccepts.isEmpty()) { throw new IllegalArgumentException( "The following directory service accept elements are missing the URL path. You may need to add a trailing slash): " + failedAccepts); } String directory = properties.get("directory"); if (directory == null) { throw new IllegalArgumentException("Missing required property: directory"); } File directoryFile = toFile(webDir, directory); String welcomeFile = properties.get("welcome-file"); if (welcomeFile != null) { String pathSeparator = File.pathSeparator; if (welcomeFile.contains(pathSeparator)) { throw new IllegalArgumentException("Unexpected character \"" + pathSeparator + "\" in welcome file: " + welcomeFile); } } File errorPagesDir = toFile(webDir.getParentFile(), properties.get("error-pages-directory")); File clientAccessPolicyXml = new File(directoryFile, "/clientaccesspolicy.xml"); if (clientAccessPolicyXml.exists()) { for (String accept : accepts) { logger.warn( "Ignoring user-defined file contents for {}clientaccesspolicy.xml, please modify configuration instead", accept); } } handler.setServiceContext(serviceContext); handler.setBaseDir(directoryFile); handler.setWelcomeFile(welcomeFile); handler.setErrorPagesDir(errorPagesDir); handler.setPatterns(buildPatternsList(properties)); String indexes = properties.get("options"); if ((indexes != null) && "indexes".equalsIgnoreCase(indexes)) { handler.setIndexes(true); } } HttpDirectoryService(); }
HttpDirectoryService implements Service { @Override public void init(ServiceContext serviceContext) throws Exception { this.serviceContext = serviceContext; handler = new HttpDirectoryServiceHandler(); File webDir = serviceContext.getWebDirectory(); ServiceProperties properties = serviceContext.getProperties(); Collection<String> accepts = serviceContext.getAccepts(); Collection<String> failedAccepts = new HashSet<>(); for (String accept : accepts) { String path = URIUtils.getPath(accept); if (path == null || path.isEmpty()) { failedAccepts.add(accept); } } if (!failedAccepts.isEmpty()) { throw new IllegalArgumentException( "The following directory service accept elements are missing the URL path. You may need to add a trailing slash): " + failedAccepts); } String directory = properties.get("directory"); if (directory == null) { throw new IllegalArgumentException("Missing required property: directory"); } File directoryFile = toFile(webDir, directory); String welcomeFile = properties.get("welcome-file"); if (welcomeFile != null) { String pathSeparator = File.pathSeparator; if (welcomeFile.contains(pathSeparator)) { throw new IllegalArgumentException("Unexpected character \"" + pathSeparator + "\" in welcome file: " + welcomeFile); } } File errorPagesDir = toFile(webDir.getParentFile(), properties.get("error-pages-directory")); File clientAccessPolicyXml = new File(directoryFile, "/clientaccesspolicy.xml"); if (clientAccessPolicyXml.exists()) { for (String accept : accepts) { logger.warn( "Ignoring user-defined file contents for {}clientaccesspolicy.xml, please modify configuration instead", accept); } } handler.setServiceContext(serviceContext); handler.setBaseDir(directoryFile); handler.setWelcomeFile(welcomeFile); handler.setErrorPagesDir(errorPagesDir); handler.setPatterns(buildPatternsList(properties)); String indexes = properties.get("options"); if ((indexes != null) && "indexes".equalsIgnoreCase(indexes)) { handler.setIndexes(true); } } HttpDirectoryService(); @Override String getType(); @Override void init(ServiceContext serviceContext); @Override void start(); @Override void stop(); @Override void quiesce(); @Override void destroy(); }
HttpDirectoryService implements Service { @Override public void init(ServiceContext serviceContext) throws Exception { this.serviceContext = serviceContext; handler = new HttpDirectoryServiceHandler(); File webDir = serviceContext.getWebDirectory(); ServiceProperties properties = serviceContext.getProperties(); Collection<String> accepts = serviceContext.getAccepts(); Collection<String> failedAccepts = new HashSet<>(); for (String accept : accepts) { String path = URIUtils.getPath(accept); if (path == null || path.isEmpty()) { failedAccepts.add(accept); } } if (!failedAccepts.isEmpty()) { throw new IllegalArgumentException( "The following directory service accept elements are missing the URL path. You may need to add a trailing slash): " + failedAccepts); } String directory = properties.get("directory"); if (directory == null) { throw new IllegalArgumentException("Missing required property: directory"); } File directoryFile = toFile(webDir, directory); String welcomeFile = properties.get("welcome-file"); if (welcomeFile != null) { String pathSeparator = File.pathSeparator; if (welcomeFile.contains(pathSeparator)) { throw new IllegalArgumentException("Unexpected character \"" + pathSeparator + "\" in welcome file: " + welcomeFile); } } File errorPagesDir = toFile(webDir.getParentFile(), properties.get("error-pages-directory")); File clientAccessPolicyXml = new File(directoryFile, "/clientaccesspolicy.xml"); if (clientAccessPolicyXml.exists()) { for (String accept : accepts) { logger.warn( "Ignoring user-defined file contents for {}clientaccesspolicy.xml, please modify configuration instead", accept); } } handler.setServiceContext(serviceContext); handler.setBaseDir(directoryFile); handler.setWelcomeFile(welcomeFile); handler.setErrorPagesDir(errorPagesDir); handler.setPatterns(buildPatternsList(properties)); String indexes = properties.get("options"); if ((indexes != null) && "indexes".equalsIgnoreCase(indexes)) { handler.setIndexes(true); } } HttpDirectoryService(); @Override String getType(); @Override void init(ServiceContext serviceContext); @Override void start(); @Override void stop(); @Override void quiesce(); @Override void destroy();  }