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