|
24 | 24 | */ |
25 | 25 |
|
26 | 26 | import java.io.File; |
27 | | -import java.io.FileNotFoundException; |
28 | 27 | import java.io.IOException; |
29 | 28 | import java.io.UnsupportedEncodingException; |
30 | 29 | import java.net.URLDecoder; |
| 30 | +import java.nio.file.FileAlreadyExistsException; |
31 | 31 | import java.util.Base64; |
32 | 32 | import java.util.concurrent.Future; |
33 | 33 |
|
34 | | -import jakarta.json.Json; |
35 | | -import jakarta.json.stream.JsonGenerator; |
36 | 34 | import javax.servlet.RequestDispatcher; |
37 | 35 | import javax.servlet.ServletConfig; |
38 | 36 | import javax.servlet.ServletContext; |
|
53 | 51 | import digilib.image.ImageOpException; |
54 | 52 | import digilib.pdf.PDFFileWorker; |
55 | 53 | import digilib.util.DigilibJobCenter; |
| 54 | +import jakarta.json.Json; |
| 55 | +import jakarta.json.stream.JsonGenerator; |
56 | 56 |
|
57 | 57 | /** |
58 | 58 | * A class for handling user requests for pdf documents made from digilib |
@@ -223,12 +223,18 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr |
223 | 223 | // start PDF creation thread |
224 | 224 | createNewPdfDocument(pdfji, docid); |
225 | 225 | // redirect client with docid parameter |
226 | | - String url = ""; |
227 | | - url += "?docid=" + encodeDocid(docid); |
| 226 | + String url = "?docid=" + encodeDocid(docid); |
228 | 227 | logger.debug("redirecting to {}", url); |
229 | 228 | response.sendRedirect(url); |
230 | 229 | return; |
231 | | - } catch (FileNotFoundException e) { |
| 230 | + } catch (FileAlreadyExistsException e) { |
| 231 | + // temp file actually exists - assume WIP |
| 232 | + logger.warn("Temp file seems to exist: {} - assume WIP.", e.getMessage()); |
| 233 | + String url = "?docid=" + encodeDocid(docid); |
| 234 | + logger.debug("redirecting to {}", url); |
| 235 | + response.sendRedirect(url); |
| 236 | + return; |
| 237 | + } catch (IOException e) { |
232 | 238 | // error in pdf creation |
233 | 239 | logger.error(e.getMessage()); |
234 | 240 | notifyUser(PDFStatus.ERROR, docid, request, response); |
@@ -365,16 +371,19 @@ public PDFStatus getStatus(String documentid) { |
365 | 371 | } |
366 | 372 |
|
367 | 373 | /** |
368 | | - * create new thread for pdf generation. |
| 374 | + * Create new thread for pdf generation. |
369 | 375 | * |
370 | 376 | * @param pdfji |
371 | 377 | * @param filename |
372 | 378 | * @return |
373 | | - * @throws FileNotFoundException |
| 379 | + * @throws IOException |
374 | 380 | */ |
375 | | - public Future<File> createNewPdfDocument(PDFRequest pdfji, String filename) throws FileNotFoundException { |
| 381 | + public Future<File> createNewPdfDocument(PDFRequest pdfji, String filename) throws IOException { |
376 | 382 | // start new worker |
377 | 383 | File tempf = this.getTempFile(filename); |
| 384 | + if (!tempf.createNewFile()) { |
| 385 | + throw new FileAlreadyExistsException(tempf.toString()); |
| 386 | + } |
378 | 387 | File finalf = this.getCacheFile(filename); |
379 | 388 | PDFFileWorker job = new PDFFileWorker(dlConfig, tempf, finalf, pdfji, pdfImageJobCenter); |
380 | 389 | // start job |
|
0 commit comments