aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-03-01 20:16:37 +0300
committerGravatar Vitaly Takmazov2018-03-01 22:15:47 +0300
commit185625ef92e7c2991030d5db35ca5904d88ba922 (patch)
tree8d97f01a227b2490f88332caa1eaa5d529495b39
parent6564cc617d72f06261009db94f839eba5d13c6eb (diff)
server: fix rss content type
-rw-r--r--juick-server/src/main/java/com/juick/server/api/rss/MessagesView.java11
-rw-r--r--juick-server/src/main/java/com/juick/server/api/rss/RepliesView.java11
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java3
3 files changed, 21 insertions, 4 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/rss/MessagesView.java b/juick-server/src/main/java/com/juick/server/api/rss/MessagesView.java
index f61757a6..3ee458c8 100644
--- a/juick-server/src/main/java/com/juick/server/api/rss/MessagesView.java
+++ b/juick-server/src/main/java/com/juick/server/api/rss/MessagesView.java
@@ -38,6 +38,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.view.feed.AbstractRssFeedView;
+import javax.annotation.Nonnull;
+import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URI;
@@ -55,8 +57,15 @@ public class MessagesView extends AbstractRssFeedView {
private static final Logger logger = LoggerFactory.getLogger(MessagesView.class);
+ @PostConstruct
+ public void init() {
+ setContentType("application/rss+xml;charset=UTF-8");
+ }
+
@Override
- protected List<Item> buildFeedItems(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
+ protected List<Item> buildFeedItems(@Nonnull Map<String, Object> model,
+ @Nonnull HttpServletRequest request,
+ @Nonnull HttpServletResponse response) {
List<Message> msgs = (List<Message>)model.get("messages");
return msgs.stream().map(this::createRssItem).collect(Collectors.toList());
}
diff --git a/juick-server/src/main/java/com/juick/server/api/rss/RepliesView.java b/juick-server/src/main/java/com/juick/server/api/rss/RepliesView.java
index b53e9750..a5411397 100644
--- a/juick-server/src/main/java/com/juick/server/api/rss/RepliesView.java
+++ b/juick-server/src/main/java/com/juick/server/api/rss/RepliesView.java
@@ -34,6 +34,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.view.feed.AbstractRssFeedView;
+import javax.annotation.Nonnull;
+import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URI;
@@ -49,8 +51,15 @@ public class RepliesView extends AbstractRssFeedView {
private static final Logger logger = LoggerFactory.getLogger(RepliesView.class);
+ @PostConstruct
+ public void init() {
+ setContentType("application/rss+xml;charset=UTF-8");
+ }
+
@Override
- protected List<Item> buildFeedItems(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
+ protected List<Item> buildFeedItems(@Nonnull Map<String, Object> model,
+ @Nonnull HttpServletRequest request,
+ @Nonnull HttpServletResponse response) {
List<ResponseReply> msgs = (List<ResponseReply>)model.get("messages");
return msgs.stream().map(this::createRssItem).collect(Collectors.toList());
}
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index 4496f68c..ecb06d45 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -68,7 +68,6 @@ import java.util.stream.IntStream;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.when;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -352,7 +351,7 @@ public class ServerTests extends AbstractJUnit4SpringContextTests {
mockMvc.perform(
get("/rss/"))
.andExpect(status().isOk())
- .andExpect(content().contentType("application/rss+xml"))
+ .andExpect(content().contentType("application/rss+xml;charset=UTF-8"))
.andExpect(xpath("/rss/channel/description").string("The latest messages at Juick"));
}
@Test