@Test public void overridePortFileWithDefault() throws Exception { System.setProperty("PORTFILE", this.temporaryFolder.newFile().getAbsolutePath()); WebServerPortFileWriter listener = new WebServerPortFileWriter(); listener.onApplicationEvent(mockEvent("", 8080)); FileReader reader = new FileReader(System.getProperty("PORTFILE")); assertThat(FileCopyUtils.copyToString(reader)).isEqualTo("8080"); }
@Override public void onApplicationEvent(WebServerInitializedEvent event) { File portFile = getPortFile(event.getApplicationContext()); try { String port = String.valueOf(event.getWebServer().getPort()); createParentFolder(portFile); FileCopyUtils.copy(port.getBytes(), portFile); portFile.deleteOnExit(); } catch (Exception ex) { logger.warn(String.format("Cannot create port file %s", this.file)); } }
WebServerPortFileWriter implements ApplicationListener<WebServerInitializedEvent> { @Override public void onApplicationEvent(WebServerInitializedEvent event) { File portFile = getPortFile(event.getApplicationContext()); try { String port = String.valueOf(event.getWebServer().getPort()); createParentFolder(portFile); FileCopyUtils.copy(port.getBytes(), portFile); portFile.deleteOnExit(); } catch (Exception ex) { logger.warn(String.format("Cannot create port file %s", this.file)); } } }
WebServerPortFileWriter implements ApplicationListener<WebServerInitializedEvent> { @Override public void onApplicationEvent(WebServerInitializedEvent event) { File portFile = getPortFile(event.getApplicationContext()); try { String port = String.valueOf(event.getWebServer().getPort()); createParentFolder(portFile); FileCopyUtils.copy(port.getBytes(), portFile); portFile.deleteOnExit(); } catch (Exception ex) { logger.warn(String.format("Cannot create port file %s", this.file)); } } WebServerPortFileWriter();  WebServerPortFileWriter(String filename);  WebServerPortFileWriter(File file); }
WebServerPortFileWriter implements ApplicationListener<WebServerInitializedEvent> { @Override public void onApplicationEvent(WebServerInitializedEvent event) { File portFile = getPortFile(event.getApplicationContext()); try { String port = String.valueOf(event.getWebServer().getPort()); createParentFolder(portFile); FileCopyUtils.copy(port.getBytes(), portFile); portFile.deleteOnExit(); } catch (Exception ex) { logger.warn(String.format("Cannot create port file %s", this.file)); } } WebServerPortFileWriter();  WebServerPortFileWriter(String filename);  WebServerPortFileWriter(File file); @Override void onApplicationEvent(WebServerInitializedEvent event); }
WebServerPortFileWriter implements ApplicationListener<WebServerInitializedEvent> { @Override public void onApplicationEvent(WebServerInitializedEvent event) { File portFile = getPortFile(event.getApplicationContext()); try { String port = String.valueOf(event.getWebServer().getPort()); createParentFolder(portFile); FileCopyUtils.copy(port.getBytes(), portFile); portFile.deleteOnExit(); } catch (Exception ex) { logger.warn(String.format("Cannot create port file %s", this.file)); } } WebServerPortFileWriter();  WebServerPortFileWriter(String filename);  WebServerPortFileWriter(File file); @Override void onApplicationEvent(WebServerInitializedEvent event);  }