aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-www/src/main/java')
-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() {
-
- }
}