Simplify exception handling
This commit is contained in:
parent
5415459087
commit
bec21c49dd
2 changed files with 107 additions and 113 deletions
|
|
@ -204,6 +204,8 @@ public class AlbumServlet
|
|||
req.setAttribute("base", req.getContextPath() + req.getServletPath());
|
||||
req.setAttribute("mapper", new Mapper());
|
||||
String pathInfo = req.getPathInfo();
|
||||
|
||||
try {
|
||||
if (pathInfo != null && pathInfo.startsWith(basePrefix)) {
|
||||
pathInfo = pathInfo.substring(basePrefix.length());
|
||||
} else if (pathInfo.equals("/search")) {
|
||||
|
|
@ -259,31 +261,26 @@ public class AlbumServlet
|
|||
String size = req.getParameter("size");
|
||||
if (size != null) {
|
||||
|
||||
try {
|
||||
FileEntry e = (FileEntry)resolve(file);
|
||||
procesScaledImageRequest(req, res, file, e.getThumbnail(), size);
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("sadness", e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.fillInStackTrace();
|
||||
throw new ServletException("sadness", e);
|
||||
}
|
||||
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
|
||||
void handlePhoto(HttpServletRequest req, HttpServletResponse res, FileEntry entry) {
|
||||
try {
|
||||
void handlePhoto(HttpServletRequest req, HttpServletResponse res, FileEntry entry) throws Exception {
|
||||
res.setContentType("text/html");
|
||||
req.setAttribute("entry", entry);
|
||||
req.setAttribute("thmb", new Integer(800));
|
||||
RequestDispatcher rd = req.getRequestDispatcher("/WEB-INF/velocity/photo.vm");
|
||||
rd.forward(req, res);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("sadness", ex);
|
||||
}
|
||||
}
|
||||
|
||||
void handleAlbum(HttpServletRequest req, HttpServletResponse res, DirectoryEntry entry) {
|
||||
try {
|
||||
void handleAlbum(HttpServletRequest req, HttpServletResponse res, DirectoryEntry entry) throws Exception {
|
||||
res.setContentType("text/html");
|
||||
req.setAttribute("entry", entry);
|
||||
req.setAttribute("thmb", new Integer(250));
|
||||
|
|
@ -291,12 +288,9 @@ public class AlbumServlet
|
|||
req.setAttribute("D", "$");
|
||||
RequestDispatcher rd = req.getRequestDispatcher("/WEB-INF/velocity/dynamic.vm");
|
||||
rd.forward(req, res);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("sadness", e);
|
||||
}
|
||||
}
|
||||
|
||||
void handleMovieFrame(HttpServletRequest req, HttpServletResponse res, FileEntry entry) {
|
||||
void handleMovieFrame(HttpServletRequest req, HttpServletResponse res, FileEntry entry) throws Exception {
|
||||
|
||||
File file = entry.getPath();
|
||||
if (notModified(req, file)) {
|
||||
|
|
@ -326,6 +320,7 @@ public class AlbumServlet
|
|||
thumbDb.store(key, cimg);
|
||||
log.info(" " + key + " added to the cache with size " + cimg.bits.length + " -- now " + thumbDb.size() + " entries");
|
||||
} catch (Exception e) {
|
||||
e.fillInStackTrace();
|
||||
throw new RuntimeException("sadness", e);
|
||||
}
|
||||
}
|
||||
|
|
@ -381,6 +376,7 @@ public class AlbumServlet
|
|||
out.println(" \"name\": " + jsStr(e.getName()) + ",");
|
||||
out.println(" \"path\": " + jsStr(mapper.map(e.getThumbnail().getPath())) + ",");
|
||||
out.println(" \"type\": " + jsStr(e.getType()) + ",");
|
||||
out.println(" \"thumbtype\": " + jsStr(e.getThumbnail().getType()) + ",");
|
||||
out.println(" \"width\": " + e.getThumbnail().getSize().getWidth() + ",");
|
||||
out.println(" \"height\": " + e.getThumbnail().getSize().getHeight() + ",");
|
||||
out.println(" \"caption\": " + jsStr(e.getCaption()));
|
||||
|
|
@ -398,8 +394,7 @@ public class AlbumServlet
|
|||
return in == null ? "null" : "\"" + in.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n") + "\"";
|
||||
}
|
||||
|
||||
void handleEdit(HttpServletRequest req, HttpServletResponse res, FileEntry entry) {
|
||||
try {
|
||||
void handleEdit(HttpServletRequest req, HttpServletResponse res, FileEntry entry) throws Exception {
|
||||
String value = req.getParameter("value");
|
||||
if (value != null) {
|
||||
File propertyFile = new File(entry.getPath().getParent(), "album.properties");
|
||||
|
|
@ -423,13 +418,10 @@ public class AlbumServlet
|
|||
req.setAttribute("thmb", new Integer(640));
|
||||
RequestDispatcher rd = req.getRequestDispatcher("/WEB-INF/velocity/edit.vm");
|
||||
rd.forward(req, res);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("sadness", ex);
|
||||
}
|
||||
}
|
||||
|
||||
void handleSearch(HttpServletRequest req, HttpServletResponse res, DirectoryEntry entry) {
|
||||
try {
|
||||
|
||||
void handleSearch(HttpServletRequest req, HttpServletResponse res, DirectoryEntry entry) throws Exception {
|
||||
String query = req.getParameter("q");
|
||||
|
||||
SearchEngine search = new SearchEngine(entry);
|
||||
|
|
@ -442,9 +434,6 @@ public class AlbumServlet
|
|||
req.setAttribute("full", new Integer(800));
|
||||
RequestDispatcher rd = req.getRequestDispatcher("/WEB-INF/velocity/photo.vm");
|
||||
rd.forward(req, res);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("sadness", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,12 @@ public class PictureScaler {
|
|||
|
||||
@Override
|
||||
public CachedImage call() throws Exception {
|
||||
try {
|
||||
return scalePictureReally(file, thumbnail, size);
|
||||
} catch (Exception e) {
|
||||
log.error("sadness", e);
|
||||
return new CachedImage();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFuture(Future<CachedImage> future) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue