@@ -149,35 +149,35 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
149149 // GET must have (encoded) docid from POST
150150 String docid = request .getParameter ("docid" );
151151 if (docid == null || docid .isEmpty ()) {
152- notifyUser (PDFStatus .ERROR , "[missing docid]" , request , response );
152+ notifyUser (PDFStatus .ERROR , "[missing docid]" , null , request , response );
153153 return ;
154154 }
155155 try {
156156 docid = decodeDocid (docid );
157157 } catch (Exception e ) {
158- notifyUser (PDFStatus .ERROR , "[invalid docid]" , request , response );
158+ notifyUser (PDFStatus .ERROR , "[invalid docid]" , null , request , response );
159159 return ;
160160 }
161161
162162 PDFStatus status = getStatus (docid );
163163 if (status == PDFStatus .NONEXISTENT ) {
164164 // no file -- should not happen
165165 logger .error ("Nonexistent file for docid!" );
166- notifyUser (PDFStatus .ERROR , docid , request , response );
166+ notifyUser (PDFStatus .ERROR , docid , "Nonexistent file for docid!" , request , response );
167167 return ;
168168
169169 } else if (status == PDFStatus .DONE ) {
170170 // pdf created
171171 if (isJsonRequest (request )) {
172172 // send json status
173- notifyUser (status , docid , request , response );
173+ notifyUser (status , docid , null , request , response );
174174 return ;
175175 } else {
176176 // send file
177177 try {
178178 logger .debug ("PDF docid={} DONE" , docid );
179- ServletOps .sendFile (getCacheFile (docid ), "application/pdf" , getDownloadFilename (docid ), response ,
180- logger );
179+ ServletOps .sendFile (getCacheFile (docid ), "application/pdf" , getDownloadFilename (docid ),
180+ response , logger );
181181 return ;
182182 } catch (Exception e ) {
183183 // sending didn't work
@@ -188,7 +188,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
188188
189189 } else {
190190 // should be work in progress
191- notifyUser (status , docid , request , response );
191+ notifyUser (status , docid , null , request , response );
192192 return ;
193193 }
194194 }
@@ -218,7 +218,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
218218
219219 // if some invalid data has been entered ...
220220 if (!pdfji .isValid ()) {
221- notifyUser (PDFStatus .ERROR , docid , request , response );
221+ notifyUser (PDFStatus .ERROR , docid , "Invalid PDF parameters!" , request , response );
222222 return ;
223223 }
224224
@@ -243,7 +243,8 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
243243 } catch (IOException e ) {
244244 // error in pdf creation
245245 logger .error (e .getMessage ());
246- notifyUser (PDFStatus .ERROR , docid , request , response );
246+ notifyUser (PDFStatus .ERROR , docid , "Error creating PDF: " + e .getMessage (),
247+ request , response );
247248 return ;
248249 }
249250
@@ -258,8 +259,8 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
258259 // send the file
259260 try {
260261 logger .debug ("PDF docid={} already DONE" , docid );
261- ServletOps .sendFile (getCacheFile (docid ), "application/pdf" , getDownloadFilename (pdfji ), response ,
262- logger );
262+ ServletOps .sendFile (getCacheFile (docid ), "application/pdf" , getDownloadFilename (pdfji ),
263+ response , logger );
263264 return ;
264265 } catch (Exception e ) {
265266 // sending didn't work
@@ -276,12 +277,13 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
276277 } catch (IOException e ) {
277278 // io error in pdf creation
278279 logger .error ("IO error for request: {}" , e .getMessage ());
279- notifyUser (PDFStatus .IOERROR , docid , request , response );
280+ notifyUser (PDFStatus .IOERROR , docid , null , request , response );
280281 return ;
281282 } catch (ImageOpException e ) {
282283 // other error in pdf creation
283284 logger .error ("Error processing request: {}" , e .getMessage ());
284- notifyUser (PDFStatus .ERROR , docid , request , response );
285+ notifyUser (PDFStatus .ERROR , docid , "Error processing PDF: " + e .getMessage (),
286+ request , response );
285287 return ;
286288 }
287289 }
@@ -292,47 +294,54 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
292294 *
293295 * @param status
294296 * @param documentid
297+ * @param message TODO
295298 * @param request
296299 * @param response
297300 */
298- public void notifyUser (PDFStatus status , String documentid , HttpServletRequest request ,
299- HttpServletResponse response ) {
301+ public void notifyUser (PDFStatus status , String documentid , String message ,
302+ HttpServletRequest request , HttpServletResponse response ) {
300303
301304 String nextPage = null ;
302- String message = null ;
305+ String usermsg = null ;
303306 int httpStatus = 0 ;
304307
305308 if (status == PDFStatus .NONEXISTENT ) {
306309 // this status should not end up here
307310 logger .debug ("PDFGenerator: {} has STATUS_NONEXISTENT." , documentid );
308311 nextPage = dlConfig .getAsString (WIP_PAGE_KEY );
309- message = "Document " + documentid + " is being generated" ;
312+ usermsg = "Document " + documentid + " is being generated" ;
310313 httpStatus = HttpServletResponse .SC_ACCEPTED ;
311314
312315 } else if (status == PDFStatus .WIP ) {
313316 logger .debug ("PDFGenerator: {} has STATUS_WIP." , documentid );
314317 nextPage = dlConfig .getAsString (WIP_PAGE_KEY );
315- message = "Document " + documentid + " is being generated" ;
318+ usermsg = "Document " + documentid + " is being generated" ;
316319 httpStatus = HttpServletResponse .SC_ACCEPTED ;
317320 // TODO: show progress
318321
319322 } else if (status == PDFStatus .DONE ) {
320323 // this status should not end up here
321324 logger .debug ("PDFGenerator: {} has STATUS_DONE." , documentid );
322- message = "Document " + documentid + " has been generated" ;
325+ usermsg = "Document " + documentid + " has been generated" ;
323326 httpStatus = HttpServletResponse .SC_OK ;
324327
325328 } else if (status == PDFStatus .IOERROR ) {
326329 logger .debug ("PDFGenerator: {} has STATUS_IOERROR." , documentid );
327330 nextPage = dlConfig .getAsString (IOERROR_PAGE_KEY );
328- message = "File not found error for document " + documentid ;
331+ usermsg = "File not found error for document " + documentid ;
332+ if (message != null ) {
333+ usermsg += " " + message ;
334+ }
329335 httpStatus = HttpServletResponse .SC_NOT_FOUND ;
330336
331337 } else {
332338 // must be an error
333339 logger .debug ("PDFGenerator: {} has STATUS_ERROR." , documentid );
334340 nextPage = dlConfig .getAsString (ERROR_PAGE_KEY );
335- message = "Error in request for document " + documentid ;
341+ usermsg = "Error in request for document " + documentid ;
342+ if (message != null ) {
343+ usermsg += " " + message ;
344+ }
336345 httpStatus = HttpServletResponse .SC_BAD_REQUEST ;
337346 }
338347
@@ -349,7 +358,7 @@ public void notifyUser(PDFStatus status, String documentid, HttpServletRequest r
349358 info .writeStartObject ()
350359 .write ("docid" , documentid )
351360 .write ("status" , status .toString ())
352- .write ("message" , message )
361+ .write ("message" , usermsg )
353362 .writeEnd ();
354363 info .close ();
355364
0 commit comments