Catch a few corner case errors in web app

This commit is contained in:
Sean Owen 2017-04-15 15:31:25 +01:00
parent 6ae3a36107
commit c64568c0a2
2 changed files with 12 additions and 5 deletions

View file

@ -29,9 +29,10 @@ final class Java8Base64Decoder extends Base64Decoder {
.getMethod("getDecoder").invoke(null);
return (byte[]) Class.forName("java.util.Base64$Decoder")
.getMethod("decode", String.class).invoke(decoder, s);
} catch (IllegalAccessException | InvocationTargetException |
NoSuchMethodException | ClassNotFoundException e) {
} catch (IllegalAccessException | NoSuchMethodException | ClassNotFoundException e) {
throw new IllegalStateException(e);
} catch (InvocationTargetException ite) {
throw new IllegalStateException(ite.getCause());
}
}
}

View file

@ -63,6 +63,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@ -164,8 +165,8 @@ public final class DecodeServlet extends HttpServlet {
try {
BufferedImage image = ImageReader.readDataURIImage(imageURI);
processImage(image, request, response);
} catch (IOException ioe) {
log.info(ioe.toString());
} catch (IOException | IllegalStateException e) {
log.info(e.toString());
errorResponse(request, response, "badurl");
}
return;
@ -421,7 +422,12 @@ public final class DecodeServlet extends HttpServlet {
String text = bundle.getString("response.error." + key + ".text");
request.setAttribute("title", title);
request.setAttribute("text", text);
request.getRequestDispatcher("response.jspx").forward(request, response);
RequestDispatcher dispatcher = request.getRequestDispatcher("response.jspx");
if (dispatcher == null) {
log.warning("Can't obtain RequestDispatcher");
} else {
dispatcher.forward(request, response);
}
}
}