Advertisement
Guest User

Untitled

a guest
May 26th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. @PostMapping(path = {"/submit_analytics"}, consumes = {"multipart/form-data"}, produces = "application/json")
  2. @ResponseBody
  3. public String submitAnalytics(HttpServletRequest request,
  4. @RequestParam() Long startDate,
  5. @RequestParam() Long finishDate,
  6. @RequestParam() Integer nd,
  7. @RequestParam() Integer ns,
  8. @RequestParam() String aid,
  9. @RequestParam() String version,
  10. @RequestParam() String lang,
  11. @RequestParam() MultipartFile file) throws IOException, SQLException {
  12. String remoteAddr = request.getRemoteAddr();
  13. Enumeration<String> hs = request.getHeaders("X-Forwarded-For");
  14. if (hs != null && hs.hasMoreElements()) {
  15. remoteAddr = hs.nextElement();
  16. }
  17. if (!file.isEmpty()) {
  18. Connection conn = DataSourceUtils.getConnection(dataSource);
  19. try {
  20. PreparedStatement p = conn.prepareStatement(
  21. "insert into analytics " +
  22. "(remote_addr, date, aid, nd, ns, version, lang, start_date, finish_date, analytics_data) " +
  23. "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  24. p.setString(1, remoteAddr);
  25. p.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
  26. p.setString(3, aid);
  27. p.setInt(4, nd);
  28. p.setInt(5, ns);
  29. p.setString(6, version);
  30. p.setString(7, lang);
  31. p.setLong(8, startDate);
  32. p.setLong(9, finishDate);
  33. p.setBinaryStream(10, file.getInputStream());
  34. p.executeUpdate();
  35. } finally {
  36. DataSourceUtils.releaseConnection(conn, dataSource);
  37. }
  38. } else {
  39. throw new IllegalArgumentException("File is empty");
  40. }
  41. return "{'status':'OK'}";
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement