diff options
author | Vitaly Takmazov | 2016-11-23 12:08:45 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-11-23 12:08:45 +0300 |
commit | 42718787291bed507caf4f7ae13f6c41f9b8d7ff (patch) | |
tree | 2ba7bb057a6a740e98c5f4d6dae813af1a6b977f /juick-api/src/main | |
parent | aa3c1a06ed46f49b617e2956b6cf9a1b0d367fb0 (diff) |
using HttpServletResponse status codes
Diffstat (limited to 'juick-api/src/main')
7 files changed, 43 insertions, 43 deletions
diff --git a/juick-api/src/main/java/com/juick/api/Main.java b/juick-api/src/main/java/com/juick/api/Main.java index dffb9d66..f902fc6b 100644 --- a/juick-api/src/main/java/com/juick/api/Main.java +++ b/juick-api/src/main/java/com/juick/api/Main.java @@ -153,7 +153,7 @@ public class Main extends HttpServlet { if (vuid > 0) { messages.doGetHome(request, response, vuid); } else { - response.sendError(401); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } } else if (uri.equals("/messages")) { messages.doGet(request, response, vuid); @@ -169,19 +169,19 @@ public class Main extends HttpServlet { if (vuid > 0) { pm.doGetPM(request, response, vuid); } else { - response.sendError(401); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } } else if (uri.equals("/groups_pms")) { if (vuid > 0) { others.doGetGroupsPMs(request, response, vuid); } else { - response.sendError(401); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } } else if (uri.equals("/messages/recommended")) { if (vuid > 0) { messages.doGetRecommended(request, response, vuid); } else { - response.sendError(401); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } } else if (uri.equals("/messages/set_popular") && vuid == 3694) { messages.doSetPopular(request, response, xmpp); @@ -192,7 +192,7 @@ public class Main extends HttpServlet { } else if (uri.equals("/notifications")) { notifications.doGet(request, response, vuid); } else { - response.sendError(404); + response.sendError(HttpServletResponse.SC_NOT_FOUND); } } @@ -228,7 +228,7 @@ public class Main extends HttpServlet { vuid = Utils.getVisitorQueryStringUID(jdbc, request); } if (vuid == 0) { - response.sendError(401); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } switch (uri) { @@ -244,7 +244,7 @@ public class Main extends HttpServlet { pm.doPostPM(request, response, xmpp, vuid); break; default: - response.sendError(405); + response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); break; } } @@ -253,7 +253,7 @@ public class Main extends HttpServlet { throws ServletException, IOException { String body = request.getParameter("body"); if (body == null || body.length() < 1 || body.length() > 4096) { - response.sendError(400); + response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } body = body.replace("\r", ""); @@ -282,7 +282,7 @@ public class Main extends HttpServlet { attachmentFName = Utils.receiveMultiPartFile(request, "attach"); } catch (Exception e) { log("MULTIPART ERROR", e); - response.sendError(400); + response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } @@ -293,7 +293,7 @@ public class Main extends HttpServlet { attachmentFName = Utils.downloadImage(imgUrl); } catch (Exception e) { log("DOWNLOAD ERROR", e); - response.sendError(500); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } } @@ -366,12 +366,12 @@ public class Main extends HttpServlet { throws ServletException, IOException { int mid = NumberUtils.toInt(request.getParameter("mid"), 0); if (mid == 0) { - response.sendError(400); + response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } com.juick.Message msg = MessagesQueries.getMessage(sql, mid); if (msg == null) { - response.sendError(404); + response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } @@ -380,21 +380,21 @@ public class Main extends HttpServlet { if (rid > 0) { reply = MessagesQueries.getReply(sql, mid, rid); if (reply == null) { - response.sendError(404); + response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } String body = request.getParameter("body"); if (body == null || body.length() < 1 || body.length() > 4096) { - response.sendError(400); + response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } body = body.replace("\r", ""); if ((msg.ReadOnly && msg.getUser().getUid() != vuid) || UserQueries.isInBLAny(sql, msg.getUser().getUid(), vuid) || (reply != null && UserQueries.isInBLAny(sql, reply.getUser().getUid(), vuid))) { - response.sendError(403); + response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } @@ -403,7 +403,7 @@ public class Main extends HttpServlet { attachmentFName = Utils.receiveMultiPartFile(request, "attach"); } catch (Exception e) { log("MULTIPART ERROR", e); - response.sendError(400); + response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } @@ -413,7 +413,7 @@ public class Main extends HttpServlet { attachmentFName = Utils.downloadImage(new URL(paramImg)); } catch (Exception e) { log("DOWNLOAD ERROR", e); - response.sendError(500); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } } @@ -488,7 +488,7 @@ public class Main extends HttpServlet { vuid = Utils.getVisitorQueryStringUID(jdbc, req); } if (vuid == 0) { - resp.sendError(401); + resp.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } String uri = req.getRequestURI(); @@ -497,7 +497,7 @@ public class Main extends HttpServlet { notifications.doDelete(req, resp, vuid); break; default: - resp.sendError(400); + resp.sendError(HttpServletResponse.SC_BAD_REQUEST); break; } } diff --git a/juick-api/src/main/java/com/juick/api/Messages.java b/juick-api/src/main/java/com/juick/api/Messages.java index 93abb06b..024a79c1 100644 --- a/juick-api/src/main/java/com/juick/api/Messages.java +++ b/juick-api/src/main/java/com/juick/api/Messages.java @@ -76,13 +76,13 @@ public class Messages { if (tagObject != null) { mids = MessagesQueries.getUserTag(sql, user.getUid(), tagObject.TID, 0, before_mid); } else { - response.sendError(404); + response.sendError(HttpServletResponse.SC_NOT_FOUND); } } else { mids = MessagesQueries.getUserBlog(sql, user.getUid(), 0, before_mid); } } else { - response.sendError(404); + response.sendError(HttpServletResponse.SC_NOT_FOUND); } } else { if (!StringUtils.isEmpty(popular)) { @@ -94,7 +94,7 @@ public class Messages { if (tagObject != null) { mids = MessagesQueries.getTag(sql, tagObject.TID, vuid, before_mid, 20); } else { - response.sendError(404); + response.sendError(HttpServletResponse.SC_NOT_FOUND); } } else { mids = MessagesQueries.getAll(sql, vuid, before_mid); @@ -108,14 +108,14 @@ public class Messages { com.juick.Message msg = MessagesQueries.getMessage(sql, mid); if (msg != null) { if (!MessagesQueries.canViewThread(sql, mid, vuid)) { - response.sendError(403); + response.sendError(HttpServletResponse.SC_FORBIDDEN); } else { List<com.juick.Message> replies = MessagesQueries.getReplies(sql, mid); replies.add(0, msg); feedMessages(request, response, replies); } } else { - response.sendError(404); + response.sendError(HttpServletResponse.SC_NOT_FOUND); } } @@ -131,10 +131,10 @@ public class Messages { String json = messageSerializer.serializeList(msgs); Main.replyJSON(request, response, json); } else { - response.sendError(404); + response.sendError(HttpServletResponse.SC_NOT_FOUND); } } else { - response.sendError(404); + response.sendError(HttpServletResponse.SC_NOT_FOUND); } } @@ -146,7 +146,7 @@ public class Messages { if (user != null && user.getUid() == vuid && MessagesQueries.setMessagePrivacy(sql, mid)) { Main.replyJSON(request, response, "{\"status\":\"ok\"}"); } else { - response.sendError(400); + response.sendError(HttpServletResponse.SC_BAD_REQUEST); } } diff --git a/juick-api/src/main/java/com/juick/api/Notifications.java b/juick-api/src/main/java/com/juick/api/Notifications.java index 707df6e4..dbd128b0 100644 --- a/juick-api/src/main/java/com/juick/api/Notifications.java +++ b/juick-api/src/main/java/com/juick/api/Notifications.java @@ -33,7 +33,7 @@ public class Notifications { public void doGet(HttpServletRequest request, HttpServletResponse response, int vuid) throws IOException { User visitor = UserQueries.getUserByUID(jdbc, vuid).orElse(new User()); if ((visitor.getUid() == 0) || !(visitor.getName().equals("juick"))) { - response.sendError(403); + response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } String type = request.getParameter("type"); @@ -54,7 +54,7 @@ public class Notifications { Main.replyJSON(request, response, mapper.writeValueAsString(mpnsTokens)); break; default: - response.sendError(400); + response.sendError(HttpServletResponse.SC_BAD_REQUEST); } } else { @@ -84,11 +84,11 @@ public class Notifications { Main.replyJSON(request, response, mapper.writeValueAsString(mpnsTokens)); break; default: - response.sendError(400); + response.sendError(HttpServletResponse.SC_BAD_REQUEST); } } } else { - response.sendError(400); + response.sendError(HttpServletResponse.SC_BAD_REQUEST); } } } @@ -96,7 +96,7 @@ public class Notifications { public void doDelete(HttpServletRequest request, HttpServletResponse response, int vuid) throws IOException { User visitor = UserQueries.getUserByUID(jdbc, vuid).orElse(new User()); if ((visitor.getUid() == 0) || !(visitor.getName().equals("juick"))) { - response.sendError(403); + response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } ObjectMapper mapper = new ObjectMapper(); diff --git a/juick-api/src/main/java/com/juick/api/Others.java b/juick-api/src/main/java/com/juick/api/Others.java index 6b032531..446c03b5 100644 --- a/juick-api/src/main/java/com/juick/api/Others.java +++ b/juick-api/src/main/java/com/juick/api/Others.java @@ -46,7 +46,7 @@ public class Others { String json = "{\"pms\":" + userSerializer.serializeList(lastconv) + "}"; Main.replyJSON(request, response, json); } else { - response.sendError(404); + response.sendError(HttpServletResponse.SC_NOT_FOUND); } } } diff --git a/juick-api/src/main/java/com/juick/api/PM.java b/juick-api/src/main/java/com/juick/api/PM.java index 86d9c534..1e06e67d 100644 --- a/juick-api/src/main/java/com/juick/api/PM.java +++ b/juick-api/src/main/java/com/juick/api/PM.java @@ -39,7 +39,7 @@ public class PM { } if (uid == 0) { - response.sendError(400); + response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } @@ -48,7 +48,7 @@ public class PM { String json = messageSerializer.serializeList(msgs); Main.replyJSON(request, response, json); } else { - response.sendError(404); + response.sendError(HttpServletResponse.SC_NOT_FOUND); } } @@ -63,12 +63,12 @@ public class PM { String body = request.getParameter("body"); if (uid == 0 || body == null || body.length() < 1 || body.length() > 10240) { - response.sendError(400); + response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } if (UserQueries.isInBLAny(sql, uid, vuid)) { - response.sendError(403); + response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } @@ -103,7 +103,7 @@ public class PM { } } else { - response.sendError(500); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } } diff --git a/juick-api/src/main/java/com/juick/api/Subscriptions.java b/juick-api/src/main/java/com/juick/api/Subscriptions.java index f8bd162f..126832a9 100644 --- a/juick-api/src/main/java/com/juick/api/Subscriptions.java +++ b/juick-api/src/main/java/com/juick/api/Subscriptions.java @@ -27,7 +27,7 @@ public class Subscriptions { public void doGet(HttpServletRequest request, HttpServletResponse response, int vuid) throws IOException { User visitor = UserQueries.getUserByUID(jdbc, vuid).orElse(new User()); if ((visitor.getUid() == 0) && !(visitor.getName().equals("juick"))) { - response.sendError(403); + response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } int uid = NumberUtils.toInt(request.getParameter("uid"), 0); @@ -43,6 +43,6 @@ public class Subscriptions { Main.replyJSON(request, response, userSerializer.serializeList(users)); } } - response.sendError(400); + response.sendError(HttpServletResponse.SC_BAD_REQUEST); } } diff --git a/juick-api/src/main/java/com/juick/api/Users.java b/juick-api/src/main/java/com/juick/api/Users.java index a98af7a8..04e53346 100644 --- a/juick-api/src/main/java/com/juick/api/Users.java +++ b/juick-api/src/main/java/com/juick/api/Users.java @@ -66,7 +66,7 @@ public class Users { String json = userSerializer.serializeList(users); Main.replyJSON(request, response, json); } else { - response.sendError(404); + response.sendError(HttpServletResponse.SC_NOT_FOUND); } } @@ -97,7 +97,7 @@ public class Users { } } } - response.sendError(404); + response.sendError(HttpServletResponse.SC_NOT_FOUND); } public void doGetUserReaders(HttpServletRequest request, @@ -122,6 +122,6 @@ public class Users { Main.replyJSON(request, response, json); return; } - response.sendError(404); + response.sendError(HttpServletResponse.SC_NOT_FOUND); } } |