1919import org .slf4j .LoggerFactory ;
2020import org .springframework .http .MediaType ;
2121import org .springframework .stereotype .Service ;
22+ import org .springframework .util .FileSystemUtils ;
2223
2324/**
2425 * Create Html String from a mustache template file and Json Input File
@@ -44,7 +45,9 @@ public String createHtml(@Nonnull final String advisoryJson) throws IOException
4445 // It has to bbe available in the Context WorkingDirectory
4546 final String documentEntityScript = "DocumentEntity.mjs" ;
4647 final Path tempDir = Files .createTempDirectory ("mustache" );
48+ LOG .info ("Creating temporary directory: {}" , tempDir .toFile ().getAbsolutePath ());
4749 final Path tempDocFile = tempDir .resolve (documentEntityScript );
50+ LOG .info ("Creating temporary doc file: {}" , tempDocFile .toFile ().getAbsolutePath ());
4851
4952 try (final InputStream in = JavascriptExporter .class .getResourceAsStream (documentEntityScript )) {
5053 Files .write (tempDocFile , in .readAllBytes ());
@@ -70,6 +73,13 @@ public String createHtml(@Nonnull final String advisoryJson) throws IOException
7073 final Value renderFunction = scriptResult .getMember ("renderWithMustache" );
7174 final Object result = renderFunction .execute (template , advisoryJson , createLogoJson ());
7275 return result .toString ();
76+ } finally {
77+ try {
78+ LOG .info ("Delete temporary directory: {}" , tempDir .toFile ().getAbsolutePath ());
79+ FileSystemUtils .deleteRecursively (tempDir );
80+ } catch (IOException ex ) {
81+ LOG .warn ("Failed to delete temporary directory: {}" , tempDir .toFile ().getAbsolutePath (), ex );
82+ }
7383 }
7484 }
7585
0 commit comments