From d5c5ce29eb53f6f396ed9fe309f7a8804287a558 Mon Sep 17 00:00:00 2001 From: Daniel Gerhardt <code@dgerhardt.net> Date: Sat, 10 Feb 2018 12:53:24 +0100 Subject: [PATCH] Explicitly set media type text/plain for non-JSON --- .../controller/v2/CommentController.java | 7 ++-- .../controller/v2/ContentController.java | 41 +++++++++++-------- .../controller/v2/FeedbackController.java | 25 +++++------ .../arsnova/controller/v2/RoomController.java | 19 +++++---- .../controller/v2/SocketController.java | 3 +- .../controller/v2/StatisticsController.java | 13 +++--- 6 files changed, 60 insertions(+), 48 deletions(-) diff --git a/src/main/java/de/thm/arsnova/controller/v2/CommentController.java b/src/main/java/de/thm/arsnova/controller/v2/CommentController.java index d79b860ca..dc7a9fc5b 100644 --- a/src/main/java/de/thm/arsnova/controller/v2/CommentController.java +++ b/src/main/java/de/thm/arsnova/controller/v2/CommentController.java @@ -35,6 +35,7 @@ import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -68,11 +69,11 @@ public class CommentController extends PaginationController { @ApiOperation(value = "Count all the comments in current room", nickname = "getCommentCount") - @RequestMapping(value = "/count", method = RequestMethod.GET) + @RequestMapping(value = "/count", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) @DeprecatedApi @Deprecated - public int getCommentCount(@ApiParam(value = "Room-Key from current room", required = true) @RequestParam("sessionkey") final String roomShortId) { - return commentService.count(roomShortId); + public String getCommentCount(@ApiParam(value = "Room-Key from current room", required = true) @RequestParam("sessionkey") final String roomShortId) { + return String.valueOf(commentService.count(roomShortId)); } @ApiOperation(value = "count all unread comments", diff --git a/src/main/java/de/thm/arsnova/controller/v2/ContentController.java b/src/main/java/de/thm/arsnova/controller/v2/ContentController.java index c83c07b66..590ef0b36 100644 --- a/src/main/java/de/thm/arsnova/controller/v2/ContentController.java +++ b/src/main/java/de/thm/arsnova/controller/v2/ContentController.java @@ -41,6 +41,7 @@ import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -343,22 +344,25 @@ public class ContentController extends PaginationController { nickname = "getContentCount") @DeprecatedApi @Deprecated - @RequestMapping(value = "/count", method = RequestMethod.GET) - public int getContentCount( + @RequestMapping(value = "/count", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String getContentCount( @RequestParam(value = "sessionkey") final String roomShortId, @RequestParam(value = "lecturequestionsonly", defaultValue = "false") final boolean lectureContentsOnly, @RequestParam(value = "flashcardsonly", defaultValue = "false") final boolean flashcardsOnly, @RequestParam(value = "preparationquestionsonly", defaultValue = "false") final boolean preparationContentsOnly ) { + int count = 0; if (lectureContentsOnly) { - return contentService.countLectureContents(roomShortId); + count = contentService.countLectureContents(roomShortId); } else if (preparationContentsOnly) { - return contentService.countPreparationContents(roomShortId); + count = contentService.countPreparationContents(roomShortId); } else if (flashcardsOnly) { - return contentService.countFlashcards(roomShortId); + count = contentService.countFlashcards(roomShortId); } else { - return contentService.countByRoomShortId(roomShortId); + count = contentService.countByRoomShortId(roomShortId); } + + return String.valueOf(count); } @ApiOperation(value = "Delete answers and content", @@ -584,9 +588,9 @@ public class ContentController extends PaginationController { nickname = "getAnswerCount") @DeprecatedApi @Deprecated - @RequestMapping(value = "/{contentId}/answercount", method = RequestMethod.GET) - public int getAnswerCount(@PathVariable final String contentId) { - return contentService.countAnswersByContentIdAndRound(contentId); + @RequestMapping(value = "/{contentId}/answercount", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String getAnswerCount(@PathVariable final String contentId) { + return String.valueOf(contentService.countAnswersByContentIdAndRound(contentId)); } @ApiOperation(value = "Get the amount of answers for a content, identified by the content ID", @@ -601,9 +605,9 @@ public class ContentController extends PaginationController { @ApiOperation(value = "Get the total amount of answers by a content, identified by the content ID", nickname = "getTotalAnswerCountByContent") - @RequestMapping(value = "/{contentId}/totalanswercount", method = RequestMethod.GET) - public int getTotalAnswerCountByContent(@PathVariable final String contentId) { - return contentService.countTotalAnswersByContentId(contentId); + @RequestMapping(value = "/{contentId}/totalanswercount", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String getTotalAnswerCountByContent(@PathVariable final String contentId) { + return String.valueOf(contentService.countTotalAnswersByContentId(contentId)); } @ApiOperation(value = "Get the amount of answers and abstention answers by a content, identified by the content ID", @@ -640,18 +644,21 @@ public class ContentController extends PaginationController { nickname = "getTotalAnswerCount") @DeprecatedApi @Deprecated - @RequestMapping(value = "/answercount", method = RequestMethod.GET) - public int getTotalAnswerCount( + @RequestMapping(value = "/answercount", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String getTotalAnswerCount( @RequestParam(value = "sessionkey") final String roomShortId, @RequestParam(value = "lecturequestionsonly", defaultValue = "false") final boolean lectureContentsOnly, @RequestParam(value = "preparationquestionsonly", defaultValue = "false") final boolean preparationContentsOnly ) { + int count = 0; if (lectureContentsOnly) { - return contentService.countLectureContentAnswers(roomShortId); + count = contentService.countLectureContentAnswers(roomShortId); } else if (preparationContentsOnly) { - return contentService.countPreparationContentAnswers(roomShortId); + count = contentService.countPreparationContentAnswers(roomShortId); } else { - return contentService.countTotalAnswersByRoomShortId(roomShortId); + count = contentService.countTotalAnswersByRoomShortId(roomShortId); } + + return String.valueOf(count); } } diff --git a/src/main/java/de/thm/arsnova/controller/v2/FeedbackController.java b/src/main/java/de/thm/arsnova/controller/v2/FeedbackController.java index 863a08eda..1d15fada0 100644 --- a/src/main/java/de/thm/arsnova/controller/v2/FeedbackController.java +++ b/src/main/java/de/thm/arsnova/controller/v2/FeedbackController.java @@ -27,6 +27,7 @@ import de.thm.arsnova.web.DeprecatedApi; import de.thm.arsnova.websocket.ArsnovaSocketioServerImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -57,34 +58,34 @@ public class FeedbackController extends AbstractController { @DeprecatedApi @Deprecated - @RequestMapping(value = "/session/{shortId}/myfeedback", method = RequestMethod.GET) - public Integer getMyFeedback(@PathVariable final String shortId) { + @RequestMapping(value = "/session/{shortId}/myfeedback", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String getMyFeedback(@PathVariable final String shortId) { Integer value = feedbackService.getByRoomShortIdAndUser(shortId, userService.getCurrentUser()); if (value != null && value >= Feedback.MIN_FEEDBACK_TYPE && value <= Feedback.MAX_FEEDBACK_TYPE) { - return value; + return value.toString(); } throw new NotFoundException(); } @DeprecatedApi @Deprecated - @RequestMapping(value = "/session/{shortId}/feedbackcount", method = RequestMethod.GET) - public int getFeedbackCount(@PathVariable final String shortId) { - return feedbackService.countFeedbackByRoomShortId(shortId); + @RequestMapping(value = "/session/{shortId}/feedbackcount", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String getFeedbackCount(@PathVariable final String shortId) { + return String.valueOf(feedbackService.countFeedbackByRoomShortId(shortId)); } @DeprecatedApi @Deprecated - @RequestMapping(value = "/session/{shortId}/roundedaveragefeedback", method = RequestMethod.GET) - public long getAverageFeedbackRounded(@PathVariable final String shortId) { - return feedbackService.calculateRoundedAverageFeedback(shortId); + @RequestMapping(value = "/session/{shortId}/roundedaveragefeedback", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String getAverageFeedbackRounded(@PathVariable final String shortId) { + return String.valueOf(feedbackService.calculateRoundedAverageFeedback(shortId)); } @DeprecatedApi @Deprecated - @RequestMapping(value = "/session/{shortId}/averagefeedback", method = RequestMethod.GET) - public double getAverageFeedback(@PathVariable final String shortId) { - return feedbackService.calculateAverageFeedback(shortId); + @RequestMapping(value = "/session/{shortId}/averagefeedback", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String getAverageFeedback(@PathVariable final String shortId) { + return String.valueOf(feedbackService.calculateAverageFeedback(shortId)); } @DeprecatedApi diff --git a/src/main/java/de/thm/arsnova/controller/v2/RoomController.java b/src/main/java/de/thm/arsnova/controller/v2/RoomController.java index 00603eb58..6fa4d191b 100644 --- a/src/main/java/de/thm/arsnova/controller/v2/RoomController.java +++ b/src/main/java/de/thm/arsnova/controller/v2/RoomController.java @@ -39,6 +39,7 @@ import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.security.access.AccessDeniedException; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -101,9 +102,9 @@ public class RoomController extends PaginationController { nickname = "countActiveUsers") @DeprecatedApi @Deprecated - @RequestMapping(value = "/{shortId}/activeusercount", method = RequestMethod.GET) - public int countActiveUsers(@ApiParam(value = "Room-Key from current Room", required = true) @PathVariable final String shortId) { - return roomService.activeUsers(shortId); + @RequestMapping(value = "/{shortId}/activeusercount", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String countActiveUsers(@ApiParam(value = "Room-Key from current Room", required = true) @PathVariable final String shortId) { + return String.valueOf(roomService.activeUsers(shortId)); } @ApiOperation(value = "Creates a new Room and returns the Room's data", @@ -400,26 +401,26 @@ public class RoomController extends PaginationController { return toV2Migrator.migrate(room.getSettings()); } - @RequestMapping(value = "/{shortId}/lockfeedbackinput", method = RequestMethod.POST) + @RequestMapping(value = "/{shortId}/lockfeedbackinput", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE) @ApiOperation(value = "locks input of user live feedback", nickname = "lockFeedbackInput") - public boolean lockFeedbackInput( + public String lockFeedbackInput( @ApiParam(value = "Room-Key from current Room", required = true) @PathVariable final String shortId, @ApiParam(value = "lock", required = true) @RequestParam(required = true) final Boolean lock, final HttpServletResponse response ) { - return roomService.lockFeedbackInput(shortId, lock); + return String.valueOf(roomService.lockFeedbackInput(shortId, lock)); } - @RequestMapping(value = "/{shortId}/flipflashcards", method = RequestMethod.POST) + @RequestMapping(value = "/{shortId}/flipflashcards", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE) @ApiOperation(value = "flip all flashcards in Room", nickname = "lockFeedbackInput") - public boolean flipFlashcards( + public String flipFlashcards( @ApiParam(value = "Room-Key from current Room", required = true) @PathVariable final String shortId, @ApiParam(value = "flip", required = true) @RequestParam(required = true) final Boolean flip, final HttpServletResponse response ) { - return roomService.flipFlashcards(shortId, flip); + return String.valueOf(roomService.flipFlashcards(shortId, flip)); } /* internal redirections */ diff --git a/src/main/java/de/thm/arsnova/controller/v2/SocketController.java b/src/main/java/de/thm/arsnova/controller/v2/SocketController.java index 8899dfa50..5553f513e 100644 --- a/src/main/java/de/thm/arsnova/controller/v2/SocketController.java +++ b/src/main/java/de/thm/arsnova/controller/v2/SocketController.java @@ -30,6 +30,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -83,7 +84,7 @@ public class SocketController extends AbstractController { @ApiOperation(value = "retrieves a socket url", nickname = "getSocketUrl") - @RequestMapping(value = "/url", method = RequestMethod.GET) + @RequestMapping(value = "/url", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) public String getSocketUrl(final HttpServletRequest request) { return (server.isUseSSL() ? "https://" : "http://") + request.getServerName() + ":" + server.getPortNumber(); } diff --git a/src/main/java/de/thm/arsnova/controller/v2/StatisticsController.java b/src/main/java/de/thm/arsnova/controller/v2/StatisticsController.java index a5d7ac826..3ec01c8f0 100644 --- a/src/main/java/de/thm/arsnova/controller/v2/StatisticsController.java +++ b/src/main/java/de/thm/arsnova/controller/v2/StatisticsController.java @@ -25,6 +25,7 @@ import de.thm.arsnova.web.DeprecatedApi; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @@ -52,27 +53,27 @@ public class StatisticsController extends AbstractController { nickname = "countActiveUsers") @DeprecatedApi @Deprecated - @RequestMapping(method = RequestMethod.GET, value = "/activeusercount", produces = "text/plain") + @RequestMapping(method = RequestMethod.GET, value = "/activeusercount", produces = MediaType.TEXT_PLAIN_VALUE) public String countActiveUsers() { - return Integer.toString(statisticsService.getStatistics().getActiveUsers()); + return String.valueOf(statisticsService.getStatistics().getActiveUsers()); } @ApiOperation(value = "Retrieves the amount of all currently logged in users", nickname = "countLoggedInUsers") @DeprecatedApi @Deprecated - @RequestMapping(method = RequestMethod.GET, value = "/loggedinusercount", produces = "text/plain") + @RequestMapping(method = RequestMethod.GET, value = "/loggedinusercount", produces = MediaType.TEXT_PLAIN_VALUE) public String countLoggedInUsers() { - return Integer.toString(statisticsService.getStatistics().getLoggedinUsers()); + return String.valueOf(statisticsService.getStatistics().getLoggedinUsers()); } @ApiOperation(value = "Retrieves the total amount of all sessions", nickname = "countSessions") @DeprecatedApi @Deprecated - @RequestMapping(method = RequestMethod.GET, value = "/sessioncount", produces = "text/plain") + @RequestMapping(method = RequestMethod.GET, value = "/sessioncount", produces = MediaType.TEXT_PLAIN_VALUE) public String countSessions() { - return Integer.toString(statisticsService.getStatistics().getOpenSessions() + return String.valueOf(statisticsService.getStatistics().getOpenSessions() + statisticsService.getStatistics().getClosedSessions()); } } -- GitLab