Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. @RestController
  2. @RequestMapping(value = "/students")
  3. public class AtheniumController {
  4.  
  5. private final AtheniumServiceImpl service;
  6.  
  7. @Autowired
  8. public AtheniumController(AtheniumServiceImpl service) {
  9. this.service = service;
  10. }
  11.  
  12. @RequestMapping("/student/{studentSurname}/{studentName}/{studentPatronymic}/{studentNumber}")
  13. @ResponseBody
  14. public String checkLogin(@PathVariable(value = "studentSurname") String studentSurname,
  15. @PathVariable(value = "studentName") String studentName,
  16. @PathVariable(value = "studentPatronymic") String studentPatronymic,
  17. @PathVariable(value = "studentNumber") String studentNumber) {
  18.  
  19. Student lvStudent = new Student(studentSurname, studentName, studentPatronymic, Long.valueOf(studentNumber));
  20. if (service.checkLogin(lvStudent)) {
  21. return "OK";
  22. } else {
  23. return "Проверьте введенные данные! (Также возможна проблема в серверах ДГУ)";
  24. }
  25. }
  26.  
  27. @RequestMapping(value = "marks", method = RequestMethod.GET)
  28. @ResponseBody
  29. public List<Mark> getMarks() {
  30. return service.getMarks();
  31. }
  32.  
  33. @RequestMapping(value = "marks/{id}", method = RequestMethod.DELETE)
  34. @ResponseBody
  35. public void delete(@PathVariable long id) {
  36. service.remove(id);
  37. }
  38. }
  39.  
  40. public class RequestRegister extends AsyncTask<Student, Void, String> {
  41. BufferedOutputStream bos;
  42.  
  43. @Override
  44. protected String doInBackground(Student... pStudents) {
  45.  
  46. try {
  47. URL url = null;
  48. try {
  49. url = new URL(Constants.POST_STUDENT);
  50. } catch (MalformedURLException pE) {
  51. pE.printStackTrace();
  52. }
  53. HttpURLConnection urlConnection = null;
  54. try {
  55. assert url != null;
  56. urlConnection = (HttpURLConnection) url.openConnection();
  57. } catch (IOException pE) {
  58. pE.printStackTrace();
  59. }
  60. assert urlConnection != null;
  61. urlConnection.setRequestProperty("Content-Type", "application/json");
  62. urlConnection.setRequestMethod("POST");
  63. urlConnection.setDoInput(true);
  64. urlConnection.setDoOutput(true);
  65. urlConnection.connect();
  66.  
  67. JSONObject jo = new JSONObject();
  68.  
  69. jo.put("studentSurname", pStudents[0].getStudentSurname());
  70. jo.put("studentName", pStudents[0].getStudentName());
  71. jo.put("studentPatronymic", pStudents[0].getStudentPatronymic());
  72. jo.put("studentNumber", pStudents[0].getStudentNumber());
  73.  
  74. bos = new BufferedOutputStream(urlConnection.getOutputStream());
  75. bos.write(jo.toString().getBytes());
  76.  
  77. String result = urlConnection.getResponseMessage();
  78.  
  79. } catch (JSONException | IOException e) {
  80. e.printStackTrace();
  81. } finally {
  82. try {
  83. bos.flush(); //очищает поток output-a
  84. bos.close();
  85. } catch (IOException e) {
  86. e.printStackTrace();
  87. }
  88. //urlConnection.disconnect();
  89. }
  90. //return null;
  91.  
  92. return null;
  93. }
  94.  
  95. @RequestMapping(value = "/student", method = RequestMethod.POST)
  96. @ResponseBody
  97. public String checkLogin(@RequestParam(value = "studentSurname") String studentSurname,
  98. @RequestParam(value = "studentName") String studentName,
  99. @RequestParam(value = "studentPatronymic") String studentPatronymic,
  100. @RequestParam(value = "studentNumber") String studentNumber) {
  101.  
  102. Student lvStudent = new Student(studentSurname, studentName, studentPatronymic, Long.valueOf(studentNumber));
  103. if (service.checkLogin(lvStudent)) {
  104. return "OK";
  105. } else {
  106. return "Проверьте введенные данные! (Также возможна проблема в серверах ДГУ)";
  107. }
  108. }
  109.  
  110. @RequestMapping(value = "/student", method = RequestMethod.POST)
  111. @ResponseBody
  112. public ResponseEntity<?> checkLogin(Student student) {
  113. if (service.checkLogin(student)) {
  114. return ResponseEntity.ok();
  115. } else {
  116. return ResponseEntity.badRequest().body("Проверьте введенные данные! (Также возможна проблема в серверах ДГУ)");
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement