Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @PostMapping(path = {"/submit_analytics"}, consumes = {"multipart/form-data"}, produces = "application/json")
- @ResponseBody
- public String submitAnalytics(HttpServletRequest request,
- @RequestParam() Long startDate,
- @RequestParam() Long finishDate,
- @RequestParam() Integer nd,
- @RequestParam() Integer ns,
- @RequestParam() String aid,
- @RequestParam() String version,
- @RequestParam() String lang,
- @RequestParam() MultipartFile file) throws IOException, SQLException {
- String remoteAddr = request.getRemoteAddr();
- Enumeration<String> hs = request.getHeaders("X-Forwarded-For");
- if (hs != null && hs.hasMoreElements()) {
- remoteAddr = hs.nextElement();
- }
- if (!file.isEmpty()) {
- Connection conn = DataSourceUtils.getConnection(dataSource);
- try {
- PreparedStatement p = conn.prepareStatement(
- "insert into analytics " +
- "(remote_addr, date, aid, nd, ns, version, lang, start_date, finish_date, analytics_data) " +
- "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
- p.setString(1, remoteAddr);
- p.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
- p.setString(3, aid);
- p.setInt(4, nd);
- p.setInt(5, ns);
- p.setString(6, version);
- p.setString(7, lang);
- p.setLong(8, startDate);
- p.setLong(9, finishDate);
- p.setBinaryStream(10, file.getInputStream());
- p.executeUpdate();
- } finally {
- DataSourceUtils.releaseConnection(conn, dataSource);
- }
- } else {
- throw new IllegalArgumentException("File is empty");
- }
- return "{'status':'OK'}";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement