aboutsummaryrefslogtreecommitdiff
path: root/juick-www
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-23 12:08:45 +0300
committerGravatar Vitaly Takmazov2016-11-23 12:08:45 +0300
commit42718787291bed507caf4f7ae13f6c41f9b8d7ff (patch)
tree2ba7bb057a6a740e98c5f4d6dae813af1a6b977f /juick-www
parentaa3c1a06ed46f49b617e2956b6cf9a1b0d367fb0 (diff)
using HttpServletResponse status codes
Diffstat (limited to 'juick-www')
-rw-r--r--juick-www/src/main/java/com/juick/www/Errors.java2
-rw-r--r--juick-www/src/main/java/com/juick/www/Login.java8
-rw-r--r--juick-www/src/main/java/com/juick/www/Main.java28
-rw-r--r--juick-www/src/main/java/com/juick/www/NewMessage.java28
-rw-r--r--juick-www/src/main/java/com/juick/www/PM.java6
-rw-r--r--juick-www/src/main/java/com/juick/www/RSS.java2
-rw-r--r--juick-www/src/main/java/com/juick/www/Settings.java10
-rw-r--r--juick-www/src/main/java/com/juick/www/TwitterAuth.java4
-rw-r--r--juick-www/src/main/java/com/juick/www/UserThread.java2
9 files changed, 45 insertions, 45 deletions
diff --git a/juick-www/src/main/java/com/juick/www/Errors.java b/juick-www/src/main/java/com/juick/www/Errors.java
index 85ebf1a6..75fdddde 100644
--- a/juick-www/src/main/java/com/juick/www/Errors.java
+++ b/juick-www/src/main/java/com/juick/www/Errors.java
@@ -20,7 +20,7 @@ public class Errors {
public static void doGet404(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
- response.setStatus(404);
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.setContentType("text/html; charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
PebbleTemplate template = Utils.getEngine().getTemplate("views/404.html");
diff --git a/juick-www/src/main/java/com/juick/www/Login.java b/juick-www/src/main/java/com/juick/www/Login.java
index 19cc855b..27f34c1c 100644
--- a/juick-www/src/main/java/com/juick/www/Login.java
+++ b/juick-www/src/main/java/com/juick/www/Login.java
@@ -186,7 +186,7 @@ public class Login {
protected void doGetLogin(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String hash = request.getQueryString();
if (hash.length() > 32) {
- response.sendError(400);
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
@@ -196,7 +196,7 @@ public class Login {
response.addCookie(c);
response.sendRedirect("/");
} else {
- response.sendError(403);
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
}
}
@@ -204,7 +204,7 @@ public class Login {
String username = request.getParameter("username");
String password = request.getParameter("password");
if (username == null || password == null || username.length() > 32 || password.isEmpty()) {
- response.sendError(400);
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
@@ -222,7 +222,7 @@ public class Login {
response.sendRedirect("/");
}
} else {
- response.sendError(403);
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
}
}
diff --git a/juick-www/src/main/java/com/juick/www/Main.java b/juick-www/src/main/java/com/juick/www/Main.java
index 075b33fa..99d06fe6 100644
--- a/juick-www/src/main/java/com/juick/www/Main.java
+++ b/juick-www/src/main/java/com/juick/www/Main.java
@@ -182,7 +182,7 @@ public class Main extends HttpServlet {
pm.doGetInbox(sql, request, response, visitor);
} catch (PebbleException e) {
log("pebble exception", e);
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
break;
case "/pm/sent":
@@ -190,7 +190,7 @@ public class Main extends HttpServlet {
pm.doGetSent(sql, request, response, visitor);
} catch (PebbleException e) {
log("pebble exception", e);
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
break;
default:
@@ -206,10 +206,10 @@ public class Main extends HttpServlet {
rss.doGet(sql, response, uid);
} catch (PebbleException e) {
log("pebble exception", e);
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
} else {
- response.sendError(404);
+ response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
} else if (uri.equals("/logout")) {
login.doGetLogout(sql, request, response);
@@ -218,7 +218,7 @@ public class Main extends HttpServlet {
settings.doGet(sql, request, response);
} catch (PebbleException e) {
log("pebble exception", e);
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
} else if (uri.equals("/_fblogin")) {
loginFacebook.doGet(sql, request, response);
@@ -231,7 +231,7 @@ public class Main extends HttpServlet {
signup.doGet(sql, request, response);
} catch (PebbleException e) {
log("pebble exception", e);
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
} else if (uri.equals("/help") || uri.equals("/help/")) {
help.doRedirectToHelpIndex(response);
@@ -240,10 +240,10 @@ public class Main extends HttpServlet {
help.doGetHelp(sql, request, response);
} catch (PebbleException e) {
log("pebble exception", e);
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
} catch (URISyntaxException e) {
log("help exception", e);
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
} else if (uri.startsWith("/tag/")) {
discover.doGet(sql, sqlSearch, request, response);
@@ -332,7 +332,7 @@ public class Main extends HttpServlet {
if (visitor.getUid() > 0 && !visitor.isBanned()) {
pagesNewMessage.doPostMessage(sql, request, response, xmpp, visitor);
} else {
- response.sendError(403);
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
}
break;
}
@@ -341,7 +341,7 @@ public class Main extends HttpServlet {
if (visitor.getUid() > 0 && !visitor.isBanned()) {
pagesNewMessage.doPostComment(sql, request, response, xmpp, visitor);
} else {
- response.sendError(403);
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
}
break;
}
@@ -350,7 +350,7 @@ public class Main extends HttpServlet {
if (visitor.getUid() > 0 && !visitor.isBanned()) {
pagesNewMessage.doPostRecomm(sql, request, response, xmpp, visitor);
} else {
- response.sendError(403);
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
}
break;
}
@@ -359,7 +359,7 @@ public class Main extends HttpServlet {
if (visitor.getUid() > 0 && !visitor.isBanned()) {
pm.doPostPM(sql, request, response, xmpp, visitor);
} else {
- response.sendError(403);
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
}
break;
}
@@ -374,11 +374,11 @@ public class Main extends HttpServlet {
settings.doPost(sql, request, response);
} catch (PebbleException e) {
log("pebble exception", e);
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
break;
default:
- response.sendError(405);
+ response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
break;
}
}
diff --git a/juick-www/src/main/java/com/juick/www/NewMessage.java b/juick-www/src/main/java/com/juick/www/NewMessage.java
index 29c834d6..f6e8ec47 100644
--- a/juick-www/src/main/java/com/juick/www/NewMessage.java
+++ b/juick-www/src/main/java/com/juick/www/NewMessage.java
@@ -151,7 +151,7 @@ public class NewMessage {
public void doPostMessage(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, XmppSession xmpp, com.juick.User visitor) 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", "");
@@ -180,7 +180,7 @@ public class NewMessage {
attachmentFName = Utils.receiveMultiPartFile(request, "attach");
} catch (Exception e) {
logger.error("MULTIPART ERROR", e);
- response.sendError(400);
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
@@ -191,7 +191,7 @@ public class NewMessage {
attachmentFName = Utils.downloadImage(imgUrl);
} catch (Exception e) {
logger.error("DOWNLOAD ERROR", e);
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
}
@@ -307,12 +307,12 @@ public class NewMessage {
public void doPostComment(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, XmppSession xmpp, com.juick.User visitor) 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;
}
@@ -321,20 +321,20 @@ public class NewMessage {
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() != visitor.getUid()) || UserQueries.isInBLAny(sql, msg.getUser().getUid(), visitor.getUid()) || (reply != null && UserQueries.isInBLAny(sql, reply.getUser().getUid(), visitor.getUid()))) {
- response.sendError(403);
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
@@ -343,7 +343,7 @@ public class NewMessage {
attachmentFName = Utils.receiveMultiPartFile(request, "attach");
} catch (Exception e) {
logger.error("MULTIPART ERROR", e);
- response.sendError(400);
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
@@ -353,7 +353,7 @@ public class NewMessage {
attachmentFName = Utils.downloadImage(new URL(paramImg));
} catch (Exception e) {
logger.error("DOWNLOAD ERROR", e);
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
}
@@ -420,16 +420,16 @@ public class NewMessage {
public void doPostRecomm(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, XmppSession xmpp, com.juick.User visitor) 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;
}
if (msg.getUser().getUid() == visitor.getUid()) {
- response.sendError(403);
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
@@ -451,7 +451,7 @@ public class NewMessage {
Utils.replyJSON(request, response, "{\"status\":\"ok\"}");
} else {
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
}
diff --git a/juick-www/src/main/java/com/juick/www/PM.java b/juick-www/src/main/java/com/juick/www/PM.java
index 79128e3d..78dbff10 100644
--- a/juick-www/src/main/java/com/juick/www/PM.java
+++ b/juick-www/src/main/java/com/juick/www/PM.java
@@ -99,12 +99,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, visitor.getUid())) {
- response.sendError(403);
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
@@ -143,7 +143,7 @@ public class PM {
Utils.sendTemporaryRedirect(response, "/pm/sent");
} else {
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
}
diff --git a/juick-www/src/main/java/com/juick/www/RSS.java b/juick-www/src/main/java/com/juick/www/RSS.java
index 5218494d..a343d13b 100644
--- a/juick-www/src/main/java/com/juick/www/RSS.java
+++ b/juick-www/src/main/java/com/juick/www/RSS.java
@@ -44,7 +44,7 @@ public class RSS {
protected void doGet(JdbcTemplate sql, HttpServletResponse response, int uid) throws ServletException, IOException, PebbleException {
List<Integer> mids = MessagesQueries.getUserBlog(sql, uid, 0, 0);
if (mids.isEmpty()) {
- response.sendError(404);
+ response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
diff --git a/juick-www/src/main/java/com/juick/www/Settings.java b/juick-www/src/main/java/com/juick/www/Settings.java
index 5c25564f..89eb6718 100644
--- a/juick-www/src/main/java/com/juick/www/Settings.java
+++ b/juick-www/src/main/java/com/juick/www/Settings.java
@@ -118,7 +118,7 @@ public class Settings {
protected void doPost(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, PebbleException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor.getUid() == 0) {
- response.sendError(400);
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
List<String> pages = Arrays.asList("main", "password", "about", "email", "email-add", "email-del",
@@ -126,7 +126,7 @@ public class Settings {
"facebook-enable", "vk-del");
String page = request.getParameter("page");
if (StringUtils.isEmpty(page) || !pages.contains(page)) {
- response.sendError(400);
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
String result = "";
@@ -191,7 +191,7 @@ public class Settings {
result = String.format("<p>New secret email: <strong>%s@mail.juick.com</strong></p>" +
"<p><a href=\"/settings\">Back</a>.</p>", newHash);
} else {
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
break;
@@ -218,7 +218,7 @@ public class Settings {
} catch (MessagingException ex) {
logger.error("mail exception", ex);
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
}
@@ -277,7 +277,7 @@ public class Settings {
result = "<p><a href=\"/settings\">Back</a></p>";
break;
default:
- response.sendError(400);
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
response.setContentType("text/html; charset=UTF-8");
diff --git a/juick-www/src/main/java/com/juick/www/TwitterAuth.java b/juick-www/src/main/java/com/juick/www/TwitterAuth.java
index 173ad7b7..5ea58eb3 100644
--- a/juick-www/src/main/java/com/juick/www/TwitterAuth.java
+++ b/juick-www/src/main/java/com/juick/www/TwitterAuth.java
@@ -49,7 +49,7 @@ public class TwitterAuth {
}
com.juick.User user = UserQueries.getUserByHash(sql, hash);
if ( user == null || user.getUid() == 0) {
- response.sendError(403);
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
OAuth10aService oAuthService = new ServiceBuilder()
@@ -79,7 +79,7 @@ public class TwitterAuth {
response.setStatus(HttpServletResponse.SC_FOUND);
response.setHeader("Location", "http://juick.com/settings");
} else {
- response.sendError(500);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
}
diff --git a/juick-www/src/main/java/com/juick/www/UserThread.java b/juick-www/src/main/java/com/juick/www/UserThread.java
index 394d6712..6355e87e 100644
--- a/juick-www/src/main/java/com/juick/www/UserThread.java
+++ b/juick-www/src/main/java/com/juick/www/UserThread.java
@@ -42,7 +42,7 @@ public class UserThread {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (!MessagesQueries.canViewThread(sql, MID, visitor.getUid())) {
- response.sendError(403);
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}