private void replaceFileWithPackagedOne(File jettyConfig) { InputStream inputStream = null; try { inputStream = getClass().getResourceAsStream(JETTY_XML_LOCATION_IN_JAR + "/" + jettyConfig.getName()); if (inputStream == null) { throw new RuntimeException(format("Resource {0}/{1} does not exist in the classpath", JETTY_XML_LOCATION_IN_JAR, jettyConfig.getName())); } FileUtils.copyInputStreamToFile(inputStream, systemEnvironment.getJettyConfigFile()); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(inputStream); } }
private void performCustomConfiguration() throws Exception { File jettyConfig = systemEnvironment.getJettyConfigFile(); if (jettyConfig.exists()) { replaceJettyXmlIfItBelongsToADifferentVersion(jettyConfig); LOG.info("Configuring Jetty using {}", jettyConfig.getAbsolutePath()); FileInputStream serverConfiguration = new FileInputStream(jettyConfig); XmlConfiguration configuration = new XmlConfiguration(serverConfiguration); configuration.configure(server); } else { String message = String.format( "No custom jetty configuration (%s) found, using defaults.", jettyConfig.getAbsolutePath()); LOG.info(message); } }
@Test public void shouldReplaceJettyXmlIfItDoesNotContainCorrespondingJettyVersionNumber() throws IOException { File jettyXml = temporaryFolder.newFile("jetty.xml"); when(systemEnvironment.getJettyConfigFile()).thenReturn(jettyXml); String originalContent = "jetty-v6.2.3\nsome other local changes"; FileUtils.writeStringToFile(jettyXml, originalContent, UTF_8); jetty9Server.replaceJettyXmlIfItBelongsToADifferentVersion(systemEnvironment.getJettyConfigFile()); assertThat(FileUtils.readFileToString(systemEnvironment.getJettyConfigFile(), UTF_8), is(FileUtils.readFileToString(new File(getClass().getResource("config/jetty.xml").getPath()), UTF_8))); }
@Test public void shouldNotReplaceJettyXmlIfItAlreadyContainsCorrespondingVersionNumber() throws IOException { File jettyXml = temporaryFolder.newFile("jetty.xml"); when(systemEnvironment.getJettyConfigFile()).thenReturn(jettyXml); String originalContent = "jetty-v9.4.8.v20171121\nsome other local changes"; FileUtils.writeStringToFile(jettyXml, originalContent, UTF_8); jetty9Server.replaceJettyXmlIfItBelongsToADifferentVersion(systemEnvironment.getJettyConfigFile()); assertThat(FileUtils.readFileToString(systemEnvironment.getJettyConfigFile(), UTF_8), is(originalContent)); }
@Test public void shouldFindJettyConfigInTheConfigDir() { assertThat(systemEnvironment.getJettyConfigFile(), is(new File(systemEnvironment.getConfigDir(), "jetty.xml"))); systemEnvironment.set(SystemEnvironment.JETTY_XML_FILE_NAME, "jetty-old.xml"); assertThat(systemEnvironment.getJettyConfigFile(), is(new File(systemEnvironment.getConfigDir(), "jetty-old.xml"))); }
when(systemEnvironment.configDir()).thenReturn(configDir = temporaryFolder.newFile()); when(systemEnvironment.get(SystemEnvironment.GO_SSL_RENEGOTIATION_ALLOWED)).thenReturn(true); when(systemEnvironment.getJettyConfigFile()).thenReturn(new File("foo")); when(systemEnvironment.isSessionCookieSecure()).thenReturn(false); when(systemEnvironment.sessionTimeoutInSeconds()).thenReturn(1234);