diff --git a/spring-security-oauth/src/main/java/org/baeldung/config/MyAuthorizationCodeAccessTokenProvider.java b/spring-security-oauth/src/main/java/org/baeldung/config/MyAuthorizationCodeAccessTokenProvider.java index ca37ab3f82..598f97a556 100644 --- a/spring-security-oauth/src/main/java/org/baeldung/config/MyAuthorizationCodeAccessTokenProvider.java +++ b/spring-security-oauth/src/main/java/org/baeldung/config/MyAuthorizationCodeAccessTokenProvider.java @@ -23,9 +23,6 @@ import org.springframework.util.MultiValueMap; public class MyAuthorizationCodeAccessTokenProvider extends AuthorizationCodeAccessTokenProvider implements Serializable { - /** - * - */ private static final long serialVersionUID = 3822611002661972274L; private StateKeyGenerator stateKeyGenerator = new DefaultStateKeyGenerator(); diff --git a/spring-security-oauth/src/main/java/org/baeldung/web/RedditController.java b/spring-security-oauth/src/main/java/org/baeldung/web/RedditController.java index f6fe2d241c..8fbca7fc75 100644 --- a/spring-security-oauth/src/main/java/org/baeldung/web/RedditController.java +++ b/spring-security-oauth/src/main/java/org/baeldung/web/RedditController.java @@ -24,7 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Controller public class RedditController { - private final Logger LOGGER = LoggerFactory.getLogger(getClass()); + private final Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private OAuth2RestTemplate redditRestTemplate; @@ -33,38 +33,37 @@ public class RedditController { @RequestMapping("/info") public final String getInfo(Model model) { - JsonNode node = redditRestTemplate.getForObject("https://oauth.reddit.com/api/v1/me", JsonNode.class); - String name = node.get("name").asText(); + final JsonNode node = redditRestTemplate.getForObject("https://oauth.reddit.com/api/v1/me", JsonNode.class); + final String name = node.get("name").asText(); model.addAttribute("info", name); return "reddit"; } @RequestMapping("/submit") public final String submit(Model model, @RequestParam Map formParams) { - MultiValueMap param = new LinkedMultiValueMap(); + final MultiValueMap param = new LinkedMultiValueMap(); param.add("api_type", "json"); param.add("kind", "link"); param.add("resubmit", "true"); param.add("sendreplies", "false"); param.add("then", "comments"); - - for (Map.Entry entry : formParams.entrySet()) { + for (final Map.Entry entry : formParams.entrySet()) { param.add(entry.getKey(), entry.getValue()); } - LOGGER.info("User submitting Link with these parameters: " + formParams.entrySet()); + logger.info("User submitting Link with these parameters: " + formParams.entrySet()); JsonNode node = redditRestTemplate.postForObject("https://oauth.reddit.com/api/submit", param, JsonNode.class); - LOGGER.info("Full Reddit Response: " + node.toString()); + logger.info("Full Reddit Response: " + node.toString()); String responseMsg = parseResponse(node); model.addAttribute("msg", responseMsg); return "submissionResponse"; } @RequestMapping("/post") - public final String showSubmissionForm(Model model) { - String needsCaptchaResult = needsCaptcha(); + public final String showSubmissionForm(final Model model) { + final String needsCaptchaResult = needsCaptcha(); if (needsCaptchaResult.equalsIgnoreCase("true")) { - String iden = getNewCaptcha(); + final String iden = getNewCaptcha(); model.addAttribute("iden", iden); } return "submissionForm"; @@ -72,34 +71,33 @@ public class RedditController { // === private - List getSubreddit() throws JsonProcessingException, IOException { - String result = redditRestTemplate.getForObject("https://oauth.reddit.com/subreddits/popular?limit=50", String.class); - JsonNode node = new ObjectMapper().readTree(result); - node = node.get("data").get("children"); - List subreddits = new ArrayList(); + final List getSubreddit() throws JsonProcessingException, IOException { + final String result = redditRestTemplate.getForObject("https://oauth.reddit.com/subreddits/popular?limit=50", String.class); + final JsonNode node = new ObjectMapper().readTree(result).get("data").get("children"); + final List subreddits = new ArrayList(); for (JsonNode child : node) { subreddits.add(child.get("data").get("display_name").asText()); } return subreddits; } - private String needsCaptcha() { + private final String needsCaptcha() { String result = redditRestTemplate.getForObject("https://oauth.reddit.com/api/needs_captcha.json", String.class); return result; } - private String getNewCaptcha() { - Map param = new HashMap(); + private final String getNewCaptcha() { + final Map param = new HashMap(); param.put("api_type", "json"); - String result = redditRestTemplate.postForObject("https://oauth.reddit.com/api/new_captcha", param, String.class, param); - String[] split = result.split("\""); + final String result = redditRestTemplate.postForObject("https://oauth.reddit.com/api/new_captcha", param, String.class, param); + final String[] split = result.split("\""); return split[split.length - 2]; } - private String parseResponse(JsonNode node) { + private final String parseResponse(final JsonNode node) { String result = ""; - JsonNode errorNode = node.get("json").get("errors").get(0); + final JsonNode errorNode = node.get("json").get("errors").get(0); if (errorNode != null) { for (JsonNode child : errorNode) { result = result + child.toString().replaceAll("\"|null", "") + "
";