aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-05-22 22:36:18 +0300
committerGravatar Vitaly Takmazov2018-05-22 22:36:18 +0300
commitbc32308c2802b239d9741c994ebe2b2287d5504b (patch)
tree9c85713b4f1ab7003037cd11bc1724225618de90 /juick-www/src/main/java/com/juick
parentf800eaa88d4b03a424b568cf0fb423ede19cf4fb (diff)
www: AnythingFilter is OncePerRequestFilter
Diffstat (limited to 'juick-www/src/main/java/com/juick')
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/AnythingFilter.java23
1 files changed, 9 insertions, 14 deletions
diff --git a/juick-www/src/main/java/com/juick/www/controllers/AnythingFilter.java b/juick-www/src/main/java/com/juick/www/controllers/AnythingFilter.java
index 2e6da6c3..d4519539 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/AnythingFilter.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/AnythingFilter.java
@@ -5,27 +5,28 @@ import com.juick.service.MessagesService;
import com.juick.service.UserService;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import org.springframework.web.util.UriComponents;
+import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Component
-public class AnythingFilter implements Filter {
+public class AnythingFilter extends OncePerRequestFilter {
@Inject
private MessagesService messagesService;
@Inject
private UserService userService;
- @Override
- public void init(FilterConfig filterConfig) throws ServletException {
-
- }
@Override
- public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+ public void doFilterInternal(@Nonnull HttpServletRequest servletRequest,
+ @Nonnull HttpServletResponse servletResponse,
+ @Nonnull FilterChain filterChain) throws IOException, ServletException {
UriComponents components = ServletUriComponentsBuilder.fromCurrentRequestUri().build();
String anything = components.getPath().substring(1);
int before = NumberUtils.toInt(components.getQueryParams().getFirst("before"), 0);
@@ -39,9 +40,8 @@ public class AnythingFilter implements Filter {
com.juick.User author = messagesService.getMessageAuthor(messageId);
if (author != null) {
- HttpServletResponse response = ((HttpServletResponse)servletResponse);
- response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
- response.setHeader("Location", "/" + author.getName() + "/" + anything);
+ servletResponse.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
+ servletResponse.setHeader("Location", "/" + author.getName() + "/" + anything);
return;
}
}
@@ -61,9 +61,4 @@ public class AnythingFilter implements Filter {
}
}
}
-
- @Override
- public void destroy() {
-
- }
}